…and now ANOTHER music post: SparkPunk Sequencer MIDI synchronisation with Arduino (work in progress)

“Tunz-tunz-tunz” 😀 my dear geek-musician friends (female and male of course)!

Today I used for you my “house-disco-techno”-style “hello”, because today I wan t to talk you about msuica (again).

Some day ago I bought from my preferred store (RobotItaly, as you know), and I assembled two new exciting toys from Sparkfun: Sparkpunk Sound Generator and SparkPunk Sequencer.

The Sparkpunk Sound generator is a very interesting sound generator similar to the famous ATARI Punk Console,  The Sparkpunk Sequencer is a control voltage step sequencer used to control the the Sound Generator.

After the assembly of the two devices, I played some hour with these objects… but, as you know, I am a (pro-am) musician, and I would like to have a MIDI IN  port in all my instruments. Because I attach my devices to my DAW (digital audio workstation, examples are: Steinberg Cubase, Ableton Live, Cakewalk Sonar, Apple Logic Pro etc.) resident on my computers (Mac or PCs), and my DAW  is ALWAYS the MIDI master for my set of instruments. I should command the tempo, the start and stop of my devices.

Before to do my modifications, I printed (and read) the following IMPORTANT page: https://learn.sparkfun.com/tutorials/sparkpunk-sequencer-theory-and-applications-guide . So, firstly I followed the steps for modifications in the section “Synchronizing Multiple Sequencers” and I opened the connections between IN and OUT for the pins CLK, BTN, RUN, STOP (and I used jumpers in order to re-close them again, in case the sequencer isn’t controlled from another device and it used stand alone).

After this, I thinked to use an Arduino UNO as interface between my MIDI master (the DAW) and the Sparkpunk Sequencer in order to force the Sparkpunk Sequencer to follow the MIDI clock of the DAW. This is the actual setup of my experiment:

wpid-20141021_071110.jpg

Well, the PC (Midi OUT port) to Arduino (MIDI IN port) is not difficult: it’s a very simple circuit described in one of my old posts. Using this setup the MIDI in signal pin will be connected to the Arduino D10 pin via SoftSerial.

In order to build logicaly and electrically the interface between Arduino and the SparkPunk Sequencer I studied the signals on the CLK IN, BTN IN, RUN IN, STOP IN pins in the Sequencer stand-alone configuration (so the CLK IN is connected to CLK OUT, BTN IN is connected to BTN OUT, RUN IN is connected to RUN OUT and STOP IN is connected to STOP OUT… using my preferred tools: the jumpers!).

I studied them connectinfg the oscilloscope on the pins and pressing the Run button on the Sequencer in order to start and stop the sequence. These are the results (drawn by hand… it’s so stylish and vintage! 🙂 ):

wpid-storageemulated0DCIMCamera2014-10-21-07.58.15.png.pngWell… as you see the behavior is very simple. And we can simply replicate it using Arduino with the following logic:

  • When Arduino receives from DAW the MIDI START message it commands the RUN IN pin high, the STOP IN pin  low and BTN IN pin firstly high and after a short delay (I used 5ms and it works…but you can measure the real value with the oscilloscope if you want) it commands it again low.
  • When Arduino receives from DAW the MIDI STOP message it commands the RUN IN pin low, the STOP IN pin high and BTN IN pin firstly high and after a short delay (I used 5ms and it works…but you can measure the real value with the oscilloscope if you want) it commands it again low.
  • The CLK IN value is commanded by Arduino following the reception of the MIDI CLK message, in order to synchronize the tempo of Sparkpunk Sequencer with the DAW tempo.

IMPORTANT Note: a standard MIDI CLK message is sent by a DAW 24 times per quarter note. A time of 120 BPM (beats per minute) is equivalent to 120 quarter notes per minute, so in this case the DAW sends from the MIDI out (120*24)/60 messages per second. It’s too much for our Sparkpunk sequencer (if you sends all these messages to ther sequencer, it doesn’t work…and you can’t see the ON/OFF of the Rate led).

So I decided to send to the SparkPunk sequencer only one MIDI CLK message per 24 received by the MIDI IN port on Arduino. In other words Arduino decreases the rate of MIDI CLK message in order to correctly command the sequencer.

