Sunday, May 10, 2015

Building MIDI 3pedal for Pianoteq 5


I have Pianoteq 5 and learning classical piano playing. 3 pedal (with continuous input for all 3 pedals) is must-have item but it is nearly impossible to find. So I'd built it using Roland RPU-3 and Arduino Uno.

This is MIDI output box for RPU-3.


And this is RPU-3.


If your PC doesn't have a MIDI input, UM-ONE converts MIDI to USB for you.

My Pianoteq 5 settings:

Building Hardware

MIDI output box with the lid opened

Circuit diagram

TA4805S 5V1A voltage regulator is used.


MIDI Connector pin assign:

RPU-3 TRS connector. 

Ring: put +5V, Sleeve: connect to GND, Tip: pedal potentiometer output.

Software for Arduino


Here is the program for Arduino. convert pedal analog voltage to integer value (0 to 127) and send it to the MIDI output.

  int gController[] = {64, 66, 67};
  int gPrevValue[] = {0, 0, 0};
  int gPort[] = {A0, A1, A2};
  int gLight = 0;

  // the setup function runs once when you press reset or power the board
  void setup() {
     // initialize digital pin 13 as an output.
     pinMode(13, OUTPUT);

    // MIDI output rate is 31250Hz
    Serial.begin(31250);
  }

  // the loop function runs over and over again forever
  void loop() {
     for (int i=0; i<3; ++i) {
       int sensorValue = analogRead(gPort[i]);
       float sensor01 = sensorValue * (1.0f / 1023.0f);
       float sensorSq = sqrt(sensor01);
      
      int encoded127 = (sensorSq*1023) / 8;
      if (127 < encoded127) {
        encoded127 = 127;
      }

      if (gPrevValue[i] != encoded127) {
        gPrevValue[i] = encoded127;
        sendMidi(0xb0, gController[i],encoded127);

        blinkLed();
      }
   }
  }

  void blinkLed()
  {
     gLight = !gLight;
     if (gLight==1) {
       digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
     } else {
       digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
     }
  }

  void sendMidi(int cmd, int secondByte, int thirdByte) {
    Serial.write(cmd);
    Serial.write(secondByte);
    Serial.write(thirdByte);
  }

That's all.

● Update on June 6, 2015

Here is my pedal settings.


● Updated on June 7, 2015

On my Arduino program, Pedal potentiometer value is sqrt'ed
I'd like to explain the reason of this sqrt.
Pedal potentiometer value has a range from 0(fully released) to 1023(fully depressed) and
MIDI pedal value is 0(fully released) to 127(fully depressed) so, at first, I multiplied (127.0f / 1023.0f) by pedal potentiometer value to get MIDI pedal value.
I asked my teacher about pedal feeling and he said half pedaling position must be exist on more smaller pressed position, so I sqrt'ed A/D converter input value(see the graph below). Also I changed the pedal calibration curve on Pianoteq (see above) and he is satisfied with these settings combined. I reconsidered about that, the Arduino program looks messy and now think using only Pianoteq pedal calibration can produce similar result and sqrt is not necessary :)





● Updated on June 9, 2015

(About linear ADC value to MIDI value conversion)

if you'd like to get linear pedal response 0 to 127 from ADC value range 0 to 1023 , sensorValue/8 is better than sensorValue*127/1023. See table below, sensorValue*127/1023 outputs max value only when input value is 1023, while sensorValue/8 outputs all output values in the same occurrence. This is because integer arithmetic unit omits decimals. if you like bit shift operator more than division operator, you have better feeling from (sensorValue >> 3) than from  sensorValue/8 .

sensorValue         , sensorValue*127/1023    , sensorValue/8
0                   ,   0                    ,    0
1                   ,   0                    ,    0
2                   ,   0                    ,    0
3                   ,   0                    ,    0
4                   ,   0                    ,    0
5                   ,   0                    ,    0
6                   ,   0                    ,    0
7                   ,   0                    ,    0
8                   ,   0                    ,    1
9                   ,   1                    ,    1  
...
1014                ,   125                  ,    126
1015                ,   126                  ,    126
1016                ,   126                  ,    127 (max output)
1017                ,   126                  ,    127 (max output)
1018                ,   126                  ,    127 (max output)
1019                ,   126                  ,    127 (max output)
1020                ,   126                  ,    127 (max output)
1021                ,   126                  ,    127 (max output)
1022                ,   126                  ,    127 (max output)
1023(max input)     ,   127 (max output)     ,    127 (max output)


Arduino source code `linear version'  is as follows

int gController[] = { 64, 66, 67 };
int gPrevValue[] = { 0, 0, 0 };
int gPort[] = { A0, A1, A2 };
int gLight = 0;

// the setup function runs once when you press reset or power the board
 void setup() {
     // initialize digital pin 13 as an output.
     pinMode(13, OUTPUT);

     // MIDI output rate is 31250Hz
     Serial.begin(31250);
 }

 // the loop function runs over and over again forever
 void loop() {
     for (int i = 0; i<3; ++i) {
         int sensorValue = analogRead(gPort[i]);
         int encoded127 = sensorValue / 8
;

         if (gPrevValue[i] != encoded127) {
             gPrevValue[i] = encoded127;
             sendMidi(0xb0, gController[i], encoded127);
         }
     }
 }

 void sendMidi(int cmd, int secondByte, int thirdByte) {
     Serial.write(cmd);
     Serial.write(secondByte);
     Serial.write(thirdByte);
 }



● Updated on June 26, 2015

Created another one, this time I built metal case
http://manoreken2.blogspot.jp/2015/06/midi-3pedal-for-pianoteq-5-metal-case.html

3 comments:

Unknown said...

Is there a common alternative to the TA4505S? Will any 5V 1A voltage regulator do it without any modification to the circuit? Thx for sharing this great project!

manoreken2 said...

Thank you for your comment and sorry for late reply! Any 7805 variant 5V regulator should work without circuit change. Power consumption is about 0.5 watt. Please be careful the polarity of electrolytic capacitors!

hadimoon said...

I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues.
free4crack.net
Pianoteq Crack