Go Down

Topic: printing BYTE (8bit) to serial (Read 1 time) previous topic - next topic

Lionel Lemarie

#5
Jan 11, 2007, 01:55 pm Last Edit: Jan 11, 2007, 01:55 pm by llemarie Reason: 1
How about "unsigned int" ? (as a test only).

lenox

Quote
How about "unsigned int" ? (as a test only).


(testing  :-?)

   unsigned int v = 200;
   Serial.print(v, BYTE);

I get 63  :'(  ;)

Lionel Lemarie

Ok, next suspect : the PC software.
What application do you use to read from the serial port ?

mellis

Sending 8-bit data works for me, so I don't think it's broken in general.  What's your Arduino code look like?  How are you reading it on the PC?

Here's the Processing code I'm using to dump the data I get from the serial port:

Code: [Select]

import processing.serial.*;

Serial port;

void setup()
{
 port = new Serial(this, Serial.list()[0], 9600);
}

void draw()
{
 while (port.available() > 0) {
   int val = port.read();
   println(((char) val) + " " + str(val));
 }
}


lenox

I have found the problem. In VB.net I was using SerialPort.ReadExisting(). It returns a string converting any value greater than 127 to 63.
       
Code: [Select]
Dim encoding As New System.Text.ASCIIEncoding, data() as Byte
       data = encoding.GetBytes(SerialPort.ReadExisting())


Using SerialPort.ReadBuffer with a byte array is a possible solution.

Thanks.

Go Up