Go Down

Topic: Serial.print() (Read 1 time) previous topic - next topic

rbonari

Sep 11, 2011, 10:04 pm Last Edit: Sep 11, 2011, 10:58 pm by rbonari Reason: 1
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.

billcramer07

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

robtillaart


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

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

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

GaryP

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
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

robtillaart

can you give an example of a hex input value?

is it a string or an int type?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

GaryP

Yes of course!

Setup part from code, with the normal serial.write:
Code: [Select]

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
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

robtillaart


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

Quote
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.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

GaryP

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

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy