Go Down

Topic: MPU6050 Accellerometer\gyroscope MAPPED to MIDI (Read 1 time) previous topic - next topic

Sdreoos

Hello everybody, I'm trying to map the Gyroscope data of this sketch to MIDI variable CC from 0 to 127 but all attempts are failed. Could someone help me please? Thank you :)

Code: [Select]
#include "Wire.h"
#include "MIDI.h"

int cc1 ;
int cc2 ;
int cc3 ;
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,GyX,GyY,GyZ;

MIDI_CREATE_DEFAULT_INSTANCE();

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
 
  MIDI.begin();
  Serial.begin(9600);
}

void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
 AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
 AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
 AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
 // Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
 GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
 GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
 GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

  //AcX= map(AcX, 0, 255, 127, 255);   
  //AcY= map(AcY, 0, 255, 127, 255);
  //AcZ= map(AcZ, 0, 255, 127, 255);
 // Tmp= map(Tmp, 0, 255, 127, 255);
  //GyX= map(GyX, 0, 255, 127, 255);
  //GyY= map(GyY, 0, 255, 127, 255);
  //(GyZ= map(GyZ, 0, 255, 127, 255);
 

  //Serial.print(" | AcX = "); Serial.print(AcX);
  //Serial.print(" | AcY = "); Serial.print(AcY);
  //Serial.print(" | AcZ = "); Serial.print(AcZ);
 // Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  //Serial.print(" | GyX = "); Serial.print(GyX);
  //Serial.print(" | GyY = "); Serial.print(GyY);
  //Serial.print(" | GyZ = "); Serial.println(GyZ);
  //delay(10);
 
 
//  MIDI Values

cc2= map(GyX, -255, 255, 0, 127);
cc1= map(GyY, -255, 255, 0, 127);
cc3= map(GyZ, -255, 255, 0, 127);


if (cc1>=127)
{
  cc1=127;
  }
if (cc1 <=0)
{
  cc1=0;
  }

if (cc2>=127)
{
  cc2=127;
  }
if (cc2 <=0)
{
  cc2=0;
  }

if (cc3>=127)
{
  cc3=127;
  }
if (cc3 <=0)
{
  cc3=0;
  }


  {
  MIDI.sendControlChange(16,cc1,1);
  }
 
  {
  MIDI.sendControlChange(17,cc2,1);
  }
 
  {
  MIDI.sendControlChange(18,cc3,1);
  }
 }
 
void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
{
   Serial.write(command);
   Serial.write(data1);
   Serial.write(data2);
}

PieterP

but all attempts are failed.
You'll have to be much more specific than that.

Pieter

slipstick

So the obvious question is exactly what values are you seeing for GyX, GyY, GyZ?

And what values do you get get for cc1,cc2 and cc3 IMMEDIATELY after the map command?

The initial versions of the map() command looks reasonable, depending on what range of values you actually get from the MPU6050.

Steve

Grumpy_Mike

Quote
It's because I'm not able to adapt the Gyroscope excursion range 0-255 to 0-127
Simply take the Gyro data and shift it to the right by one place.
Code: [Select]

midiData = gyroData >>1;


The >> is the shift to the left operator.

Go Up