I try to send temperature data form the Arduino pro mini to the Arduino UNO.But lose a lot data but the first .
I think the i2c work like a multi-threading .So,I do this code.But How I could send a data easy???
The temperature it a double number,I couldn't recevie the data formally.
#include <Wire.h>
int test[]={};
int i=0;
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(400);
Serial.println("fd");
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int h)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x=Wire.read();
Serial.println(x);
delay(100);
}
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
double z=15.52;
int t=(int)z;
int y;
y=(z-t)*100;
byte ts=14;
delay(500);
Wire.beginTransmission(4); // transmit to device #4
Wire.write(y);
Wire.endTransmission(); // stop transmitting
delay(500);
Wire.beginTransmission(4); // transmit to device #4
Wire.write(t);
Wire.endTransmission(); // stop transmitting
delay(500);
Wire.beginTransmission(4); // transmit to device #4
Wire.write(ts);
Wire.endTransmission(); // stop transmitting
}