Values get cut short from esp8266 Huzzah to Teensy 3.6

Status
Not open for further replies.
Hi:D

I'm working on a project that needs to send values from my esp8266 HUZZAH to my Teensy 3.6.
I got the communication working between the two but there is a slight problem.
The values get "cut".

I send 200 and 50

But the result on the monitor of the Teensy is:

205205205205205205

How can I fix this issue?



This is the code on the Teensy:

void setup() {

Serial1.begin(115200);

}

void loop() {

// Send bytes from Teensy to computer
if ( Serial1.available() ) {
Serial.write( Serial1.read() );
analogWrite (13, Serial1.read() );
}

}

This is the code on the Esp8266 HUZZAH

void setup() {

// Setup computer to Arduino serial
Serial.begin(115200);

// Setup Arduino to ESP8266 serial
// Use baud rate 115200 during firmware update
Serial1.begin(115200);

}

void loop() {

Serial.write ("200");

delay (1000);

Serial.write ("50");

delay (1000);

}


Thank you for reading! Please comment if you have any idea that could help ;)
 
Last edited:
Update:

When I remove

analogWrite (14, Serial1.read() );

From the code it sends over the complete value like this:

502005020050200

So that is a slight improvement.
But I would like to control a led with the value. So I Tried to store the value like this:

void loop() {
char val = 0;
// Send bytes from ESP8266 to computer
if ( Serial1.available() ) {
val = Serial1.read();
Serial.write( Serial1.read() );
analogWrite (13, val);
}

Which results to this on the serial monitor:

0⸮00⸮00⸮00

What am I overlooking?
 
The value read is into a char - so it will print as a char ? Should that be uint8_t val=0; ?

Also is this intended to read Serial1 twice ? Alternate readings with Print one then analog write the other:
Code:
val = Serial1.read();
Serial.write( Serial1.read() );
analogWrite (13, val);

Or should it be:
Code:
val = Serial1.read();
[B]Serial.write( [U]val[/U] );[/B]
analogWrite (13, val);
 
Thank you that did the trick! It is now sending over the values in the correct way.
But the led is not turning on.
Any clue why that is not happening?
 
Thank you that did the trick! It is now sending over the values in the correct way.
But the led is not turning on.
Any clue why that is not happening?

teensy code:
In setup() you need to add the pinMode command to configure pin 13 as an output or the led will not work.
In loop() change Serial.write to Serial.println(to send an ASCII representation of the binary value).

esp8266 code:
Remove the double quotation marks used in the Serial.write commands(to send a binary value instead of an ASCII representation).
 
Status
Not open for further replies.
Back
Top