• warning: get_headers() [function.get-headers]: This function may only be used against URLs in /var/www/html/myrobotlab/themes/superclean/repoFile.php on line 35.
  • warning: file_get_contents(/JFugue.pingPiano.py) [function.file-get-contents]: failed to open stream: No such file or directory in /var/www/html/myrobotlab/themes/superclean/repoFile.php on line 38.

Wireless piano using a Ultrasonic Ping Sensor and JFugue Service :D

Hi :D this is my latest project...a wirless piano using an Ultrasonic ping sensor hooked to an Arduino...

Ultrasonic Ping Sensor->Arduino->Serial->MRL->JFugue-> Musical Note

Sensor measure how far is my hand and send distance in cm over serial connection using Arduino...

MRL receive the distance using serial service and if the hand is at less than 20 cm from the sensor, play a 'A' musical note using JFugue service

TODO : more musical notes


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
GroG's picture

Ahahahahaa ! :DAwesome

Ahahahahaa ! :D

Awesome Alessandruino !

This is great !  Lets add more notes, and make it more snappy ! Ooooh Drums too !!!

You are Beethoven ! Ahaha :D

Ok - what's the formula conversion for the value of the long = cm for this ping sensor?

It looked pretty quick response ... what do you think?

Alessandruino's picture

ya...response is very

ya...response is very quick.... :D 

Here is the Arduino Code :

// # Description:
// # The Sketch for scanning 180 degree area 4-500cm detecting range
// # Connection:
// #       Pin 1 VCC (URM V3.2) -> VCC (Arduino)
// #       Pin 2 GND (URM V3.2) -> GND (Arduino)
// #       Pin 4 PWM (URM V3.2) -> Pin 3 (Arduino)
// #       Pin 6 COMP/TRIG (URM V3.2) -> Pin 5 (Arduino)
// #
int URPWM = 3; // PWM Output 0-25000US,Every 50US represent 1cm
int URTRIG=5; // PWM trigger pin
unsigned int Distance=0;  
void setup(){                                 // Serial initialization
  Serial.begin(9600);                         // Sets the baud rate to 9600
void loop()
}                      //PWM mode setup function
void PWM_Mode_Setup(){ 
  pinMode(URTRIG,OUTPUT);                     // A low pull on pin COMP/TRIG
  digitalWrite(URTRIG,HIGH);                  // Set to HIGH
  pinMode(URPWM, INPUT);                      // Sending Enable PWM mode command 
void PWM_Mode(){                              // a low pull on pin COMP/TRIG  triggering a sensor reading
    digitalWrite(URTRIG, LOW);
    digitalWrite(URTRIG, HIGH);               // reading Pin PWM will output pulses
    unsigned long DistanceMeasured=pulseIn(URPWM,LOW);
    if(DistanceMeasured==50000){              // the reading is invalid.
      Distance=DistanceMeasured/50;           // every 50us low level stands for 1cm


Mats's picture

JFugue 5.0.7

I found that the classpath in Eclipse was using 4.0.3 but the dependency in the JFugue service showed 5.0, so JFugue would not install unless used from Eclipse.

First I tried to use JFugue from Eclipse, but no sound. Doh.

So I started to dig. Two routes possible:

1. Upgrade the repo and the classpath in Eclipse to use JFugue5.0.7

2. Change the dependency in JFugue to version 4.0.3 so that using Eclipse and installing myrobotlab.jar would be consistent.

It tried the first alternative: Downloaded latest JFugue-5.0.7.jar and put it to the repo, changed the classpath and compiled. Still no sound in Eclipse.

Then I tried to download the same JFugue-5.0.7.jar to my Raspberry PI and created a small testprogram. That worked better and I could get JFugue to play som tunes. I used the examples and the BlueJ IDE to make a small testprogram. I tried several examples from http://www.jfugue.org/ and the work.

So I tried to update MRL in Eclipse to use the JFugue-5.0.7.jar. I had to make some small changes because the name of the methods had changed in the include, but I could compile without errors, but still no sound in Eclipse. 

So I pushed the changes and Travis started to build. Doh. The JFugue-5.0.7.jar was built with a newer compiler than the one MRL uses. So I had to revert the changes.

So currently JFugue works, but with version 4.0.3.

I can't get sound when using Eclipse, but it works fine when downloading myrobotlab.jar. I can get sound in both Windows 10 and Raspberry PI. I also played around a bit with JFugue on the PI. Works well. 

Two problems remain:

1. I can't get any sound when using it in Eclipe. Anyone have the same problem ? Any clue to what the problem could be ? I get sound when using JFugue examples with the downloaded myrobotlab.jar but not from Eclipse.

2. If I try to use the latest JFugue-5.0.7.jar the build fails because it is compiled with a later compiler than Travis is using. So either the JFugue-5.0.7 has to be rebuilt with an older compiler, Travis be updated to a later version of the compiler, or we stay with version 4.0.3. 



Alessandruino's picture

fridge located at 265 cm :D

fridge located at 265 cm :D

GroG's picture

WoooHooo - full range worky

WoooHooo - full range worky !

Here are some other things you can do with JFugue..

jfugue.play("A"); # can play single note
jfugue.play("C D E F G A B"); # can play sequence
jfugue.playRythm(); # pre made rythm by me - bass drum
jfugue.play(30); # can play integer
jfugue.play("E5s A5s C6s B5s E5s B5s D6s C6i E6i G#5i E6i | A5s E5s A5s C6s B5s E5s B5s D6s C6i A5i Ri"); # long sequence
Here's the examples for JFugue - http://www.jfugue.org/examples.html
So when you say it "remembers" and loops - I think whats happening is your sample rate for the ping is high and that leads to many notes played quickly which sounds like ELECTRONICA ! 
There are many dimensions of music - and I don't know much about how JFugue controls things... but it would be neat to add control somehow ...  the sensor is Linear but there are controls we could derive.
Like position could control one thing and accelleration could control another...