printing BYTE (8bit) to serial

When I use print.serial(data, BYTE), data has to be smaller than 127 (7 bits)
Can I send a 8bits data using serial port?

Thanks in advance

As far as I can tell (without my hardware right now, but looking at runtime code), I see no reason why Serial.print(x,BYTE) should limit you to 7 bits... 8 bits should work just fine.

As far as I can tell (without my hardware right now, but looking at runtime code), I see no reason why Serial.print(x,BYTE) should limit you to 7 bits... 8 bits should work just fine.

I tried to use Serial.print(x, BYTE) with x>127 and I got 63 in the PC port (?) :cry:
By code, it's possible to convert a 8bit value in two 7bit values but It would easier send a 8bit value.

byte x=150, x0, x1;
x0 = x & 127;
x1 = (x >>7) & 1;
Serial.print(x0, BYTE);
Serial.print(x1, BYTE);

I would like to send a byte without making this conversion.

Is byte signed ? Can you try "unsigned byte x" ?

Is byte signed ? Can you try "unsigned byte x" ?

ops it doesn't work :-/. I can't define a unsigned byte but:

unsigned char x = 200;
Serial.print(x, BYTE);
prints 63

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

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

(testing :-?)

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

I get 63 :cry: :wink:

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

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:

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));
  }
}

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.

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.