If you are on windows you could use putty.exe as serial monitor.
FYI, putty can also communicate at higher speeds than 115200. I succesfully communicated the Arduino at 230400 and 345600 baud. This latter is approx 40 char per millisecond,
Better option is to use a second Arduino that talks 31250 on hardwareserial and 115200 on a software serial
Be aware that the serial monitor is not able to interpret MIDI bytes,
So if you have an Arduino to spare go for option 2 and build us a MIDI sniffer and "thou will gather eternal f(l)ame"
here a 0.1 MIDI sniffer sketch
//
// FILE: MIDIsniffer.pde
// AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: get insight in MIDI comamnds
//
// HISTORY:
// 0.1.00 - 2011-07-16 initial version, rob tillaart
// hex dump only
//
//
// Released to the public domain
//
#include <NewSoftSerial.h>
#define MIDI_BAUD 31250
#define MONITOR_BAUD 115200
NewSoftSerial Monitor(4, 5);
void setup()
{
Serial.begin(MIDI_BAUD);
Monitor.begin(MONITOR_BAUD);
Monitor.println("MIDI sniffer 0.1.0");
}
int i = 0;
void loop()
{
if (Serial.available() > 0)
{
int m = Serial.read();
Monitor.print(m, HEX);
Monitor.print("\t");
i++;
if (i == 10)
{
i = 0;
Monitor.println();
}
}
}
There exist midi2text tools (and vice versa) that may be used to extend above sketch
Shit. I really dont know what the problem is, and if there is actually a Problem.
}
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
Serial.print("incomingByte");
// wait for as status-byte, channel 1, note on or off
if (incomingByte== 144){ // note on message starting starting
action=1;
}else if (incomingByte== 128){ // note off message starting
action=0;
}else if (incomingByte== 208){ // aftertouch message starting
//not implemented yet
}else if (incomingByte== 160){ // polypressure message starting
//not implemented yet
}else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
note=incomingByte;
playNote(note, 0);
note=0;
velocity=0;
action=2;
}else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
note=incomingByte;
}else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
velocity=incomingByte;
playNote(note, velocity);
note=0;
velocity=0;
action=0;
}else{
//nada
}
}
this is the code and i always get 4 integers on the serial monitor, when i send a midi note to it.
perhaps it is because the arduino is also connected to my pc serially. could this be a problem?
}else if (incomingByte== 160){ // polypressure message starting
//not implemented yet
}else if ( (action==0)&&(note==0) )
after reading a byte from the line you set some flags which are tested in the same if then else ladder as the incoming bytes. Think you have to remove the 2nd else in above snippet.
read values & set flags
take action upon flags.
General remarks:
use of proper indentation makes the flow more clear
Serial.print("incomingByte"); is informative, but why not printing the incoming byte itself too?
its so strange, when i do stuff on my midi gear, like editing a note and change the menu, then there comes 144 as byte to the midi in. sometimes it works after hitting a key of the keyboard very often.
thats even still working when i write incomingByte = Serial.read()- '0';
@robtillaart, i ll take a closer look at what you said, when actually anything is working
EDIT:
this now comes in the Serial.Monitor (i played one note) :
-48-48-48-48-48-48206 (if initiliaze the variable "incomingByte" not as byte but as int
if i set it to byte again and "Serial.print(incomingByte, DEC) i get this for a note :
208208208208208206
if i do not write incomingByte = Serial.read()- '0'; but incomingByte = Serial.read();
i get this as decimal serial print for a note:
00254254000254
So that seems to be the proper way to interpret the data..
Stil I don't understand your code. I would expect something like this below (not tested).
void interpretMIDI()
{
while (1) // do it forever
{
while (Serial.available() == 0); wait for start of MIDI message
incomingByte = Serial.read();
// Serial.print("input: ");
// Serial.println(incomingByte, DEC);
switch(incomingByte)
{
case 128: // note off message
while (Serial.available() < 1); // wait until whole message in buffer - assumption you need 1 other byte
note = Serial.Read(); // read the note to stop
playNote(note, 0);
break;
case 144 : // note on message
while (Serial.available() < 2); // wait until whole message in buffer - assumption you need 2 other bytes
note = Serial.Read();
velocity = Serial.Read();
playNote(note, velocity);
break;
case 160: // polypressure message starting
// read the rest of the command
// and action
//not implemented yet
break;
case 208: // aftertouch message starting
// read the rest of the command
// and action
//not implemented yet
break;
default:
// Serial.print("unknown code : ");
// Serial.println(incomingByte, DEC);
} // end of switch
} // end of while
}