Pages: [1]   Go Down
Author Topic: Sending a Midi Note  (Read 1889 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I have just bought the arduino Uno and I am trying to send a midi note and play with it in Reason (a software to make music) all I have is:
-Serial-Midi Converter Program
-Midi Yoko
-Arduino Uno
-1 button
-Protoboard

The only thing I want is that when I press the button, arduino send a midi note.

I have connected 5V to the button, and the other part of the button (switch) is connected to the digital port 2.

I would really appreciate how can I do that (the code).

Thanks and sorry for my English
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1255
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should break the problem down into component parts. There are clearly 2 things that you need to do:

1. Read a button and register that this has changed from OFF to ON. There is plenty of example code on how to do this. You should consider debouncing the switch so that you do not read false presses (sounds like you have not from the description).

2. Sending the note to the MIDI device. Again, lots of examples on how to do this (look for MIDI in the Playground) using various libraries trhat will do most of the work for you.

The easiest way to learn is to try writing some simple code from existing examples and then asking for more help when you get stuck.

« Last Edit: November 05, 2012, 02:43:15 am by marco_c » Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

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

Thanks for the reply, this is my code:

const int button1 = 2;     // the number of the pushbutton pin

int buttonState = 0;       

void setup() {
  pinMode(button1, INPUT);     
  Serial.begin(31250);
}

void loop(){
  buttonState = digitalRead(button1);
  if (buttonState == HIGH) {
    noteOn(0x90, 0x1E, 0x45);
    delay(100);
  }
}


void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}



In the Serial-Midi Converter, I can choose different speed rates: 31250, 38400, 57600, 115200. Which should I use?

Thanks
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1255
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The MIDI standard is 31250.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

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

Okey but the code isn't working
Logged

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have connected 5V to the button, and the other part of the button (switch) is connected to the digital port 2.

where is your pulldown resistor?
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1255
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When you have a switch wired to an input up you need to have a definite electrical signal for both when it is off and when it is on. When you switch the switch on, you are connecting it to 5V and your get a HIGH in the code. If you simply disconnect the switch and do not pull it down to 0V with through a resistor, then you get a floating input that can flip all over the place. Look up the principle for the "pull down" resistor circuit either on this forum or using google.

The same applies for a circuit that is normally at 5V and is switched to low. In this case the resistor is called a pull-up resistor, but the reasoning behind it is the same.
« Last Edit: November 04, 2012, 04:46:47 am by marco_c » Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13479
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


you can use the internal pull-down resistor this way

Code:
void setup()
{
  pinMode(button1, INPUT);     
  digitalWrite(button1, HIGH);
  Serial.begin(31250);
}

Please use the # button to apply [ code] tags to code to make it more readable
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

It was my fault, it was working. By the way I was using a 4.7k resistor.

Other question (As robtillaart said):

void setup()
{
  pinMode(button1, INPUT);     
  digitalWrite(button1, HIGH);
  Serial.begin(31250);
}


if button1 is an input, what does "  digitalWrite(button1, HIGH);" do? If somebody can explain it.

Thanks everybody
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1255
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It turns on an internal pull down resistor when used that way.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

France
Offline Offline
Sr. Member
****
Karma: 2
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was my fault, it was working. By the way I was using a 4.7k resistor.

Other question (As robtillaart said):

void setup()
{
  pinMode(button1, INPUT);     
  digitalWrite(button1, HIGH);
  Serial.begin(31250);
}


if button1 is an input, what does "  digitalWrite(button1, HIGH);" do? If somebody can explain it.

Thanks everybody

This a kind of inverse logic.

Doing by this way, you don't need to use an external resistor between the button and the ground.

In that case, if the button is pressed, the value returned by digitalRead value will be LOW. When the button is depressed, the value returned by digitalRead will be HIGH.
Logged

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

Hi everybody,
i'm aiming to do the same thing as Readytodie and i added the pull down thing.
Yet ,the midi message sent out is incomplete(a status message ?) .Check the picture to see the message received at midi ox.
Thanks.


* 1.jpg (261.07 KB, 1366x768 - viewed 34 times.)
Logged

Pages: [1]   Go Up
Jump to: