Close

Making a Physical Fluxum, Part 2

A project log for Real World Fluxly, Physics Looper

A hardware implementation of Fluxly, a software musical physics looper in which you create new instruments by spinning colorful fluxum.

fluxlyFluxly 10/01/2018 at 20:540 Comments

Now that the Fluxum controller and the Yak Shaver are talking to each other, the next step is to read the gyro sensor and send some actual data. I started with Kris Winer's MPU9250 example and added the Wifi and UDP broadcast code, this time calculating the angular velocity in degrees per second and sending that as four bytes. The gyro code hasn't been made into an Arduino library so the setup code is a little long to post here (it's in the files section). Here's the loop() code snippet:

void loop() {  
  
    // If intPin goes high, all data registers have new data
    if (readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) {  // On interrupt, check if data ready interrupt
        readGyroData(gyroCount);  // Read the x/y/z adc values
        getGres();
 
        // Calculate the gyro value into actual degrees per second
        gx = (float)gyroCount[0]*gRes;  // get actual gyro value, this depends on scale being set
        gy = (float)gyroCount[1]*gRes;  
        gz = (float)gyroCount[2]*gRes;   
  
    }
  
    Now = micros();
    deltat = ((Now - lastUpdate)/1000000.0f); // set integration time by time elapsed since last filter update
    lastUpdate = Now;

    sum += deltat; // sum for averaging filter update rate
    sumCount++;
  
    if (!AHRS) {
        delt_t = millis() - count;
        if(delt_t > 50) {
            count = millis();
        }
    }

    byte val1 = 0;
    byte val2 = 0;
    byte val3 = 0;
    byte val4 = 0;
    int v = abs(gz);
    
    int thisVal = v;

    if (!((thisVal < (prevVal + 2)) && (thisVal > (prevVal-2)) || (thisVal < 5)) && connected) {
      //Send a packet
      udp.beginPacket(udpAddress,udpPort);
      packetBuffer[0] = command;
      packetBuffer[1] = dir;
      if (thisVal < 5) val1 = 0;
      packetBuffer[2] = val1;
      packetBuffer[3] = val2;
      packetBuffer[4] = val3;
      packetBuffer[5] = val4;
     
      udp.write(packetBuffer, 6);
      udp.endPacket();
  } 
  
  prevVal = thisVal;
  delay(20);
}

For the first iteration of this project I am only sending the absolute value of the z axis angular velocity. The next iteration will use the command field to indicate the direction of rotation so the sample can play forward or backward.

Here's the first working iteration of the Fluxum controller:

(Text from Richard Brautigan's All Watched Over By Machines of Loving Grace, copyleft 1967 by author):

...I like to think
of a cybernetic forest
filled with pines
and electronics
where deer roam peacefully
past computers
as if they were flowers
with spinning blossoms

Next steps:

Discussions