Created Thu, 19 Dec 2013 20:05:01 +0000 by kaaasap
Thu, 19 Dec 2013 20:05:01 +0000
this rookie is stumped
I am using an uC32 to monitor the status of a sensor. The sensor returns 5 bytes after a reading. The first byte is an acknowledgement byte, stating this is the command performed. The next four bytes (32 bit with lsb first, in raw hex 0 to 253800) are the actual reading. The decimal values of the each byte are used in an equation to get the final reading. I am having trouble capturing the four bytes that represent the reading. Here is my testing code:
unsigned long testVal;
void setup() {
Serial.begin(115200); Serial1.begin(187500);
pinMode(8, OUTPUT); digitalWrite(8, LOW); }
void loop() { int buffer = 3; unsigned char reading[buffer]; unsigned char meas1; unsigned char meas2; unsigned char meas3; if (Serial1.available()) { reading[buffer] = Serial1.read(); delayMicroseconds(180); Serial.println(reading[buffer],HEX); for (int i = 0; i < 15; i++) {if (i == 4) else if (i == 5) else if (i == 6) } testVal = ((meas3 + meas2 + meas1)/16384); Serial.println(testVal, DEC); } }
I get the following when I println(reading[buffer]):
0
4C the command to read
1
4C command returned
A start of reading bytes lsb (meas1)
0 (meas2)
0 (meas3)
0 end of the reading bytes, this byte can be ignored.
0
47 status report
1
47
0
0
8
Any advice or help on capturing the four bytes to use in an equation would be greatly appreciated.
Thu, 19 Dec 2013 23:00:33 +0000
I'm not sure I quite follow the format of the message. Can you post an example of the 4 bytes in question by themselves, with what you would expect the answer to be?
Fri, 20 Dec 2013 15:14:45 +0000
I have it working! When a measurement is performed I receive the following:
5305 counts 0.3238 mm
All with a uC32 and 4D Systems uLCD4.3.
Will post a final video of it working later.