Hey guys,
I am trying to build a wifi weighing scale. I have connected a HX711 sensor to arduino and able to get the values. I also had it displayed to a lcd from arduino. For wifi part, I am using ESP8266-12
Now, I am trying to send the weight value from the arduino to the ESP for transmission to android app and a web client. I initially tried using I2C with arduino master and esp8266 slave. But it seems esp does not support slave mode as of now. When esp is the master, and arduino as slave, the setup works.
But basically I want arduino to send weight data only when there are any readings. But since a slave cannot initiate a data transfer, I cant use this.
So, I tried setting them both as masters, assigning each an address. For testing, I uploaded a sketch on arduino which will send send a text and an integer continuously. The esp has to just receive it and print it on serial monitor. the leds connected to gpios 4 and 5(sda and scl) blink continuouslY(I have a test board, which has leds conneced to the gpios). But i dont receive anything on serial monitor. Here are my codes:
For Arduino:
#define ard 0x01// this sketch is for arduino
#define esp 0x02
#include<Wire.h>
void setup() {
Wire.begin(ard); // join i2c bus (address optional for master)
Wire.onReceive(receiveESP);
}
byte x = 0;
void loop() {
Wire.beginTransmission(esp); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
}
void receiveESP(int howMany)
{
while(Wire.available()>0)
{char c = Wire.read();
Serial.print(c);}
Serial.println();
}
Code for ESP:
#include<Wire.h>
#define esp 0x01// this sketch is for esp
#define ard 0x02
void setup() {
Serial.begin(9600);
Wire.begin(esp); // join i2c bus (address optional for master)
Wire.onReceive(receiveARD);
}
void loop() {
}
void receiveARD(int howMany) {
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(); // receive byte as an integer
Serial.println(x); // print the integer
}
And ya, while the arduino is powered by usb, I have connected the esp to a usb-serial adapter pl2303. I tried opening the serial monitor to that com port. But I dont have any output.
Pls help me out!
Thanks in advance