chipKIT® Development Platform

Inspired by Arduino™

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

Created Tue, 30 Dec 2014 23:15:14 +0000 by Becherraecher


Becherraecher

Tue, 30 Dec 2014 23:15:14 +0000

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:

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:

void loop() {
  char data;
  digitalWrite(PIN_LED1, LOW);
 
  if (Serial1.available() &gt; 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

Wed, 31 Dec 2014 01:06:02 +0000

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

Wed, 31 Dec 2014 10:23:31 +0000

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

Wed, 31 Dec 2014 14:24:59 +0000

Here is an example of what is happening: board 1

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

board 2

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

Fri, 13 Mar 2015 08:14:48 +0000

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)