A-to-D converter with the Raspberry Pi Zero W - ADS1015 (#133)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today i'm going to look at this this is um an analog to digital converter the texas instruments ads1015 you'll see that this particular board it says uh ads1115 stroke 101.5 so the this same board is obviously designed to support two different chips so this this chip actually is the 101.5 which is a 12 bit 80d converter and it's bigger brother the 1115 is 16 bit so has 16 times more resolution i'll talk a little bit more about resolution uh in a minute but for now i just want to introduce the purpose of this so i'm going to need to um to solder on a header so that we can experiment with this um you'll see on on the back there you've got some silk screw silk screen that shows the the various pins so we've got sscl sda which are for the i squared c bus so we're going to use i squared c today and there are four inputs here a0 to a3 which uh because you as you'll see this chip has got a built-in multiplexer so i'm gonna experiment with this particular atd converter today because what i wanted to do is do some um read some analog signals on the raspberry pi now the the raspberry pi doesn't have any intrinsic hd converters so you always have to add something and if you've seen any of my previous videos i've before i've used something called the pcf 8259 which is a it's a it's a much worse resolution hd converter than this uh the pcf chip is only um eight bits um so that one's particularly easy easy to use this one with 12 bits resolutions quite nice quite a good match for the capabilities of the of the raspberry pi and can also provide at least 128 samples per second which is quite fast so if you want to read analog signals on the raspberry pi then you do need to add on an hd converter you're using the arduino then the arduino has hd converters built in in that case 10 bit 80d converters so there's no need to add any hardware on but often it's really convenient to use the raspberry pi and it means that you can write software in python that can integrate to a variety of different analog sources like like sensors and i'll dig something out that we can use um maybe uh uh ldr for light measurement um well i'll see what i've got in in the way of analog sensors so let me just um solder this up and we can start experimenting with the pi let's just have a quick look at the data sheet for the ads 101.5 because there's quite a nice block diagram here that shows the internals so you can see on this side we've got the the four inputs a in zero two three um over this side you've got the i squared c interface the alert ready pin which i'll talk a little bit about in a minute and in terms of building blocks of the um hd converter itself so you've got the the 12-bit adc here in the center this here is a programmable amplifier that you can use to change the gain so you can [Music] change the sensitivity of the hd converter and then this is quite interesting here so the reason that it has these four inputs is because although you know there's four inputs but there's only one hd converter so this is a multiplexer or mux i've got here but this is a multiplexer so um one possible thing that you can do actually what we're doing today is if we close one of these switches in the mux and we've got a0 connected through the pga into the hd converter so then we're just reading from this one port here but having four ports allow allows us to actually connect four bits of equipment and by changing the switch configuration we can take it take a reading of multiple voltage inputs but another thing that's quite interesting is he here you see um so there's a switch here to pull down to ground so if this uh if this pin is pulled down to ground then you're comparing whatever's on this pin with zero so you're getting an absolute reading but if you open that switch you can then have um so you can have for example a in three if you close this switch you've got a and three on one pin and you could have a and zero on another pin so you're actually subtracting one from the other and you're taking a a differential reading so um you know there's a lot of really clever stuff that you can do with the ads 101.5 over and above just simply reading an analog value so i've connected up the ads 101.5 here so rather than show you how these are plugged in in detail um i'll show you a picture in in in a moment of how i uh interconnected these it'll be clearer than trying to show you the wires here i think um now an interesting thing so if we look at the raspberry pi screen here the raspberry pi now has this useful command if you type in pin out it actually it prints out what kind of board you've got so here we're using the the raspberry pi zero w um so it shows you what kind of processor it's got and you know what kind of uh network it has which is quite nice and then it shows you the the connector so when the board is this way up with the uh the sd card at the top of the micro sd so the the pin out here is what you see on the screen so that's quite useful and it helps to get all of the wires located correctly when you're trying to connect something like this so if we just do a quick check that it can see the board so if we use the i squared c detect i've used this a few times before in previous videos so there you can see that at port 48 we have an i squared c device which is visible so so we do see something um and so in a moment we'll run a script and we'll actually interrogate that port and try and read a value from it so let's first have a look at how i've interconnected the wires and i'll explain that that address 48 so the board is wired up in in this way so we've basically got the four wires of the i squared c so the 3.3 volts and the ground which are the power supply and then i squared c's got these two control lines so scl and sda so those are quite clearly marked on this uh ads1015 board so those connect as you you see here um there's also this pin uh address so addr which uh it's quite clever actually because depending on which of these four pins you interconnect it to uh it sets a different i squared c address for the board so you see i've got a note here so because i've tied um addr to ground uh it's it should have an i squared c address of 48 48 hexadecimal which is 72 in in decimal um the other lines that are exposed on this border of course the input so we've got a0 to a3 as their marks on this particular board um but if you look in the data sheet it calls these a and 0 to a in 3 so i'll just put both nomenclatures there so that you can you can see the the correspondence there's also this pin alert ready which has a couple of different functions depending on how you program the chip [Music] so one of the things that you can do with this for example is you can get it to set this pin high when the 80d conversion has happened but i i'm not going to use this particular pin today so um so i might leave that for another day so there with that address pin pulled down to ground so we're looking at we're looking at i squared c address 4 8 and if i have if i just show you this script that i'm going to run so so what we've got here in fact if i just load this let's load it into the editor okay so i've got a few libraries that i'm installing here so these first two ones that i've shown on my channel before they're just a convenient way of talking to the i squared c bus but today i'm using this um adafruit provided library which is specifically for the ads 101.5 or 1115 so you see here i'm doing a bit of initialization so first of all creating an i squared c object this actually calls ads1015 so this is saying that i've got a 101.5 a to d converter connected to the i squared c bus and so i'm connecting creating an object ads to here to represent that and then finally chan here is going to represent the chip and it offers some abstraction so that i can um quite easily use the uh the values coming back from it so so here if you look at what i'm printing out here we've got chan dot values so this is literally the value the binary value that's being read from the i squared c bus and then you can also do chan dot voltage that does a little bit of conversion under the covers because it knows that it's a 3.3 volt um interface on the raspberry pi and so it does some conversion it will actually return the real voltage so if we have a look at what that looks like if i run my script now so it prints out two values here so if you notice i've actually got my a zero pin here it's connected to this here which is the ground wire so this should should be reading back zero because everything has been grounded so we see the value is zero and then in turn the return voltage is also zero now if i if i allow that to float uh so if you allow um a mos gate to float there'll be a voltage that i can pick up on this pin so let's have a look at that so we'll run read a d again and this time so it's now reading a value of 5232 and then it converts that into the real voltage so it can see a 0.81 volt reading on that pin and if i actually hold on to the pin it will read even higher so if i do that so that's now uh saying 27152 that's actually flipped to a negative voltage now that's interesting because it seems to have so that seems to have read so so high that it's gone over into a negative number because of the two's complement system i guess what we could do um because i've i've found a sensor that we can use so this is actually a um this is a silicon uh solar cell that came from a garden light that i i tore down so this should produce about two volts something like that um so if i get the multimeter out just put that on the voltage setting and if we i'm not sure which pin is which but let's just connect that i've actually got that the wrong way around so the so the white is the positive here so there we go it's reading about 2 volts now if i cover it up the voltage drops right down so we've got 1.3 something um and if i increase the illumination so that's just it's about 2.3 volts now so that's quite a useful range that won't overwhelm the hd converter so if we just find some some crop clips so i just connect this one into ground connect that to the black and i've got a red one which will be my signal wire like so and once again we'll do a read so that's quite nice so now we're getting that value one six one four four and uh when it converts that into a voltage it's just over two volts and similarly if i make it dark with my hand just run that again so now the voltage is dropped down to 1.08 volts or i could illuminate it even more and now the voltage has gone up to 2.3 volts so this ads 101.5 you know quite a nice hd converter because it's got good precision but it's relatively easy to use as well especially with that uh that adafruit library which just kind of does does all the the hard work for you so i promised i'd say something about the precision of a to d converters so let me just quickly uh show you that so to talk a little bit about the hd converter resolution so the that pcf mentioned which is quite a humble device so this has got eight eight bit resolution so two to the power eight gives you 256 as the the range the um the resolution so uh so if for example you have a five volt interface um so five divided by two five six is it gives you the step size so here five divided by two five six would give you about 20 millivolts so with a 5 volt range you've only got steps of 20 millivolts which if you wanted to do something like um have a a volt meter build your own volt meter then 20 millivolts is quite a big jump and and it's not a very precise device but the the 8259 is quite good for things like connecting to an ldr because if you just want to know whether um the light reading is dark or or light or somewhere in the middle then you don't need much resolution and so the 8259 is quite a nice inexpensive chip for that the arduinos have got a 10 bit resolution built in so that gives you a range up to 1023 so 10 10 bits is 2 to the power 10 so you get the 1024 range which is not bad and a whole range of sensors work very well on the arduino the one we're looking at today the ads 101.5 is a more sophisticated device and it's got 12 bit resolution so um with two more bits then uh then the arduino actually gives you four times the resolution so instead of 1024 as your range you've now got 4096 so you can see that as you add more bits you're adding quite a lot more capability and then the ads1115 which is like the bigger brother for the 101.5 goes up to 16 bits so you can see again you've got uh another another four bits gives you 16 times the resolution of the of the cheaper chip um so i mean which which one you use depends very much on the application but uh but you can see there's a there's a whole range of different capabilities to choose from so that's a basic simple introduction to this this particular device my test script i'll put on my github site as usual so that you can also use it and i'll also put a link to the the adafruit library which is uh which makes this experimentation so uh so very easy uh so thanks for watching see you in the next video
Info
Channel: Martyn Davies
Views: 3,705
Rating: undefined out of 5
Keywords: electronics, software, raspberry, pi, adc, ad, converter, ads1015, python, arduino
Id: IJI_2rlCEis
Channel Id: undefined
Length: 20min 46sec (1246 seconds)
Published: Sun Mar 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.