I'm a beginner, I have this script to send and receive Hex from a hardware device. The reply that I've receive is in Hex but doesn't print the leading zero. For example it should print E2 00 00 16 60 10 02 27 18 20 5A 76 but it just printed E2 0 0 16 60 10 2 27 18 20 5A 76
Can someone help me?Thanks
#include "Arduino.h"
//#define DEBUG
unsigned char incomingByte;
void sendIdentifyCmd ()
{
Serial1.write (0xbb);
Serial1.write (0x00);
Serial1.write (0x22);
Serial1.write (0x00);
Serial1.write (0x00);
Serial1.write (0x22);
Serial1.write (0x7e);
#ifdef DEBUG
Serial.print (0xbb);
Serial.print (0x00);
Serial.print (0x22);
Serial.print (0x00);
Serial.print (0x00);
Serial.print (0x22);
Serial.print (0x7e);
Serial.println ();
#endif
}
void setup ()
{
Serial.begin (115200);
Serial1.begin (115200);
Serial.println ("begin initial Serial!\n");
}
void loop ()
{
sendIdentifyCmd ();
delay (2);
while(Serial1.available () > 0)
{
incomingByte=Serial1.read ();
Serial.print (incomingByte,HEX);
Serial.print (' ');
}
Serial.println ();
delay (1000);
}