Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Serial.write Teensyduino question.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    3

    Serial.write Teensyduino question.

    Serial.print seems to work for me, but Serial.write doesn't.

    Teensyduino 1.16 on a Mac.

    Should this work?

    Code:
    void setup(){
        Serial.begin(9600);
    }
    
    
    void loop(){
      byte controlByte = B00000001;
      Serial.println("hello:");
      Serial.write( controlByte);
      delay(500);  
    }

    I get:

    Code:
    hello:
    hello:
    hello:
    
    in my Serial monitor
    Am I doing something wrong?

  2. #2
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    419
    Serial.write(1) sends the binary value 1, this is a nonprinting character.
    Serial.print(1) converts the number 1 to its text representation "1", ascii character for 1,
    and send this as a byte with numerical value 49.

    So your code is doing what is supposed to, the binary value 1 is not shown in your text window.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks for the info!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •