Serial Fubarino SD <-> Arduino: dec output instead of ASCII

Post Reply
Becherraecher
Posts: 6
Joined: Tue Dec 30, 2014 2:09 pm

Serial Fubarino SD <-> Arduino: dec output instead of ASCII

Post by Becherraecher » Wed Dec 31, 2014 12:15 am

Hi

second 'problem' I encounter with the Fubarino SD.

I have programmed an Arduino to output a loop of chars from '0' to '9', one char every second with a serial.print() over and over again.
As simple as this:

Code: Select all

void loop() {
  Serial.print(count);
  delay(1000);        
  count++;
  
  if(count == 10){
    count = 0;
  }
}
Fubarino is connected to RX/TX of Arduino with pins 28/29 (Serial1 RX/TX, because 5V tolerant).
The code I use at Fubarino side is:

Code: Select all

void loop() {
  char data;
  digitalWrite(PIN_LED1, LOW);
 
  if (Serial1.available() > 0){
     data = Serial1.read();
     digitalWrite(PIN_LED1, HIGH);
     Serial.println(data);

     delayMicroseconds (100);
  }
}
Fubarino recieves data, blinks LED shortly and puts recieved data from Serial1 to Serial (USB-Port). So long so good.

The 'problem' I can't get rid off is:
Arduino is sending ASCII chars and Fubarino is putting the recieved data as DEC interpretation to the serial console. So a '0'-ASCII from Arduino is printed as '48'-DEC by Fubarino to serial console. (or as '49', '50', ... and so on with the other ASCII-numbers)

I'm using the Arduino IDE serial console for reception of Fubarino output because MPIDE consoel is crashing with java errors.

Any hint what is going wrong?
Thanks for any help.

My best guesses at the moment:
1. Arduino serial console is interpreting something wrong
2. My Fubarino code conversion from Serial1 to Serial is not correct
3. Arduino needs a 'serial.flush()' or a 'serial.println()', because I recognized this very moment the TX-Led on Arduino is permanently on for one second and shortly changing to off every second.

Late enough here in europe. My wife is complaining I should go to sleep.
So until tomorrow ;)

mikes
Posts: 74
Joined: Mon May 14, 2012 10:37 pm

Re: Serial Fubarino SD <-> Arduino: dec output instead of AS

Post by mikes » Wed Dec 31, 2014 2:06 am

Code: Select all

     Serial.write(data);
     Serial.print("\r\n");
On the Fubarino try replacing print with write. Write does not interpret the data is just sends it.

Becherraecher
Posts: 6
Joined: Tue Dec 30, 2014 2:09 pm

Re: Serial Fubarino SD <-> Arduino: dec output instead of AS

Post by Becherraecher » Wed Dec 31, 2014 11:23 am

Hi

working. Thank you.

But at the moment I don't get why it is working.

In the documentation of the (Arduino) serial library there is mentioned that "print" always puts out ASCII and "write" puts out binary (Link)

mikes
Posts: 74
Joined: Mon May 14, 2012 10:37 pm

Re: Serial Fubarino SD <-> Arduino: dec output instead of AS

Post by mikes » Wed Dec 31, 2014 3:24 pm

Here is an example of what is happening:
board 1

Code: Select all

Count = 9;
Serial.print(count); //sends 0x39 (ASCII value for 9) out the Serial port
board 2

Code: Select all

data = Serial1.read(); //recieves 0x39 from serial port
Serial.print(data); //sends 0x35 0x37 (ASCII value for 0x39 in decimal) out the Serial port
Serial.write(data); //sends 0x39 out the Serial port
The problem is that the data is converted to ASCII from a number twice.

Xumerlove
Posts: 1
Joined: Tue Feb 03, 2015 8:33 am

Re: Serial Fubarino SD <-> Arduino: dec output instead of AS

Post by Xumerlove » Fri Mar 13, 2015 9:14 am

Arduino is sending ASCII chars and Fubarino is putting the recieved data as DEC interpretation to the serial console. So a '0'-ASCII from Arduino is printed as '48'-DEC by Fubarino to serial console. (or as '49', '50', ... and so on with the other ASCII-numbers)
Sumer

Post Reply