Fig. 1 - Ignore the breadboard, it’s coming in the next post. Also, the ADC is under the Pi.
Holy crap this project is totally moving along! Next up are the analog sticks. At their core, analog joysticks are just two potentiometers attached to springs. They are (hopefully) centered at 0.5*Vcc, though there is likely some error in there. Moving them to one extreme, down for example, will give you 0v and moving to the other gives you Vcc. One pot takes care of up and down and another pot takes care of left and right. That means we have 2*2 analog inputs that we need to digitize which is perfect since the ADS1115 has 4 single-ended ADC channels!
Here’s some material on single-ended vs differential: http://ww1.microchip.com/downloads/en/DeviceDoc/Differential-and-Single-Ended-ADC-WhitePaper-DS00003197A.pdf
Some also have a “select” button for when you push in the analog stick. The one I got also has a pad to add a pullup resistor if you like.
The Raspberry Pi has internal pullups/pulldowns on all of its GPIO which is a super bonus since that means we can save a ton of space by not adding rows and rows of resistors for each button (the final design plan has 12).
So really, it just comes down to interfacing with the ADS1115!
There are probably a lot of libraries out there. As you hopefully know by now, this is a “how you do it” blog where we don’t spare you the gory details of writing the code so here’s how we do it from scratch.
The Hardware Hookup
First let’s investigate how the hardware gets hooked up.
I2C lines always need to be pulled up with a resistor. It’s because they use what’s called an “open collector” design. At the SDA and SCL lines, on each side, there are transistors with the SDA & SCL on the collector, the emitter to ground, and the base controlled by the I2C module. That means when the base-emitter is activated, it pulls the SDA and SCL low strongly. But when the transistor is turned off, the collector just floats so it needs to be pulled up.
So the circuit becomes pretty dead simple. Here’s a Fritzing breadboard for it.
Fig. 2 - ADS1115 breadboard layout. Lots of iterations before I got it looking so clean ^^;
The Software
For the test software, we need to know the registers we’re dealing with. For that, we turn to the datasheet here:
https://www.ti.com/lit/gpn/ads1115
Some things to pull out from the datasheet:
Fig. 3 - Table showing why we chose this chip
We chose the ADS1115 because it gave us 4 single-ended channels and an I2C interface. You can see there are other models with other combos of channels, sample rates, and resolutions and we can choose SPI versions as well so these can be factors to make a good part decision.
The doc outlines how we can set the device’s address using the ADDR pin:
Fig. 4 - Table showing how to change the slave address
On the perfboard, I ended up having to tie to SCL which is shown in the breadboard diagram too, yielding the address 1001011 or 0x4B.
It also shows how to perform writes and reads over I2C (pg. 24) and the registers (starting on pg. 27).
Essentially, to write, we send in this order:
Device’s I2C address (0x4B)
We send the address pointer value
0x00 for the conversion result register
0x01 for the ADC configuration register
0x02 for the Low threshold (which triggers the RDY pin when crossed)
0x03 for the High threshold (which triggers the RDY pin when crossed)
Send the data to write (for config register, Low thresh, and high thresh)
Writing to the conversion register tells it to start the conversion, then we have to wait until the conversion finishes. You can configure the registers to trigger an interrupt on the ALERT line which we may do later. For now, let’s just check that the basics are working.
We can wait a requisite amount of time depending on our sampling rate. For the demo, I’m sampling at 860 samples/sec just because that’s plenty fast for the analog sticks for now. The delay has to be at least 1.2ms to which I added just 20us as a buffer.
After that, we can issue a read command to the conversion register.
Install wiringpi
sudo apt install wiringpi
Enable I2C
sudo raspi-config
Interfacing options
I2C
Would you like the ARM I2C interface to be enabled - yes
ARM I2C interface is enabled - Ok
It won’t prompt you to reboot but I had to reboot.
and that will give you access to wiringPi’s libraries.
So this is our starter program. Down the line, we’ll turn it into a useful API, do some threading (allowing multiple programs to run at once), and tie it into the main program but, for now, it looks like we can get analog input from the ADS1115!
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
âś“ Live Streamingâś“ Interactive Chatâś“ Private Showsâś“ HD Qualityâś“ Free Actions
Free to watch • No registration required • HD streaming
Data akusisi dengan sensor hidrogen, suhu dan kelembaban #microcontrollers #microcontroller #sensorkelembaban #sensorhidrogen #arduino #akusisidata #sht11 #mikrokontroller #adc #ads1115
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
âś“ Live Streamingâś“ Interactive Chatâś“ Private Showsâś“ HD Qualityâś“ Free Actions
Free to watch • No registration required • HD streaming