Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Erni
#32381 If the number is less than 255 buffer[0] Will be 0 and buffer[1] wil be the number.
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:

Code: Select allint value = Wire.read() << 8 | Wire.read(); // combine two bytes into integer
User avatar
By bogdanioanliviu
#32469 Hy
Thank you for all you're help . I finally got it working correctly .
The problem was that i was trying to send receivedValue instead of saving the returned value and send that one.
I have to clean up the code for the esp and i will post it for everybody.
I have to test as well with a real sensor connected to the arduino.
Thank you
User avatar
By zmajkoo
#78942 Hello guys!

I have problem with I2C (esp8266 - 01 master and Arduino UNO slave).
Arduino send data to esp and its displayed on Serial, but when i tried to send data from esp to Arduino it wont work, from my perspective it looks like loop in ESP's code isn't working... Esp prints once "Hello Arduino" and nothing after that just code from Arduino.

Here is my ESP8266 01 Master code:

Code: Select all#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);
}


Here is my Arudino UNO Slave code:
Code: Select all#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("]");
}


This is my Serial Monitor, but I have one note... I use only one USB cable so i have to switch wires after uploading code to ESP, keeping that on mind the first line is printed while wire aren't connected properly.
Serial Monitor print:
Code: Select allReceived 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]