SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By shmulik
#199277
Hello

I'm trying to use both your products SX1509 Expander Breakout and HX711 Load cell amplifier.
My purpose is to read from several Load cells using the SX1509.
This is my hookup for 1 amplifier:
The connection is very simple:
arduino____SX1509____HX711
SCL------------SCL
SDA -----------SDA
GND---------- GND---------- GND
3.3V-----------3v3----------- VDD
5V------------------------------VCC
----------------- 0------------- CLK
----------------- 1------------- DAT

Image

For Start, from your HX711.cpp liabrory i took the read function, and placed it into arduino code, to see if this is the only function that i need to read RAW data from the HX711, and it was right.
After finding the calibration factor and the offset i could translate the RAW data to real force/weight.

Then i adjusted it alittle bit and added it to your SX1509.cpp lieberary:
(ofcurse i declared on this function in the header file - SX1509.h)
long SX1509::read_my(byte DOUT, byte PD_SCK)
Code: Select all
long SX1509::read_my(byte DOUT, byte PD_SCK) {
	// byte DOUT = 1;
	// byte PD_SCK = 0;
	byte GAIN = 1;

	unsigned long value = 0;
	uint8_t data[3] = { 0 };
	uint8_t filler = 0x00;

	// pulse the clock pin 24 times to read the data
	data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
	data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
	data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);

	// set the channel and the gain factor for the next reading using the clock pin
	for (unsigned int i = 0; i < GAIN; i++) {
		digitalWrite(PD_SCK, HIGH);
		digitalWrite(PD_SCK, LOW);
	}

	// Replicate the most significant bit to pad out a 32-bit signed integer
	if (data[2] & 0x80) {
		filler = 0xFF;
	} else {
		filler = 0x00;
	}

	// Construct a 32-bit signed integer
	value = ( static_cast<unsigned long>(filler) << 24
			| static_cast<unsigned long>(data[2]) << 16
			| static_cast<unsigned long>(data[1]) << 8
			| static_cast<unsigned long>(data[0]) );

	return static_cast<long>(value);
}
Then i tried to use it like that:
Code: Select all
#include <Wire.h> // Include the I2C library (required)
#include <SparkFunSX1509.h> // Include SX1509 library
#define SX1509_Data 1
#define SX1509_CSK 0

const byte SX1509_ADDRESS = 0x3E;  // SX1509 I2C address
SX1509 io; // Create an SX1509 object to be used throughout

void setup(){
  Serial.begin(38400);
  delay(10);
  
  if (!io.begin(SX1509_ADDRESS))
    Serial.println("Failed to communicate.");
  else
    Serial.println("SX1509 Alive");
  delay(10);
  io.pinMode(SX1509_Data, INPUT);
  io.pinMode(SX1509_CSK,  OUTPUT);
  Serial.println("Starting:");
}

void loop() {
  Serial.print("Reading: ");
  long t1 = io.read_my(SX1509_Data, SX1509_CSK);
  Serial.println(t1);
  
  delay(100);
}
Unfortunately the result that i'm getting is very different form the first attempt. And the values are jumping from 1 value to another, and it seems to be constant no matter what force i apply on the load cell.

I would appreciate if you could help me with that
Thanks
You do not have the required permissions to view the files attached to this post.
By Valen
#199388
No need to post 2 same/similar questions in the same forum. It confuses the discussion if it is in multiple places.

Remove one thread, and post an example of the readout values in the other. I'm guessing you just receive gibberish because you are not properly bit-banging the HX711 pins with the SX1509. In actuallity sending the stream out on arduino pins D0 and D1 instead of using the commands to set the SX1509 pins 0 and 1 to high or low (in the right order).

Temporarily remove the Serial.println statements in your loop and upload the code to the arduino. Once executed do the RX and TX led still blink and still receiving gibberish in the serial monitor? If so, then this is confirmed. Just copying and pasting a function into it is not going to make this work. The code needs to mesh/integrate.
By n1ist
#199391
The HX711 is an SPI device. To talk to it, you need to need to wait for DOUT to go low, then clock it 24 times, reading DOUT each time and assembling the answer. When you connect it to the Arduino directly, you are using the Arduino's SPI logic to do the clocking 8 bits at a time behind the scenes, so you do three 8-bit reads and build the response.

Instead of using the Arduino's SPI port to talk to the HX711, you are now using its I2C port to talk to the SX1509, and will need to manually bit-bang GPIO 0 and 1 on the SX1509 to clock the data out of the HX711. The SX1509 has commands to configure the GPIO as input (DOUT) and output (PD_SCK), to read DOUT, and to set PD_SCK hi and low. In this configuration, you can not use shiftIn and digitalWrite to talk to the HX711, since it is not connected to the Arduino itself.

/mike