Skip to content

Commit c69d334

Browse files
fixed bug in computation of rate (use micros, not millis), some other small updates
1 parent b83f75f commit c69d334

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

esp8266_imu_osc/esp8266_imu_osc.ino

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ void setup() {
8181
WiFi.hostname(host);
8282
WiFi.begin();
8383

84-
Wire.begin(5, 4); // SDA=D1=5, SCL=D2=4
85-
Wire.setClock(400000L);
86-
87-
pinMode(0, OUTPUT); // RESET=D3=0
88-
digitalWrite(0, LOW); // reset on
84+
pinMode(0, OUTPUT); // RESET=D3=0
85+
digitalWrite(0, LOW); // reset on
8986
delay(10);
9087
digitalWrite(0, HIGH); // reset off
9188

89+
Wire.begin(5, 4); // SDA=D1=5, SCL=D2=4
90+
Wire.setClock(400000L);
91+
9292
SPIFFS.begin();
9393

9494
// Used for OSC
@@ -205,6 +205,7 @@ void setup() {
205205
CONFIG_TO_JSON(sensors, "sensors");
206206
CONFIG_TO_JSON(decimate, "decimate");
207207
CONFIG_TO_JSON(calibrate, "calibrate");
208+
CONFIG_TO_JSON(raw, "raw");
208209
CONFIG_TO_JSON(ahrs, "ahrs");
209210
CONFIG_TO_JSON(quaternion, "quaternion");
210211
CONFIG_TO_JSON(temperature, "temperature");
@@ -247,7 +248,7 @@ void setup() {
247248

248249
// Read the WHO_AM_I register, this is a good test of communication
249250
byte c = mpu[i].readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
250-
Serial.print(F("MPU9250 I AM 0x"));
251+
Serial.print(F("MPU9250 I am 0x"));
251252
Serial.print(c, HEX);
252253
Serial.print(F(" I should be 0x"));
253254
Serial.println(0x71, HEX);
@@ -281,7 +282,7 @@ void setup() {
281282
// Read the WHO_AM_I register of the magnetometer, this is a good test of communication
282283
byte d = mpu[i].readByte(AK8963_ADDRESS, WHO_AM_I_AK8963);
283284
Serial.print("AK8963 ");
284-
Serial.print("I AM 0x");
285+
Serial.print("I am 0x");
285286
Serial.print(d, HEX);
286287
Serial.print(" I should be 0x");
287288
Serial.println(0x48, HEX);
@@ -290,10 +291,6 @@ void setup() {
290291
status++;
291292
}
292293

293-
// mpu[i].Gscale = MPU9250::GFS_2000DPS;
294-
// mpu[i].Ascale = MPU9250::AFS_2G;
295-
// mpu[i].Mmode = MPU9250::M_100HZ;
296-
297294
// Get magnetometer calibration from AK8963 ROM
298295
mpu[i].initAK8963(mpu[i].factoryMagCalibration);
299296
// Initialize device for active mode read of magnetometer
@@ -313,8 +310,7 @@ void setup() {
313310
mpu[i].getMres();
314311

315312
if (config.calibrate == 1) {
316-
// The next call delays for 4 seconds, and then records about 15 seconds of
317-
// data to calculate bias and scale.
313+
// The next call delays for 4 seconds, and then records about 15 seconds of data to calculate bias and scale.
318314
mpu[i].magCalMPU9250(mpu[i].magBias, mpu[i].magScale);
319315

320316
Serial.println("AK8963 mag biases (mG)");
@@ -359,7 +355,7 @@ void loop() {
359355
if (WiFi.status() != WL_CONNECTED) {
360356
ledRed();
361357
}
362-
else if ((millis() - tic_web) < 5000) {
358+
else if ((millis() - tic_web) < 3000) {
363359
// serving content on the http interface takes a lot of resources and
364360
// messes up the regular timing of the acquisition and transmission
365361
ledBlue();
@@ -394,9 +390,11 @@ void loop() {
394390
mpu[i].my = (float)mpu[i].magCount[1] * mpu[i].mRes * mpu[i].factoryMagCalibration[1] - mpu[i].magBias[1];
395391
mpu[i].mz = (float)mpu[i].magCount[2] * mpu[i].mRes * mpu[i].factoryMagCalibration[2] - mpu[i].magBias[2];
396392

397-
String(id[i] + "/a").toCharArray(msgId, 16); bundle.add(msgId).add(mpu[i].ax).add(mpu[i].ay).add(mpu[i].az);
398-
String(id[i] + "/g").toCharArray(msgId, 16); bundle.add(msgId).add(mpu[i].gx).add(mpu[i].gy).add(mpu[i].gz);
399-
String(id[i] + "/m").toCharArray(msgId, 16); bundle.add(msgId).add(mpu[i].mx).add(mpu[i].my).add(mpu[i].mz);
393+
if (config.raw) {
394+
String(id[i] + "/a").toCharArray(msgId, 16); bundle.add(msgId).add(mpu[i].ax).add(mpu[i].ay).add(mpu[i].az);
395+
String(id[i] + "/g").toCharArray(msgId, 16); bundle.add(msgId).add(mpu[i].gx).add(mpu[i].gy).add(mpu[i].gz);
396+
String(id[i] + "/m").toCharArray(msgId, 16); bundle.add(msgId).add(mpu[i].mx).add(mpu[i].my).add(mpu[i].mz);
397+
}
400398

401399
if (config.calibrate == 2) {
402400
mpu[i].magContinuousCalMPU9250(mpu[i].magCount, mpu[i].magBias, mpu[i].magScale);
@@ -466,7 +464,7 @@ void loop() {
466464
}
467465

468466
// this section is in micros
469-
Now = millis();
467+
Now = micros();
470468
rate = 1000000.0f / (Now - Last[i]);
471469
String(id[i] + "/rate").toCharArray(msgId, 16); bundle.add(msgId).add(rate);
472470
String(id[i] + "/time").toCharArray(msgId, 16); bundle.add(msgId).add(Now / 1000000.0f);

0 commit comments

Comments
 (0)