Hello,
I want to transmit the values from four analog sensors connected to the Arduino to my computer. My four sensors are handled in a loop.
My first option was to send the four values with Serial.print() and a separator within the loop, followed by a Serial.println() inserted after the loop. However in between I have decided to apply a noise threshold to avoid transmitting whenever possible (I have noticed my computer's fan starts to run quite soon when the serial port has much activity). So I need to find another option.
What is the most efficient way (from the point bandwidth's point of view) to identify each sensor prior to sending each sensor's value ? I am thinking about prepending a special ascii value but which one should I use to avoid confusion with any byte coming from a sensor's value ?
Also, would a transmission of the data as binary numbers be more efficient ?
Thank you in advance.
If it is sensor data from the A/D then this is a 10 bit value, giving you four bits to play about with the identifying of the channel.
The most efficient way is to use the most significant nibble to indicate the channel with 0xxx where xxx are 0s or 1s giving the channel number, with the rest of the byte as data (that's the most significant four bits).
Then the 6 least significant bits of the second byte for the rest of the data, leaving the top two bits to identify the fact that it is a least significant bit by having them fixed at 10. This distinguishes it from the first byte.
Then on the receive side you look to see if the most significant bit is 1, if it is you know it is the first byte, if not it is a second byte got out of sequence so ignore it.
Grumpy_Mike:
If it is sensor data from the A/D then this is a 10 bit value, giving you four bits to play about with the identifying of the channel.
I understand the idea but how do you get this number of bits (four) ?
If you have 10 bits of data you can't use one byte so you will have to use two bytes.
Actually it gives you 6 bits to play with, sorry does that make sense.
What is the data you're measuring and by extension, how often do you need to sample it? How much and how rapidly does it vary? Could you send initial readings in the original format and then send four nibbles of delta when there is a change? Could you stage the data in RAM or better, an SD card and send it when your staging memory is full? Lastly, does using the original format work if you don't send until some reading has changed more than your threshold? i.e. have you solved the problem with the fan already?
Grumpy_Mike:
Actually it gives you 6 bits to play with, sorry does that make sense.
OK, this matches my knowledge of bytes better !
Thanks a lot.
wildbill:
What is the data you're measuring and by extension, how often do you need to sample it? How much and how rapidly does it vary? Could you send initial readings in the original format and then send four nibbles of delta when there is a change? Could you stage the data in RAM or better, an SD card and send it when your staging memory is full? Lastly, does using the original format work if you don't send until some reading has changed more than your threshold? i.e. have you solved the problem with the fan already?
My data vary quite much and rapidly (finger pressure sensing). I'm going to try using Grumpy_Mike's idea to identify each sensor with the unused bits, which means I could keep the threshold's idea.