Hello,
I'm using an Arduino Uno to interface with a current transformer for monitoring current. It is correctly reading and printing the current values in the Serial Monitor. I am then using the Uno as a Slave Sender to pass this data to an Arduino MEGA 2560 when it requests as a Master Reader. The Serial Monitor for the Master displays completely different information than what the Serial Monitor for the Slave displays. I'm wondering if I'm not using a correct data type when sending or receiving the information. The following is my code.
Slave Sender:
void setup() {
Serial.begin(115200);
Wire.begin(8); // join i2c bus
Wire.onRequest(requestEvent); // register event
emon1.current(2, 64.3); // Current: input pin, calibration for first sensor.
emon2.current(3, 64.3); // Current: input pin, calibration for second sensor.
}
void requestEvent() {
float Irms1 = emon1.calcIrms(1480); // Calculate Irms based on first current sensor
float Irms2 = emon2.calcIrms(1480); // Calculate Irms based on second current sensor
Serial.println(Irms1);
Wire.write((byte)Irms1); // respond with current 1
Wire.write((byte)Irms2); // respond with current 2
// as expected by master
}
Master Reader (within the Void loop):
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available())
{
// slave may send less than requested
float Irms1 = Wire.read(); // receive a byte as float
float Irms2 = Wire.read();
genie.WriteObject(GENIE_OBJ_METER, 0, Irms1);
genie.WriteObject(GENIE_OBJ_METER, 1, Irms2);
Serial.println(Irms1);
I've attached images of the Serial Monitors so that you can see the current values from the Slave and the values that were read and displayed by the Master. The current values are very low because it's not reading any current right now (the sensor is going to read amperage up to 150A AC).
Thanks for any help.
Sketch_RevB_Master.ino (17.7 KB)
Sketch_RevB_Slave.ino (2.33 KB)