-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from TorturedEngineersDept/esp32-sensor-tests
ESP32<->MPU6050 Connection Automated Test
- Loading branch information
Showing
12 changed files
with
752 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
"unwantedRecommendations": [ | ||
"ms-vscode.cpptools-extension-pack" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY | ||
// | ||
// PlatformIO Debugging Solution | ||
// | ||
// Documentation: https://docs.platformio.org/en/latest/plus/debugging.html | ||
// Configuration: https://docs.platformio.org/en/latest/projectconf/sections/env/options/debug/index.html | ||
|
||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "platformio-debug", | ||
"request": "launch", | ||
"name": "PIO Debug", | ||
"executable": "/home/sanjit/Documents/y2_eie/summer-project/BalanceBot/esp32/.pio/build/esp-wrover-kit/firmware.elf", | ||
"projectEnvName": "esp-wrover-kit", | ||
"toolchainBinDir": "/home/sanjit/.platformio/packages/toolchain-xtensa-esp32/bin", | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"preLaunchTask": { | ||
"type": "PlatformIO", | ||
"task": "Pre-Debug" | ||
} | ||
}, | ||
{ | ||
"type": "platformio-debug", | ||
"request": "launch", | ||
"name": "PIO Debug (skip Pre-Debug)", | ||
"executable": "/home/sanjit/Documents/y2_eie/summer-project/BalanceBot/esp32/.pio/build/esp-wrover-kit/firmware.elf", | ||
"projectEnvName": "esp-wrover-kit", | ||
"toolchainBinDir": "/home/sanjit/.platformio/packages/toolchain-xtensa-esp32/bin", | ||
"internalConsoleOptions": "openOnSessionStart" | ||
}, | ||
{ | ||
"type": "platformio-debug", | ||
"request": "launch", | ||
"name": "PIO Debug (without uploading)", | ||
"executable": "/home/sanjit/Documents/y2_eie/summer-project/BalanceBot/esp32/.pio/build/esp-wrover-kit/firmware.elf", | ||
"projectEnvName": "esp-wrover-kit", | ||
"toolchainBinDir": "/home/sanjit/.platformio/packages/toolchain-xtensa-esp32/bin", | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"loadMode": "manual" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "MPU6050.h" | ||
|
||
MPU6050::MPU6050() | ||
{ | ||
} | ||
|
||
bool MPU6050::begin(unsigned long timeout) | ||
{ | ||
unsigned long start = 0; | ||
Serial.println("Adafruit MPU6050 test!"); | ||
|
||
// Try to initialize! | ||
if (!mpu.begin()) | ||
{ | ||
Serial.println("Failed to find MPU6050 chip"); | ||
while (start < timeout) | ||
{ | ||
delay(10); | ||
start += 10; | ||
} | ||
} | ||
if (!mpu.begin()) | ||
{ | ||
return false; | ||
} | ||
|
||
Serial.println("MPU6050 Found!"); | ||
|
||
mpu.setAccelerometerRange(MPU6050_RANGE_8_G); | ||
Serial.print("Accelerometer range set to: "); | ||
switch (mpu.getAccelerometerRange()) | ||
{ | ||
case MPU6050_RANGE_2_G: | ||
Serial.println("+-2G"); | ||
break; | ||
case MPU6050_RANGE_4_G: | ||
Serial.println("+-4G"); | ||
break; | ||
case MPU6050_RANGE_8_G: | ||
Serial.println("+-8G"); | ||
break; | ||
case MPU6050_RANGE_16_G: | ||
Serial.println("+-16G"); | ||
break; | ||
} | ||
|
||
mpu.setGyroRange(MPU6050_RANGE_500_DEG); | ||
Serial.print("Gyro range set to: "); | ||
switch (mpu.getGyroRange()) | ||
{ | ||
case MPU6050_RANGE_250_DEG: | ||
Serial.println("+- 250 deg/s"); | ||
break; | ||
case MPU6050_RANGE_500_DEG: | ||
Serial.println("+- 500 deg/s"); | ||
break; | ||
case MPU6050_RANGE_1000_DEG: | ||
Serial.println("+- 1000 deg/s"); | ||
break; | ||
case MPU6050_RANGE_2000_DEG: | ||
Serial.println("+- 2000 deg/s"); | ||
break; | ||
} | ||
|
||
mpu.setFilterBandwidth(MPU6050_BAND_5_HZ); | ||
Serial.print("Filter bandwidth set to: "); | ||
switch (mpu.getFilterBandwidth()) | ||
{ | ||
case MPU6050_BAND_260_HZ: | ||
Serial.println("260 Hz"); | ||
break; | ||
case MPU6050_BAND_184_HZ: | ||
Serial.println("184 Hz"); | ||
break; | ||
case MPU6050_BAND_94_HZ: | ||
Serial.println("94 Hz"); | ||
break; | ||
case MPU6050_BAND_44_HZ: | ||
Serial.println("44 Hz"); | ||
break; | ||
case MPU6050_BAND_21_HZ: | ||
Serial.println("21 Hz"); | ||
break; | ||
case MPU6050_BAND_10_HZ: | ||
Serial.println("10 Hz"); | ||
break; | ||
case MPU6050_BAND_5_HZ: | ||
Serial.println("5 Hz"); | ||
break; | ||
} | ||
|
||
Serial.println(""); | ||
return true; | ||
} | ||
|
||
void MPU6050::getEvent(sensors_event_t *a, sensors_event_t *g, sensors_event_t *temp) | ||
{ | ||
mpu.getEvent(a, g, temp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
#include <Adafruit_MPU6050.h> | ||
#include <Adafruit_Sensor.h> | ||
#include <Wire.h> | ||
|
||
class MPU6050 | ||
{ | ||
public: | ||
MPU6050(); | ||
bool begin(unsigned long timeout = ULONG_MAX); | ||
void getEvent(sensors_event_t *a, sensors_event_t *g, sensors_event_t *temp); | ||
|
||
private: | ||
Adafruit_MPU6050 mpu; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "MPU6050.h" | ||
#include <Arduino.h> | ||
#include <Wire.h> | ||
#include <unity.h> | ||
|
||
MPU6050 mpu; | ||
|
||
void setUp(void) | ||
{ | ||
// This will be run before each test | ||
Wire.begin(); | ||
TEST_ASSERT_TRUE_MESSAGE(mpu.begin(100), "Failed to initialize MPU6050"); | ||
} | ||
|
||
void tearDown(void) | ||
{ | ||
// This will be run after each test | ||
// Any cleanup code can be put here | ||
} | ||
|
||
void test_accelerometer_values(void) | ||
{ | ||
sensors_event_t a, g, temp; | ||
mpu.getEvent(&a, &g, &temp); | ||
TEST_ASSERT_TRUE_MESSAGE(a.acceleration.x != 0.0 || | ||
a.acceleration.y != 0.0 || | ||
a.acceleration.z != 0.0, | ||
"Accelerometer output is 0,0,0"); | ||
} | ||
|
||
void setup() | ||
{ | ||
delay(2000); // Allow some time for the serial port to initialize | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_accelerometer_values); | ||
} | ||
|
||
void loop() | ||
{ | ||
UNITY_END(); | ||
} |