Programmatic Control with OLA and RPi

227 views
Skip to first unread message

Allen

unread,
Feb 9, 2022, 8:58:04 AM2/9/22
to open-lighting
Hello OLA Experts!

I recently followed the tutorial at https://www.tomshardware.com/how-to/control-dmx-lights-raspberry-pi to setup OLA on my original Raspberry Pi and ENTTEC OPEN DMX USB controller to control a simple generic 3-channel DMX par can light. From the OLA web interface, I can use the sliders for channels 1-3 to control it so that works fine but the example project at https://github.com/rydercalmdown/dmx_lights.git didn't work for me. I am able to run commands from terminal like "ola_streaming_client -u 1 -d 0,255,0" though which sets the par can to green for a few seconds before turning off.

Looking for guidance on how to programmatically control this single light from a script or Python program. Basically whatever the next step is on my learning journey for OLA. My end goal is to have a program/service that runs continuously and pings a public scoring API to check for score updates in a game (such as the Super Bowl though I know time is running out for that). Then when a score change is detected, the light would automatically flash that team's preprogrammed colors.

Any suggestions are greatly appreciated!

Thanks,
Allen

Peter Newman

unread,
Feb 9, 2022, 9:11:25 AM2/9/22
to open-lighting
Hi Allen,

Be aware that if you've got the OLA web UI open on the faders tab, it will also send data which will fight with, and possibly beat, things like the example Python code you've linked to (and possibly ola_streaming_client too). Is that your issue.

When you say the ryderclamdown one didn't work, do you mean at all? Or the same problems as the streaming client? The example is sending on universe zero by default, whereas your ola_streaming_client is sending on universe 1...

We've got lots of APIs, which language do you want to write in?

You've got four or five days until the Superb Owl tournament, as long as you can get your scores, that's plenty of time to do the rest of it!

Allen

unread,
Feb 9, 2022, 9:54:16 AM2/9/22
to open-lighting
Thanks for the quick reply Peter!

Ah, that's good to know that the OLA web UI conflicts with the Python code and ola_streaming_client commands. I've confirmed that with the OLA web UI closed, running ola_streaming_client commands for specific colors now works as expected staying on indefinitely as opposed to only a few seconds like before.

The ryderclamdown sample didn't work at all for me. I had noticed previously that my universe is 1 whereas his was 0 but I didn't edit that line in dmx_controller.py. I just did that and the code is running as expected.

So moving forward, should I create like a shell script/daemon that calls ola_streaming_client as required or just use C++ or Python? If more the latter, I'll probably lean towards Python as my C++ skills are quite rusty. Any examples would be appreciated.

-Allen

Peter Newman

unread,
Feb 9, 2022, 11:24:19 AM2/9/22
to open-lighting
Glad to hear the other example is working too now.

That's a bit of a how long is a piece of string question! What if any effect do you want to happen when no-one has scored? What about when someone scores? If it's not just a static colour, can you programme the effect with code or do you want to using something more advanced like a lighting desk/QLC+ recorded via ola_recorder?

ola_streaming_client can also accept DMX data via STDIN, so anything that can output to STDOUT could be used to generate data.

Perhaps the better place to start is what is your preferred language and what if any libraries already exist to access the score data?

Allen

unread,
Feb 9, 2022, 1:00:08 PM2/9/22
to open-lighting
If no one has scored (or between scores) the light can either remain off or static on whatever color it was last. Here is some code that I came up with to have the light flash between two colors for a score by a team:

# Test app for DMX control of lights
import array
import time
from ola.ClientWrapper import ClientWrapper


universe = 1
wrapper = ClientWrapper()
client = wrapper.Client()

# define color constants
orange = array.array('B', [255, 100, 0])
white = array.array('B', [255, 255, 255])
blue = array.array('B', [0, 0, 255])
yellow = array.array('B', [255, 255, 0])


def DmxSent(state):
  wrapper.Stop()
 
def dmx_team_score(color1,color2):
    count = 0
    while (count < 20):
      count = count + 1
      client.SendDmx(universe, color1, DmxSent)
      wrapper.Run()
      time.sleep(1)
      client.SendDmx(universe, color2, DmxSent)
      wrapper.Run()
      time.sleep(1)


# Bengals score
dmx_team_score(orange,white)


# Rams score
dmx_team_score(blue,yellow)


Thoughts welcomed. Now I just need to find a public API to gather scores, implement the necessary logic, and have this run as a service/daemon somehow polling the API every few seconds or so.

Peter Newman

unread,
Feb 11, 2022, 8:07:41 PM2/11/22
to open-lighting
Hi Allen,

While it may work, you don't really want to use sleep or keep calling wrapper.Run(), instead you should use our event system to keep calling a function to e.g. change the colour. See this example for instance:

In your case you could add another event via AddEvent which does the score checking.

Peter Newman

unread,
Feb 14, 2022, 8:10:23 AM2/14/22
to open-lighting
So did you manage to find a source of data and get it all working in time for the big game Allen?

Allen

unread,
Feb 14, 2022, 9:43:07 AM2/14/22
to open-lighting
Thanks a bunch for the follow-up Peter.

I just created a PHP page with two buttons (one Bengals and one Rams) that fired the appropriate Python script to flash the light colors. Maybe next year I'll make it more elaborate but all the guests enjoyed it nonetheless. :)

Peter Newman

unread,
Feb 14, 2022, 10:28:18 AM2/14/22
to open-lighting
Ah cool, glad you managed to sort something out and that people enjoyed it!

Peter Newman

unread,
Feb 16, 2022, 10:22:18 AM2/16/22
to open-lighting
I've just seen this, which has some possible sources of data:
https://www.raspberrypi.com/news/track-football-teams-with-this-led-scoreboard/
Reply all
Reply to author
Forward
0 new messages