I am using MFRC522 RFID reader for my project. I am receiving the card number using arduino nano and convert it as wiegand signal. But I want to communicate with the door controller using RS485 protocol. For this purpose
I want to receive and send hexadecimal values through serial port of Arduino .The protocol contains hexa decimal values with start and end sentinel.
Can someone help me with examples how to send hexa decimal values.
There are not "hexa decimal values" at all. Hex format is a representation to human only. Hex, decimal and binary numbers are perfectly the same for controller.
Therefore, you don't need to convert your values to hex to sending it by RS485 link
Serial.write(0xA3); will send one byte whose value is 163 in decimal over the Serial line whereas Serial.print(0xA3); will send the ASCII representation of 0xA3 in decimal over the serial line so you’ll get 3 bytes the first one with the ascii code for ‘1’, then the ascii code for ‘6’ and then the ascii code for ‘3’
Print can also send the ascii representation in hexadecimal. Use Serial.print(0xA3, HEX); and it will send the ASCII representation of 0xA3 in hexadecimal over the serial line: you’ll get 2 bytes the first one with the ascii code for ‘A’, then the ascii code for ‘3’
None of these send the leading text 0x so if you want it you need to add it yourself
uint8_t message[]{0x07,0x42,0x31,0x46,0x31,0x30,0x37,0x0D};
void debug(){
for (auto &i : message){
Serial.write(i); // what the device might expect
// and now just for demo to see something in the serial monitor
Serial.print(" ");
Serial.print(i); // just for you
Serial.print(" ");
Serial.print(i, HEX); // just for you
Serial.println();
}
}
void setup() {
Serial.begin(115200);
debug();
}
void loop() {
// put your main code here, to run repeatedly:
}
will bring
7 7
B 66 42
1 49 31
F 70 46
1 49 31
0 48 30
7 55 37
13 D
where the first byte 0x07 and the last 0x0D are not printable characters - hence you don't see them on the built in Serial Monitor.
Are you didn't understand the answers? There are no "hexadecimal values"... You should make it clear whether you want the values as bytes or as a text string. This is the main thing, and not that they are hex or not
Serial hardware port set up – E,8,1, 19200 (Even parity, 8 bit, 1 stop bit, 19,200 baud rate)
Data Packet:
The general protocol format is as follows:-
SS RDR ADDRESS COMMAND DATA CC1 CC2 ES
SS- start sentinel =07
RDR - reader type = can vary 40 to 45
Address- Reader address can vary from 30 to 38
Command-
Data-
CC1 and CC2- checksums
ES- end sentinel = 0D
I have gone through "Serial Input Basics- updated" by Robin 2, It is really a great tutorial. But in the example 6 sending data as binary values ,it shows start and end sentinel as '<' and '>'. But if I want to send binary values as start and end sentinel how can I modify this 6th example?
I am developing a mifare RFID reader with Wiegand and RS485 output. Using MFRC522 reader module and Arduino Nano for processing the received data. For RS485 part I am using MAX485 chip for converting the data from Arduino (TXD and RXD pin) . Reader communicate with door access controller by sending binary data.
So I believe I have to serial write and read for achieving this.