Hardware Reference
In-Depth Information
One important thing to note is the way the data is sent to the Raspberry Pi. In order to mini-
mise the number of bytes sent, you send only the X and Y coordinates that need to be plotted.
However, you can't just send the bytes because you then have no way of knowing which was
which at the receiving end. If one was missed, then the whole thing would be out of sequence,
and the data would be corrupted. here are two ways around this problem: he irst is to send
data in packets - send the data and add a header to it. he header should be a unique value that
does not appear in the data. he receiving side keeps ishing bytes out of its bufer until it sees
this header byte; then it has a good chance of knowing that the next few bytes are in the order
they are sent. his is ine especially for larger amounts of data, but you have to ensure a unique
value for the start of packet indicator, and that often means restricting the data to something
like a string representation, which is ineicient. Here, the approach I have used is to tag each
individual byte, which works because you are trying to send two 10-bit data values and there
are plenty of spare bits if you divide the data up correctly. Figure 16-18 shows what I have
done. Basically each coordinate is split up into two 5-bit ields, and the top two bits of each ield
have a unique bit pattern to identify them. herefore the receiving side can identify if the bits
come in in the right order and verify that none have been dropped. his was important, espe-
cially during development, because initially the Raspberry Pi's bufer was illing up to overlow-
ing and data was being lost. herefore I knew I had to do something to alleviate the problem;
more on that when you see the Python code in the section “Programming the Pi”.
Figure 16-18:
Splitting up the
data to tag each
byte.
Search WWH ::




Custom Search