If you combine the two buffervalues back into an int like I did, you would'n have to bother.
So combining the two bytes into an int:
int value = Wire.read() << 8 | Wire.read(); // combine two bytes into integer
Explore... Chat... Share...
Moderator: igrr
int value = Wire.read() << 8 | Wire.read(); // combine two bytes into integer
#include <Wire.h>
#define I2CAddressESPWifi 6
void setup()
{
Serial.begin(9600);
Wire.begin(0,2);
}
void loop()
{
Wire.beginTransmission(I2CAddressESPWifi);
Wire.write("Hello Arduino");
Wire.endTransmission();
delay(1);//Required. Not sure why!
Wire.requestFrom(I2CAddressESPWifi,10);
Serial.print("Received from Arduina:[");
while (Wire.available())
{
delay(1);
char c = Wire.read();
//int error = Wire.endTransmission(); I tried with or without this two lines but still not working
//Serial.print("error: " + error); I tried with or without this two lines but still not working
Serial.print(c);
}
Serial.println("]");
delay(500);
}
#include <Wire.h>
#define I2CAddressESPWifi 6
void setup()
{
Serial.begin(9600);
Wire.begin(I2CAddressESPWifi);
Wire.onReceive(espWifiReceiveEvent);
Wire.onRequest(espWifiRequestEvent);
}
void loop()
{
delay(1);
}
void espWifiReceiveEvent()
{
Serial.print("Received from ESP [");
while (Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
Serial.println("]");
}
void espWifiRequestEvent()
{
Wire.write("0123456789");
Serial.print("Sending to ESP:[");
Serial.print("0123456789");
Serial.println("]");
}
Received from A⸮⸮⸮⸮ٕ⸮⸮from Arduina:[]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
Received from ESP [Hello Arduino]
Sending to ESP:[0123456789]
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]