<< return to Pixycam.com

checksum calculation question

Hi again,

I’m writing a script in python to do a checksum of the values, according to the instruction the checksum is always the sum of the remainder of the message.

However, this is what I get straight from pixy:

ex1: [6314, 256, 1024, 768, 2304, 1792] = (256+1024+768+2304+1792) = 6144 (170 out)

ex2: [5546, 256, 1024, 512, 2304, 1280] = 5376 (170 out)

The other issue example is when the checksum goes over max uint16 (assumed to be 65535):

ex3: [4522, 257, 20480, 6144, 30464, 12544] = 69889 - 65535 = 4354 (168 out)

The final example is where is goes over the max twice:

ex4: [938, 258, 29952, 13824, 60160, 27648] = 131842 - (2 x 65535) = 772 (166)

seems to drop 2 every time it goes over.

Is this by design? or I’m I missing something.

Many thanks,

Khris

Hello Kris,
Bear in mind that when the checksum overflows from 65535 to 0, effective value is 65536. In other words, you should subtract 65536 instead of 65535. This explains why you are off by 1 each time the checksum overflows.

Hope this helps!

Edward

Thanks, that explains the missing 1. what about the constant 170?

Hi Edward,

I’m writing on both issues just in case they are independent. On i2c checksum is correct for all cases. I am copying my decoding code for UART in case there is a mistake there. To be honest, I am 99% sure the problem in on my code, rather than on the firmware as no one seems to have mentioned any issues with their UART interface.

That my python script for reading pixy via UART

def getLocation(ser):
msg = ser.read(12)
checksum = struct.unpack("<H", msg[0:2])[0]
signature = struct.unpack("<H", msg[2:4])[0]
xloc = struct.unpack("<H", msg[4:6])[0]
yloc = struct.unpack("<H", msg[6:8])[0]
width = struct.unpack("<H", msg[8:10])[0]
height = struct.unpack("<H", msg[10:12])[0]

Thanks,

Khris