Created Tue, 30 Dec 2014 23:15:14 +0000 by 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() > 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:
Late enough here in europe. My wife is complaining I should go to sleep. So until tomorrow ;)
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.
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)
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.
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)