In the last days, i have ventured into i2c.
I used two Arduino UNO (master and slave), two load cells and one hx711 connected to the arduino slave. The information read by the slave is sent by i2c to the master. Finally, the master Arduino displays the received data.
LOAD CELL -> HX711 -> SLAVE ARDUINO -> (I2C) -> Arduino Master -> (Serial.println)
Overall, what i did seems to work fine. However, when i reset the slave, the data received by the master arrives modified. For example: If the master receives the value 0.00kg, and soon after i reset the slave, the master will display unrealistic values: 767284.00kg, 717223.00kg, 7321312.00kg ...
Why does this happen? i already researched and couldn't reach big conclusions ...
Master code:
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
delay(3000);
}
void loop() {
Wire.requestFrom(8, 10);
while(Wire.available()){
Serial.print((char)Wire.read());
}
Serial.println();
delay(10);
}
Slave code:
#include <HX711.h>
#include <Wire.h>
HX711 left_knee; //DOUT, CLK
float calibration_factor_left_knee = 2033.25; // this calibration factor is adjusted according to my load cell
String out;
float units;
void setup() {
Wire.begin(8);
Wire.onRequest(requestEvent);
left_knee.begin(2,3);
left_knee.tare(); // Tara a balança
left_knee.set_scale(calibration_factor_left_knee); // Ajusta fator de calibração
}
void loop() {
delay(100);
}
void requestEvent() {
out = "";
units = left_knee.get_units();
out = data();
Wire.write(out.c_str(),out.length());
}
float data(){
if (units < 0)
{
units = 0.00;
}
return (units);
}
btw, the communication only returns to normal when the master is rebooted.
Thanks in advance