Regarding the hardware connections, the are very simple:

  • Connect the Arduino GND to a GND point of the Sparkpunk system (i.e. the ground of the Speaker port on the Sound Generator)
  • Connect the Arduino pin D2 to the RUN IN of Sparkpunk sequencer
  • Connect the Arduino pin D3 to the STOP IN of Sparkpunk sequencer
  • Connect the Arduino pin D4 to the CLK IN of Sparkpunk sequencer
  • Connect the Arduino pin D5 to the BTN IN of Sparkpunk sequencer

This is the simple Arduino code:

#include <SoftwareSerial.h>
SoftwareSerial MidiSerial(10, 11); // RX, TX

byte midi_start = 0xfa; 
byte midi_stop = 0xfc; 
byte midi_clock = 0xf8; 
byte midi_continue = 0xfb; 
int play_flag = 0;
byte data;

//synchro values
int number_of_received_clocks=0;

#define MAX_BPM 160
#define MIN_BPM 20

void setup() 
{ 
  MidiSerial.begin(31250); 
  Serial.begin(115200);
  //led 13 used for debug
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
 
  //interface --->Sparkpunk sequencer
  pinMode(2,OUTPUT);
  digitalWrite(2,LOW); //midi start sequencer
  
  //interface --->Sparkpunk sequencer
  pinMode(4,OUTPUT);
  digitalWrite(4,LOW); //midi synch sequencer
  
  //interface --->Sparkpunk sequencer
  pinMode(3,OUTPUT);
  digitalWrite(3,HIGH); //midi stop sequencer
  
  //interface --->Sparkpunk sequencer
  pinMode(5,OUTPUT);
  digitalWrite(5,LOW); //button sequencer 
}

void loop() 
{
  if(MidiSerial.available() > 0) 
  {
    data = MidiSerial.read();
     if(data == midi_start) {
       Serial.println("Start Midi");
       
       //sparkpunk interface commands
       digitalWrite(2,HIGH);//start/run sequencer
       digitalWrite(3,LOW);//stop sequencer
       digitalWrite(5,HIGH);//button sequencer
       delay(10);
       digitalWrite(5,LOW);//button sequencer
       
       play_flag = 1;
      }
      else if(data == midi_continue) 
      {
        play_flag = 1;
      }
      else if(data == midi_stop) {
        Serial.println("Stop Midi");
       
       digitalWrite(2,LOW);//start/run sequencer
       digitalWrite(3,HIGH);//stop sequencer
       digitalWrite(5,HIGH);//button sequencer
       delay(10);
       digitalWrite(5,LOW);//button sequencer
       
        play_flag = 0;
        number_of_received_clocks=0;
      }
      else if((data == midi_clock) && (play_flag == 1)) { 
        number_of_received_clocks++;
        //Serial.println(number_of_received_clocks);
        if(number_of_received_clocks%24==0) //see MIDI specification: the clock is sent 24 times for quarter note, and 120BMP=120 quarter notes for minute => BPM value= 60/time to receive 24 clocks
          {
            Sync();
          }
      } 
  }
}

void Sync() {
     digitalWrite(4, HIGH);
     delay(100); //high part of the clock square wave.
     digitalWrite(4, LOW);
}

As you see I used for the CLK IN  a square wave with a period of 200 ms (100 ms high and 100 ms low). It seems sufficient in order to command the step ahead of the sequence.

Ok, using this sketch and starting the MIDI clock on my DAW, the Sparkpunk Sequencer starts working, exactly synchronized with the DAW (and the sound is correctly generated by the Sound Generator). Modifying the BPM tempo on the DAW causes that Sparkpunk SEquencer changes correctly his tempo, and it correctly starts/stopswhen the start/stop command is sent by the DAW. Yeahhhhhhhhh! 😉

But.

Yes, there are always some “But” in my projects. 🙂

In this case there are still some strange behaviors of the system, to be investigated and debugged (also with YOUR contribution, my dear followers, if you want):

  1.  The Sequencer start working also if the POWER switch is OFF, and at the same time the . It’s clear that the sequencer and sound module takes power from the 4 pins connected to Arduino…
  2. In this condition the ouput volume of the Sound Generator is a little low… maybe the Arduino doesn’t drive the correct power supply to all the system. 😦
  3. In this condition (POWER switched OFF) only the LONG pulse works, if I switch on SHORT no sound is emitted from the Sound Generator.
  4. If I change the POWER switch from OFF to ON on the sequencer (or on the Sound Generator), only the SHORT pulse is emitted (if I switch to LONG pulse no sound is emitted)
  5. Finally, in this case (POWER switched ON on the Sequencer) the output volume of the Sound Genrator is higher.

