How to send Hexadecimal to a UART communication device

Hello. I have a question here. how i'm gonna send hexadecimal value to serial UART devices. i'm done a little bit study. the hex value can be send by using serial write like example below.

Serial.write(0x10); <----right (HEX)

but how about 0x10, 0x27, 0x08, 0x00, 0xA0, 0x10, 0xB4, 0xA3
Where last bit is a checksum of D1 to D7.
The problem is I need to send this data packet with 10mSec delay between each Data byte from D1 to D8 and packet to packet atleast 55 to 65 mSec delay should be required. As shown in the image.

if i manage to send this type of data to my serial device, i can do lots more things with that.
Please help.
Thank you!
Regards,
Jatin Srivastav

Keep in mind that you are sending binary values to the device. "Hexadecimal" is a human readable representation of binary values.

but how about 0x10, 0x27, 0x08, 0x00, 0xA0, 0x10, 0xB4, 0xA3

char values[] = {0x10, 0x27, ...
Serial.write(values, sizeof(values));

Edit: the above won't work if you need a delay between individual bytes.

Simply

Send a character, delay 10 ms. 8 times with a loop

delay 65 ms.

Rinse and when needed, repeat.

There are more sophisticate ways, but this will do it.

With, as @jremington shows, the values in an array for your convenience.

a7

Okay understood but i need delay in between individuals data bytes.

for(int i=0; i<sizeof(values); i++) {
Serial.write(values[i]);
delay(10);
}
1 Like

Okay but after D8 byte there should be 65msec delay and then again send D1 to D8 with 10ms this should run in Infinite loop.

Srsly? Take some time away to learn basic coding.

while (true) {
  for(int i = 0; i < sizeof(values); i++) {
    Serial.write(values[i]);
    delay(10);
  }
  delay(65);
}

HTH

a7

1 Like

Might it be a good idea to learn how to do some of this by yourself?

Are there any other requirements that you haven't mentioned?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.