Pages: [1]   Go Down
Author Topic: Arduino pro Mini char compare problem  (Read 391 times)
0 Members and 1 Guest are viewing this topic.
Paris, France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone!
I am currently running into a weird problem with a sketch:
* basically i am sending commands all ending with a newline for end of command("\n") from a python script. 
* The newline on the arduino side (whether using the ascii code or simple character compare) is reckognized correctly  on all my other Arduinos except on the Arduino Pro Mini (8mhz, 3.3V)
* Here is the relevant part of the code:
Code:
void loop()
{
while(Serial.available()>0)
  {
    uint8_t c=Serial.read();

    if((c == 10) || (c == 13))
    {
      parse_command(commandBuffer,commandIndex);
      for (int i=0;i<commandIndex;i++)
      {
        commandBuffer[i]=' ';
      }
      commandIndex=0;
    }
    else
    {
      commandBuffer[commandIndex]=c;
      commandIndex++;
    }
  }
}

I am completely baffled by what is going on so if anyone has an idea, i would be very glad !
Thanks in advance!
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46249
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, the return type for Serial.read() is int, not uint8_t.

How do you KNOW that the CR/LF are not being recognized?

If the baud rate on the PC is 9600, and the baud rate on the 8MHz mini is also 9600, they do not match. The baud rate setting on the PC assumes a 16MHz processor on the other end.
Logged

Paris, France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Paul , thanks for the quick reply!
* you are right about the uint8_t, it was an attempts to check if the problem was present with different datatypes , i forgot to cast it (i have trying doing the compare with char & ints before, with casting etc to no avail)
*i know it is not being recognized since it never goes to the part where it parses the command, after some debugging i have tried sending back all the individual elements given by Serial.read(), and all the characters are ok except for the newline (which is recognized as a garbage character ("à") to be more precise
* wow i didn't think of the clock speed having any influence on the serial coms ! that seems kinda weird, i thought it was completely separate ...if it is the case i am in for a whole lot of other problems... but i will give that a try, thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Having different clock rates should not cause a huge problem. Just put double the baud rate in the Serial.begin(BAUDRATE) in setup, or however much it needs to be for 8Mhz compared to 16Mhz. Roughly half, but I'd calculate it completely as I know that it isn't exactly 16Mhz.
Logged

Pages: [1]   Go Up
Jump to: