Here’s the code for a recent project I did to drive the Pihut Christmas triee from Sonic Pi. (This is the new colour version)
CoventryCarol.rb
#CoventryCarol.rb
#controlling ThePiHut RGBXmasTree via OSC commands
#these are sent from Sonic Pi to a python OSC server running on the Pi
#which then controls the leds on the tree
#written by Robin Newman, Decemeber 2019
use_real_time
use_osc"192.168.1.34",8000
use_bpm 120
##| osc"/setAll",'black'
##| stop
This file has been truncated. show original
ReadMe.md
The python server runs on the Raspberry Pi with the Xmas tree attached.
Set the treeServer.py file executable using chmod+x treeServer.py
start it running with ./treeServer.py -ip 192.168.1.34 -sp 192.168.1.129
where 192.168.1.34 is the ip address of the Raspberry Pi, and 192.168.1.129 is the address of the computer running Sonic Pi.
Set the correct IP address in line 7 of the Sonic Pi program, and use port 8000 as shown.
EDIT
You need to have installed the tree.py file for the RGBXmasTree in the same folder as the treeServer.py file. This can be found at https://github.com/ThePiHut/rgbxmastree#rgbxmastree colorzero should already be installed in the latest Raspbian Buster distribution.
If you need it use
This file has been truncated. show original
treeServer.py
#!/usr/bin/env python3
#this script allows OSC control of ThePiHut RGBXmasTree
#it is intended for use with Sonic Pi 3
#written by Robin Newman, December 2019
#it utilises the python-osc library and also the colorzero library
#this latter is used because of its support for gradient commands
#and a large list of named colours.
#see API doc at https://colorzero.readthedocs.io/en/release-1.1/api_color.html
#Sonic Pi can be on same computer if using Pi3, but if using pizero must be on separate computer
from tree import RGBXmasTree
This file has been truncated. show original
previously I did a similar project for the monochrome version.
Three years ago at Christmas 1974 I produced a medley of carols for Sonic Pi. During the last week I acquired one of the PiHut Christmas Trees, which gave me a good test of my soldering skills in assembling it. Having built it, I thought that it would be nice to get Sonic Pi to control it, and to get the lights to flash in time to the carol pieces. This was similar to other projects I had previously done, and I wrote a small python OSC server to which Sonic Pi 3 could be a client, sending OSC me…
I hav also done several other projects on driving led displays from the Raspberry Pi, including PiBorg’s TroPI board, and a hack of the lightshowpi project to work with Sonic Pi.
Note if you want to use a Pi4, you will need to build your own Sonic Pi on it, as the current version contained on Raspbian doesn’t support MIDI or OSC.
You can of course use a Pi3 or earlier with Sonic Pi 3.0.1 with the earlier projects here.