The AD7193 is 4 channel sigma-delta ADC, which is handy for sensor measurement applications - particularly sensors that generate a very small voltage that needs to be measured. Examples include thermocouples and bridge-type sensors (such as load cells). This tutorial is for a K-type thermocouple, but the AD7193 can be used for a variety of thermocouples, and other voltage measurements.
The multiple channels and built-in PGAs and filtering enable measurements of multiple sensors, and flexibility measurement settings.
What you'll need:
- 3.3V Arduino - I used an Adafruit Feather
- K-type Thermocouple - I used this one from Adafruit
- AD7193 - I used a Digilent Pmod AD5
- AD7193 Arduino Library - can be installed using Arduino Library Manager
- Prototyping materials
If you chose to use a 5V Arduino (such as an Arduino Uno or Leonardo), you'll need to shift the logic levels to ensure that the AD7193 receives 3.3V logic, as well as power from a 3.3V supply (available on the Uno as the "3.3V" power pin) - I cannot be held responsible if you fry your AD7193 using a 5V Arduino!
Arduino specs table - look for Arduinos with 3.3V Operating voltage
Arduino is an open source prototyping platform - there are many, many "Arduino-compatible" boards out there. And, chances are good that you could get any one of them to work for this example. But, to keep things simple, I am going show how connect the AD7193 to the Adafruit Feather. If you deviate from this example, you are on your own. But, don't worry! There are loads of examples on the web, books in the bookstore/library, etc, that will very quickly help you to become an Arduino expert.
Getting started with Arduino
- Download and install the Arduino IDE - https://www.arduino.cc/en/Main/Software
- Get your Arduino working with the Blink Example - https://www.arduino.cc/en/Tutorial/Blink
Do not continue until you get Blink working. If you're struggling with Blink, keep working through tutorials and getting started guides until you understand how to communicate with and program.
- Arduino - Getting Started
- Learn Arduino Tutorial Series by Simon Monk
- Adafruit Feather 32u4 Adalogger tutorial
Installing the AD7193 library
To install the AD7193 library using the Arduino Library Manager, click Sketch -> Include Library -> Manage Libraries. When the library manager comes up, type "AD7193" in the filter field, and click the "Install" button to install the library.
See Installing Additional Arduino Libraries for more detailed information about using the Library Manager.
Connecting AD7193 to Arduino
Make the following connections between your Arduino and the AD7193 (using Pmod AD5 in this example):
Arduino Pin | Pmod AD5 Pin |
Wire Color in picture below |
---|---|---|
3.3V | VCC (J1, Pin 6) | Red |
GND | GND (J1, Pin 5) | Black |
SCLK or 13 or ICSP-3 | SCLK (J1, Pin 4) | Yellow |
MISO or 12 or ICSP-1 | MISO (J1, Pin 3) | Green |
MOSI or 11 or ICSP-4 | MOSI (J1, Pin 2) | Blue |
10 | ~CS (J1, Pin1) | White |
Connecting thermocouple to AD7193
Connect the thermocouple leads to AIN1 and AIN2 on the AD7193 - in the case of the Pmod AD5 and the K-type thermocouple from Adafruit, connect the yellow thermocouple lead to Pin 1 on J2, and the red thermocouple lead to Pin 2 on J2. This is where alligator clips can come in very handy - the leads from the thermocouple are not rigid enough to push into J2.
Open and upload thermocouple example sketch
In Arduino IDE, select File -> Examples -> AD7193 -> AD7193_Thermocouple_Example
Click the "Upload" button (right pointing arrow, circled in red). When upload is complete, click the "Serial Monitor" button on the far right (also circled in red).
Observe data on serial monitor
This example includes a wait loop, that's necessary for default USB devices, like the Leonardo and the Feather.
while (!Serial) {
}
This means code you've just uploaded won't actually run until it detects that the Serial Monitor is open. Open the serial monitor to view the setup and measured results.
If you want to modify this example for use in a more embedded application (meaning, no serial monitor), just remove the wait loop.
The example below is what the serial monitor looks like when I have the thermocouple in a cup of ice water. (Keep in mind, I'm using the on-chip temp sensor, which according to the datasheet, has a ±2°C accuracy AFTER user calibration. Also, this example does not include any user calibration of the on-chip temperature sensor, so you'll need to determine if your application requires calibration to get the accuracy you need.)
Troubleshooting tips
Issue: When sketch is running through initial setup, the "Read All Registers" portion of serial monitor output is showing all registers as all zeros.
Check power and ground connections to the AD7193, and check all SPI connections. Debugging the SPI connectivity can be tricky - I've seen bad connections due to poor quality wiring, faulty breadboards, etc. Pay particular attention to CSB connection. If you can get your hands on a logic analyzer, probe the SPI connections to see.
I have a Saleae logic analyzer, which is easily one of the handiest things I own. https://www.saleae.com/
Issue: "Read All Registers" portion of serial monitor output is showing all registers as all ones (F's).
Similar to issue above - check all SPI connections, and debug with a logic analyzer.
Issue: Calculated temperature isn't what I expected.
Rerun sketch, just to be sure there was an issue with the program load and initial execution. If temperature is low when you expect high, or vice versa, try reversing thermocouple terminals. Program as written only supports K-type thermocouples. If using a different type, you'll need to add the linearization code for that type.
Questions and Feedback
Leave any questions or feedback in the comments below.