Hey guys,
I am a mechanical engineer being pressed into service as an electrical/computer/software engineer, so I am still learning a tremendous amount. Anyways, I am trying to create a system that uses four load cells. My goal is to connect these to a Raspberry Pi 3 and I am trying to use a 24bit 4 channel ADC to do it. I didn't know which ones to use so I ordered an ADS1234, 4 ADS1231's, and an MCP3304.
I have hooked up the ADS1234 with all four load cells and connected it to the SPI interface on an Arduino Uno (for testing). I am having some trouble getting it to work and I was hoping you all could help. I followed Figure 42 in the ADS1234 datasheet, but to no avail. Also, this is the first time I am using SPI, so I really have no idea what I am doing.
I have attached the code that I am using in arudino as well as a schematic of how I have hooked them up. If you all could help me out I would greatly appreciate it!
Thanks!
PS: My VIN is 5V. Forgot to put that into the image.
#include <SPI.h> #define MISOPIN 12 #define SCLKPIN 13 byte byte1; byte byte2; byte byte3; // declare 3 bytes = 24 bits void setup() { Serial.begin(9600); pinMode(SCLKPIN, OUTPUT); pinMode(MISOPIN, INPUT); // corresponding to SCK pin and DRDY/DOUT pin on ADC reset_adc(); // put ADC on reset at the outset SPI.begin(); // initialize SPI (with default settings, including... // CPOL = 0: so that SCLK is normally LOW // CPHA = 0: data sampled on rising edge (LOW to HIGH) // perhaps try changing CPHA ?? digitalWrite(SCLKPIN, LOW); // release ADC from reset; now we're at a known point // in the timing diagram, and just have to wait for // the beginning of a conversion cycle } void loop() { if (digitalRead(MISOPIN) == HIGH) read_adc(); // "sort of" an interrupt to go to read_adc routine; // can use hardware interrupt in future but now just poll } void reset_adc() // to reset ADC, we need SCLK HIGH for min of 4 CONVCYCLES // so here, hold SCLK HIGH for 5 CONVCYCLEs = 1440 usec { digitalWrite(SCLKPIN, HIGH); delayMicroseconds(1440); } void read_adc() { drdy_wait(); // go to drdy_wait routine, where we wait for // DRDY phase to pass, and thus for DOUT phase to begin byte1 = SPI.transfer(0x00); byte2 = SPI.transfer(0x00); byte3 = SPI.transfer(0x00); // read in adc data (sending out don't care bytes) // and store read data into three bytes */ Serial.println(byte1, DEC); Serial.println(byte2, DEC); Serial.println(byte3, DEC); Serial.println(); // print out data; // will these instructions eat into time significantly? // possible improvement: store all data from multiple cycles // into array, and print out only later at end. } void drdy_wait() // wait for DRDY to pass and to reach start-point of DOUT { delayMicroseconds(30); // to be safe, 30 usec, instead of 27 usec, which is // the expected period of DRDY phase }