I am creating a project to monitor 24 batteries used in a solar array. I built a simple test with a Pro Mini master and a Micro slave using I2C. Sensors will be attached to the Micro and all processing, reporting and data storage will occur in the Pro Mini. (I will be adding additional SRAM to the mini to accomplish this.)
I can get the master and slave to talk to each other, but in this simple test, the receive bytes differ from the send bytes. For example, the slave send byte of tempA0 is 87 but the master receive byte is 96 and the send byte of voltA6 is 12 (1.2 volts x 10 to convert to an integer) but the receive byte is 15.
Am I missing something with the timing of the send/receive? I've poured over the internet and I can't find anything related to this.
I'm using pins D18 (SDA) and D19 (SLC) on the Pro Mini and pins D2 (SDA) and D3 (SLC) on the Micro. There is common ground and for this test, I am powering the Micro using VCC from the Pro Mini. They are both 5 volt boards.
The Master sketch on the Pro Mini is:
#include <Wire.h>
void setup(){
Serial.begin(9600);
Wire.begin();
}
void loop() {
Wire.requestFrom(1,2);
int recTempA0 = Wire.read();
int recVoltA6 = Wire.read();
Serial.println(recTempA0);
Serial.println(recVoltA6);
delay(500);
}
The Slave sketch on the Micro is:
#include <Wire.h>
void setup() {
Serial.begin(9600);
pinMode(18, INPUT);
pinMode(4,INPUT);
digitalWrite(A0, LOW);
digitalWrite(A6, LOW);
Wire.begin(1);
Wire.onRequest(requestEvent);
}
void loop()
{
delay(100);
}
void requestEvent() {
byte tempA0 = analogRead(A0) * .4888;
byte voltA6 = analogRead(A6) * .0049 * 10;
Wire.write(tempA0);
delay(100);
Wire.write(voltA6);
delay(100);
Serial.println(tempA0);
Serial.println(voltA6);
}