Bluetooth Foot Pedal for Onsong – an alternative to Airturn ?

Project History!

 

The intention of this post is to serve as an aide-memoire for a little project I’ve been working on recently.

From time to time, I lead worship at my church, and play acoustic guitar.  For song lyrics / chord charts I use a popular app on IOS called Onsong.

A while ago I found an old guitar foot switch unit that started life belonging to a Marshall amp.  I took most of it’s inwards out and wired up a simple Bluetooth keyboard to the 4 main switches, and then in turn, paired this with my Ipad.  Within Onsong settings, I configured the footpedal options to respond to “keyboard” presses – u = Up, d = down, n = next song .and p = previous song.

So far so good…..apart from one bug-bear.  When IOS detects an external keyboard, it disables the on-screen keyboard functionality – a feature I use to add sticky notes, edit chord charts and so on.

And thus this project was born….to find a better way of doing this.  The result ?  An Arduino based board that transmits MIDI notes over Bluetooth Low Energy.

The Arduino board I used is an Adafruit Feather M0 Bluefruit LE  – https://www.adafruit.com/product/2995 coupled with a small 3.7v LiPo battery (https://www.modmypi.com/raspberry-pi/power-1051/li-ion-and-lipo-1053/lithium-ion-polymer-lipo-battery-3.7v-140mah)

Now, I am the first to admit that I am not a “programmer” by any means and so the Arduino sketch part of the project contained much stumbling in the dark – along with lots of cross referencing to the following guides:

https://learn.adafruit.com/adafruit-feather-m0-bluefruit-le?view=all

https://learn.adafruit.com/wireless-untztrument-using-ble-midi/overview-uniontownlabs

https://io.adafruit.com/blog/tip/2016/12/14/feather-power-switch/

The first challenge I had was that my board needed a firmware update to enable the Midi functionality properly…nothing like an Arduino baptism of fire.  Fortunately though, there are easy to follow instructions here: https://learn.adafruit.com/adafruit-feather-m0-bluefruit-le?view=all#dfu-bluefruit-updates

 

Schematic:

I have chosen to use 5 momentary switches for Up, Down, Next Song, Previous Song and Pad track Start/Stop Toggle (I control volume with a passive volume pedal)

 

 

 

 

 

 

 

 

 

Onsong settings

 

Demo

 

 

Arduino Sketch

#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "Adafruit_BLEMIDI.h"
#if SOFTWARE_SERIAL_AVAILABLE
 #include <SoftwareSerial.h>
#endif

#include "BluefruitConfig.h"

#define FACTORYRESET_ENABLE 1
#define MINIMUM_FIRMWARE_VERSION "0.7.0"

// Create the bluefruit object, either software serial...uncomment these lines
/*
SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);

Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
 BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
*/

/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
// Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
// BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
// BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

Adafruit_BLEMIDI midi(ble);


bool isConnected = false;
int current_note = 60;

// A small helper
void error(const __FlashStringHelper*err) {
 Serial.println(err);
 while (1);
}

// callback
void connected(void)
{
 isConnected = true;

Serial.println(F(" CONNECTED!"));
 delay(1000);

}

void disconnected(void)
{
 Serial.println("disconnected");
 isConnected = false;
}

void BleMidiRX(uint16_t timestamp, uint8_t status, uint8_t byte1, uint8_t byte2)
{
 Serial.print("[MIDI ");
 Serial.print(timestamp);
 Serial.print(" ] ");

Serial.print(status, HEX); Serial.print(" ");
 Serial.print(byte1 , HEX); Serial.print(" ");
 Serial.print(byte2 , HEX); Serial.print(" ");

Serial.println();
}

