Arduino, ADS1115 16-Bit ADC with I2C Bus and Adafruit Library – The Details

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there I have here on my breadboard and breakout board within Texas Instruments a ds-11 one five 16-bit analog to digital converter and it's bought four multiplexed inputs you can use them single ended or you can pair them up to have two differential inputs it also sports an internal voltage reference and programmer will gain amplifier and it communicates with my obviously Arduino Nano why are the I squared C bus and yeah obviously I've already software installed on running it's basically an example from Adafruit they provide a library for these things and well it's great I get some values here from the voltages I feed into the inputs two inputs are connected to 5 volt rail and the two other inputs are connected to ground so on the breadboard my nano supplying everything with five volts and it's a four serial data and a 5 serial clock pin connected to 0 o'clock serial data of the 80s one one one five breakout port and both lines pulled up wire to 4.7 kayra sisters like you use to do it when you use I squared C the module has a connection to 5 volts of course to ground and the analog inputs simply yeah connected to 5 volts ground 5 volts ground and I get 0 and 0 on to and on the others I get 25,000 something not 5 volts mmm well I guess this video will be a little bit longer than expected anyway for the mailbag where I got these things yeah caught link let's first have a look on what's on the breakout board and credit where credit is due Adafruit developed that kind of breakout board and they also sell them so buy them please from Adafruit I just got mines from Peng good because I didn't know about that I just thought oh great I know not to digital converter and somebody yeah well asked for this video a review of these things and yeah well happens I ordered it on bang good but you should order it from Adafruit on to the circuit so the Adafruit circuit has a decoupling capacitor 1 micro farad ok directly on the power input pins and then on BDD and ground poly fuse ok and the ABS 11:15 in our case 16-bit has a decoupling capacitor on its power pin 1 micro farad probably not and four resistors yeah so s clock s da and the alert pin are routed out of the connectors wire 10k resistors ok and the address pin is pulled low it's also router to the connector while also a 10k resistor let's compare that to the breakout board from China on the Chinese breakout board we have a decoupling capacitor here near our analog to digital converter we have an for resistor array 10k and I guess these two are the poly fuses at the power input pin ground and VCC and another decoupling capacitor across ground and VCC yeah that one on that one are probably not one micro far out but while the datasheet of the ad s 1115 says it needs only 100 nano decoupling capacitor on its power supply and I'm not sure why we need here on one microfarad so yeah if that is a few hundred nano all 100 nano that should be perfectly okay this is a code I'm currently using and it's basically one of the examples that come with the Adafruit ATS 1015 library which also includes the Adafruit a ds-11 1/5 class which I'm using here for the 16-bit version of that chip yeah the objects called 80s and of course we need the wild library for the I squared C communication within setup nothing much yeah a my serial stuff here so I can print out something on the serial monitor there's a lot of comment stuff here or a very commendable from Adafruit what the different gains for the programmable game amplifier are and most importantly what the least significant bit means in our case and I'm using gain 2 thoughts it's 0.1875 millivolts per bit or least significant bit and the rest IDs begin initializes the library we will come back to that later and then I added that line yeah explicitly setting the game for my amplifier within the ADC nothing much in the loop either I have here 4 variables for the 4 channels and they are assigned 16-bit integer and then I have these 4 read ADC single-ended commands for my 4 analog in parts of the chip zero to three and obviously that function returns simply assigned 16-bit integer not properly scaled and yeah the rest I print that stuff out and there's a little delay that's all if we want our voltage in volts we have to multiply the return 16-bit value here with 0.0001 eight seven five vaults or 0.1875 millivolts let me whip up some code that looks much better so input 0 4 point 7 volts input 1 0 volt and put 24.7 something bolts and input 3 minus minus zero volts okay so and yeah my inputs are connected to 5 volt rail round 5 volt rail ground yeah 5 volt rail four point seven or Walt's mmm let's check that and indeed my multimeter says four point seven one two three bolts so yeah seems to be okay so what did I change I brought myself a vault function but returns a float obviously the voltage in vaults and that gets at some argument the raw 16-bit integer value from the ADC it also gets the game the programmer will gain amplifier is operating on and this type 80s gain T is provided within that other fruit library and the possible values for that are gain two-thirds can gain one etc etc up to gain sixteen and depending on that I set a multiplier float to the vaults value of the least significant bit and I use that multiplier simply to multiply the raw 16-bit value and that gives me my value in vaults up here I simply yeah and have redefined all these variables it floats and I use that vault function to convert directly the values read from the ADC and this little function here from the other fruit library that provides us the current gain the ADC is operating under at this point it might be worth to have a look into the 60-page 80s one one one five data feed and yeah for now just some highlights so supply voltage two bolts to five point five volts so that thing will work with your 3.3 volt outer we know programmable data rate eight samples per second to 860 samples per second okay we know that I squared C interface for pins electable addresses we will try that and for single ended or two differential inputs we will definitely try that we are using at the moment for single ended inputs and we already seen that in the code the program will gain amplifier offers input ranges from yeah plus minus 256 millivolts to which we are currently using plus minus six point one four four volts and that's a rough diagram of what's inside our little shape so we have here the input multiplexer and we have the programmable gain amplifier note it has a positive and negative input and it goes to a differential analog digital converter yeah it has a voltage inference and reference and that I squared C interface of course and it also has a comparator we will try that also and yeah something is missing here from the MUX there's also a line going to ground we are currently using one of the four inputs single-ended so the negative input of our pre grade 3 gain amplifier is always connected to ground the first and most important section absolute maximum ratings yeah how not to destroy your little trip so power supply range - 3 - 7 volts yeah 8 won't operate at minus 3 volts ok analog input voltage yeah on the analog input pins - 3 Waltz to supply voltage plus 0.3 volts keep that in mind please digital input voltage minus 3 volts to 5 point 5 volts input current continuous which is interesting - 10 - 10 millions we have to have a look into that further down the datasheet and further down on page 15 we find that detailed picture of the input multiplexer and you see here these diode protections on each input yeah we will talk about them in a second but while we are here you see how that input multiplexer works and this is the ground connection I talked about so if you use single-ended inputs you can use all four inputs and connect them here the green line to the positive input of your programmable gain amplifier and the negative input of the programmable gain amplifier yeah that blue line will be connected to ground if you use that thing in differential mode which we will do next you can either connect the input one all the input three yeah the other blue lines here to the negative input of your amplifier and yeah then take any other input as your positive input but now let's talk about this protecting diodes that's the ten milli amp limit we saw in the absolute maximum ratings finally we are on page 32 we find something about input protection the important part here is the analog inputs feature protection diodes to the supply rails yeah we seen that in the multiplexer picture however count abilities of these diodes is limited and they cannot take more than continuous 10 milliamps so if you really want for my input protection for higher voltages you have to put in a serious resistance and yeah here again mentioned analog input voltages that exceed approximately 300 millivolts beyond the rails that is ground minus 300 millivolts and BCC plus 300 millivolts okay yeah keep that in mind and while we are here unused inputs and outputs okay I have a float unused analog inputs or title unused analog inputs to mid supply or bdd connecting unused analog inputs which is a very common technique to grant as possible but may yield higher leakage currents than the previous options so for that chip yeah you don't use them let them float the easiest yeah I've afloat no connect pins all tied or no connect pins to ground if a lot output pin is not used leave the pin unconnected all tie the pin to be d using a weak pull-up resistor so that chip is very very tolerant about letting unused pins just float yeah it's the easiest that brings us to a probably a lot statement with in the example from the other fruit library so it states here yeah the ADC input range can be trained by the following functions blah blah blah but be careful never to exceed VDD plus 0.3 volts yeah and we have to adhere all ground minus 0.3 volts yeah but then it follows all to exceed the upper and lower limits if you adjust the input range which is sorry not correct and I will demonstrate that I will set the gain in my software to gain 16 so our voltage range will be 0.25 6 volts plus minus and yeah that - really can only or cure yeah when you use differential mode that's for differential input modes again no negative voltages on the analog inputs ok so I'm running that now you have two of my inputs still connected to the 5 volts rail with gain 16 and yeah nothing exploded let me stop the scrolling and we get for these inputs a value of 0.25 5 9 9 to 1 baa baa waltz and it's always the same value yeah normally it fluctuates a little bit you have seen that before and it doesn't so that's some kind of an overflow value it's an interesting overflow value but anyway our ADC should be okay and I will prove that to you with the next version of the code where I go back to lower game and we add some differential input reading now I'm doing in each loop two differential measurements between first inputs 1 0 and 1 and then second between inputs 2 & 3 and let me stop the auto scroll so these our single-ended measurements and 4.70 7 minus 0.015 1 should be about it yeah four point six nine zero of course the unit doesn't do arithmetic it really yeah measures the difference in voltage between the two inputs and for our second pair here the the ground sum is measured somehow a little bit lower there I mean right bought up adults yeah how what differential is yeah the same like the single ended input with three connected to ground um but anyway that's a bad example let me let me take import tool to ground yeah and now we see sorry scrolling and now we see differential reading from two to three is zero volts because two and three are connected to ground and if I call mix input 3 to the 5 volt rail we finally have auto scroll off a negative value to read from our ad so anyway again don't put negative value negative voltages yeah reference to ground on to your analog inputs of that thing yeah the negative values will appear when you do differential measuring between two inputs and yeah in this case yeah the plus input has a lower voltage than the minus input that's it let's have a look at the code it's really simple the only change I really did was in the loop I added two more variables yet to hold the voltage values ADC zero one for the differential between the inputs 0 and 1 and ADC 2 3 4 inputs 2 3 I added 2 more read ADC and this time not single-ended but differential statements yeah to get these values and well the library only provides two statements yeah for differential reading different reading between the inputs 0 and 1 and between 2 and 3 yeah we will see that in theory there's more possible here and yeah I print out the values and that's all let's continue with the alarm feature of the trip to demonstrate that I have uploaded some new code into my Nano we will have a look at that in a second and I connected an LED to the alert pin of my breakout board and yeah the LED is connected with the anode to the alert pin and the cathode of the LED goes directly to ground there is no resistor involved because remember there is an on board resistor of 10k at that allowed pins so yeah that's the reason the LED is a little bit dim it only gets less than 1/2 milliamp it would need 2 milliamps to be really bright but I think you can see it's on also I connected the zero input to the wiper of a potential meter and the potentiometer is between ground and five volt rail going back to the schematic I showed in the intro I've added here that led to the ready-alert pin and a zero is now going to the Viper of that potentiometer here between 5 volts and ground and we account the reading at the a zero input zero volts here I'm completely here to the left and if I turn it slowly to the right we see yeah the value rising quite nicely and if I reach three Walt's my LED should turn off well that is well not completely turning off it's still blinking why I will I will explain that in a second let's have a look at the code the code I'm using is another example that comes with the Adafruit library it's called comparator and I just modified it a wee bit yeah I removed the commentary stuff we saw in the other example so it would fit on one page I added my yeah explicit set gain statement here in the setup I have my world function further down here so we can actually print out the measured voltage in volts okay and the set up the important thing is that statement here start comparator single-ended and then comes the number of the channel we are working on here we thought we work in channel zero and then the value the comparator should act on this is again the raw 16-bit value that our ADC expects yeah so if we want the comparator to act on three walls we have to divide these three bolts by the value of the least significant bit which is 0.18 75 millivolts for a gain of 2/3 and that gives us the value of 16,000 now that statement here causes the ADC to continuously sample yeah even if we don't read anything out of it it continuously samples and at the same time compare see a comparator the sampled value with the value we've given it here and as soon as the measured value yeah exceeds that limit here the alert pin goes low and our LED goes off now there's a little Kebede here and this comes down in the loop the alert will stay on yeah even if the actual value is decreasing again below our 3 volts and less we read the last conversion result from the ADC which is happening here with that statement get less conversion results it's only one result but yeah results whatever and yeah that's also the reason you saw when we are going beyond three walls in the input the LED basically goes out but it still flickers because the comparator raises the alarm in and somewhere in the loop we read the last conversion result and we resset the comparator but only for very short time until it finishes the next conversion and compares the value again and says okay we are still over three volts so I pull that pin low again that's basically it for the comparator and alert pin and alarms and stuff well that you can do with other fruit library that brings us to the last feature of the Adafruit library respectively our little analog digital converter here and that is it can operate on four different addresses on the I squared C bus so you can put up to four of these devices on one I squared C bus and that's happening through the address pin here and I connected the address pin now heart to my five volt rail remember in the circuit of that breakout port it's normally pulled down by a 10k resistor to ground now I pulled it up to VCC let's say you see I'm returned to my old coat here yeah and yeah new feature we can actually change the value of our zero input yeah that's still working no a la habra changer see you just pulled the address pin high so in my schematic the address pin which was previously pulled down to ground by that 10k onboard resistor is now connected to five volts and so pulled up hi have a look into the code now the code changes for that are really minimal that was the constructor for our ad s object we use so far and it uses as default the hexadecimal address 48 yeah because our address pin is pulled down to ground wire that 10k resistor so this statement here is the same as that statement but now I pulled the address pin to VDD to our five volt rail and so the address of our ATS one one one five changes to hexadecimal 49 okay and I can pass that and you see yeah I can talk to my ADC you have two more possibilities here you can connect the address pin to the SDA line that will give you an address off for a or to the SCL line which will give you an address of 4b so all in all from 48 to 4b we can address four devices on the bus which is nice I mean then you have a sixteen single-ended 16 bit ADC channels so that's a lot let's have a look in the datasheet and they're on page 23 we find that I squared C address election stuff I explained already yeah address plane connected to ground VDD SDA or SEL results in a different address of the device and this connecting an address pin to SDA or SEL that's a trick I didn't know before so that's yeah kudos to the sorry Texas Instruments developers for coming up with that and that would be it for the Adafruit library but the ad has one one one five can do a wee bit more and the Adafruit library is not really exploring each and every feature of that so we will now dive in a little bit further into the datasheet and well if you're not in yeah modifying that library yourself and you think that's enough yeah you can switch off now and do something else remember when we first had a look at the data sheet there was something like a programmable data rate from 8 samples per second to 806 these samples per second the Adafruit library is always using a data rate of 128 samples per second and this table here on page 13 gives you some information how many bits are really yeah worth while that's the number in brackets depending on your data rate and depending on your full scale range so yeah the gain you set and you see that 128 samples per second is quite good compromise yeah you only lose an hour two-thirds of a bit down here when you choose the highest gain and yeah but you can do better if you need that or low full-scale range you could do better using only 64 samples per seconds and if you want to be faster and you don't care about the last significant bit yeah you could go up in many ranges up to 475 samples per second and if you say okay I don't care about the last two significant bits you could go up up to 860 samples per second that brings us to the issue how these read ADC statements work from the other fruit library so basically they sent data to the ADC and config it yeah into that's called a single-shot mode and 128 samples per second and yeah the right input or differential input etc then it waits nine milliseconds until the sample is finished and then it reads the value from the ADC if you have time critical code you can do a lot in nine milliseconds like a query some keypad or update a displace so yeah keep that in mind there's room for improvement on page 21 of the datasheet we actually learned that our one one one five actually has two modes it can operate it the single-shot mode yeah which is used by that read ADC command from the Adafruit library but we can also run it in continuous conversion mode where it yeah with the set template it yeah convert convert convert convert convert from one input okay or from yeah two inputs when it's in differential mode but that continuous conversion mode is only used by that other Adafruit library method and that was the start comparator single-ended okay where we really just said the conflict to our ADC continuous mode and the high threshold okay when it should set the pull the alert pin down and we get the last conversion results via peak at last conversion results which really just reads the value from the ADC talking about alerts the 80s one one one five has actually two threshold registers waffle ah one for a high value yeah when you exceed that the alarm pin is set poor low and one for a low value when your value is going below that threshold the alert pin is also pulled low and of course with the other fruit library you can only use the high threshold that was on page thirty by the way talking about the alert ready pin and I'm off page 19 you could also use that pin to indicate when a conversion is finished let's say you start a conversion yeah all you have that thing run in continuous mode and every time it's finished a conversion you could yeah for example connect that a lot ready pin to an interrupting of your Arduino and read out the result of one conversion by an interrupter T or something like that sorry cut one more the Adafruit library only supports differential readings from the input pairs 0 & 1 & 2 & 3 hour 1 1 1 5 also supports differential readings from the input 0 & 3 & 1 & 3 this video wouldn't be complete without being a look at some of the electrical characteristics of the 80s one one one five and we start with the analog input impedance of better resistance and you see it's different for common mode input and for differential input impedance and it also depends on your gain or full-scale range and you see the higher you turn your game the smaller your full-scale range the lower the input impedance so at yeah our 2/3 gain we have a 10 Meg input impedance on common mode inputs sorry and that goes down six Meg free Meg and then according to the datasheet 100 Meg I'm pretty sure that's an error in the data sheet and it should say 100 kilo ohms okay that's pretty low impedance yeah for differential impedance oh yeah this is much higher and it's really the impedance between the two inputs we're talking about here 22:15 4.9 2.4 and yeah 710 kilo ohms so generally between two inputs it's much higher than a single input to ground and yeah you can see while I don't believe that datasheet value here please also take a note on the integral non-linearity yeah of that ADC so yeah for 8 samples per second and it gets birth a year higher your sample rate is and for full-scale range of two point something both it's just maximum one least significant bit the offset error yeah typical if you use differential inputs are another least significant bit ahead if you single ended input we are typical at three least significant bit so if you use a thing really a single ended and yeah you could throw away your last for two bits two bits of your value it's yeah there are also yeah and gain arrow which is 0.01 percent which should be okay for 16 bit da and offset channel match match between two inputs freely significant bit you should aware be aware this is more or less a very affordable ADC not necessarily a high precision ADC and yeah I'll think I stopped right now you can read the rest yourself from the datasheet so that's it for today the 80s one one one five turns out to be quite a versatile Beast though the Adafruit a library does not explore each and every feature of it however as you might have guessed I looked into the code of the Adafruit library and it's very well written code easy to understand and it's a good starting point if you need to explore these other features I mentioned and with that I say bye
Info
Channel: Robert's Smorgasbord
Views: 21,641
Rating: undefined out of 5
Keywords: Robert's Smorgasbord, Robert’s Smorgasbord, tutorial, tutorials, how-to, Adafruit, Arduino, ADS1115, module, breakout, breakout board, ADC, 16-bit ADC, I2C, library, code, example, examples, datasheet, single-ended, single ended, differential, comparator, data rate, SPS, precision, multiplexer, I2C addressing, I2C addresses, I2C address, analog to digital converter, analog-to-digital converter, Arduino code, Arduino example, Arduino library, ADS1115 Arduino, Arduino ADS1115
Id: 7iL94z5XRFA
Channel Id: undefined
Length: 41min 51sec (2511 seconds)
Published: Sun May 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.