My Setup:
The XIAO reads a load cell with a sparkfun HX711 breakout board (load cell amplifier).
Connections: VCC to external power supply, VDD to 3V3 of the XIAO, GND to common GND, communication to XIAO pins 4 and 5. If the HX711 is recogniced, the onboard LED will blink green/blue. If not, it will become red.
XIAO is connected to an Arduino via SoftwareSerial, on XIAO pins 8 and 9. The Arduino writes the result to the serial monitor.
Power Scenario 1: USB to XIAO, external power supply to VCC on HX711 tested with 3.5...5 VDC.
Result: on my Arduino i recieve via software Serial the values from my load cell accuratly, as seen with the serial monitor. Independent of the voltage on VCC via external power supply (3.5 ... 5V).
Example output:
HX711 scale demo
Begin HX711 done
HX711 found.
Set Scale HX711 done
Tare HX711 done
Setup finished:
0.00
-0.00
0.00
0.00
Power Scenario 2: external power supply with 3.7V to BAT+/BAT- on XIAO and VCC on HX711.
Power Scenario 3: external power supply with 5V to 5V-pin on XIAO and VCC on HX711.
Result: on both scenarios, the onboard LED blinks green/blue, but on my Arduino i recieve no readable data.
Example output:
���=�=��o_����{{}ou�w}o��zuwmo�o_����oou��N_����wouow�
At the beginning a lot of characters appear, then only all second a new character as i programmed it with the non-blocking timing. And the onboard LED blinks, so the HX711 is recognised. Therefore the programm works somehow, but not fully.... which is confusing...
Here is my code of the reader:
/* Read load cell, sends data via SoftwareSerial to an Arduino */
// ======== BLE
//#include <bluefruit.h>
// ======== Serial for debug
//#include <Adafruit_TinyUSB.h>
// ======== Serial UART
#include <SoftwareSerial.h>
SoftwareSerial SUART(9, 8); // RX, TX
// ======== load cell amp
#include <HX711.h>
HX711 scale;
#define calibration_factor 12160.0
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;
const int LOADCELL_GAIN = 128;
// ======== LED
bool ledState_red = HIGH; // HIGH == LED off
bool ledState_blue = HIGH;
bool ledState_green = HIGH;
// ======== timing
long currentTime = 0; // current time in ms
long lastTime = 0; // endTime of last loop
int rate = 1000; // rate of main loop in ms
// ======== Setup
void setup() {
delay(100);
SUART.begin(9600); // Start USB SUART communication
delay(50);
// initialize the Bluetooth® Low Energy hardware
//BLE.begin();
/*while (!SUART) {
delay(10); // Wait for the USB connection
}
*/
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
ledState_blue = LOW;
digitalWrite(LED_BLUE, ledState_blue); // set red LED high
SUART.println("");
SUART.println("===");
SUART.println("HX711 scale demo");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN, LOADCELL_GAIN);
delay(250);
scale.power_up();
delay(250);
SUART.println("Begin HX711 done");
if (scale.wait_ready_timeout(1000)) {
SUART.println("HX711 found.");
} else {
ledState_red = LOW;
digitalWrite(LED_BUILTIN, ledState_red); // set red LED high
SUART.println("HX711 not found.");
} // print a raw reading from the ADC
scale.set_scale(calibration_factor);
//scale.set_scale(); // DEBUG Scale
SUART.println("Set Scale HX711 done");
scale.tare();
SUART.println("Tare HX711 done");
SUART.println("Setup finished:");
ledState_blue = LOW;
digitalWrite(LED_BLUE, ledState_blue); // set red LED high
}
// ======== Main loop
void loop() {
currentTime = millis();
if(currentTime-lastTime >= rate){
if (!scale.is_ready()) {
ledState_red = LOW;
digitalWrite(LED_BUILTIN, ledState_red); // set red LED high
}
else{
ledState_red = HIGH;
digitalWrite(LED_BUILTIN, ledState_red); // set red LED high (off)
ledState_blue = !ledState_blue;
digitalWrite(LED_BLUE, ledState_blue); // set blue LED blinking
ledState_green = !ledState_green;
digitalWrite(LED_GREEN, ledState_green); // set green LED blinking
//SUART.print("Reading: ");
float result = scale.get_units();
//long result = scale.get_units(10); // DEBUG scale
SUART.println(result);
//SUART.println(" N");
}
lastTime = millis();
}
}
And this would be my receiver on an Arduino UNO:
#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = 2, STX = 3
void setup() {
Serial.begin(9600);
SUART.begin(9600);
Serial.println();
Serial.println("==============");
Serial.println("Setup finished");
}
void loop(){
byte n = SUART.available();
if (n != 0)
{
char ch = SUART.read();
Serial.print(ch);
}
}