3
$\begingroup$

I'm new to blender and python. I want to read analog data from arduino to blender. I'm using the bellow code and it works fine. Even though arduino sends data quickly blender reads them very slow(about 800 ms). Does anyone knows whats the mistake I have done here?

ser = serial.Serial('COM3', 9600 , timeout=1)
 sensor00 = ser.read(size=1)
 sensor0 = ord(sensor00)
 print ("sensor0=",`sensor0)

This code is repeated 9 times for 9 other sensors (flex sensors).

$\endgroup$
2
$\begingroup$

Serial communication uses start and stop (1,1.5 or 2 bit length) and optionally a parity bit. Assuming it would be 10 bits 9600 bits/s would transfer 960 bytes in a second.

You're reading the data byte by byte.

If you have messages with variable length it would be better to transfer a header containing the size of your message and read this first.

e.g.

<Header>     <message>
0x0000 0100  256 bytes of data

then you could read first the header (size=4) followed by reading the message at once.

To make the protocol more robust you could introduce a checksum (in the header) and an end-of-message marker which is not contained in the data (or escaped there), this would allow you to recover from transmission errors and re-synchronize.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.