Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Arduino serial problems

  1. #1
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Question Arduino serial problems

    My arduino is freaking out! I have a basic program that prints the serial value it receives. It worked fine until a while ago when it started doing this. Here is my code.

    Code:
    int incomingByte = 0;    // for incoming serial data
    
    void setup() {
        Serial.begin(9600);    // opens serial port, sets data rate to 9600 bps
    }
    
    void loop() {
    
        // send data only when you receive data:
        if (Serial.available() > 0) {
            // read the incoming byte:
            incomingByte = Serial.read();
    
            // say what you got:
            Serial.print("I received: ");
            Serial.println(incomingByte);
        }
    }
    If input a 1 in it should show 1 right?

    Well it instead it says:

    I received: 49

    For the letter A it says:

    I received: 69

    Can anyone help?
    Dalton Caughell

  2. #2
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: Arduino serial problems

    I checked and my baud rate is set to 9600 so its not a baud rate problem.
    Dalton Caughell

  3. #3
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Arduino serial problems

    I think you'll find for the letter A it's displaying "65" not "69".

    I suspect the code you're showing us is not the code compiled and running on the device. You actually have a byte cast in there somewhere.

    65 Dec. is ASCII A
    49 Dec. is ASCII 1
    I Void Warranties�

  4. #4
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: Arduino serial problems

    Ya its 65. No way I know its the code I have running. I just copied it from this page and tried it with the same results. Could it be a setting I changed?
    Dalton Caughell

  5. #5
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    127

    Re: Arduino serial problems

    Wait, so when you send A it says 65?

    If so, nothing is wrong. You sent an ASCII 1 (which is decimal 49). If you want it to say 1, you have to send decimal 1, your terminal should have something like a "send hex" mode.... use that.

    -Fergs

  6. #6
    Join Date
    Apr 2009
    Location
    Brisbane, Australia
    Posts
    48
    Rep Power
    36

    Re: Arduino serial problems

    Yeah. Arduino IDE sends ASCII in serial mode. I'm sure there's a setting somewhere to change it. Or you can just compensate for ASCII instead.

  7. #7
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Arduino serial problems

    Good catch - I didn't realize he was sending with the IDE. If you type as Byte you'll get ASCII on the device (which is handy if you're talking to an LCD). If you type as char or int, then you get what you expect. That's how I talk to the SSC32 across the XBee link from the Arduino
    I Void Warranties�

  8. #8
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: Arduino serial problems

    OK problem solved all I have to do is convert with the BYTE command. How to implement this into my code is still a mystery. I don't know why it automatically converts to ACSII now but if anyone can find out how to fix it it would be nice.
    Dalton Caughell

  9. #9
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Arduino serial problems

    Actually - the BYTE data type will spit ascii encoded data out. You want to convert to an int, char, or similar.

    But, really, why not just process the ASCII-armored byte? That's probably more robust anyway.
    I Void Warranties�

  10. #10
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: Arduino serial problems

    Ya I think your right.
    Dalton Caughell

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. "ALMower" [was: Robotic Lawn Mower]
    By revoltage in forum Robotics General Discussion
    Replies: 363
    Last Post: 07-19-2009, 08:06 AM
  2. Kondo web page translated.
    By Droid Works in forum Humanoids, Walkers & Crawlers
    Replies: 4
    Last Post: 10-06-2007, 05:49 PM

Posting Permissions

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