send int-var with Serial1.write()

Status
Not open for further replies.

AdmiralCrunch

Well-known member
Hi

I somehow have serious trouble sending vars through serial between my Teensy and Raspi.

(I want to send strings like: "myVar:1;")

Code:
  int i = 2;
  Serial1.write("myVar:");
  Serial1.write(i);
  Serial1.write(";");

.. doing this, I recieve "myVar:;" on the other Teensy.


in the docs there is:
Serial.write(val);
val: a value to send as a single byte
so I tried
Code:
  byte = 2;
  Serial1.write("myVar:");
  Serial1.write(i);
  Serial1.write(";");
.. but with same results.

how can I send my vars through Serial?
 
The correct way to do this is:
Code:
int i = 2;
Serial1.print("myVar:");
Serial1.print(i);
Serial1.print(";");

Marc
 
Status
Not open for further replies.
Back
Top