Sensor Data Integrity- Basic fixed array with special start and stop symbols?

I need a remote arduino+magnetometer to send (serial) constant real-time compass headings to a second Arduino? The data string will be a 3 digit number between 000 - 360 (sensor significant figures will be trimmed off and rounding will be done) for processing the control of a special directional antenna servo motor.

I am worried about dropped bytes creating corrupted sequences of compass headings. I can check for crazy values > 360 but what is the best method to maintain the correct data sequence? I was thinking to use a fixed sized array with added special start and stop symbol on the sensor Arduino side and on the other end of the serial communiation have the second Arduino discard strings without the correct symbols/position. Alternately, I guess I could calculate some checksum and send that as a pair of data string and checksum.

Am I over thinking the issue and/or does the serialsoftware library offer some solution?

tia
Jerry

You're thinking along the right lines. The best way is to use both methods - start/stop characters and a checksum.

I have a library that people use that works with hardware serial, but not software serial - you can modify it for software serial if you like, or just use it for inspiration.

Many thanks. My skills are too basic to undertake a conversion of your library for hardware to software serial... but I wish I had the time to learn as it certainly would enhance my programming knowledge beyond the basics.

I can manage adding and verifying special start and stop symbols. Which would be faster in code - a CRC look-up table or checksum calculation?

Most of the time the Arduinos will be in sleep mode but when the sensor is made active (by specific request), it will send changing data continuously as the antenna rotor direction changes. The speed of rotation is relatively slow about 10 seconds for 360 revolution so I am not that worried about missing a sequence here and there so I wont bother to resend dropped corrupted sequences. I do want to recognize and count persistent corrupted strings maybe to send a Arduino reset to get things back in correct sequence.

Thanks for your help and advice

jerry

There's two ways of doing checksum calculation - the right way and the wrong way :wink:

The best simple checksum calculation is one which, where the sum of all the bytes in the packet including the checksum byte (mod 256) equals 0. That's basically what TCP/IP uses (but a 16-bit version), and is so easy to check - it's just a case of adding the incoming bytes to an 8-bit counter and if it ends up as 0 then the packet is good.

This is called a ones-compliment checksum. Just set the checksum on your outgoing packet to 0, sum all the bytes into a byte value (so it automatically "mod"s to 256), subtract the result from 256, and store it in the checksum.