Serial.print()

Just wondering how one sends a hex value of oxAF out the serial port using the Serial.print() function? In Vbscript there is a statment chr(&hA0). What would be the equivalent statement for sending this data out the serial port using Serial.print() function? Thanks much.

I believe the proper syntax it Serial.write().

int x = 1234; Serial.println(x, HEX);

See - http://arduino.cc/en/Serial/Print -

Hi!

I am using VR-module that needs HEX input to control functions. Problem is that I also need to simultaneously debug with serial interface. NewSoftSerial doesn't support .write, at least I couldn't make it work? Am I wrong? I hope so, because I can't use Arduino Mega with this project.

Cheers, Kari

can you give an example of a hex input value?

is it a string or an int type?

Yes of course!

Setup part from code, with the normal serial.write:

void setup()
{
Serial.begin(9600);
  Serial.write(0xAA);
  Serial.write(0x37);

  Serial.write(0xAA);
  Serial.write(0x21);
}

Commands are send in pairs of “head” (0xAA) and “key” (0X37=compact mode and 0X21=Import group 1 and be ready for voice instruction).

Quite simple actually.

Cheers,
Kari

OK I understand what you meant, specify an integer value in hexadecimal notation.

Problem is that I also need to simultaneously debug with serial interface.

Check NewSoftSerial (0.22) or SOftSerial (1.0) IT provides you with an extra serial port, and if you only need a TX (transmit/write) line you can define the RX as -1 and vice versa.

Thanks Rob! I'll try that tomorrow, and I'll be back to tell how it went!

Cheers, Kari