Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial #52

Open
ManuelLevi opened this issue Jun 16, 2017 · 9 comments
Open

Serial #52

ManuelLevi opened this issue Jun 16, 2017 · 9 comments

Comments

@ManuelLevi
Copy link

I edited the code a bit so now it supports serial communication too.

I can't really test how efficient it is as I only have a small 8 LED ring (this is my first time testing the ws2812b chips).

If anyone is interested, I can make a pull request with the Arduino sketch and code modifications.

@deepak-divakar
Copy link

I would love to test this. Can u please share the sketch?

@ManuelLevi
Copy link
Author

ManuelLevi commented Jun 17, 2017

The sketch is a modified version of LedStripColorTester of the PololuLedStrip lib.

rgb_color color;
current_led = Serial.parseInt();
color.red = Serial.parseInt();
color.green = Serial.parseInt();
color.blue = Serial.parseInt();
colors[current_led] = color;
current_led +=1;
current_led = current_led % LED_COUNT;
ledStrip.write(colors, LED_COUNT);

It receives a string with four integers, the number of the LED, and the values for RGB.

I'm confident this is not the most efficient way to implement as we should only need to send 4 bytes. One byte for each int.

I decided not to care too much about this optimization as with 8 LED's it seems to be working with no major problems.

@joeybab3
Copy link
Collaborator

Do you have the python part?

@ManuelLevi
Copy link
Author

Yes. It's quite simple.
This would be the most important function.

def _update_serial():
    global pixels
    pixels2 = np.clip(pixels, 0, 255).astype(int)
    for i in range(8):
        tmp = pixels2[:,i]
        s = '{},{},{},{}!'.format(i,tmp[0],tmp[1],tmp[0])
        ser.write(bytes(s,"utf-8"))

@tab26715
Copy link

tab26715 commented Aug 5, 2017

Where would that python code be written? In led.py?

@joeybab3
Copy link
Collaborator

Do you have the rest of this? I would love to try implementing this a little better.

@ManuelLevi
Copy link
Author

Unfortunately, I don't have that code anymore but I don't think you need much more than what I've posted here, have you tried it following the posts?

I don't have much time now, but if you have any problems I'll try to help as much as I can.

Good luck!

@artemanderson
Copy link

Hi Manuel, when I injected your snippet into the LedStripColorTester sketch, the
" current_led = Serial.parseInt();" line gives an error -
"error: 'current_led' was not declared in this scope"

I'm very new to working in Arduino, would you be able to explain what is needed to fix this?

@ManuelLevi
Copy link
Author

You'll have to define all those variables before using them, like int current_led;.
https://www.arduino.cc/en/Reference/VariableDeclaration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants