SPI Load cell chip ADS1231

Hi

I'am playing with an ADS1231 (http://www.ti.com/lit/ds/sbas414c/sbas414c.pdf) chip to read a load cell value.

#include <SPI.h>

const int dataReadyPin = 9;
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  pinMode(dataReadyPin, INPUT);
}

void loop() {
  if (digitalRead(dataReadyPin) == LOW) {
    unsigned int result1 = 0;
    byte inByte = 0;
    for (int c = 0; c <= 3; c++) { 
      result = result << 8;
      inByte = SPI.transfer(0x00);
      Serial.print(inByte);
      Serial.print("<<");
      result = result | inByte;
    }
    Serial.print("=");
    Serial.println(result);
    delay(1000);
  }
}

With a progressive pressure on the load cell (with my hand) the output looks like :

1+139+170+255+=43775
1+200+219+127+=56191
2+156+31+255+=8191
3+59+255+255+=65535
3+225+95+255+=24575
0+175+159+127+=40831 <== Problem !
4+7+15+255+=4095

I thinks it's realy noisy, but it seems to be working.

So my questions about this :

  • My line with "if (digitalRead(dataReadyPin) == LOW)" is really bad, because it will not be only true in falling. I don't want to use an interrupt, so how can I do that ?
  • Is there a cleaner way to read the SPI bus than writing 0 on it ?
  • About noise, have you any clues ?
  • What do you think about the "problem" of 0 on the output ?

Thank you very mutch.

Jul

I don't think that is a SPI mode 0 device. It appears to be a mode 1 device. It has a clock that is LOW with HIGH pulses (CPOL = 0) and propagates on the rising edge (CPHA = 1).

SurferTim:
I don't think that is a SPI mode 0 device. It appears to be a mode 1 device. It has a clock that is LOW with HIGH pulses (CPOL = 0) and propagates on the rising edge (CPHA = 1).
Serial Peripheral Interface - Wikipedia

Ohoho you are right !

May you share your experiences. What load cell did you use, where you satisfied with the resolution in the end? I'm asking because I used an ADS1115 with an insufficient gain amplifier, see Load Cell and ADS1115 as ADC, do I need an additional OpAmp (e.g. INA125P) - #3 by Clemens - Sensors - Arduino Forum - and a suggestion was the ADS1231.

I tried this code and changed

  • "result1" to "result" in "unsigned int result1 = 0;" think this was a typo
  • I also changed in "SPI.setDataMode(SPI_MODE0);" "SPI_MODE0" to "SPI_MODE1"[/li][/list] as reaction to one of this posts hiere.

But I got with a constant pressure something like this:

0<<93<<236<<127<<=60543
0<<93<<226<<255<<=58111
0<<93<<225<<255<<=57855
0<<93<<252<<127<<=64639
0<<93<<239<<255<<=61439
0<<93<<239<<255<<=61439
0<<93<<226<<255<<=58111
0<<93<<208<<255<<=53503
0<<94<<3<<255<<=1023
0<<93<<240<<255<<=61695
0<<93<<218<<255<<=56063
0<<93<<228<<255<<=58623

I don't know whats going on and how the output has to be interpreted. Can anyone explain what is there going on .

to my understanding the ADS1231 is not using the SPI standart protocol at all. In the datasheet the pulsing sequence is defined.

At the moment I'm also working on a project using the ADS1231 and therefore implemented a little library for communication with it. It is not ready for fullscale usage yet, just a beta version, but its working on all my tests and I think it may help you. An example is included.
Similar to the servo lib you can attach multiple instances of the ADS1231 (in the ADS1231.h it is limited to 6 units, but thats only an arbitrary number and can be increased with only RAM and pin limitations). Actualy the writing was basend on the servo lib XD makes live easier.

known issues:

  • not fully validated yet
  • no usage of speedpin
  • communication results in jiberish data if the communication is at the same time, a sample is finished. The output buffer of the ADS1231 changes immediatly after sample without respect to maybe running communications
  • the lib is compatible for ADS1232 and ADS1234, but dont use the input multiplexer and the gain scaling yet
  • a read process takes approx 500us at the moment. This is mainly due to the shift/or operation of the build up of read data. Maybe i find a solution to speed it up. However it already should be fast enough for most applications. Also maybe the ram usage might be improved in future.
  • ...

ADS1231_beta.zip (3.32 KB)

Wow, that was helpful! I get now really stable readings from the load cell with your code. The number of load cells is also ok for me--I need only one atm. Also reaction time is sufficient for my purpose.

In the meantime I found an other implementation for the ADS1231: A barkeeper robot: http://barwin.suuf.cc/ You can find the code under GitHub - rfjakob/barwin-arduino: Arduino code for the Barwin cocktail robot and the part for the ADS1231 under https://github.com/rfjakob/barwin-arduino/tree/master/lib/ads1231 . Unfortunately it is not a genuine implementation, it contains some stuff for the robot also. Perhaps it could help to improve your code or is at least interesting how other solved similar problems.

When someone needs advices how to wire an ADS1231 and Arduino have a look at this posting:
http://forum.arduino.cc/index.php?topic=198139.msg1567761#msg1567761

How you can find ADS1231's pin1 is shown on:
http://forum.arduino.cc/index.php?topic=213263

it appears that in your for loop you are doing 4 shifts

for (int c = 0; c <= 3; c++)

there should only be three bytes, because it is a 24 bit device

remember that for loops run zero, then 1, then 2, etc.
it should be:
for (int c = 0; c <= 2; c++)
or
for (int c = 0; c < 3; c++)

I've made this painful mistake far too many times

Hello, Could you share the code for the ads1232 with Arduino loadcell reading, I saw a post that could make reading, need to do a project and I'm having difficulty.

Tree before yours is a posting SPI Load cell chip ADS1231 - #6 by system - Networking, Protocols, and Devices - Arduino Forum with an attached lib, at the bottom, the link "ADS1231_beta.zip"

Thanks, did not see the link with the library, and taken as the binding of ads1232 with arduino? I need to put a crystal or can I use a pwm pin? :slight_smile:

There is now an adapted version for the ESP8266 also: