Adalight and python pyserial

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sailsee
 
Posts: 6
Joined: Thu Feb 02, 2012 10:18 am

Adalight and python pyserial

Post by sailsee »

Hello everyone,

I'm developping my own libraries for controlling a led strand (12mm Diffused Thin Digital RGB LED Pixels (Strand of 25) - WS2801) with a python script using module pyserial. I'm using Adalight and the strand works like a charm with lightpack or processing, but I experience problems when I try to send my own serial data to it.

Here is a piece of code I use to test it :

Code: Select all

from serial import Serial
from time import sleep

# magic word + led number + checksum which are recognized as valid by my adalight
buffer = ['A','d','a','\x32','\x35','\x52']

# filling my buffer variable with 0 (6 bytes for header and 75 bytes for rgb leds data)
for i in range(75):
    buffer.append('0')

# opening my serial port, works well
arduino = Serial('COM3',115200)

# then I send a dim white (10,10,10) to my 25 leds
while 1:
    for i in range(6,81):
        buffer[i] = chr(10)
    arduino.write(buffer)
    sleep(.01)
As a result, the color are applied (I try with red too, it works, just to be sure) but the two first light stays respectively full white and blue.


I figure out that if I send
- header then 25 rgb data for red then, without sending the header again, 25 rgb data for green, I get my 25 Led with proper color.
but if I send color data without resending header, my strand goes stuck after a few iteration, so I guess I've to send the header every time.

I spend hours testing things, I can't figure out what's wrong.

User avatar
sailsee
 
Posts: 6
Joined: Thu Feb 02, 2012 10:18 am

Re: Adalight and python pyserial

Post by sailsee »

I have the solution ! My header is bad... For thos like me who're unfamiliar with binary operation, here is how I determined it
In ASCII Table, here is the hexadecimal for magicword

Code: Select all

A = 0x41
d = 0x64
a = 0x61
This is pretty staightforward here and I made no mistake.
Now, I've 25 leds, 25 is 11001 in decimal, so on 16 bits, : 00000000 00011001

so 25 will be in hex 0x00 and 0x19.

Now the checksum which is 00000000 XOR 00011001 XOR 01010101 (0x55)

Code: Select all

00000000 XOR 00011001 = 00011001 (pretty easy  ?)
00011001 XOR 01010101 = 01001100
Which result in 0x4d

So my header look like this as a python list

Code: Select all

['\x41', '\x64', '\x61', '\x00', '\x18', '\x4d']
But a problem remains, I still experience weird bugs after that.
I resolved the problem with lowering the baudrate to 57600 in my python script and of course in adalight code.

And tadaaaaaa ! It works.

I will post soon my library there if someone is interested.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”