cosplay eyes mpu5060

hi poeple im struggling to find and write some code for the mpu 5060 module, my end goal is to control the direction of some servos (that are hooked up to eyes) in relation to my head movement ie left, right, up and down.

can anyone help PLEASE
thank you

im struggling to find and write some code for the mpu 5060 module

Do you mean the MPU-6050 ?

If so, start here Arduino Playground - HomePage and follow the links to the example code

ive read and its still going over my head am im still not on how i use this the control multiple servos ?

N8-cosplay:
ive read and its still going over my head am im still not on how i use this the control multiple servos ?

Can you read and print the values from the 6050 ?
As you move the 6050 the values will change. Based on the change of values what do you want the servos to do ?

How are the servos and the Arduino going to be powered ? It is not usually a good idea to power servos from the 5V pin of an Arduino as the current available is limited.

What type of servos do you have ?

hi
the servos have a separate power supply to the uno,(sg90) i currently have three servos set up, one to control up and down movement on the Y axes, one for left movement 90 to 0 and one for right movement 90 to 180 on the X axes.
This is currently set up with a joystick i got with my kit, but im hoping 6050 will allows me to free up my hands and use my head as a on controller ie when i move my head the eyes follow, well that whats im hoping :slight_smile: .

can you shed some light on the headache.
thank you

can you shed some light on the headache.

Try the example 6050 programs. Note which values vary when you move it in the required directions. Use the map() function to convert the values to the required range of servo movements and write them to the relevant servo.

hi
ive gotten this far but im drawing a blank and it doesnt seam to be working i have no idea what in doing.
:frowning:

#include <MPU6050_tockn.h>
#include <Servo.h>
#include <Wire.h>
#include <SPI.h>

Servo servo1;
Servo servo2;
Servo servo3;
int Yaw;
const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,GyX,GyY,GyZ;

void setup() {
// put your setup code here, to run once:
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);

servo1.attach(9);

}

void loop() {
// put your main code here, to run repeatedly:
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); )
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);

//AcX=Wire.read()<<8|Wire.read();
//AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();

//GyX=Wire.read()<<8|Wire.read();
// GyY=Wire.read()<<8|Wire.read();
//GyZ=Wire.read()<<8|Wire.read();

Yaw = map(Yaw, -90, 90, 0, 90); // Yaw AZ axes
servo1.write(Yaw);

}

Did you start by trying the example programs with the library, in particular GetAngle.ino ?

ive got this example, ????

// MPU-6050 Short Example Sketch
//www.elegoo.com
//2016.12.9

#include<Wire.h>
const int MPU_addr=0x68; // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
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);
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)
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(333);
}

ive got this example, ????

You're asking us?

Please remember to use code tags when posting code.

i am as im losing my head over trying to figure it out and i need to get this project done asap.
sorry for any confusion im a complete newbie.

Start with the GetAngle example that comes with the MPU6050_tockn library

It produces output like this

angleX : 1.87	angleY : 86.97	angleZ : 1.80
angleX : 1.88	angleY : 86.97	angleZ : 1.78
angleX : 1.87	angleY : 86.98	angleZ : 1.76
angleX : 1.87	angleY : 86.97	angleZ : 1.75
angleX : 1.88	angleY : 86.98	angleZ : 1.75

Run it, hold the 6050 still whilst it is calibrated then move it an observe the readings changing. Once you know which angle you want to associate with the servo you can take the angle and convert it into servo movement.

ok ive got the angle i what, but im stuggling on how to write the code for the mapping and getting everthing to work.

This forum is not a free code writing service. It’s for getting help with the code you’ve written. If you want help, you must post your best attempt and ask specific questions. So far, you’ve shown no attempt to do this.

If you want someone to write it for you, check out Gigs and Collaborations.

There you may be able to find someone willing to write it for you, after negotiating a mutually-agreeable fee for the service.

hi
sorry just struggling but after reading though everything again and again and having a break and looking at everything with fresh eyes and just having you guys to bounce off and thank you for that, ive got something that has clicked and ive got a little way to go to get all that i what to happen working and i will share when im done as a thank you