I think all is tied to the fact that Arduino power is not sufficient to drive all the circuits (Arduino itself+MIDI interface, Sound Generator and Sequencer), and to the fact that Arduino uses 5V as HIGH value for the CLK IN, but Sparkpunk sequencer uses 7.5V. See also the paragraph called “Switch Voltage Processing” in the  https://learn.sparkfun.com/tutorials/sparkpunk-sequencer-theory-and-applications-guide …I think it is very involved in this behavior of the circuit. I’m continuing my investigation.

Another solution I would try in the near step of my experiment is to use a MOSFET commanded by Arduino pin D5 (connecting the D5 to the gate pin, the CLK IN to the source pin and the CLOCK OUT to the drain pin, for example), in order to control the synch pulse on the CLK IN connecting it to the CLK OUT (something similar to a electronic switch), in order to have the same situation of the stand alone Sequencer configuration, but generating the clock pulses using the MIDI tempo. It’s a solution similar to which used in this video from Sparkfun: https://www.youtube.com/watch?v=LUcqDM4k1gU

Well… but now, after this ordeal, I’m really ready for a glass (…a bottle?) of my preferred grappa. If you know what I mean. 😉

Bye bye daft-punk-electronicmusicians-techno friends!

 

Garretlabs meets Bleep Drum: an Arduino based drum machine with some “tasty hacks”!

Hi techno girls and techno boys!

A long time is passed from my last post, but I worked to many projects in parallel… some of these will pe published here in the near (…ehhhhmmmm!) future. 😉

Since you know I am also a musician (please visit my italian music homepage, which contains  good music to download 😉 : www.marcolastri.net), today I present you a very interesting “hack” which I’ve done starting from a beautiful device from Bleep Labs: the famous, open source and open hardware, and overall groovy Bleep Drum (a very powerful drum machine with a set of 80’s sounds):

The great Bleep Drum with MIDI controller

I asked Dr. Bleep (the Bleep Labs boss) the permission to publish here my complete hacking project….and he gave it to me with pleasure. Many thanks Dr. Bleep, you’re a great!

…So, I am here to describe you my work.

Starting from the schematic of Bleep Drum I noticed that the device used one ATMEGA 328 with 16Mhz quartz….very similar to Arduino architecture.

Then I downloaded the source code (version 07)  for Bleep Drum from the official repository…and I saw that the code was written for Arduino! 🙂 . Note the newest version of the software is the 09.

So, I replicated the embedded project using and Arduino Uno (using the well known mapping between Arduino GPIO pins and the ATMEGA328 pins) and two/three breadboards in order to apply my hacks.

Well, I wanted to add three main functionalities to Bleep Drum:

  1. A two channels-mon0 output instead the original one channel mono (because in my home studio I would like to use the output of the Bleep Drum to enter in two mono parallel filters)
  2. A Volume control
  3. A little amplification functionality

So, I worked on the output stage of the Bleep Drum and I applied the following modifications (all is designed “by hand”, as usual! 😉 ). In the drawing (made by ML 🙂 ) you can see the differences from my output stage and the original one.

wpid-storageemulated0DCIMCamera2014-10-08-10.19.22.png.png

In practice, I directly connected the output of the MPC4901 DAC to a LM358 dual operational amp, removing the resistor and the capacitor and adding a 10K potentiometer in order to control the volume.

I connected this output to the two gates of the LM358, in order to have two amplified mono channels.

Finally,  as you see,  I’ve connected the two outputs of the  LM358 gates to the jack tip and ring using two 10uF capacitors.

This is the complete Fritzing schema of the project (click to view the full size image).

BleepDrumsML_v04---FINAL---amplified+stereo_bbThis is the overall project photo:

wpid-20141008_065606.jpg

And finally, thi is the detail of the modified output stage:

wpid-20141008_065617.jpg

Regarding the Arduino software, the version 07 of the official sofware is working great on my hack! 😉

Now the output of my homemade Bleep Drum is very loud (and also “pumping”, if you know what I mean 😉 ), controlled in volume and on two mono channels. YEAHHHHHH! 🙂 So…I will use this instrument in my next electronic music compositions… because (as many of you know) I love the 80’s sounds!

Before to close this post I would like to thank again Dr. Bleep (and Bleep Labs) for his great work and for his helpfulness.

Bye bye geek-girls and geek-boys: I go to compose some good music…using my new instrument! 😉

See you soon!