Hello
I need help to read a hex stream from a serial port and convert HEX to decimal values to be printed on my LCD display.
I use an Arduino Duemilanove
I have mapped out all the bytes on a packet med no stuffing.
Stream: 7E FE 46 5D 5C BE 00 00 00 00 7E
Pos: 1 2 3 4 5 6 7 8 9 10 11
1,2,11 - used to mark begin&end
7,8,9,10 - unused
3 - ADC1, range is 3.3V = FF
4 - ADC2, range is 3.3V = FF
5 - link quality, 110db = 6E
6 - link quality2, 110db = 6E
I will print the decimal value of position 3,4,5 and 6
Data stream coming in continuously:
00 00 00 7E 7E FE 46 5D 5B BF 00 00 00 00 7E 7E FE 46 5D 5B C0 00 00 00 00 7E 7E FE 46 5D 5B C0 00 00 00 00 7E 7E FE 46 5D 5C BF 00 00 00 00 7E 7E FE 46 5D 5D BF 00 00 00 00 7E 7E FE 46 5D 5D BE 00 00 00 00 7E 7E FE 46 5D 5D BE 00 00 00 00 7E 7E FE 46 5D 5D BE 00 00 00 00 7E 7E FE 46 5D 5D BE 00 00 00 00 7E 7E FE 46 5D 5D BD 00 00 00 00 7E 7E FE 46 5
Writing to the display is not a problem but when I tried to get data in via Rx port on the Arduino, I haven't managed to select the desired data in the stream. You can see my setup and LCD below.
I hope some can help with a clue, and much like the necessary code to convert the data stream to int's to print.
Thanks in advance.
My setup and loop code so far: NO SERIAL INPUT SO FAR, just analog data for testing, not everything in use.
void setup()
{
pinMode(txPin, OUTPUT);
LCD.begin(9600);
clearSerLcd();
backlightSerLcd(50);
displaySerLcdChar(1,5, "Analog data");
displaySerLcdChar(2,1, "AD1");
displaySerLcdChar(2,10, "mV");
displaySerLcdChar(2,13, "TEMP 15 C");
displaySerLcdChar(2,20, " ");
displaySerLcdChar(3,1, "AD2");
displaySerLcdChar(3,10, "mV");
displaySerLcdChar(4,1, "RSSI"); // AV-receiver RSSI
displaySerLcdChar(4,10, "%");
displaySerLcdChar(4,12, "RSSI");
displaySerLcdChar(4,20, "%");
}
void loop() {
// read the value from the sensor:
// sensorValue = analogRead(sensorPin);
// TempValue = analogRead(sensorPin1);
RSSIValue = analogRead(sensorPin2);
// Convert inputdata to mV, calculation: 5V / 1.0230 = 4.8876;
// millivolts = sensorValue * 4.8876;
// Tempvolts = TempValue * 4.8876;
// Temp = Tempvolts / 10 - 284;
RSSIAVrx = RSSIValue * 0.12773; // calculation for % : (5V / 1.0230) / 50 = 0.09775;
// calculation for % with 3.7V=100%: (RSSIValue * 4.8876) / 0,7653 / 50 = RSSIValue * 0.12773
//Print Data
displaySerLcdChar(2,5, "0");
LCD.print(" ");
displaySerLcdChar(3,5, "0"); // displaySerLcdData(3,5, millivolts);
LCD.print(" ");
displaySerLcdData(4,6, RSSIAVrx); // AV-receiver RSSI
LCD.print(" ");
}