Long time programmer but super new to microcontroller programming.
I’ve copied/created an Arduino sketch that interfaces with a HX711 for weight measurement. Everything works perfectly when I use an Arduino Uno with the code. However, when I upload the code to the XIAO nRF52840 I must unplug and re-plug then DAT pin (pin 3) before data will flow to the Arduino Serial Monitor. Symptoms are the same each time the USB cable is unplugging and re-plugging.
I tried combinations of changing the pin 3 pin mode as well as setting it to low or high. Other than changing pin mode to OUTPUT, which stops everything from ever working, no other combination seemed to have any effect.
I’m out of ideas. Please help!
COMPLETE CODE BELOW
#include “Adafruit_TinyUSB.h”
#include “HX711.h”
// This assumes the following connections have been made
// Amplifier Board DAT = Arduino digital pin 3
// Amplifier Board CLK = Arduino digital pin 2
HX711 scale(3, 2);
float force = 0;
#define calibration_factor -3500
unsigned long previousMillis = 0; // will store last time the serial output was updated
const long interval = 1;
void setup() {
Serial.begin(57600);
scale.set_scale(calibration_factor);
scale.tare(); //Zero the load cell - this is important to remove factors such as drift or when starting with something on the load cell
//ATTEMPTED FIXES
pinMode(3, OUTPUT);//OUTPUT ONLY NEVER WORKS
pinMode(3, INPUT);//OUTPUT THEN INPUT STILL REQUIRES UNPLUG REPLUG
digitalWrite(3,LOW);//LOW ONLY NO CHANGE, LOW THEN HI NO CHANGE
digitalWrite(3,HIGH);//HIGH ONLY NO CHANGE
}
void loop() {
force = scale.get_units();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.println(force);
}
}