Skip to content

Commit 484793e

Browse files
committed
adding basic bno reading
1 parent 737b890 commit 484793e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

ArduinoClassRobot.ino

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@
2323
*/
2424
#include <ESP32Servo.h>
2525
#include <WiiChuck.h>
26+
#include <Wire.h>
27+
#include <Adafruit_Sensor.h>
28+
#include <Adafruit_BNO055.h>
29+
#include <utility/imumaths.h>
2630

2731
Servo left;
2832
Servo right;
2933
Accessory nunchuck;
34+
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire);
3035

36+
bool bnoStarted = false;
3137
float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
3238
const float run = in_max - in_min;
3339
if(run == 0){
@@ -46,10 +52,33 @@ void setup() {
4652
right.write(90);
4753
Serial.begin(115200);
4854
nunchuck.begin();
55+
bnoStarted=bno.begin();
56+
delay(100);
4957
}
5058

5159
// the loop function runs over and over again forever
5260
void loop() {
61+
if(bnoStarted){
62+
sensors_event_t orientationData;
63+
bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER);
64+
Serial.print("Orient:");
65+
double x = orientationData.orientation.x;
66+
double y = orientationData.orientation.y;
67+
double z = orientationData.orientation.z;
68+
if(abs(x)<0.001 && abs(y) < 0.001 && abs(z)<0.0001){
69+
Serial.println("IMU Died, reset");
70+
bnoStarted=false;
71+
}else{
72+
Serial.print("\tx= ");
73+
Serial.print(x);
74+
Serial.print(" |\ty= ");
75+
Serial.print(y);
76+
Serial.print(" |\tz= ");
77+
Serial.println(z);
78+
}
79+
}else{
80+
bnoStarted=bno.begin();
81+
}
5382
nunchuck.readData(); // Read inputs and update maps
5483

5584
float x= -fmap(nunchuck.values[1],0,255,-1.0,1.0);
@@ -59,4 +88,6 @@ void loop() {
5988

6089
left.write(lval);
6190
right.write(rval);
91+
delay(100);
92+
6293
}

0 commit comments

Comments
 (0)