Arduino MIDI Remapper - Part 6 - Serial Interface

In Part 5 we looked at controlling the effects using the XB5s pushbuttons, e.g. vibrato, chorus, percussion (2nd & 3rd harmonic) etc. Although everything functioned as intended, there has been an ongoing issue where occasionally a spurious note would get played and get stuck on. I suspected this was just due to glitches/latency from running a ‘software’ serial port on the Arduino. 

The Serial Interface

The original MIDI standard specifies an opto-isolated serial interface running at 31.25 kbit/s. Although the Arduino Uno (R3) microcontroller board has a dedicated hardware serial port (using the USART in the ATmega328 microcontroller), I initially attempted to use a ‘software’ serial port for the MIDI communications. This was to allow the hardware serial port to be available for the Arduino console, for sending messages to the screen to help with program debugging. For the software serial port I initially used SoftwareSerial library, utilizing digital I/O pins 8 and 9 (see Part 1). Unfortunately it did not work reliably, i.e. the received messages were being corrupted. I believe this was due to timing/latency issues. I solved this problem by using a different library - AltSoftSerial (see Part 2). However, I still had the occasional problem with rogue notes being generated. I expected that this issue would be fixed by using the hardware serial port for MIDI communications.

Utilizing the Arduino Hardware Serial Port

Once I had completed and tested all the code, there was no need to have the hardware serial port available for debugging messages. To use the hardware serial port I just needed to reverse the hardware mod that I originally did to the Sparkfun MIDI board and modify the program slightly. 

Fig.1 shows the Sparkfun MIDI PCB after removing the two blob links and adding two blob links to connect up Arduino pins D0 & D1 for serial communication. 

Fig.1 - Sparkfun MIDI PCB Configured for Hardware Serial Port

The code snippet below shows the revisions to the definitions. 

 
// *** XB5remap8 ***
// This uses hardware serial port
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
// MIDI RX/TX pins are D0/D1

I also deleted the following section of code concerned with the serial console:

  Serial.begin(115200);
  Serial.println("starting serial with debug monitor");
  Serial.println("MIDI RX/TX pins are 8/9");

A minor inconvenience with using the hardware serial port for MIDI is that the Sparkfun MIDI board has to be switched to “PROG” mode before uploading the code to the Arduino. Of course, it then has to be switched back to “RUN” mode afterwards. This is all necessary because the Arduino needs to use the same serial port for communicating with the host PC via the USB interface. 

After carrying out the changes to the hardware and software, the MIDI remapper worked faultlessly. Even after several hours of testing, I have not yet had any problems with it. 

The next stage is to build the MIDI remapper hardware into the XB5 organ. 

Link to Part 5.


Reference

Sparkfun MIDI Tutorial


Disclaimer: This is my personal blog. Views expressed in my posts are my own and not of my employer. The information provided comes with no warranty. I cannot be held responsible for the content of external websites. Any practical work you undertake is done at your own risk. Please make health and safety your number one priority.

Comments