Hello all,
I am new to coding and Arduino and am trying my best to get up to speed. I just started delving into this about three weeks ago.
My project involves interfacing to a two way radio to emulate a control head. So far I have the buttons and various other control working fine. My next hurdle is to properly display the information which would be displayed on the control head. The protocol is regular RS232 but it's in hex strings which are formatted in a certain way. My thought was to circumvent having to do full packet parsing and parsing and just flag for the first few hex bits. The first few characters of each string will be similar but will be specific to each of the four or five strings and only differ by one bit which is the last one 0x03 in the code I posted. A different line would be the same information but with 0x04 etc.... the variable checksum is toward the very end of the packets and it has an end of line marker but I was thinking that if I flag for those first few and I know the length then I shouldn't have to worry about checksums and watching for end of lilnes right?
I'm pretty sure I need to use a substring to do this but I'm getting lost in how to set that up properly and how to position the data on the display in the place I want. It seems to want to just print to one character place when I try to utilize lcd.setCursor(col, row)
This code is probably very ugly but seems to be working as intended to at least sniff out strings that match the parameters set.
(firstchar = Serial.read()); {
if (firstchar > 0) { //get incoming byte
if (firstchar == 0x24,0x0F,0x81,0x2E,0x03) { // data beyon 0x03 is hex encoded display information such as frequency number 10,000.00
byte acknowledge[6] = {0x24,0x01,0x10,0xF3,0x28,0x03}; // Ack packet to initiate next string of data from the device when information is received
Serial.write(acknowledge, 6); // will write the array of bytes to the serial port in raw hex form length and keep the data flowing as long as the display information is updated (changes from radio)
char buffer[34];
delay(22);
for (i=0;i<34;i++) {
buffer = Serial.read();
- String frequencyString = buffer;*
_ lcd.write(buffer*);*_
The packet continues on past the 0x03 and includes ten characters of hex encoded display information. I would like to somehow grab the data from spots 7 through 17 (counting space 0 of course) and display only that information on the LCD. As it is now it is just flooding the LCD with the information and writing the display frequency over and over starting with LCD row 0 then goes to row 2 then jumps back up to row 1 and ends at row 3 with a lot of garbage intermixed.
I hope this makes sense.
Thanks in advance.