hybridgroup / gobot

Golang framework for robotics, drones, and the Internet of Things (IoT)
https://gobot.io
Other
8.84k stars 1.04k forks source link

Neopixel RGB LED strip support? #430

Open hairyhenderson opened 7 years ago

hairyhenderson commented 7 years ago

I'm wondering if it'd be possible to add support for NeoPixel-type RGB LED strips (https://www.adafruit.com/product/1376) - these are basically just arrays of WS2812 or SK6812 individually-addressable RGB LEDs.

There are some Raspberry-Pi specific libraries, and there's also an Arduino library, but I'm looking for something more generic that I could use with an ESP8266 over WiFi with Firmata.

Or if there's a different approach I could use, I'm open to options 🙂

deadprogram commented 7 years ago

Hi @hairyhenderson

So I've been working on this for a bit, your issue prompted me to get a little further.

The branch https://github.com/hybridgroup/gobot/tree/feature/neopixels contains some of my WIP. The initial implementation uses a plugin for ConfigurableFirmata that I've committed some initial work on here https://github.com/hybridgroup/FirmataNeopixels

Since it extends ConfigurableFirmata, it should work fine with Gobot's TCPFirmata on an ESP8266 once I get a little further I will test that out to confirm.

The next major milestone will be to implement a GPIO "bitblaster" interface that can send the signals from one of the GPIO pins on a Raspberry Pi, Beaglebone Black, etc. I intend to work on this further over the next week or so. This document show pretty much exactly what the pin bitblaster will need to do:

https://cdn-shop.adafruit.com/datasheets/WS2812.pdf

What do you think?

deadprogram commented 7 years ago

TO elaborate a little more:

Firmata-based Neopixel driver that already at least mostly works is here: https://github.com/hybridgroup/gobot/blob/feature/neopixels/platforms/firmata/neopixel_driver.go

Placeholder for GPIO-based Neopixel driver is here: https://github.com/hybridgroup/gobot/blob/feature/neopixels/drivers/gpio/neopixel_driver.go

hairyhenderson commented 7 years ago

What do you think?

I think this is awesome! Thanks @deadprogram 😁

I'll try to test this out too once I get a little free time.

joek commented 6 years ago

Hi, what is the status about this project? I am looking for something similar. Do you have the Arduino code, you where using somewhere? It seems the StdFirmata will not work.

One thought about the GPIO Version. There are some problems and limitations to raspberry, which makes it more complicated to implement. Details: https://learn.adafruit.com/neopixels-on-raspberry-pi/overview

deadprogram commented 6 years ago

Hi @joek you are correct, I have a repos with some work in progress on the Arduino side of things.

https://github.com/hybridgroup/FirmataNeopixels

Sorry about the complete lack of docs, as of yet. It is a pluging for configurablefirmata if that helps get you started before I can update the READMEs.

You are indeed correct about the speed issues with the raspi, but I expect that for at least a very short length of LEDs a Golang sysfs bitbanging approach might be viable.

ghost commented 6 years ago

any updates? I would love to use the raspberry pi with Gobot and some neopixels...

deadprogram commented 6 years ago

Hi @hairyhenderson your best bet with Raspberry Pi is probably to use a SPI based LED strip like the APA102 https://github.com/hybridgroup/gobot/blob/master/drivers/spi/apa102.go the speed of the Raspi bus is not really enough to drive NeoPixels without an attached microcontroller.

n00dles commented 6 years ago

Hey Guys, any update on getting this working?

Thought I had it going (1 pixel lit up for me) but I haven't been able to replicate.

When adding to the esp firmware do I need to add :

firmataExt.addFeature(Neopixels);

or similar? to the initFirmata() function.

n00dles commented 6 years ago

ok figured I did need to use addFeature and I get lights !!

but just a flash the I get an exception on the ESP and it goes in to a reboot loop. I'm just using your example code.

any suggestions?

deadprogram commented 6 years ago

The ESP8266 basically goes into the reboot loop under many circumstances and one in particular is when it does not have enough time to process all the WiFi data. I ran into that exact problem with it, and was not even using code that is so timing dependent as the Neopixels. My Neopixel experiments were using an Intel TinyTile and using BLE not WiFi, as I recall.

One thought was to switch over to using Homie on the ESP8266 https://github.com/marvinroger/homie-esp8266 and use an MQTT based protocol. I have done some experiments with defining a Firmata-like protocol on top of Homie but it is far from complete.

Another useful approach might be to do the same sort of thing as Homie, but using COAP instead of MQTT. That would have quite a few benefits, such as not requiring a server, and also allowing for pure browser-based clients to test the device, but I have not seen that anyone has done anything even close to that yet. It is just one of several ideas I have been playing with.

n00dles commented 6 years ago

@deadprogram Thanks for the update and advise.

I have it working now on wifi on esp8266 but I still get the odd reboot after about a minute. so I'll keep at it.

I'm so close to having it for what I want, not fancy animations just to be able to light up sequences of leds.

deadprogram commented 6 years ago

That is good news. Please update this issue with details once you get it working to your liking.

n00dles commented 6 years ago

quick question.

what is the purpose of the lines

[code] Firmata.write(START_SYSEX); Firmata.write(NEOPIXEL_CMD); Firmata.write(PIXEL_SHOW); Firmata.write(END_SYSEX); [/code]

in the arduino code?

Removing it seems to get rid of any exceptions I'm getting. is this required for proper operation?

deadprogram commented 6 years ago

That is the expected Firmata response sent from the Arduino back to the caller. The exception is on the ESP8266 side or the Go side?

n00dles commented 6 years ago

ignore the above, I was doing something stupid....

NomadMaker commented 6 years ago

It would probably be a lot easier to use DotStar strips than NeoPixel ones. DotStar is AdaFruit's name for LED's controlled via the APA102. They don't have the strict speed requirement that the NeoPixel ones do.

I have both DotStar and NeoPixel things, but I can't get to them for the next week or so because I'm packing up my motorhome and moving it from Florida to Pennsylvania shortly. If I can find a DotStar strip fast enough then I will see if I can test it when I'm stopped for the night. However, they may be already boxed and put away and I don't have the time to search for them until I get to my destination.

I am planning on eventually replacing the LED strips on my RV with DotStar strips so that I can be ready for holidays with a simple command. Imagine various types of Christmas lighting, then 4th of July, then just basic white, then Halloween, then Easter. That way nobody can make me change lights. :)