Issue with interference from Serial Connection

Hi all - I’m experiening a really strange thing that is slightly confusing me.

I have two load cell chips connected to a photon - I’m reading Load Cell data from them via an HX711 library (which seems to just bit bang the data in) over pins D2 & D3.

Thing is - they read perfectly stable over my web interface but as soon as I plug in a USB cable to read serial debug data from the photon, the Load Cell data goes completely haywire and jumps all over the place.

Has anyone experienced interference like this?

I have even tested it with printing no serial data over the usb wire and just having it plugged in - same behaviour.

How do you power the device while not connected via USB?

Have you got a common GND rail?

Code or link to your lib might help too.

2 Likes

I have a 12V PSU running through an off the shelf Vreg circuit which powers the photon - the GND rail is common.

The chip’s library reads the info from the chip as follows:

// pulse the clock pin 24 times to read the data
for (byte j = 3; j--;) {
	for (char i = 8; i--;) {
		digitalWrite(PD_SCK, HIGH);
		bitWrite(data[j], i, digitalRead(DOUT));
		digitalWrite(PD_SCK, LOW);
	}
}

@mhazley, we need to see more of your code, especially the front end and setup().

1 Like

Basically, I create a LoadCell class that uses the HX711 library.

void setup() {
  Serial.begin(115200);
  loadCells[LOAD_A] = new LoadCell( LOAD_A, D3, D2 )
}

The constructor looks like this

LoadCell::LoadCell(LoadCellRole role, int clockPin, int dataPin ) {
  this->role = role;
  this->clockPin = clockPin;
  this->dataPin = dataPin;

  this->chip = new HX711(this->dataPin, this->clockPin);
};

Then it uses the for loop I have noted above to read the chip on the HX711 board.

@mhazley, can you provide a link to the HX711 library you are using? We really need to see more to be able to help.

I’ve copied the Library I am using here (in my code above I have simplified it a bit as I was trying to ease explanation):

Apologies for being so vague before - theres is loads of the library I am not using so was trying to pin it down to the code I was using for ease of explanation.

@mhazley, I don’t see anything obvious but…

  1. There is a strange mix of int, byte and char var types sprinkled throughout IMO. Cleaning up var types to match required size, etc. would be good.

  2. In HX711.h, there is:

#else
  #include "spark_wiring.h"
  #include "spark_wiring_usbserial.h"
#endif

This should be replaced with #include application.h

One concern I have is in the read() function which was obviously written for Arduino:

	// wait for the chip to become ready
	while (!is_ready());

If you are wifi or cloud connected, the while could stall the connection. You would adjust as follows:

long HX711::read() {
	// wait for the chip to become ready
	while (!is_ready()) Spark.process();

Give those changes a go. I am still not sure why you get Serial interference but it’s a start.

3 Likes

Thanks for your help - I will try and get these in during the next few days to start with.

1 Like

Sounds like a grounding issue rather than firmware.

You could be forming a ground loop somewhere, which causes noise on hi-Z measurement inputs.

You could have a floating 12V PSU, but a earth grounded computer, futzing things up.

Easy way to test is with a laptop, try unplugging everything from it (monitor, power, any other devices) so it’s floating and then plug in the serial cable and see if it persists.

2 Likes