Hi all,
I recently bought a Arduino Micro board. I intent to use it for a midi footcontroller project. I tried a few basic sketches and the confirmed the board functions OK.
I want to use Franky's MIDI library for this project. The midi over serial is also an other option. Anyways, I tried a few basic codes for sending the midi message, but non of them working. Do I need to modify the code especially for arduino MICRO? All documentation on arduino Micro is based on Leonardo board, and it seems like some parts are out of date or doesnot really apply to MICRO board. I would really appreciate any help on this.
Midi out; pin3 goes to arduino ground, pin4 goes to 5v with a 220ohm resistor, pin5 goes to arduino TX with a 220ohm resistor.
Button is connected to arduino digital 2.
I tested the following codes but
The first code I tried:
#include <MIDI.h>
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
MIDI.begin();
}
void loop(){
MIDI.sendNoteOn(42,127,1);
delay(1000);
MIDI.sendNoteOff(42,0,1);
delay(1000);
MIDI.sendNoteOn(25,127,1);
delay(1000);
MIDI.sendNoteOff(25,0,1);
delay(1000);
}
This code is constantly sending note on/off messages but midi in monitor displays nothing.
The second code is to send to note when a button is pressed. The led flashes when is pressed.
#include <MIDI.h>
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // 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);
MIDI.begin(1);
}
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) {
digitalWrite(ledPin,HIGH);
MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000); // Wait for a second
MIDI.sendNoteOff(42,0,1); // Stop the note
digitalWrite(ledPin,LOW);
}
}
Button is working and the led is flashing when it is pressed. But again no signal in midi monitor.
The final code I tried is just using serial.write and doesnt include the midi library. This also didnt work. Again No midi signals
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);
}
I checked my midi cable and it is working perfectly. MIDI in port at my soundcard also functions OK with other devices. So all external factors are isolated.
Thanks in advance...