void setup(void)
{
 // while (!Serial); // required for Flora & Micro
 delay(500);

Serial.begin(115200);
 Serial.println(F("Adafruit Bluefruit MIDI Example"));
 Serial.println(F("---------------------------------------"));

pinMode(5, INPUT_PULLUP);
 pinMode(6, INPUT_PULLUP);
 pinMode(10, INPUT_PULLUP);
 pinMode(11, INPUT_PULLUP);
 pinMode(12, INPUT_PULLUP);
 pinMode(13, OUTPUT);

/* Initialise the module */
 Serial.print(F("Initialising the Bluefruit LE module: "));

if ( !ble.begin(VERBOSE_MODE) )
 {
 error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
 }
 Serial.println( F("OK!") );

if ( FACTORYRESET_ENABLE )
 {
 /* Perform a factory reset to make sure everything is in a known state */
 Serial.println(F("Performing a factory reset: "));
 if ( ! ble.factoryReset() ) {
 error(F("Couldn't factory reset"));
 }
 }

//ble.sendCommandCheckOK(F("AT+uartflow=off"));
 ble.echo(false);

Serial.println("Requesting Bluefruit info:");
 /* Print Bluefruit information */
 ble.info();

/* Set BLE callbacks */
 ble.setConnectCallback(connected);
 ble.setDisconnectCallback(disconnected);

// Set MIDI RX callback
 midi.setRxCallback(BleMidiRX);

Serial.println(F("Enable MIDI: "));
 if ( ! midi.begin(true) )
 {
 error(F("Could not enable MIDI"));
 }

ble.verbose(false);
 Serial.print(F("Waiting for a connection..."));
}

void loop(void)
{
 // interval for each scanning ~ 500ms (non blocking)
 ble.update(400);

// bail if not connected
 if (! isConnected)
 return;


 // send note on
// midi.send(0x90, 61, 0x64);
// delay(500);

// send note off
// midi.send(0x80, 61, 0x64);
// delay(500);

int delay_time = 50;

// increment note pitch
// current_note++;

// only do one octave
// if(current_note > 72)
// current_note = 60;

// Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
 // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the
 // button's pressed, and off when it's not:
 if (digitalRead(5) == LOW) {
 current_note = 60;
 Serial.print("Sending pitch ");
 Serial.println(current_note, HEX);
 midi.send(0x90, current_note, 0x64);
 }
 delay(delay_time);

if (digitalRead(6) == LOW) {
 current_note = 62;
 Serial.print("Sending pitch ");
 Serial.println(current_note, HEX);
 midi.send(0x90, current_note, 0x64);
 }
 delay(delay_time);
 
 if (digitalRead(10) == LOW) {
 current_note = 64;
 Serial.print("Sending pitch ");
 Serial.println(current_note, HEX);
 midi.send(0x90, current_note, 0x64);
 }
 delay(delay_time);

if (digitalRead(11) == LOW) {
 current_note = 66;
 Serial.print("Sending pitch ");
 Serial.println(current_note, HEX);
 midi.send(0x90, current_note, 0x64);
 }
 delay(delay_time);

if (digitalRead(12) == LOW) {
 current_note = 68;
 Serial.print("Sending pitch ");
 Serial.println(current_note, HEX);
 midi.send(0x90, current_note, 0x64);
 }
 delay(delay_time);
 
// }

}

 

Wrap-up

I’d love any comments or questions about this project – I will do my best to answer them!

Also, if you have any suggestions for how the Arduino code could be improved or tweaked I’d love to hear your ideas.

Thank you!

Continue Reading

8 more sleeps!

9daystogo
The lovely London Marathon page on Facebook today popped up to say there are 9 days to go!!!

The most fantastic way to start this update is to be able to say I have reached my Fundraising target and at the time of posting it stands at – £ 2127.65
I am truly humbled and blessed by the generosity that people have shown in supporting WaterAid in helping me reach this target.

Continue Reading

Counting down…as the miles go up!!

Having been a month since my last post, I figured it’s about time for a quick update.

I took part in the Cancer Research ‘Winter Run’ on the 31st January.  It’s a popular 10k race starting in Trafalgar Square, and finishing along Whitehall.
It was the first race of it’s size that I’ve taken part in, with around 15,000 people taking part.
I really enjoyed it, especially as I finished in 53:32 which is about 4 minutes off my previous 10k PB!

I’ve been thinking about how best to capture the marathon day experience and have wondered about wearing a GoPro-type camera to record the run as I go.  I was able to borrow a GoPro Hero from a friend to try out on the Winter Run.  Apart from lots of rain drops on the lens it was a great experiment and definitely something I will do for the Marathon.

winterrun1

The training volume has ramped up a bit and now the runs are getting longer – last Sunday was 13.1miles which I managed in 2hr 08 which I’m really happy with.

Fundraising is also going well, and I want to take the opportunity to say a massive “Thank You” to all those who have donated already – it is so encouraging to receive such generous support.  At the last check the total was £ 453.20.

