#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 ?
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
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.
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.
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.