I'm getting confused with MPU IMU click. It is a Mikroe 1577 that uses MPU6000. How do I code it so that it measures acceleration and orientation. This is the description. Can anybody help me code it?
MPU IMU click carries the MPU-6000 integrated6-axis motion tracking device that combines a3-axis gyroscope, a 3-axis accelerometer, and aDMP (Digital Motion Processor) into a singlesmall chip.• IC/module: MPU-6000• Interface: SPI, I2C, RST and INT • Power supply: 3.3V • Supports 3D MotionProcessing • Gesture recognition
The code for me does not work. Well it sort of does. It displays the same numbers over and over.
As shown in the image, the numbers keep repeating itself. It seems like it took the measure at 1 point and is just printing the same numbers over and over. Even after moving it, it will still show the same numbers.
Is there a code that can help with this?
MPU IMU click carries the MPU-6000 integrated6-axis motion tracking device that combines a3-axis gyroscope, a 3-axis accelerometer, and aDMP (Digital Motion Processor) into a singlesmall chip.• IC/module: MPU-6000• Interface: SPI, I2C, RST and INT • Power supply: 3.3V • Supports 3D MotionProcessing • Gesture recognition
Im using Arduino UNO board and it is being directly connected to it without a breadboard because it is not needed. May you please assist me?
#include<Wire.h>
// MPU-6000 I2C address is 0x68(104)
#define Addr 0x68
void setup()
{
// Initialise I2C communication as Master
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select gyroscope configuration register
Wire.write(0x1B);
// Full scale range = 2000 dps
Wire.write(0x18);
// Stop I2C transmission
Wire.endTransmission();
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select accelerometer configuration register
Wire.write(0x1C);
// Full scale range = +/-16g
Wire.write(0x18);
// Stop I2C transmission
Wire.endTransmission();
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select power management register
Wire.write(0x6B);
// PLL with xGyro reference
Wire.write(0x01);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
}
void loop()
{
unsigned int data[6];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x3B);
// Stop I2C transmission
Wire.endTransmission();
// Request 6 bytes of data
Wire.requestFrom(Addr, 6);
// Read 6 byte of data
if(Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
// Convert the data
int xAccl = data[0] * 256 + data[1];
int yAccl = data[2] * 256 + data[3];
int zAccl = data[4] * 256 + data[5];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x43);
// Stop I2C transmission
Wire.endTransmission();
// Request 6 bytes of data
Wire.requestFrom(Addr, 6);
// Read 6 byte of data
if(Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
// Convert the data
int xGyro = data[0] * 256 + data[1];
int yGyro = data[2] * 256 + data[3];
int zGyro = data[4] * 256 + data[5];
// Output data to serial monitor
Serial.print("Acceleration in X-Axis : ");
Serial.println(xAccl);
Serial.print("Acceleration in Y-Axis : ");
Serial.println(yAccl);
Serial.print("Acceleration in Z-Axis : ");
Serial.println(zAccl);
Serial.print("X-Axis of Rotation : ");
Serial.println(xGyro);
Serial.print("Y-Axis of Rotation : ");
Serial.println(yGyro);
Serial.print("Z-Axis of Rotation : ");
Serial.println(zGyro);
delay(500);
}
This code is being used for the Mikroe 1577. I want to continuously display data but with this code it only displays code once. May anybody help me solve this issue?
Also my wiring is directly connected to the Arduino board. The ground to ground, 3.3V to 3.3V, SDA to A4, SCL to A5. May you tell me if my wiring is wrong,
or it is missing something? Thank you.
1. Your original problem was as quoted above -- is that solved?
2. Now, you are reporting the problem that your program is not updating the sensor value?
Read data sheets and check if the sensor needs "Start Command"? If yes, then issue "Start Command" and wait until acquisition/conversion is complete and then read data from the sensor.
Sorry for not being clear. The code you formatted is displaying the same data over and over. So, no the problem is not yet solved
The type number of the sensor is Mikroe 1577. MPU IMU click carries the MPU-6000 integrated6-axis motion tracking device that combines a3-axis gyroscope, a 3-axis accelerometer, and aDMP (Digital Motion Processor) into a singlesmall chip.• IC/module: MPU-6000• Interface: SPI, I2C, RST and INT • Power supply: 3.3V • Supports 3D MotionProcessing • Gesture recognition MPU IMU click - Board with MPU-6000 integrated 6-axis motion tracking device
If you are using Arduino UNO, then use level shifter (Fig-1) to connect the sensor as the sensor is a 3.3V device and the UNO is a 5V device. The levl shifter is needed for safe operation and logic level matching.
Oh I see. Still, I think the code I have is not working as intended.
As shown in the image, the numbers keep repeating. The data seems to be taken at one point then it kept repeating itself even when I was moving the sensor. Also, I think the numbers are way too high. So, I was wondering if anybody may help in this coding? I need it to measure acceleration and orientation.
There is an internal temperature sensor within the IMU (MPU-6000) of your Breakout Board. Preapre a simple sketch to acquire temperature signal just to veryfy that your is correct and the sensor is apparently functional.
Upload the following sketch and check if it works. This is a sketch that I made long time ago for my MPU-6050 IMU which is dead now.
#include<Wire.h>
#define MPUaddr 0x68
void setup()
{
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPUaddr);
byte busStatus = Wire.endTransmission();
if (busStatus != 0)
{
Serial.print("MPU is not found!");
while (true); //wait for ever
}
Serial.println("MPU is found");
}
void loop()
{
Wire.beginTransmission(MPUaddr); //Start communication with the MPU
Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex).
Wire.write(0x00); //
Wire.endTransmission();
//----pointing temp sensor-----------------
Wire.beginTransmission(MPUaddr); //Start communication with the MPU
Wire.write(0x41); //pointing Temp_Out_High Reg //Set the register bits as 00000000 to activate the gyro.
Wire.endTransmission();
Wire.requestFrom(MPUaddr, 2); //two-byte temp data
byte x1 = Wire.read();
byte x2 = Wire.read();
int x = (int)(x1 << 8) | (int)x2;
//------compute temp from x-----
float mpuTemp = (float)(x / 340.0 + 36.53); //formula from data sheets
Serial.print("Temp = ");
Serial.print(mpuTemp, 2); //2-digit after decimal point
Serial.println(" degC");
delay(1000);
}
The value 4294967295 is exactly the maximum value of an unsigned variable of type 4 bytes as a unsigned long. I think this suggests some kind of variable type problem.
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.