#112 Analog inputs for your Raspberry Pi 🥧Model 3B+ (easy)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and welcome back now this week we're going to be talking about the analog inputs to Rhodri Pyatt which of course as we know amount to a total of zero so when I was playing about with my PI here being an Arduino I thought one now I can just measure some voltage and turn up one of those little neopixel things and then of course immediately discovered oh yes of course we haven't got any analog pins on here have we no surprise really I mean I did sort of know that as we all do if you have a PI so I thought right let's see what we can do about that so I did a search on the internet for some analog to digital converter chips and of course immediately stumbled across the microchip 1 and then I'm not the first person to think of this I discovered a little kit that uses that microchip format so I thought well rather than reinvent the wheel let's just bothered by the kit itself more money than not normally want to spend but just to get the thing off the ground I thought fine so that's what we're in and up down here this Rossby oh and log zero you can just about make out the name of the website there it looks all very neat and the documentation that comes with it is second to none I've got to say is absolutely superb so what's what's to be done then about the analogue inputs well basically you would have to use some kind of bus so I squared C SPI well one of those two haven't got much choice and that's exactly what this little board does now this is the board for it I'm getting wrong way up so what happens in the raspberry pi world is that whereas we in the arduino it will have shields they have hats which stands for hardware attached on top yes really so this series of pins basically it fits over this ones these pins here that's on the Raspberry Pi via one of these sockets so then these sockets goes underneath so that that goes through there like that we just make out see they fit on there like that that then plugs on there and then that will attach on top hence the Hat hardware attached on top really doesn't mean that now what that means of course is that you've then blocked off all these pins here so whereas in the Arduino we'll really expect pins to be sticking up here so what he's done here and what many people do in fact is expose all those GPIO pins again as a second row next to it they might think hang a minute there's there's more pins here this double row of 20 than there is in that single row there yes well spotted but what they've done in these double roses have multiple ground pins and they got a couple of 5 volt pins at the top here and the first two there so you take all those out these in fact do make up the rest so the idea is then you put a header which it's in the box behind me this is heck no it wasn't at the bottoms behind me I can't find it in fact but it's something like this some of this is a nice red one the one that was applied but the kit was in fact black well I like colored stuff so basically this this header then just plugs into those holes aids you know you have to snap it off for the right size as a nod we night you'd probably know this as a matter of fact but anybody watching this who's just got a Raspberry Pi may not be quite so familiar with it so that's that's what happens right so the double set pins here single exposes them all again and then in the middle you've got room for a chip another set of headers here for the analog port so you got seven on here which brings it up to nano standard and what else why just that couple of components just to bring things in line he's also brought out some where's my little pointy thing rod my fingers right so he's also brought out the five volts here and three point three and ground and then some little bits in the middle there just add a few components you will see in the documentation that I just showed you where he solders some stuff on here in fact he solders them on the underneath to keep it out of the way so it looks nice and neat on top as a prototype I'd say that it's fine it's all a bit messy I think otherwise so as a prototype it's good and you can measure the analogs you put in an eight-way header in here socket yeah and it works well I assume it works as you can see I've actually built it yet but I mean I've read about it enough and I'm sure it does work so we will build it up and make sure it works according to what we want now the chip that he's chosen here is in fact the mCP three zero zero eight which gives you what as it shows you here eight analog pins but rather surprisingly he's chosen the 10 bit chip now that 10 bit means you get values from 0 to 100 2 3 exactly the same as it is for the Arduino so from that point of view you go well what's the problem that is what we expect is it not so that works yes that's fine but I've also done a video or two perhaps on the Arduino where you can increase that sensitivity and there is a drop-in replacement chip which he doesn't that mentioned give him credit that gives you 12 bit resolution so it's not too 409 6 which I just happen to have here somewhere so this this is the new one I believe trying to get that in focus is a little bit tough well that's it no that's the original one so the other one must be in here anyway so that's the drop-in replacement that we'll be trying out ok so let's build this up and just make sure the analog bits all work exactly as we would expect that's right a little sketch no don't call them sketches do we what do we call them I don't know Python programs maybe well well whatever it is we'll write one very simple one just make sure all works here we have the built unit I mean quite frankly it was very simple to put together tedious I think is the word I'd use because you've got all these little things to solder up on the underneath and then this 41 here and now I've got a very small soldering iron bit but even then it was quite tight to get inside him but let me show you my soldering iron I'm gonna have to switch between video workstation and soldering workstation over here it's a bear with me so this is my soldier I'm still switched on that's the bit I've got well that's not the finest but you can get by any means and certainly wouldn't be any good for surface mount devices SMD components for this was okay although the cone shape to mean it's or could touch two pins at the same time if you're not careful so i've got several other bits i might swap that out next time i do a little tiny thing like this with lots of pins anyway apart from being it's not somewhat tedious to put all these soldering joints in it was pretty straightforward now the other things i do have here to remind me to tell you about is this we've mentioned it before it's an IC pin leg straightener it's got that size that's either still and that's the wide bodied Dyl so what you do you drop here IC into here squeeze it and your pin legs are perfectly straight but putting into the socket otherwise they're slightly splayed out now I have one here to do if we look at this chip end on if you like you can see that the legs there are very slightly splayed out goodness knows why they do that I don't know it purpose is to stop them falling out when you flip it underneath but whatever is it's rubbish you couldn't put that as it stands into that socket okay just it just doesn't fit so all you do is drop it into this thing here like that and then you give it a squeeze and then you take it back out again and now if you look at it dead-on end on rather you'll see the legs are now totally square and that will fit into that socket no trouble at all as I said we were trying that chip out a little bit later in the meantime then this is the original tip the 10 bit all I've done here is put a DuPont cable into channel 1 and a lot of channel 1 because obviously there are eight channels here at the moment from a zero to a seven so the other end is just sort of floating about at the moment so let's flip over to the code window and look at the bear code and now this is Python code fairly straightforward amenity of a dozen lines there isn't there the way you invoke Python if you've never done it before not on a PI it simply to go to this raspberry thing at the top click that programming Python 3 they've left python 2 in here as well because that was the old standard 2.7 but things have moved on since then so PI 3 is click that and you'll get either this or the runtime screen depending on what preferences you've chosen as part of the options so in the options where you say configure idle you can say under general at startup what you want in any window open shell window and just play about and see which one you like the best anyway this this is a file that I've loaded to run it all I've got to do is press 5 if it's not saved so if I here cut the space lines and then back again so now this is not saved when you hit f5 it should prompt you to do that source must be saved ok to save yes it is as soon as I press ok it will open up a a Python shell window there it goes and splats over everything else of course and there it is reading the details in so let me just resize that move it out the way a little bit so what that's reading in now is the channel 0 the very first pin on that and log pin so it's reading in the value here on device 0 that means SPI device 0 because there's a 2 available on the Python 2 dedicated hardware pins recipe.i printing out the value x 102 3 because that's what we're used to is arduino so if you if you're not interested in 102 2 r if you want the actual voltage then just multiply that by 3 point 3 because that's the maximum we can read here and then not just this is the equivalent of a delay you know we know terms that's a delay of half a second so you have to say import time at the top I want to get this this in NCP 3000 you have to do that import as well these are all ponies and things and I guess the best way to do it is is just do it for a bit learn it get a book Raspberry Pi for dummies for example okay anyway so it's reading those values and as you can see it's all over the shop at the moment if I if I touch this you'll probably see it jump up out of it in fact it still seems to be jumping out fairly much everywhere now if I hold it on them there's no jumper that's 3.3 volts whoops trying to do this across pinches OH the duplicate let's snap Toffler the little a little bit on top what poor quality is that don't get me started about the quality stuff from China believe me now lucky I've got a few thousand in the cupboard behind me back soon okay right another cable still arranged though continuity yeah there's something so if I hold it onto this little jumper which says what's the voltage reference you'll see if it goes to one or two three because that is the 3.3 volt reference voltage and remember this can only measure up to three point three because the Python the PI the Rosary PI is a 3.3 volt device make it will come on to how to measure higher voltage in a sec now hold it onto the zero on that board if you remember us so there's some there's a zero thing let's just go back to the main workbench so on this board here you've got 3.3 volts a bit of secretary of just for putting in your own stuff five volts and ground okay so if I hold it on to the zero one hmm I was hoping that was going to go to absolute zero not quite as zeros we my fault then and it's and it stops how nice now the way I'm connecting to the Raspberry Pi is via something called VNC well and SSH so what's happening is that my Windows PC has fired up VNC viewer which is a free program I've used it for a long time and not for this but generally and it's connected at the PI on the PI you do have to say allow the VNC viewer to connect to me which is why we have this this thing up here it says VNC so what happens though sometimes it's all freezes I'm not quite sure why so it's not quite down to zero but then again sometimes the Arduino didn't go down to zero either now that's a 3.3 volts and should stay at 183 but as you can see if casion it says 102 two point zero zero for now of course this device is not that actress when we see these stupidly long figures like this it's just nonsense we're not actually measuring that voltage is always just some random fluctuation so what we could do with really is just formatting this help a little bit to hold figures the nearest whole figure really now that we can do pretty easily so we need to format this so we say single quote squiggly bracket how many should we have well not really we don't want any decimal places so it's colon dot naught F really and single dot format where am i I've got four different screens at the moment and now spelling it wrong format don't break it and now of course we need a break at the end and if you saw those little helper came up when I typed in form it does it come up on the screen yes it does though you can see that so python is very nice like this and will give you these little hints about what you should be typing in the same happened when I did this mCP 3008 I'll just do that again so you can see it so fine Oh yup so it says we've got a channel differential equals false you can have differential inputs here let's not go there maximum voltage three point three fun now you don't have to measure up to three point three say you've got something that measured I know one volt just as an example what you'd have to do on this board here where that little jumper is connected to the V ref reference voltage to three point three take that off and connect the V ref to a one volt reference and then the 102 three values that we're seeing jumping around here is in fact between zero and one but not zero and three points for his it isn't home so you can measure any voltage up to three point three but no more okay so there we are we've chain made this little change now if I press f5 again it should prompt me to say do you wanna save it yes we do it should restart here we are restarting the actual Python and there we are now we have whole figures we can go bet in that we can make it more sensitive and I'm going to connect up the other chip and a potentiometer on here and we can see then how it changes things a little bit alright four oh nine six steps rather than one oh two three could be interesting right so connects is up a potentiometer I'm just rebooting the pie at the moment which you can probably see and just trying to connect to the pie but there's nothing to connect to at the moment so we just let that run so this chip we we're saying that this is this is an MCP three zero zero eight it has 102 three steps of resolution because it's a 10 bit chip let me just show you that while that's some booting up it's coming up soon be there if you look in the browser this is the chip we're looking at this one here channel 0 to channel seven is on the right-hand side that's the one we got and while the other ones are just very simple to connect up power a couple of decoupling capacitors and the SPI pins I'll put this data sheet which some people find a little bit dry and be corner said why but every now and again you just hit a little nugget of information in there and if you want to know anything about the chips this is where you got to go this is the manufacturers data sheet and well it will tell you everything you ever wanted to know and a whole lot more that you didn't about those chips right the the one we're gonna try in a minute though is this one here so it's pretty much the same the numbers changed now it's got this two in it and we're gonna do the three two oh eight exactly the same problem this one says twelve bit if you notice the other one said ten bit okay that's the only difference that run from anything from 2 point 7 volts to 5 point 5 volts so these chips are good for anywhere that you need analog inputs so no pics toys Arduino is although we do tend to have a lot of analog pins on there already but if you need more this is the way to do right now the poised booted up so let's go back to the code window so now let's just run that five and off we go what's what that is now doing is is reading this value on here so if I turn it down to absolutely nothing so we get we actually get 0 this time not something close to zero and as I wind it up it gets bigger and bigger now of course they're quite big jumps here because we're sleeping for half a second between values so as I'm turning of course lots of things are happening and then well that's a full full volume as it were 102 3 Khojaly 102 - something's bear in mind that slight fluctuation the end there if you're actually reading an analog value really it's best to take everything you have a lot 102 0 as being full value laws you might never reach 102 3 for dimming bulbs or something like that you know if you want a maximum brightness okay so that's that's all working fine right so what we're gonna do now is take that chip out and put in that one there which is the 12 bit and perhaps will speed up the the delay here a little bit maybe every naught point one so we can see how many steps can be meaningfully read okay let's swap it out back soon the new chips been put in the 12-bit one we just got to change the code now because that's some 409 six steps we've got now 409 six and oh yeah I've changed the time down here to not point to five just give it a little bit more urgency in its output I said don't do anything else Oh f5 yes we do want to save and off it goes right look now if I turn these let's turn over down to zero or not perhaps okay low so it's going to go to is to for reasons best known to the chip hmm okay and okay goes all the way around - all right on six well if you can see there's a four oh nine - appearing every now and again so the extreme seems to be a little bit off don't they but apart from that yeah it seems to be okay cool okay so this is a better resolution now than what you might find on an Arduino everyday or nano whether you need that level of resolution so it's probably about what a millivolt something like that because when you're using 3.3 as well if we were to divide 3.3 by 409 six it actually comes out 2.8 so that's just under the millivolt per step just under the millivolt 0.0 0.8 of a million fact get it right point eight of the millivolt now if we were to just prove the point that I'm just doing this on the calculator we have five volts divided by 102 three that comes out as point naught naught for eight yes that's it's about five just under 5 millivolts four point eight million actually 5 millivolts per step for the Arduino so that's 5 - just under 1 there's quite a difference isn't it if you're say you were measuring for example on know what what gives out a very low voltage a microphone or a stylus or something on I don't know why you'd be doing that with either an Arduino or a PI but you could do it now with them a 12 bit ADC chip but you couldn't do that one they attend bit because the difference in voltage he went from zero to two millivolts the Arduino would say it's still the same value of zero whereas the pie now with its 12 bit chip on it would say oh yes there's there's two different distinct values there are three impact from zero to 1 to 2 and so on so there may be some some usefulness in having a chip that's a bit more sensitive let me show you where I got the stuff from this analog 0 kit just so that you can see all right here it is so the Ross Pio analog 0 that's exactly the one we've got tempeh on that's why I paid yes that is correct 10 pound little bit more than what I wanted to pay to become honest but the chip itself I think is thought about a couple of quid says for one it's 2 pound 56 and you see there now you couldn't buy just one for 2 pound 36 because the postage and all sorts of other stuff but say you bought hundred so you buy a hundred for 194 that's one pound mighty for each guys call it 2 quid then given that this chaps making kits and what so it's 2 quid so it's a quid left now for the board itself which is quite a nice little Borden it's you know all double-sided do you know whichever way up you want it's got a headers and also in there I'm told yeah actually he's included he's included this it's the nail dr so that you can use is to play about with him detect different light levels that comes in with a kit plus a resistor or two just so that you can connect with something meaningful so as a kit itself it's probably not not too bad value for money to be quite honest and I'm quite impressed with it the quality is very good and as I say the documentation that comes with this I'll show you the paper version let's see if we can find a PDF so here's the user guide the very thing I was waving in front of you yeah gives a couple of ideas what you can do but more to the point it does go into quite some detail about what you can do what you mustn't do certainly for a beginner which I'll guess where this videos aimed that this is this is a good value for money kit actually and I'm guessing he must be uk-based but hopefully he sells through other avenues because those all you people in the states in Canada Australia might find it difficult to get this one so okay that's great that's that's not bad at all in fact so we're gonna leave it there I hope you found this interesting I know this wasn't odd we know related exactly was definitely PI related with the actual board whoops but behind me there but the chip itself you can use for any microcontroller long as it uses SPI you're okay right great I hope you found it useful if you did give me a thumbs up and put some comments down below and I'll see you next video I hope you're 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: 44,788
Rating: undefined out of 5
Keywords: Raspberry Pi 3, Raspberry Pi, Analog, Analogue, python, Beginners, tutorial, SPI, how to, example, electronics, programming, gadgets, Arduino, analog signal, python (programming language), analog input
Id: x_86hTwqEMk
Channel Id: undefined
Length: 25min 26sec (1526 seconds)
Published: Fri Jun 01 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.