Go Down

Topic: 'midi in" project.... (Read 14 times) previous topic - next topic


Jul 08, 2006, 12:34 pm Last Edit: Jul 08, 2006, 12:36 pm by bod Reason: 1

i've been working on this project for a month or so now, and not really getting anywhere with it. in the past i've mainly used my arduino board for LED control and for switching reed relays on and off, but now i'm trying(unsuccessfuly) to get arduino to listen to incoming midi messages from an external sequencer.

having looked arround the web, i've decided to use a common schematic that is also available from Toms site.

its the top schematic, for midi in.

i have a bread board with the parts set up, and the serial out from the 6n138 chip is connected to the RX pin of my arduino board.

at the moment, all i'm trying to do is get the board to listen for a midi signal and switch on pin 13, where i have an led connected, but so far its just not working.

i have tried loads of different variations of code, heres an example, which was modified from the basic serial read tutorial.

Code: [Select]

int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the data from the serial port

void setup() {
 pinMode(ledPin,OUTPUT);   // declare the LED's pin as output
 Serial.begin(31250);        // connect to the serial port

void loop () {
 // read the serial port
 val = Serial.read();

 if (val != -1) {
   if (val == 0x90, 0x01, 0x45 ) { // note on, channel 1, note value 1, velocity 45
     digitalWrite(ledPin, HIGH);
     digitalWrite(ledPin, LOW);

i have a midi signal being sent from ableton live, through my usb midisport 2x2 and into the bread board. from there it goes through the 6n138(and the relevant diodes and resistors) to the RX pin of the arduino board. the board isnt connected via usb, and is powered from a wall adaptor.
the RX and TX leds on the board are lighted up(but very dim) but i just cant seem to get any sort of response. i can see that the Midisport is receiving the signal from ableton as its got indicator leds to show when a signal is received and sent.

so, does any one have any ideas or tips that might get this working? it would be greatly appreciated!!





i've no experience with midi (except for usb-keyboard i use). but i like the idea of "arduino<>midi"...
i cannot say anything about your hardware setup. but since you say it's a proven setup...

for the rx and tx leds: it's normal that they are lid, when you are powering the board from en external supply (not usb). still the rx led should blink on incoming data!

did you try your code without that if-clause in your loop? it would be nice to know if your board receives anything at all before you start to interpret tha data.

if it does, i'd figure out a way to see _what_ it receives. (maybe more leds?)

what about the start and stop bits of a midi message? are they compatible with arduino's serial communication?

after all it would be nice to have arduino connected to your computer via usb for debugging. but since you're using the rx/tx for your midi communication this might not work :-/

i'd really like to see you having success, so keep us updated!



by the way:

are you sure about your if-code?

if (val == 0x90, 0x01, 0x45 ) { ...}

i don't know this syntax.
"val" is (only) one byte of data or "-1".

if you're not sure, try

if ( (val==0x90) | (val==0x01) | (val==0x45) ) {...}

since you want to check if "val" is equal any of your values.


to be honest i didnt expect that code to work anyway for the same reason that val is only one byte, not a string of bytes.

my main problem at the moment is to actually receive any sort of signal from the rx pin. when i connect the circuit up, the rx and tx leds on the board dim to half their brightness, and there seems to be no signal at all being recieved by the board when i send a midi note from the midisport interface. maybe i've screwed up the hardware side of things, but i've checked it a million times.  :-?

i used to use MAX to convert midi notes to ascii characters to send over to the arduino board to activate reed relays, but i'm sure there must be a way to get arduino to do this itself.

think i'll go and bang my head against the wall a bit more.....


Some debugging tips

remove the chip from the arduino board and just open a terminal emulation program on the computer trying to setup a speed of 31250 baud when themidi data comes in you shoud see the caracters show up on the screen.

this will show you if the data is actually coming through the midi interface

then put the chip back in

on the other hand the "if" syntax you have will not work...
you need to check for 0x90 only and then have more nested if statements to check if the sequence is correct.

i think you should be able to read data from the midi interface...

let us know your progress


Go Up