Pages: [1]   Go Down
Author Topic: Serial.print()  (Read 1565 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: September 11, 2011, 03:58:39 pm by rbonari » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 47
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

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

Rob Tillaart

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

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can you give an example of a hex input value?

is it a string or an int type?
Logged

Rob Tillaart

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

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes of course!

Setup part from code, with the normal serial.write:
Code:
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
Logged


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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.

Logged

Rob Tillaart

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

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cheers,
Kari
Logged


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

Pages: [1]   Go Up
Jump to: