Go Down

Topic: How to read 17bytes from a sensor via Serial? (Read 681 times) previous topic - next topic

superkato

Hi,

I'm attached a Sensor IR-Array Sensor. With the following code I'm reading every byte it sends.
Code: [Select]

int incomingByte = 0;   // for incoming serial data
void setup() {
        Serial.begin(11500);     // opens serial port for console
        Serial.print("Output active");
        Serial1.begin(19200);     // opens serial port to sensor
        Serial.print("Sensor active");
}

void loop() {

        if (Serial1.available() > 0) {
             
                Serial1.read();
Serial.println(incomingByte , HEX);
   
        }
}


now the sensor has a output format of total 17bytes.  (please take look at the Picture ).



How can I read this 17bytes correctly from the beginning, so I don't grabing the data from the middle?

Please Help.

superkato

PaulS

Quote
How can I read this 17bytes correctly from the beginning, so I don't grabing the data from the middle?

Read two bytes. See if the first one is 0x00 and if the second one is 0xDF. If not, move byte to to byte 1, and read another byte. Repeat until the two bytes are 0x00 and 0xDF.

Then, read the next 15 bytes, as they become available.

Of course, as you read a value, you need to assign it to a variable. Discarding it (as you are doing) doesn't make sense.

superkato

00 DF  and so on is just an example

the values could be       0x6c 0x2F            0x04 0x2F     

Riva

What sensor is it + links to full datasheet please.

superkato

its a custom sensor IR array, there is no official spec yet.

Go Up