If you haven’t donated yet, please give as generously as you are able to WaterAid – every pound given is literally changing lives, and helping provide clean, safe water, and necessary sanitation to those who need it most.

Here is the link to my Virgin Money Giving page:

http://uk.virginmoneygiving.com/anthonywarren1

11 weeks and counting to marathon day!

 

Continue Reading

100 Days to Go – And Counting!

Eek!! So it seems I’ve hit the big 100 day countdown, and now it’s time to get serious!100daystogo

I started my formal training plan at the beginning of the year, but now its crunch time! So far, it seems to be going really well – running 3 – 4 times a week, with a longer run most Sundays!

I’ve forcefully become acclimatised to arctic temperatures to run in – all included in the fun of being a crazy marathon runner!

As the day gets closer, the importance to reach my fundraising target is on my mind. It’s been great to receive such generous donations already, a big thank you to everyone who has donated so far! 🙂

However, there is still plenty of opportunity to do your bit and give what you are able to such an important charity, whilst helping me hit that big £2000 – and hopefully beyond!!

Here’s the link to my Virgin Money Giving page to donate: http://uk.virginmoneygiving.com/anthonywarren1

Off for another run now!!
Thank you for reading and supporting!!

 

 

Continue Reading

Running for WaterAid

I realised it would probably be helpful to share some of the background to why I am running the Marathon, who I will be running for and why.

Why am I doing this ?

I had the opportunity to go to Rwanda in 2005 and I have very clear memories from that trip of seeing people walking huge distances, carrying heavy water containers – on a daily basis.  Everyone appeared to have to go through this – from the youngest to the oldest.

The need is huge!

There are around 630 million people in the world who don’t have access to clean, safe water.  Around 2.3 billion people don’t have access to adequate, safe sanitation.  Around 315,000 children under-five die every year from diarrhoeal diseases caused by dirty water and poor sanitation. That’s 900 children per day

WaterAid is seeking to transform this situation and has goals of reaching everyone by 2030.

So please visit my Virgin Money Giving page and donate as much as you are able http://uk.virginmoneygiving.com/anthonywarren1

In the words of a well-known supermarket chain – “Every little helps!”

Thank you.

Water

 

 

 

Continue Reading

Marathon Training plan choices?

26.2I know there is a long way to go before April, but I figured I would start looking at choices for Training plans….and I’m glad I looked now.

There are so many choices!  In fact, it’s quite bewildering how many variations there are.  Some focus on time-based runs, some on mileage, while others different again.

So far for other training , I have been using the plan feature of the Asics website and I quite like this as it syncs with my Google Calendars.

My other contenders at the moment are from The Running Bug, the official VLM plan, or maybe the plan contained within the book The Non-Runner’s Marathon Trainer”non-runners marathon trainer

So, if anyone has any tips, recommendations I would love to hear about them in the comments below.

http://therunningbug.co.uk/training-advice/running-training/plans/marathon-plans/b/weblog/archive/2011/01/17/intermediate-marathon-training-plan.aspx

 

https://www.virginmoneylondonmarathon.com/en-gb/trainingplans/intermediate-17-week-training-plan/

 

 

Continue Reading

Ballot results are in!

This week the ballot results for entry into the Virgin London Marathon 2016 are being sent out.

I have seen a lot of posts on Facebook from friends receiving the pack through the post, containing the magazine indicating whether the ballot entry was successful or not.

 

magazine

Well, yesterday, Royal Mail visited my letterbox and popped my pack through.   It too was a Sorry! version of the magazine – no ballot result for me.

 

However, I’m not dissappointed…..because I have been offered, (and accepted!) a charity place to run for WaterAid. Wooohooo!!

WaterAid are striving to provide access to clean, safe water, and sanitation to the millions in the world who currently don’t have access to these utilities that so many of us take for granted.

WaterAid-in-Supportjpg

I will expand more on the work of WaterAid in future posts, as well as fundraising updates, and my training progress.

If you would like to join me on the journey, please subscribe on my home page and you will be notified of posts as they are published.

 

 

Continue Reading

SSL Certificates from StartSSL for WebVPN on Cisco IOS

Masterpadlock-smallThis document is intended to walk-through the steps I took to successfully implement a free SSL certificate for use with WebVPN on a Cisco IOS Router.

