Skip to content

Commit

Permalink
feat(fw): update all the examples
Browse files Browse the repository at this point in the history
Some changes on the examples structure and corrections to latest source changes
  • Loading branch information
xpeqex committed Sep 17, 2024
1 parent 89173ab commit 4ce4cbb
Show file tree
Hide file tree
Showing 13 changed files with 897 additions and 3,829 deletions.
13 changes: 9 additions & 4 deletions examples/IMU_Zero/IMU_Zero.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void setup() {
}

void loop() {
//Write your code here
}

/*Initializate function*/
Expand Down Expand Up @@ -156,7 +157,8 @@ void PullBracketsOut() {
if (LowValue[i] >= Target[i]) {
Done = false;
NextLowOffset[i] = LowOffset[i] - 1000;
} else {
}
else {
NextLowOffset[i] = LowOffset[i];
}
}
Expand All @@ -167,7 +169,8 @@ void PullBracketsOut() {
if (HighValue[i] <= Target[i]) {
Done = false;
NextHighOffset[i] = HighOffset[i] + 1000;
} else {
}
else {
NextHighOffset[i] = HighOffset[i];
}
}
Expand All @@ -192,7 +195,8 @@ void PullBracketsIn() {
StillWorking = false;
if (AllBracketsNarrow && (N == NFast)) {
SetAveraging(NSlow);
} else {
}
else {
AllBracketsNarrow = true;
}
for (int i = 0; i <= 5; i++) {
Expand Down Expand Up @@ -239,8 +243,9 @@ void GetSmoothed() {
for (i = 1; i <= N; i++) {
mpu.getMotion6( & RawValue[iAx], & RawValue[iAy], & RawValue[iAz], & RawValue[iGx], & RawValue[iGy], & RawValue[iGz]);
delayMicroseconds(usDelay);
for (int j = 0; j <= 5; j++)
for (int j = 0; j <= 5; j++){
Sums[j] = Sums[j] + RawValue[j];
}
}
for (i = 0; i <= 5; i++) {
Smoothed[i] = (Sums[i] + N / 2) / N;
Expand Down
3 changes: 1 addition & 2 deletions examples/MCU_Powercycle_DMP6/MCU_Powercycle_DMP6.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
when the MCU gas been reset or powercycled but MPU6050 has not.
This example is designed for the LGT8F328. The MCU will enter deep sleep for 1 second, erasing
the RAM, causing the MCU to restart on wakeup.
the RAM, causing the MCU to restart on wakeup.
Find the full MPU6050 library docummentation here:
https://github.com/ElectronicCats/mpu6050/wiki
Expand Down Expand Up @@ -100,7 +100,6 @@ void setup() {
on the MPU6050.
*/
mpu.setMotionDetectionDuration(1);

startTime = millis();
}

Expand Down
50 changes: 28 additions & 22 deletions examples/MPU6050_DMP6/MPU6050_DMP6.ino
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
/*
MPU6050 DMP6
MPU6050 DMP6
Digital Motion Processor or DMP performs complex motion processing tasks.
- Fuses the data from the accel, gyro and extarnal magnetometer if applies,
compesating individual sensor noise and errors.
- Detect specific types of motion without the need to continuosly monitor
raw sensor data with a microcontroller.
- Reduce workload on the microprocessor.
- Output processed data such as quaternions, Euler angles, and gravity vectors.
Digital Motion Processor or DMP performs complex motion processing tasks.
- Fuses the data from the accel, gyro and extarnal magnetometer if applies,
compesating individual sensor noise and errors.
- Detect specific types of motion without the need to continuosly monitor
raw sensor data with a microcontroller.
- Reduce workload on the microprocessor.
- Output processed data such as quaternions, Euler angles, and gravity vectors.
The code incluces an auto calibration and offset generator tasks. Different
output formats available.
The code incluces an auto calibration and offset generator tasks. Different
output formats available.
This code is compatible with teapot propject by using the teapot output format.
This code is compatible with teapot propject by using the teapot output format.
Circuit: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
depends on the MPU6050's INT pin being connected to the Arduino's
external interrupt #0 pin.
Circuit: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
depends on the MPU6050's INT pin being connected to the Arduino's
external interrupt #0 pin.
Teapot processing example may be broken due FIFO structure change. if using DMP
6.12 firmware version.
Find the full MPU6050 library docummentation here:
https://github.com/ElectronicCats/mpu6050/wiki
Find the full MPU6050 library docummentation here:
https://github.com/ElectronicCats/mpu6050/wiki
*/

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050_6Axis_MotionApps612.h" // Uncomment this library to work with DMP 6.12 and comment the above library.

/* MPU6050 default I2C address is 0x68*/
MPU6050 mpu;
Expand All @@ -51,12 +55,12 @@ refernce frame. Yaw is relative if there is no magnetometer present.
- Use "OUTPUT_TEAPOT" for output that matches the InvenSense teapot demo.
-------------------------------------------------------------------------------------------------------------------------------*/
//#define OUTPUT_READABLE_YAWPITCHROLL
#define OUTPUT_READABLE_YAWPITCHROLL
//#define OUTPUT_READABLE_QUATERNION
//#define OUTPUT_READABLE_EULER
//#define OUTPUT_READABLE_REALACCEL
//#define OUTPUT_READABLE_WORLDACCEL
#define OUTPUT_TEAPOT
//#define OUTPUT_TEAPOT

int const INTERRUPT_PIN = 2; // Define the interruption #0 pin
bool blinkState;
Expand All @@ -66,25 +70,25 @@ bool DMPReady = false; // Set true if DMP init was successful
uint8_t MPUIntStatus; // Holds actual interrupt status byte from MPU
uint8_t devStatus; // Return status after each device operation (0 = success, !0 = error)
uint16_t packetSize; // Expected DMP packet size (default is 42 bytes)
uint16_t FIFOCount; // Count of all bytes currently in FIFO
uint8_t FIFOBuffer[64]; // FIFO storage buffer

/*---Orientation/Motion Variables---*/
Quaternion q; // [w, x, y, z] Quaternion container
VectorInt16 aa; // [x, y, z] Accel sensor measurements
VectorInt16 gy; // [x, y, z] Gyro sensor measurements
VectorInt16 aaReal; // [x, y, z] Gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z] World-frame accel sensor measurements
VectorFloat gravity; // [x, y, z] Gravity vector
float euler[3]; // [psi, theta, phi] Euler angle container
float ypr[3]; // [yaw, pitch, roll] Yaw/Pitch/Roll container and gravity vector

/*-Packet structure for InvenSense teapot demo-*/
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };
uint8_t teapotPacket[14] = { '$', 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, '\r', '\n' };

/*------Interrupt detection routine------*/
volatile bool MPUInterrupt = false; // Indicates whether MPU6050 interrupt pin has gone high
void DMPDataReady() {
MPUInterrupt = true;
MPUInterrupt = true;
}

void setup() {
Expand All @@ -109,7 +113,7 @@ void setup() {
Serial.println("MPU6050 connection failed");
while(true);
}
else {
else {
Serial.println("MPU6050 connection successful");
}

Expand All @@ -127,6 +131,8 @@ void setup() {
mpu.setXGyroOffset(0);
mpu.setYGyroOffset(0);
mpu.setZGyroOffset(0);
mpu.setXAccelOffset(0);
mpu.setYAccelOffset(0);
mpu.setZAccelOffset(0);

/* Making sure it worked (returns 0 if so) */
Expand Down
16 changes: 12 additions & 4 deletions examples/MPU6050_DMP6/Processing/MPUTeapot/MPUTeapot.pde
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/*
NOTE: ToxicLibs library is required.
1. Download from https://github.com/postspectacular/toxiclibs/releases
2. Extract into [userdir]/Documents/Processing/libraries (location may be different on Mac/Linux)
3. Restart Processing if needed
MPU Teapot example
This code will display a airplane graphhics which will follow the MPU6050 movements.
Use #define OUTPUT_TEAPOT output definition to make this code work.
Define the serial port in the code below (line 45). Note: Close any other serial instance using the port.
NOTE: ToxicLibs library is required.
1. Download from https://github.com/postspectacular/toxiclibs/releases
2. Extract into [userdir]/Documents/Processing/libraries (location may be different on Mac/Linux)
3. Restart Processing if needed
*/

import processing.serial.*;
Expand Down
Loading

0 comments on commit 4ce4cbb

Please sign in to comment.