Processing not recognising MIDI data from an Arduino

Hi I have been trying to send MIDI data from an Arduino to Processing, so far without success. This is my first post on Processing, many thanks in advance for any suggestions you can make. I'm using Processing 2.2.1 on Windows 7 with an Arduino Micro connected via USB as a serial connection.

For code at the Processing end I am using MidiBus and, having started with the Basic.pde in that libraries example folder, I have adapted it to match the serial rate sent by the Arduino (see code below). The basic problem is that the MidiBus.list() command produces a list of recognised input and output devices where the only input device is [0] "Real Time Sequencer", which it does regardless of whether the Arduino is connected. Hence the Arduino is not being recognised, this is my main problem at the moment, I'll work out what to do to get the note information to sound in a later step.

The Processing code that I am using at present is:

import processing.serial.*;
import themidibus.*; //Import the library

Serial port;  // Create object from Serial class
MidiBus myBus; // The MidiBus

void setup() {
  size(400, 400);
  MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
  myBus = new MidiBus(this, 0, 2); // Create a new MidiBus using the device index.
  String portName = Serial.list()[0];
  port = new Serial(this, portName, 31250);

At the Arduino end I have tried writing direct serial hex as per , where I can set the serial rate directly, e.g 9600 or 31250 bps. Thus Arduino code attempt A was:

void setup() {

void loop() {      // play some notes on channel 1:
   for (int note = 0x1E; note < 0x5A; note ++) {
     noteOn(0x90, note, 0x45);     // Play a note
     noteOn(0x90, note, 0x00);     // Silence the note

void noteOn(int cmd, int pitch, int velocity) {

I have also tried using the Arduino MIDI library, adapted from their library example, which from what I understand of the documentation is that it defaults to 31250 bps. Arduino code attempt B was:

#include <MIDI.h>
#define LED 13              // LED pin on Arduino Uno

void setup()
    pinMode(LED, OUTPUT);

void loop()
        MIDI.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
        MIDI.sendNoteOff(42,0,1);   // Stop the note

Can anyone please spot whatever obvious mistakes I am making to get the Arduino recognised?

Sign In or Register to comment.