I had tried a couple of times to use StartSSL certificates but fell at different hurdles.   However, this time I crossed the line.
The credit for this success goes 100% to a member on the StartSSL forum, dlambert – he documented his steps and I merely followed them!  This post is as much for my own reference, and if it helps someone else along – great!
Dlambert’s original post can be found at https://forum.startcom.org/viewtopic.php?p=6568&sid=1750512d3d6a4bbcc95dcd3cd94d228b#p6568

  1. Generate RSA Key-pair for use with Certificates
RTR(config)#crypto key generate rsa general-keys label RSA.StartSSL-vpn modulus 2048 exportable

RTR(config)#crypto key export rsa RSA.StartSSL-vpn pem terminal 3des <password>

This will display the RSA keys to the screen.
Copy and Paste these into a text file on your computer.  Save the section containing the private key to a file called private.key
For example:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,E3568BE1DF325CB8

lxkgHIrPBaX4QNJo7EN1QzAvB+iz7A+UXNlwJvyB2Moy7UhGXdq5ss3sQUVXdbem
nA56jYUnLKOjPUHjPfeMEa2zHdTCS5P9HFu6VjXgn1gc9tTtTsVXrVy/nQYJbTBv
.......
6m5N37apbOAypLZTKx6BekHsE4TfDv2FHJsbNwJxtVlBLwS5j0TlN8j0vZh4y6TK
gVpKU1kMbOpBtzVHoT5LCBPCXOPak1jqg66xpU0ztlD6Vy2Vtx1mhcUZXGfXo7P7
-----END RSA PRIVATE KEY-----

2. Create a template file for the Certificate Signing Request.

Save the following code snippet and save it as 2048.cpl

#################################################
[ req ]
default_bits    = 2048
distinguished_name   = dn

[ dn ]
countryName    = Country
stateOrProvinceName    = State
localityName    = City
0.organizationName    = Company
organizationalUnitName    = Department
commonName    = FQDN
emailAddress    = Email
#################################################

3. For the next step, you need to have Openssl binaries on your local PC to be able to prepare the CSR in the correct format that StartSSL are expecting.  Visit www.openssl.org for details on how to do this, for your respective Operating System.

openssl req -new -sha1 -key private.key -out server.csr -config 2048.cpl

4.  Head over to the StartSSL website to generate the Certificate, based on the CSR you just created.

Follow the Wizard to generate a Web/Server SSL/TLS certificate.
On the screen titled, Generate Private Key – click the Skip button, as you have already generated your keys on the Router.

Copy and Paste the contents of the server.csr file you generated (including header lines)   into the Submit Certificate Request box.

Save the resulting certificate text into a file name of your choice.

Also, while on the certificate screen of StartCom, save the CA Certificate, and the Intermediate CA Certificates  (Right-click save-as)

5.  Create a Trustpoint on the router to hold the CA Certificate

RTR(config)#crypto pki trustpoint StartSSL-CA-Trustpoint
RTR(config)enrollment terminal pem
RTR(config)revocation-check none

RTR(config)crypto pki authenticate StartSSL-CA-Trustpoint

At this point, paste in the contents of the ca.pem (CA certificate file you downloaded earlier.
Finish with quit on a line on it’s own.

6.  Similar to step 5, but this time creating a Trustpoint that will hold the Intermediate CA, and linked to the RSA keys generated in Step 1.

RTR(config)#crypto pki trustpoint StartSSL-Inter-Cert-Trustpoint
RTR(config)#enrollment terminal pem
RTR(config)#usage ssl-server
RTR(config)#serial-number none
RTR(config)#fqdn vpn.domain.com
RTR(config)#ip-address none
RTR(config)#revocation-check crl
RTR(config)#rsakeypair RSA.StartSSL-vpn

RTR(config)#crypto pki authenticate StartSSL-Inter-Cert-Trustpoint

Paste in the contents of the  sub.class1.server.ca.pem Intermediate CA file.

7.  Now you can import your actual certificate, and it should be tied correctly to all the components.

crypto pki import StartSSL-Inter-Cert-Trustpoint certificate

Paste the contents of your certificate file you saved earlier.
Again, finishing with quit on a single line on it’s own.

If successful, you should see a good-looking message below!

% Router Certificate successfully imported

You can now configure your Webvpn context to refer to the 2nd Trustpoint you created, that contains your certificate.

 

Hope this helps!

Continue Reading