#88 Digital Potentiometer aka Volume Control - Easy (X9C103)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and welcome back now today we're going to talk about a very very small component I've discovered but very useful it could be too and it's made to give that little thing that's thin at the back there what is it well as the title of the video shows this is in fact a digital potentiometer or volume control and let me just shield the back so we get into focus now as you can see there on the right-hand side where my thumb and finger are there's the typical picture of a potentiometer or variable resistor we have a wire in the middle and then a higher end and a low end and on the other side we have all the the other gubbins that controls this lovely chip ground and VCC top and bottom and in the middle we've got three lines CS chip select ink sensor increment and UD which as you might expect stands for up and down so let's have a closer look at this and well plug it into longs I've got it already waiting to go and we'll just see how easy it is or not to use it so here we are all connected up let's say although it looks like a lot of wires here and as I just showed you it's not really as three wires that control it and then of course you've got the three for the potential potentiometer the digital potentiometer anyway so you'd have those anyway and then of course you've got the power top and bottom so it's not really that complex I'm back here we have got a couple of switches just for demo purposes this one here is just a simple press button which will activate the well the potentiometer really or you'll turn it effectively and this one here or look a little slide switch have we seen for those before someone will either turn the potentiometer down or decrement the value where if I flip this little switch over to the right then it will start incrementing the value and I press the switch here so this is how it's connected up we've got the X Y and C one or whatever in the three lines and the variable resistor on the left we can connect this up to a new low or nano or something like that pretty easy to do let's draw those three lines straight in and I've chosen a nine and ten and the plus goes to seven which will explain a little one now on the other side we have the switches so it's got the up-down switch as that one and the next switch well it's sort of a built-in little module switch in there so it's got a built-in resistor that brings the value of that pin low when you press it like that that's it but that is a say it's not wired up I didn't put the resistor in it's on that module board or by itself just or dotted line around that show though that's all built in they're connected Ned's pins a 2 and a 1 which you are in fact using as digital pins and the wiper of the volume control is going into a 5 now that is an analog pin right such as BMI and a 1 and a 2 are being used as digital pins and that a 5 is being used as an analog and that's perfectly legal and mulleted it there's nothing funny about that at all now first things first there is an LED on board here that tells us when the power is on but even if I take the wires away can you see on no you can't and there's a very good reason for that which we'll be covering in this video well if you want the device to work properly anyway so let's have a look at the the code window now as this fires up and we'll see exactly how it works is pretty simple to be corners ok here's the code then now oK we've defined a few pins up here up down there basically two at the back here plus the ones that we need for the X 9 c 103 why is it called C 103 well these variable resistors or potentiometers are available in a variety of values and 103 is the typical nomenclature that you might find on capacitors or resistors that indicates how many zeros after the first two digits two one zero and then three three zeros so 10,000 10k you can also get a C 102 should be a 1k c104 this is 100 K and see 105 as well I believe which is a lot more right so it's a C 103 I've defined the pins here and specifically I've defined that one there which is a power pin because we're actually going to power this device from the Arduino long explained why little bit later so we just start it all up do a bit of initialization fire it up and the very first thing this does is to stay go and get me the value that's been previously stored in here null right yes if you just bought brand new version perhaps that won't be anything stored but I think I got 0 L when I first got it so no harm done because one of the features of these this devices that will store the value whenever you tell it to store it now let's think carefully about that let's assume that this was in fact a potentiometer for Wi-Fi say okay and you're controlling it with an infrared remote control of which I've done a video about before the beauty of that of course is that doesn't matter what remote control you use as long as you can detects and and decode what values been sent to you well then you can go up or down on this no trouble at all it's on old TV remote with work just as well however if you're going up and down let's say a typical hi-fi unit you might adjust the volume I'd know 30 times in the session too many all right then 20 times and let's assume that you listen to your music all day every day so seven days a week that's 140 changes in volume over a week now I think that's a gross underestimate actually because even when I'm listening to music here and my workstation I probably change the volume I know 50 times an evening you know because some things are going to allow something's being too soft somebody calls up you can't hear them see dragons turn it down but let's just say then it really was 20 times a day seven days a week 140 times in total you think I thought 140 now 140 times a whole year times 52 seven thousand two hundred and eighty times in a year now I think once again is low let's round it up okay this a is ten thousand times the right lifetime of the non-volatile memory on this chip is one hundred thousand times now given that calculation ten thousand times a year in 10 years is will go kaput I don't think it is going to be ten years I think every a lot sooner than that we did it on every single Depression so what I do for this demo purpose anyway is to say go and read the value in the code and whilst you have your finger pressed on here to turn it up or down because you tend to do that let me whether it's watching TV or listening to music you get your remote and you press it and you hold it until it's right volume then let go so this will keep changing it whilst we've got our finger pressed and then at the end of it it will say if we change the volume go and store the volume so that means now of course that would reduce the number of times we're going to write to that non-volatile memory by a considerable amount of course during my demo and preparation for the demo I probably already used up half the life time that's twice I can tell you but anyway just bear that in mind there is a hundred thousand lifetime expectancy on that non-volatile Ram okay so in the main loop then apart from checking whether or not we've pressed anything and whether we should store the value we're going to print it out over here so as you can see here some old stuff that's there's previously there so let's clear that and reset so we start at the beginning of this into the setup area our is to connect and it says send any value to continue now why am i doing that as you can see the code here the very first thing it does is in setup is to say stop wait until you press two key because I wanted you to see what happens as we go through here and what I've done it in a certain way so let's just send a value and if anything doesn't matter what it is any character just to get the thing moving and it says well I've restored the volume to 28 I must sit so if you were playing music hype i or had a lighting console or something you know neopixels or what have you then go back to volume 28 which hopefully was the value you lost and in fact well let's let's change it then vy press this button now we've got this little tiny button here this slide switch make sure you can just about see there to the left so it's going to go down if i switched it the other way it go up okay so we're going to press this button now we'd see that 28 going down so while I keep my finger press it keeps doing it and then it says right you took your finger off when it was 6 and I've stored that value into non-volatile Ram or has it not there's only one way to find out really isn't there if I disconnect all this and reconnect it back up again it should go and retrieve number 6 now the problem is as minute I disconnect my USB cable here this monitoring serial monitor window will lose its connection it won't come back again which is why I have this bit here to say stop don't do anything quit then we can press the reset and it will reconnect let's do that now so remember when it comes back we're hoping it's come back to volume 6 so off it goes powers down that's probably long enough you'll have to let my word for that I've done this a few times now and just a few seconds is enough right power back up now I've got to shut this down and re-enable it and it says connected and right there we are send any key so let's just send a key again anything will do and it says restoring volume to 5 not 6 I must have just got the 5th one there before it did it now let's switch this the other waste now we're going to go up right well I hold my finger they'll go up up it goes goes up 200 there are hundred steps in total which is quite good I'm a type of finger off then is 76 should we try that again that disconnecting bit doesn't play very long does it I'm disconnected and I'll plug it back in again I've got to reconnect here as I kill that serial monitor and reconnect it okay and send any key and I veld 76 so what we can say is yes it really is right stuff to the non-volatile Ram the EEPROM or whatever is going side it and it restores that on power up and there's the rub on power up as I said before I'm pairing this unit from the Arduino and that is why because if we power this unit just from the standard 5 volts yes it does go and retrieve the stored value but then by setting the chip select value here and the increment pin value here as well it seems to really really screw that up and nothing I would do would get it back doesn't matter if I had CS low high didn't define it the increment low I didn't define it would make no difference at all what did work though is that if I disconnected the power down here just on this device so disconnect so this device is now powered off as soon as I reconnect the power it will go and read that value again won't tell us it's done it just it just sort of does it so let me reconnect that so it's powered by caps canopic code window it doesn't nothing has changed but if I press this I would hope that it's gone back to the 76 so let's have a go and there we are up to 77 78 and so forth so that was the clue really but when we powered this up yes it did restore the value but if we powered it up and ended all this stuff in the set setting the chip select pin value in the increment pin value it just then didn't work after that there's something going on here to say I'd like cleared the EEPROM out will wrote a different value back or something whatever it took me a day thinking about it I thought what I'll just power this up the Arduino because by then we can have the chip select value to what we want we can set it high or low and we can set the ink pin high alone exactly as it want and then then we can pair it up and it should get the stored value which indeed it does right how much is does this device cost well if I said ten dollars would that be any good to anybody ten dollars well roughly ten pound any good now of course it wasn't inside look at the browser window see how much it really was right there is one pound fifty two which is course imposing more I bought it really I wasn't going to buy it as expensive one pound fifty two off away now I have actually got a real requirement for this device in as much that some at this very desk I'm sitting at I do have my music running when I'm solve investigating and did a bit of research and whatnot but under this desk under this one here there is in fact a manual rotary bullying control which is not a brilliant place to have it on over there we are and I thought well I could replace that with one of these and then have a little remote control of my desk you know wonderful well not quite like this but something like that probably the like the one I showed you before where you had the numbers on it which we did a whole video on it remember infrared communication there it is on screen now use one of those to change the volume or indeed any old broken TV remotes or there's no longer used long as you can detect the value in the infrared value you can do anything you like on it so I thought yeah I've got a real use for this and of course I can tell you guys all about it and how well it works so there we are one pound 52 now there is a yes that comes with well it comes with it is available for it shows your stuff like this here we are so here we have all the different values so as I said 102 is for the 1k 103 is the 10k that's 100 K and the 503 is a lot more right so the couple of things you have to be aware of here though is that the amount of current you can take through the wiper of this device is quite low and indeed well enter any potentiometer you should be taking an awful lot and it says on here they take about 4 millions now the absolute maximum value it says here's 8 point 8 is if you do that for too long the thing I probably burn out so if you look at here somewhere in here I tell you it says here our wiper current wiper current or point four millions that's a good values use well we're not using anything like that here in this we're probably using a few micrograms let's think one certainly not a lot because we're just reading it into an analog port additionally you've got to remember that the the terminal voltages of that digital side of the potentiometer can only be +5 volts and minus 5 volts top and bottom so 10 volts total which is unusual isn't it have them arranged greater than the VCC it mustn't be more than 5 volts it must be less than minus 5 on here of course a lot +5 and 0s that's absolutely fine and ok there is a slight warning in the blur but it also mentions a healer the charge pump noise at eight hundred and fifty kilohertz oh not in audio range could be as high was typically 20 Mille volts RMS now that's not going to be in your audio spectrum so if you were to use this to control music as I intend to I don't expect any problems whatsoever with that right what else can I tell you about this in the datasheet well there is a nice little section all about the pins we are so this tells you what each of the pins does remember that a bar over the top like this one here which says Inc or the bar that means it's active low or when it's going low let's put it that way and that's so well that triggers some the movement of the wiper up and down determines the direction if you leaves the up/down pin is high it will go up and if you bring it down to ground it will go down quite easy is it now chip selects is only active low and I'll see I've seen a couple of circuits where they actually wire the chip select to ground permanently we don't want to do that because that means you could never store the current wiper value into non-volatile Ram because Cs has to go high for that so in this circuit anyway we we keep it as an Arduino pin we keep it low most the time but then flip it high when we want to store that value as I just showed you in the sketch and then you've got plus and minus that's it simple isn't it really it has got a nice little set of diagrams that to illustrate this here are here's the timing diagrams now forget all these bits which shows about the arrows and all that that tells you how long a certain pin has got to be high before something else is allowed to happen but from our point of view that's as almost instantaneous and if you're not sure you can just put a delay of one millisecond in now as it shows you here look see s that's that's active only when it's low okay so when it's low its active and when you bring it high this module stops responding it just goes into low-power standby mode but at the same time as long as the ink lion is high as well this point here then it will store that value into non-volatile Ram if ink is low at that point it it doesn't store it but still goes into standby mode so you've got good control to do that if you want up down is as you might expect it is up it will increment it if you bring in the up down line low then it decrements the value right a lot more information about what this does here I'll leave you to read that it will be underneath this video in the video description it's not as daunting as you might think actually because this is a fairly simple chip okay with three pins to control it and unlike SPI there's no clock so therefore the sequence of events is not very important as long as you bring the cs line down low when you next to do an operation it just doesn't matter you can do it a millisecond later or 10 seconds later it just does not matter dis over the ink and up down the lot the timing is not critical except where they're showing it on here which basically says on the datasheet there must be a minimum something like 1 microseconds I'm not that before you can continue and my sketch I believe does include a couple of very small delays as well as a much bigger one as part of the demo to stop it running away with us right the next step really there is to is to plug this unit into something else really just to show you rather than the serial monitor where it could be used for example ok so let me just plug a couple of little extra bits on here and you'll see a real live demo of what it could potentially be useful I'm not going to use it for this because I'm going to use it for actual music volume now when I say music volume don't start sticking this on a speaker output it's not designed for that this is to provide the actual volume control in your amplifiers we're talking you know millivolts or volts or something but not not the output of the speaker that's not what is designed for at all ok just so you know that ok let me get some flashy flashy lights connected up to this and we'll see how that looks so just to round off this the project really I've got here as a sort of practical implementation practical alright what we're doing is like out this in the a pixel display and we've said it many times what you're seeing here is absolute rubbish on camera these are beautiful green to begin with them blue then red which you can sort of see reflecting off my hand they even better anyway that's not the point the point is that this sketch is an original sketch that we saw many many videos ago using a rotary potentiometer to determine how many of these will lit up now of course we're using the the X 9 and well the rest of the code is pretty much the same I've munched into bits of code together so if we now press this button again and let go there we are two more of this up and if we turn the switch back again so we're now decrementing the value will hold that on and then it goes now it's a little bit slow because of that mapping I'm sure there's something we can do about that the demo purposes I think it is good enough and if we just have a look at the code window while that's running you'll see so if you look at some this bit of the window here you'll still see the values going up and down so press a female or we've lost the word pinch hang on is right so what I'll press the value this down here once it's gone five for 302 in fact so now we've only got a CLE got two lasalle there you can see reflecting quite nicely so there we are I mean obviously I mean it was bound to work wasn't it because it's resistor value at the end of the day to be quite honest it would have probably worked better in real life with music I've tried using music on video before and because the Video camcorder marks and all that try to keep the value of the sound the same it is pretty difficult to hear an increase in decreasing volume basically so I thought well neopixels at least you can see them going up and down and just don't switch that over again pressing it up before and see I mean as soon as I let go bang there is I mean it's you know it's a good demo at least something's happening isn't it so there we are that's a really easy implementation obviously I'll put this code up there as well all boats there's nothing special about this code as such well I know Benny wrote it so it's pretty special but as I say it's the original code we just saw plus the bit to the neopixel oh by the way did I mention that regarding this error here actually posted a query on to the the fast LED Google site see if anybody can find out why it's giving me that issue we'll stay okay that's it then everything else I've just put into sort of methods subroutines functions call them what you like below the main one so our loop is quite nice and light isn't it anyone I say the volume has changed the resistance has changed do we light up the LEDs right I think that sort of brings it pretty much to a close for the price that we mentioned one pound fifty two I think that's so good thing to have right that's it then I think M yeah we call a halt there thanks very much indeed for watching if you've got any ideas of where else this sort of advice can be used please do post them underneath this video where you'll find lots of sketchy is links that PDF of course and anything else that I can find in the meantime okay all right thanks very much for watching and see you in the next video I hope you'll finding these videos useful and interesting there are plenty more videos to choose and a couple of shown below and if you'd like to subscribe to this channel just click on my picture below and enjoy the rest of the videos thanks for watching
Info
Channel: Ralph S Bacon
Views: 37,292
Rating: 4.8679609 out of 5
Keywords: Arduino, electronics, C++, microcontrollers, programming, gadgets, digital potentiometer, variable resistor, volume control, digital, X9C103, X9C102, X9C104, X9C105
Id: OkVPjrETyno
Channel Id: undefined
Length: 25min 34sec (1534 seconds)
Published: Thu Jun 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.