Friday, June 26, 2015

MIDI 3pedal for Pianoteq 5 (Metal case version)


I built a 3-pedal (RPU-3) to MIDI converter box for Pianoteq5 using Arduino nano. Functions are essentially the same as the converter box last built but, this time much smaller metal case, Takachi YM-100 (10cm x 3cm x 7cm) is used.

 
  


This is Roland RPU-3, pedal unit

    


This is Roland UM-ONE, MIDI to USB converter. UM-ONE USB OUT connect to PC.

 

 

Drilling holes

This is panel layout drawing. HSS drill bits (Three axis 21876) and Shinto mini hole saw 11mm, 12mm and 15mm. Scale is Shinwa 13005. Section paper is Kokuyo ホ-14B. 2.54mm pitch single-sided universal board is Picotec P-00517. Caliper (Tamiya 74030, not pictured) is used to measure diameter of connectors.


Boring holes using drilling machine (Proxxon Bench Drill Press TBM 115).




Soldering the circuit

Circuit diagram is the same as the previous build. see my previous post for detail.

My Soldering iron(Goot CX-40), solder(Almit KR-19RMA) and reverse-action tweezers (Goot TS-16 and Tamiya 74102).
Voltage regulator mounted on the universal board is TA4805S.  AC adapter is GF06-US09065A (9V 0.65A rated, not pictured).


Top view of circuit board. It looks clean.


Bottom view. looks messy...


This is the most messy part. 3-dimensional wiring of pull-down resistors. This is due to space limitation. If more space is available, circuit wiring is relaxed and bottom view looks better...


Creating harness


AWG22 wire(Kyowa UL3265 AWG22 7 colors) is used. Molex 5051 contact is crimped using Hozan P707. Faston 187 connector is crimped with Pro'sKit 6PK-230C. Insulated ring terminal is crimped with Pro'sKit 6PK-301H.







I use heat shrink tube (Sumitube F) to insulate MIDI terminal where soldered wire exposed



Preventing ground loops


There are wide variety of TRC connectors in the market but metal case prefers plastic screw connector to prevent unnecessary ground loop. I used polyimide tape to prevent accidental electrical contact with metal chassis and circuit board. Also spacers to mount universal board should be made of plastic not metal. I used solder-less ring terminal to connect metal chassis to circuit GND.









 This is King Jim Label Writer TEPRA. Used to create “Sustain Sostenuto Soft” and “DC9V” label.


Flashing software


Download Arduino Software from following website and install
https://www.arduino.cc/en/Main/Software

Connect Arduino to PC with USB cable. COM port to communicate PC to Arduino should show up in device manager.



Cut and paste the program to the editor window. Choose Arduino nano and communication port (In my case COM3. YMMV) and press upload button to flash the program onto Arduino.




This is Arduino program I flashed.


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

// the setup function runs once when you press reset or power the board
void setup() {
  // MIDI signal frequency=31250Hz
  Serial.begin(31250);

  // set AREF pin as A/D converter reference voltage input
  //analogReference(EXTERNAL);
}

// 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);
}


Power consumption measured



Power consumption = 0.4 Watt

Afterthoughts

It worked flawlessly.

I changed pedal position to MIDI value mapping curve so I must recalibrate pedal curve setting of  Pianoteq.

DC9V jack was too close to edge and interfered with chassis mount screw. Also MIDI DIN5pin connector must be rotate 90 degree not to interfere with faston 187 from TRC jack :)

YM-100 case is too small for this application and build difficulty increased by limited real estate. Circuit board must be mounted vertically to accommodate. TRC jack wiring looks busy. I recommend YM-150 (15cm x 4cm x 10cm) for more relaxed layout and easier build.




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