Simple MIDI Input via potentiometer

Hi Folks,

I've recently bought a Arduino starter kid (Fritzing Creator Kid) and I wanted to create a MIDI Input.
I Read a lot and I've seen many Tutorials but It still won't work.
I've held it simple and I just pined a potentiometer to the A0 Port and a button to A1 - btw. I operate with Windows 7.

Original pic: http://www11.pic-upload.de/03.07.14/vl7bu5pnh41f.jpg

With this code I'll get two numbers output from 0 - 127 on the Serial Monitor:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

MIDI_CREATE_DEFAULT_INSTANCE();

byte val; // create variable to store data 
byte butn;

void setup() {
  //MIDI.begin(A0); 
  Serial.begin(57600); // open serial port 
} 

void loop() { 
  val = analogRead(0) / 8; // read value from pot and make value from 0 - 127 
  butn = analogRead(1) / 8;
  Serial.write(val);
  Serial.print("  ");
  Serial.write(butn);
  Serial.println(""); // print value to serial port 
  delay(5); // wait for a brief moment 
  //Serial.write(val);
}

And I work with these tools:

LoopMIDI; hairless-midiserial; MIDI-OX;
(L to R) (I've also Installed Yoke)

So, to the Point:

In hairless-midiserial I receive an error:

like this here:

[...]
+3.231 - Error: got an unexpected data byte 0xd.
+3.231 - Error: got an unexpected data byte 0xa.
+3.236 - Error: got an unexpected data byte 0x49.
+3.236 - Error: got an unexpected data byte 0x20.
+3.236 - Error: got an unexpected data byte 0x20.
+3.236 - Error: got an unexpected data byte 0x46.
+3.236 - Error: got an unexpected data byte 0xd.
+3.236 - Error: got an unexpected data byte 0xa.
+3.24 - Error: got an unexpected data byte 0x49.
+3.24 - Error: got an unexpected data byte 0x20.
+3.24 - Error: got an unexpected data byte 0x20.
+3.24 - Error: got an unexpected data byte 0x4.
+3.24 - Error: got an unexpected data byte 0xs.
[...]

I synchronized the baud in hairless, with the code (57600). But it's still like: nope! :stuck_out_tongue:

how can I fix it?
Any Idea or links?

I've looked here and this Q&A is kinda similar but it seems like not the solution for me.
(http://forum.arduino.cc/index.php/topic,153324.0.html)

Thank You for your time. :slight_smile: :sweat_smile:

You need to post the code that does not work, I.e the code that sends the midi commands.

Posting your working code, only proves that the analog input works, and you already know that.

Well this IS my code, except from this and the Arduino MIDI libary which I downloaded and added, I got nothing else.
I don't quite understand which code you mean? : /

edit: Maybe the error appears within the hairless-MIDISerial.

:cold_sweat:

I can't see any thing in this code you posted that sends MIDI commands

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

MIDI_CREATE_DEFAULT_INSTANCE();

byte val; // create variable to store data 
byte butn;

void setup() {
  //MIDI.begin(A0); 
  Serial.begin(57600); // open serial port 
} 

void loop() { 
  val = analogRead(0) / 8; // read value from pot and make value from 0 - 127 
  butn = analogRead(1) / 8;
  Serial.write(val);
  Serial.print("  ");
  Serial.write(butn);
  Serial.println(""); // print value to serial port 
  delay(5); // wait for a brief moment 
  //Serial.write(val);
}

Can you explain what is sending the midi commands if its not this code.

i.e If you have some other device connected that is sending MIDI commands, and those commands have errors, it would suggest that the other device is at fault, as the Arduino code does not seem to be having any interaction with the MIDI system

So this may be the Problem.

I thought, this signal would be enough to be simulated in the hairless-MIDISerial as MIDI.
I've often Seen codes like this without any »MIDI.sendNoteOn(60,127,1)«

When This is the problem, how must I implement that?
I haven't found commands for MIDI Output like the sample above.

It has to be MIDI for hairless-MidiSerial, to be understood?

You've not said how the Arduino is connected to the Midi
i.e MIDI is basically Serial, but you can't use the Serial Pins on the normal Arduino to connect to Midi as they are connected to the PC, ie pins 0 and 1, so I presume the midi stuff uses Software Serial on some other pin

However unless you post all of your code and a diagram of how your Arduino is connected to the midi, I'm not sure how anyone is going to be able to help you

Arduino(Potentiometer) --> hairless-midiserial --> loopMidi --> Program-to-use-the-signals

Thank you for you time so far.
:slight_smile:

Sorry,

Midi on the Arduino is not my area of expertise. It sounds like you need to get this tread moved to the "Audio" section of this forum.

He's sending midi commands, with Serial.write(), well actually just bytes without any midi format.
You can't just send the bytes from the analogRead and nothing else. You should read a basic introduction to midi. What do you want to send? Note messages? Control change? Program change?
If you want to send a control change message, let's say, message 10 (pan), with the value from the potentiometer you have to send 3 bytes
1st is status byte, which indicates that it's a control change message, and also it tells which channel it's going.
2nd and 3rd bytes are data bytes. Once the receiver knows it's a CC at channel 1, it'll know that it has to wait for 2 bytes more, 2nd byte for the control change number(10), and 3rd byte is the value of that control change(your potentiometer).
maybe this explains it betteR:

Status Byte Data Byte 1 Data Byte 2 Message Legend
1011nnnn 0ccccccc 0vvvvvvv Controller Change n=channel c=controller v=controller value(0-127)

so. status byte is 1011 and nnnn is the channel, for control change. If you want to send it to channel 1, then the byte would be 10110000 which in decimal is 176. Next is the data byte, 10, and then the value.
With this you're sending the 3 bytes which completes a midi message.

Serial.write(176);
Serial.write(10);
Serial.write(val);

If you don't send them that way, the receiver will just read garbage.

About the hardware serial, you can send/receive midi without problems, using pin 0 and 1, you just have to have them disconnected when uploading the code.

I don't know anything about the hairless midi. But make sure to configure the program well, channels, baud rate, etc... check twice.

I don't know anything about the hairless midi

Hairless is a helper application, it runs on the host computer, it's job is to take in serial data from the USB port and make it look like a regular MIDI port for applications that use MIDI.
Hairless does not work at MIDI speeds. You must communicate with it at 115200Baud.

Rockman:
I've recently bought a Arduino starter kid (Fritzing Creator Kid) and I wanted to create a MIDI Input
I synchronized the baud in hairless, with the code (57600). But it's still like: nope! :stuck_out_tongue:

You are creating a MIDI output not an input. You are running the serial at the wrong speed.
You are not sending it MIDI messages correctly.

This code will fire off random MIDI notes:-

/* Midi note fire - Mike Cook March 2012
 *
 * ----------------- 
 * send MIDI serial data, automatically for a test
 * 
###############################################################################################

HARDWARE NOTE:
The MIDI Socket is connected to arduino TX through a PNP transistor to invert the MIDI signal.
A common anode RGB LED is pulled down through pins 9, 10, 11

################################################################################################
*/
// Arduino pin assignments
#define midiChannel (byte)0

// Start of code
void setup() {
 //  Setup serial
   Serial.begin(115200);    // Speed for Hairless
   programChange(0xc0, 14);  // Change MIDI voice

}

//********************* MAIN LOOP ***********************************

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127);
    delay(200);
    noteSend(0x80, val, 127);
   delay(800);
    } // end loop function
    
//********************* Functions *********************************** 


//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}
//  change the voice
 void programChange(char cmd, char data1) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
}

//  change the bank
void bankChange(char cmd, char data1) {
  Serial.write(0xB0 | char(midiChannel));  // control change
  Serial.write(cmd);
  Serial.write(data1);
}