I'm trying to communicate between a Teensy and an ESP8266 12-E chip.
I've connected the RX/TX from the Teensy to the TX/RX of the ESP8266, like parts of my schematic above describes.
Then I connect the Teensy to my computer using USB. I'm able to send serial data between the PC and the Teensy, and the data looks ok. Then I'm trying to pass the data from the Teensy to the ESP8266, and pass the returned data from the ESP8266 back to the computer. The ESP8266 responds when I send data to it, but the data just looks like gibberish.
Here is the code I'm using:
/*
* Testing the ESP-12E
* Serial data is sent from Arduino Serial Monitor, to the Teensy, and then to ESP-12.
* PC -> Teensy -> ES8266
* ESP8266 pin 22 is connected to Teensy pin 9
* ESP8266 pin 21 is connected to Teensy pin 10
*/
#define USB Serial
#define WIFI Serial2
int espEnablePin = 8;
void setup ()
{
pinMode(espEnablePin, OUTPUT);
delay(500);
digitalWrite(espEnablePin, HIGH);
USB.begin(9600);
WIFI.begin(9600);
}
void loop()
{
int incomingByte;
//Data coming from Arduino Serial Monitor to the Teensy. All data is just passed to the ESP-12.
if (USB.available() > 0)
{
incomingByte = USB.read();
WIFI.write(incomingByte + "\r\n");
//USB.write(incomingByte+"\r\n"); //to echo what I sent
}
//Data received from the ESP-12.
if (WIFI.available() > 0)
{
incomingByte = WIFI.read();
USB.write(incomingByte+"\r\n");
}
}
Can anyone see what I'm doing wrong?