how to pass multiple potentiometer midi output to hairless midi

Hi...

I'm new to Arduino and wanted to build a midi controller for my dj software..

I have Arduino Duemilanove

I am trying to send midi output to hairless midi using Serial.Write()

My code for One Potentiometer :-

void setup() {
  Serial.begin(9600); //initialize serial communication at 9600 bits per second
}


void loop() {
  
int sensorvalue0=analogRead(A0); //read the input fom analog pin 0



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



delay(1);


}

This is working but i'm getting a warning in hairless midi :got a status byte when we were expecting one more byte.

My first Question is :

Can you pls tell me what is the value 176 and 10 means in the first 2 Serial.write()

Second :

I'm I doing it correctly if not can you pls guide me to the correct method

Third :

how can i pass multiple potentiometer midi output to hairless midi.

My code for 2 potentiometer which is getting the output in hairless midi but not in my dj software as i can get only one potentiometer name there.

My Code for 2 potentiometer :-

void setup() {
  Serial.begin(9600); //initialize serial communication at 9600 bits per second
}


void loop() {
 

int sensorvalue0=analogRead(A0); //read the input fom analog pin 0
int sensorvalue1=analogRead(A1); //read the input fom analog pin 1


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

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

delay(1);


}

Circuit

Thank You for your time....

You can't use the values from analogRead() directly. They are from 0-1023 but the data in a MIDI message must be between 0 and 127. The map command is useful for that.

In the MIDI message:
176 means it's a Control Change message on MIDI channel 0
10 means the particular control is Pan, 0= left, 127= right.

Since you're sending both messages to the same CC all you're doing is rapidly sending different values to the Pan control. If you want to do anything useful I imagine different pots should map to different CCs so that value 10 should be different for each pot.

What exactly was it that you were trying to do?

Steve

I would also run the serial much faster than 9600 baud and make sure you set the speed in Hairless to match.

Take a look at my MIDI Controller library.
If you want to know the details, you can follow this guide on Arduino MIDI. It explains how the MIDI protocol works (it'll tell you what the magic numbers 176 (= 0xB0 in hexadecimal) and 10 mean), how to send MIDI messages over the serial port, and how to create a MIDI controller.

Pieter

@slipstick i want use the potentiometer to control the virtual button on dj software(virtual dj ) that is i want to use as a midi controller.

@grumpy mike i searched on internet for midi the baud rate is 31250 but here i'm sending serial message so i have kept it to 9600. should i change....?

@PieterP i will take a look and will update in few hours

Thnx for the help guyz....

daniel345:
@slipstick i want use the potentiometer to control the virtual button on dj software(virtual dj ) that is i want to use as a midi controller.

So the first thing you need to know is what MIDI commands your dj software responds to.

That's not something I can help with as I know nothing at all about dj software and the manual I found online tells me nothing useful. It just gives a huge list of commercial controllers that you could use.

Steve

daniel345:
@grumpy mike i searched on internet for midi the baud rate is 31250 but here i'm sending serial message so i have kept it to 9600. should i change....?

31250 baud is the MIDI hardware baud rate. It's used for standard MIDI communication with a 5-pin DIN connector.

You are sending MIDI data over a standard serial port, to a computer, the baud rate doesn't matter, as long as it's the same on the computer and on the Arduino.
I don't think ACM drivers support 31250 baud anyway.

If you are using it for a MIDI instrument/synthesizer where timing is critical (you want simultaneous notes to play simultaneously) and if you need many chords and large polyphonies, you need fast baud rates to minimize latency.
For a normal MIDI controller, this isn't so much of an issue, but it's a good idea to use Hairless's standard rate of 115200 baud.

@PieterP Thnx for the info

@slipstick and all others I have researched and built a code with the reference with this project 3 pot controller using hairless which is working with hairless midi but there is a slight problem.

First of all my code...

void setup()
{
   Serial.begin(9600);       // Set the speed of the midi port to the same as we will be using in the Hairless Midi software 
}

void loop()
{
   val = analogRead(0)/8;   // Divide by 8 to get range of 0-127 for midi
  
 if (val > lastVal+1 or val < lastVal+1 ) // If the value is not greater than or less than  the last value the MIDImessage will be called
   {
   MIDImessage(176,1,val);
   }

   lastVal = val;

delay(50); //here we add a short delay to help prevent slight fluctuations, knocks on the pots etc. Adding this helped to prevent my pots from jumpin up or down a value when slightly touched or knocked.
}


void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
{
   Serial.write(command);
   Serial.write(data1);
   Serial.write(data2);
}

My prob is when i turning the potentiometer knob to halfway around i'm getting value only as 14-15 but when i'm turning the knob further i'm getting huge addition in the value and when the knob is turned full way I'm getting value as 127 and when the knob is turned off it is giving value as 0. So why there so much difference in between

Again Thnx for your time.....

That's probably because you are using a logarithmic audio taper. You need a linear potentiometer.

@PieterP Again thnx for helping...bro!

Hi Again....

Now I have connected 2 pot to arduino

The First pot values are stable,but second once value keep on fluctuating

And when i turn the first pot knob the second pot's value also changes.

tried changing the 2nd pot

and tried inter changing the middle wire

But the issue persist

Can you tell me what is the issue

Can he issue be solved using Resistor....?

Thnx for the time....

This tends to happen when the pot values are too high. They should be 10K.

You can help this by reading each pot twice and using the second value you get.

I'm using a 10k pot also checked with digital multimeter and i tried with reading the value twice but no luck.....

Can you tell me what else i can do..

What code are you using? Did you use the MIDI Controller library? It has filtering built-in.

No I'm not using the library

My code:-

void setup()
{
   Serial.begin(9600);      
}

void loop()
{
  analogRead(0);
   val = analogRead(0)/8;   // Divide by 8 to get range of 0-127 for midi
   if (val > lastVal+1 or val < lastVal+1 ) 
   {
   MIDImessage(176,1,val);}        
   lastVal = val;

  analogRead(2);
   val2 = analogRead(2)/8;   // Divide by 8 to get range of 0-127 for midi
   if (val2 > lastVal2 + 1 or val2 < lastVal2 + 1 )
   {
   MIDImessage(176,2,val2);}         // 176 = CC command, 2 = Which Control, val = value read from Potentionmeter 2
   lastVal2 = val2;
   
   //val3 = analogRead(2)/8;   // Divide by 8 to get range of 0-127 for midi
   //if (val3 != lastVal3) 
   //{
   //MIDImessage(176,3,val3);}         // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
   //lastVal3 = val3;
   
delay(100);
}

void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
{
   Serial.write(command);
   Serial.write(data1);
   Serial.write(data2);
}

daniel345:
I'm using a 10k pot also checked with digital multimeter and i tried with reading the value twice but no luck.

Must be down to your wiring, can you post a picture of it along with a schematic.

You seem to have posted the same question on Stack Exchange (midi - Unexpected value change of 2nd Potentiometer - Arduino Stack Exchange).
If you plan on doing that in the future, at least post a link, having the same discussion in two places just wastes everyone's time.

sorry for that i was going to post the update here.

But still many thnx for the help...