Changing the code
The SPOKE uses a microcontroller called a Raspberry Pi Pico as its’ brains. It’s the green rectangular part that you connect your usb cable to. In order to change what type of things your device does, we need to edit some of the code on the pico. It’s not that difficult, and you don’t need to know the first thing about coding in order to do it. If you can copy + paste and change a few numbers, you’ll be able to customise your SPOKE to do lots of different things.
You can open up that file in Notepad to change some of the values. It might look complicated to begin with, but don’t panic.
There is a section that looks like this:
# MIDI note numbers corresponding to each touch pin - change these to whatever midi note you prefer. The default is a 2 octave diatonic scale.
midi_notes = [30, 32, 34, 35, 37, 39, 41, 42, 44, 46, 47, 49, 51, 53, 54, 56, 58, 59, 61, 63, 65, 66, 68, 70, 71, 73]
In order to edit which notes get played, just change these numbers to their midi note value. They go in order from the pin left of the board in an anti-clockwise direction.
Make sure you save the file as code.py when you edit it. The board will only run code that is named code.py when it starts up.
We can change the type of MIDI our device sends. It comes pre-installed with single notes with polyphony. Meaning we can play multiple, single notes at once. But lets say we want to play a sequence of notes with just one touch.
The Github page for this project has a series of example code that you can copy+paste onto your board and adjust depending on what you want it to do.
If you click on the part that says MIDI-USB - Sequences it will show you the code needed to turn your board into a MIDI device that plays specific sequences of MIDI notes.
The Copy All button is a bit hidden, but it’s this one up here.
Copy and Paste this new code into the code.py file on your Pico. And it will now play sequences of midi notes instead of single notes.
Again, you can customise the notes that get played by just changing the numbers in the code.
If you ever get stuck and need to reset your code, you can always just copy and paste from the github page and start again!
There are other numbers within the code that you can edit and play with, for example, on line 63 + 64 there are these 2 lines:
time.sleep(0.2) # Delay between each note in the arpeggio
time.sleep(0.5) # Duration of the arpeggio
These two numbers are in seconds, and you can change them to change the speed the sequence gets played in and how long to wait between sequences.
Next Steps…
Click here for a more advanced code editing guide.