I made a couple Midi controllers out of some Pringles Cans and piezo sensors then hooked them up to Sonic Pi with an Arduino MKRZero and played some drumbeats
I recently got the MKRZero and it is super easy to set up in Sonic Pi. It reads as a Midi device in Sonic Pi right when you hook it up without any additional software.
The code to send Midi messages was available online and is pretty straight forward and easy to modify.
Here is the code from the Pringles Project
#include "MIDIUSB.h"
byte note = 0; // The MIDI note value to be played
const int ledPin2 = 13;
const int ledPin1 = 12;
const int knockSensor1 = A1;
const int knockSensor2 = A2;
const int threshold = 100;
int sensorReading1 = 0;
int sensorReading2 = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
sensorReading1 = analogRead(knockSensor1);
sensorReading2 = analogRead(knockSensor2);
if (sensorReading1 >= threshold) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
Serial.println(sensorReading1);
noteOn(0x90, 60, 0x45);
digitalWrite(ledPin1, HIGH);
delay(50);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
digitalWrite(ledPin1, LOW);
noteOn(0x90, 60, 0x00); delay(50);
}
if (sensorReading2 >= threshold) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
Serial.println(sensorReading2);
noteOn(0x90, 48, 0x45);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin2, LOW);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, 48, 0x00); delay(50);
}
}
void noteOn(byte cmd, byte data1, byte data2) {
midiEventPacket_t midiMsg = {cmd >> 4, cmd, data1, data2};
MidiUSB.sendMIDI(midiMsg);
}
Hereās the Sonic Pi Code:
live_loop :midi_box do
use_real_time
note, velocity = sync "/midi*/note_on"
puts note, velocity
set :b, note
if note == 48
sample :bd_haus
end
if note == 60
sample :sn_zome
end
end
It can also receive Midi messages from Sonic Pi. Hereās a quick project I made that lights up different LEDs depending on which note is playing.
If anyone is interested, Iāll post the code for this one too.