IMU Stuff

This commit is contained in:
Mee2001 2021-06-14 20:32:07 +01:00
parent cc113aa086
commit c6f93039a1
3 changed files with 14 additions and 6 deletions

View file

@ -484,7 +484,6 @@ void loop()
if (!initialAngleSet)
{
//turn to angle
currentHeading = getCurrentHeading();
if (currentHeading < requiredHeading)
{ //turn right
Serial.println("turning right");
@ -647,12 +646,12 @@ void loop()
total_x = 10 * total_x1 / 157; //Conversion from counts per inch to mm (400 counts per inch)
total_y = 10 * total_y1 / 157; //Conversion from counts per inch to mm (400 counts per inch)
Serial.print('\n');
/* Serial.print('\n');
Serial.println("Distance_x = " + String(total_x));
Serial.println("Distance_y = " + String(total_y));
Serial.print('\n');
Serial.print('\n'); */
//-------------------------------------------------------SMPS & MOTOR CODE START------------------------------------------------------//
unsigned long currentMillis = millis();
if (loopTrigger)

View file

@ -15,4 +15,7 @@ framework = arduino
lib_deps =
tanakamasayuki/I2C MPU6886 IMU@^1.0.0
m5stack/M5StickC@^0.2.0
bblanchon/ArduinoJson@^6.18.0
monitor_speed = 115200
monitor_port = COM8
upload_port = COM8

View file

@ -1,5 +1,6 @@
#include <Arduino.h>
#include <M5StickC.h>
#include <ArduinoJson.h>
float pitch, roll, yaw;
@ -7,13 +8,18 @@ void setup() {
M5.begin();
M5.IMU.Init();
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, 26, 0);
Serial1.begin(9600, SERIAL_8N1, 26, 0);
}
void loop() {
M5.IMU.getAhrsData(&pitch, &roll, &yaw);
M5.Lcd.setCursor(0, 45);
M5.Lcd.printf("%5.2f\n", roll);
Serial.printf("{\"cH\":%5.2f}\n", roll);
Serial1.printf("{\"cH\":%5.2f}\n", roll);
// Serial.printf("{\"cH\":%5.2f}\n", roll);
// Serial1.printf("{\"cH\":%5.2f}\n", roll);
DynamicJsonDocument tdoc(1024);
tdoc["cH"] = roll;
serializeJson(tdoc, Serial1);
delay(50);
}