Pages: [1]   Go Down
Author Topic: format of midi messages  (Read 757 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey,

i am trying to build a midi controller with my arduino to control software. i use http://spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html to convert the serial messages to midi.
The problem is i don't know what the format is of the midi messages so that the converter can read it.

This is my code. when i press button 51 it should light up the led and send a midi message.
// set pin numbers:
int buttonPin = 51; // the number of the pushbutton pin
int ledPin = 53; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(115200);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.print("????????");       <----------------------------- what do i need to insert here?

//MIDImessage()
// prints hello with ending line break

}
else {
// turn LED off:
digitalWrite(ledPin, LOW);

}
}

sorry if it is a stupid question. i'm just totally unfamilliar with midi and i just want my arduino to send a single message to the converter so i can let my software react to the push of a button.

Thanks
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Firstly, you need Serial.write(), not Serial.print().

Secondly, http://www.midi.org/techspecs/midimessages.php.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the quick reply

do i need to send the messages in binary or in decimal?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As you should using Serial.write(), they should be sent as binary.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i still can't manage to send a message

I tried
Serial.write(00000100);
Serial.write(00000100);
Serial.write(00000100);

I tried
Serial.write("000001000000010000000100");

how do i need to seperate the midi bytes?
i want to send this message
10010010(Chan 3 Note on)    00000101(Note Number 5)    01111111(Note Velocity 127)
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.write(00000100);

sends the decimal number 100. You need the 0b prefix to tell the compiler that you are using binary numbers.

Code:
Serial.write(0b00000100);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks again for all your help

http://spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html says the midi message contains of 3 bytes and the first byte is seperated in an action part and a command part.
so i first tried sending 3 bytes
Serial.write(B00000100);
Serial.write(B00000100);
Serial.write(B00000100);
(the prefix B should also work right? http://www.arduino.cc/en/Reference/IntegerConstants)
and i tried splitting the action part and command part
Serial.write(B0010);
Serial.write(B0010);
Serial.write(B00000100);
Serial.write(B00000100);
but in the conversion software the light still turns red (which means it is reading serial data but it's not midi format.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The 'B' prefix is Arduino specific. If you want to use it, it must be followed by eight binary digits.

Did you read the link I posted. It explains the way the command and channel are merged to a single byte.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks got it working now!!
Logged

Pages: [1]   Go Up
Jump to: