SPI Load cell chip ADS1231


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() {
  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);
      result = result | inByte;

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

0+175+159+127+=40831 <== Problem !

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.


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). http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

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). http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

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 http://forum.arduino.cc/index.php?topic=198139.msg1465975 - 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:


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 https://github.com/rfjakob/barwin-arduino 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++)
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 http://forum.arduino.cc/index.php?PHPSESSID=in4288musvqk1nlak50vnu8bk5&topic=131086.msg1570340#msg1570340 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? :)

There is now an adapted version for the ESP8266 also: https://github.com/hiveeyes/arduino/tree/master/libraries/ADS1231