I guess I’ve been using Blender for so much for so long that I tend to look for ‘Blender-like’ controls in a/v projects. So inevitably when I started working with LED strips I immediately tried to weasel out of having to think through functions and loops in arduino code to create effects I could do intuitively in Blender.
So after a few bad UI attempts I thought – hey, wish I could just design a light sequence in Blender and run it with ALT-A. So that’s what I did.
On the arduino side it’s using the FastSPI and CmdMessenger libraries for LED and serial communications.
The Blender script just reads the diffuse color in r-g-b from each LED objects material and spits it out to the USB port. Getting the pyserial library hooked up in Blender wasn’t a breeze but the “sys.path.append” line should help anyone having the same issues I did.
Here’s the arduino code and Blender file
(Using Arduino Duemilanove 328 and LED strip with WS2801 chips)
EDIT:
Blendernation article (Thanks Bart!)
I forgot to mention I’m using Ubuntu so the sys.path.append thing wont work for windows, you’ll have to find the pyserial library solution elsewhere (there’s plenty of reference out there)
Also – the script runs on each frame change. Here’s how that works (WARNING: kinda hacky) http://funkboxing.com/wordpress/?p=236
QUESTION: For any API guru’s out there – currently this script opens and closes the serial port on each framechange. I know this is radically inefficient. Any ideas on how to keep the serial port open persistently but to close it when blender closes?
Is that RGB sequence too big to be stored in the Arduino itself?
This sequence is about 500 frames, each frame sends about 16 bytes per LED. So that could run up past the 30k on the Arduino pretty fast I’m guessing.
I could probably store short sequences on the board, or use a SD sheild for longer ones. For now my goal is to simplify designing the sequences.
Playing them back could be done a number of ways.
Also I guess I should do this in the BGE also to allow more live-interaction.
Perhaps you could bake the color changes into keyframes, and then optimize the keyframes and do the interpolation on the Arduino itself? Or would it still use up too much memory?
Keyframes would certainly make the memory requirements manageable, but I think that kind of interpolation might be beyond the capacity of the ATMega328. Might try it out just to see.
[…] For now it’s just USB/serial interface but over time I plan to integrate DMX/Artnet protocols (though this will probably involve creating an arduino sheild for the purpose. It’s just baby steps but I thought it might be cool enough for a post. Hope you enjoy! Get the Arduino code and blend files here. […]
incredible, nice work!!
[…] Read all about it vie blendernation. […]
[…] on funkboxing.com Like this:LikeBe the first to like […]
I know absolutely nothing about Arduino or Blender but this project reminds me of something neat I came across a few days ago.
SpokePOV
Nice work.
I stumbled across the BlenderNation article which refers to here.
As for your question at the bottom: for a project of mine (non-Blender related) I am working on controlling Arduino with the pyFirmata software (www.firmata.org). It’s a standard Sketch that can be found in the Arduino IDE. Basically, it sends all Arduino data to the host computer for processing. Serial communication is taken care of by Firmata, and you can program in Python…
There is the pyFirmata host-end (made by Tino de Bruijn, Tinodb) for python2. I am close to finished porting his module to Python3. You might want to take a look at https://github.com/appultaart/pyFirmata.git to grab the source (check the py3k branch). This might solve your issue, perhaps.
Cheers
Reallly impressed! FWIW I’ve rewritten your script to work with a modal operator timer – that way it can run continuously, does not depend on an animation frame change to trigger the script so, best of all, it keeps the serial port open all the time! Just opens the serial port once, and sends object color data every no matter what. You can just change the material diffuse color and the corresponding led will reflect that.
Hey, that’s awesome! Mind posting a link to your improved script?
Actually I’m just about to finish an 8×8 LED matrix of strips and I was going to make some Blender animations to control it with. I’d love to use your updated code!
It’s at http://swigerco.com/LEDControl_POST_9F.tar
There’s a line with the timer refresh rate (…event_timer_add(.05,context.window)) I played with that and the serial baud rate to find how much the arduino can take w/o being overwhelmed.
I’ve been staring at blender all weekend and cannot discover how the material diffuse color is controlled by the empties 😉 Any hints? Just want to add more LED’s. Eventually want to control a beaglebone black using LEDscape.
Hey thanks for that link! Please let me know what you find as far as what kind of datarate the arduino can handle.
Each diffuse material has a driver on each color channel (R,G,B) and those are driven by a scripted expression (1-x, with x being the distance between the LED object and the empty). It’s a little cumbersome to setup because each LED requires a different material and then you have to setup the drivers, so you can’t just copy/paste to add LEDs. I’ll probably make a script to add LEDs, materials, and drivers at some point, but haven’t got around to it.
PS – make sure you have ‘auto-run python scripts’ enabled or the scripted expression drivers will not work.
for a uno, 9 leds and the script time step at 0.05, a baud rate of 38400 was the fastest I could get. Ran for hours like that 😉 YMMV
looked cool to have led visual emulator on pc to see what led strips doing! can you advise where get these leds coding software from?
I’m not sure I understand what you’re looking for. There are DMX lighting control programs that are quite versatile in creating FX but you’d need a DMX interface for the LED’s. This Blender control system is really just for very simple stuff at this point and is fairly limited in how many LED’s you could control with it.