Electronics > Microcontrollers
Tutorials on code for Arduino with external ADC?
David Aurora:
I'm suuuuuper rusty with Arduino (99.999% of my work is analog electronics) but I've been designing a bit of test gear where I measure a bunch of analog voltages, do some maths to it and spit out the results on an LCD.
Using an Arduino Nano Every with its built in ADCs everything is working fine, but I wanted to switch to an external 12 bit ADC for more resolution. I opened up an example I found on the Arduino site for an MCP3208 (https://playground.arduino.cc/Code/MCP3208/) thinking I could get a feel for it from there and then add the relevant code to my design, but the example code doesn't actually explain anything about how it works or what any of it means, and all the tutorials I could find completely skip over the code and just focus on how to wire things up on a breadboard.
Does anybody know of any tutorials that go through the basics of writing code for external ADCs with Arduino? Like not just "Copy and paste this code and you'll see numbers in the serial output" but actual explanations like "The line ____ tells the microcontroller to read from input __ and store it as ____", etc.
ledtester:
External ADCs use either SPI or I2C to communicate with them.
The MCP3208 is an SPI device. SPI on an Arduino Nano can be done either by "bit-banging" (i.e. the program explicitly drives the GPIO pins) or by using the SPI device in the microcontroller.
Here is a video which explains the spi-demo.c example from the Arduino library:
Arduino Workshop - Chapter 5 - Using SPI -- Core Electronics
https://youtu.be/ZGaCXHvgcE4
Here is a video which explains the code for interfacing with the MC3208 using the SPI device:
Arduino | Tutorial | MCP3208 Interfacing -- WGLabz
https://youtu.be/qLcmI5xcN58
and here is a video which uses bit-banging code to interact with the chip:
Basics of connecting the MCP3208 12 bit ADC to Arduino -- Simon Carter
https://youtu.be/gfKdITStXio
You might find the bit-banging code easier to follow as it shows exactly which GPIO pins are being set high/low.
David Aurora:
--- Quote from: ledtester on December 05, 2022, 02:50:33 am ---External ADCs use either SPI or I2C to communicate with them.
The MCP3208 is an SPI device. SPI on an Arduino Nano can be done either by "bit-banging" (i.e. the program explicitly drives the GPIO pins) or by using the SPI device in the microcontroller.
Here is a video which explains the spi-demo.c example from the Arduino library:
Arduino Workshop - Chapter 5 - Using SPI -- Core Electronics
https://youtu.be/ZGaCXHvgcE4
Here is a video which explains the code for interfacing with the MC3208 using the SPI device:
Arduino | Tutorial | MCP3208 Interfacing -- WGLabz
https://youtu.be/qLcmI5xcN58
and here is a video which uses bit-banging code to interact with the chip:
Basics of connecting the MCP3208 12 bit ADC to Arduino -- Simon Carter
https://youtu.be/gfKdITStXio
You might find the bit-banging code easier to follow as it shows exactly which GPIO pins are being set high/low.
--- End quote ---
Thanks
I saw the last two videos earlier. The second one was excruciating to follow with the sound quality but I'll give it another chance, the last one doesn't explain anything about the code at all though.
Hadn't checked out the first one, will do though.
bidrohini:
You can see this too:https://electronoobs.com/eng_arduino_tut83.php
David Aurora:
--- Quote from: bidrohini on December 05, 2022, 07:24:45 am ---You can see this too:https://electronoobs.com/eng_arduino_tut83.php
--- End quote ---
Thanks. In that one it looks like basically everything is handled in libraries, which is handy if you have that particular chip on hand I guess, but still doesn't really teach me anything beyond copy/pasting code
Not that I'm hell bent on doing this the hard way, I may just order whatever has the best library available and make life easy. I'm just kind of surprised that I haven't found a proper walkthrough of writing code for reading ADCs
Navigation
[0] Message Index
[#] Next page
Go to full version