Csum On

This configures StampPlot to expect 3 byte values plus a 4th for the checksum value. To understand what is occurring consider the example if our data were 10, 20 and 30 for the 3 values. Instead of sending a character for 1 then a character for 0 (2 bytes) for the value 10 it sends a single byte of the value 10 and similarly for 20 and 30. The largest value that may be sent is 255 since that is the maximum value for a byte.

Checksum means that the values of the individual bytes in each data set (or packet) are added up and that is sent as a byte. What would the checksum value be in this case? If you said 60 you'd be correct (10+20+30). When StampPlot sees that it has received 4 bytes it adds up the 1st 3 and compares what it calculated to the 4th. If there is a difference StampPlot will not use the data set and issue an error message in the Immediate/Debug window.

You may often get checksum error messages when first connecting due to connecting in the middle of a packet but StampPlot will quickly recover and find good packets.

V Let's write a program to send data for this configuration:

Plotting 3 analog values from binary data

Plotting 3 analog values from binary data

Val

VAR

Byte

Val2

VAR

Byte

Val3

VAR

Byte

DO

FOR Val

= 0 TO 255

Val2 =

= Val / 2

Val3 =

= Val * 2

DEBUG

Val, Val2, Val3, Val+Val2+Val3

PAUSE

100

NEXT

LOOP

Note the difference from the previous line to plot 3 values:

DEBUG DEC VAL, ",", DEC VAL2, ",", DEC VAL3, CR

• It does not use the dec modifier.

• It does not use the quoted comma-separators (PBASIC requires a comma between each value sent).

• The last value sent is the sum of the 3 bytes.

• No cr is sent at the end. This would be a 5th character sent (a value of 13).

Since a byte can only hold values up to 255, what happens if we send the values of 255,2,2? The checksum value will 'roll over' and start back at 0, so 255+2 = 1 +2 = 3.

Don't worry though, the BASIC Stamp module and the StampPlot software know this well and take care of it for you.

NOTE: Because data is sent in predefined packet sizes and the bytes represent values, you CANNOT send any other forms of data directly, such as data to be plotted as binary or control instructions once StampPlot is in binary mode.

Solar Power

Solar Power

Start Saving On Your Electricity Bills Using The Power of the Sun And Other Natural Resources!

Get My Free Ebook


Post a comment