Skip to content

Commit e9d2979

Browse files
committed
added new BMM150 library
added the new library for BMM150 NOTE: actually is not public i'm refering in the code to it as BoschSensorClass.h
1 parent cc5ed7a commit e9d2979

File tree

6 files changed

+48
-63
lines changed

6 files changed

+48
-63
lines changed

.github/workflows/compile-examples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Arduino_HTS221
6767
- name: Arduino_LPS22HB
6868
- name: Arduino_LSM6DSOX
69-
- name: DFRobot_BMM150
69+
#- name: Arduino_BMI270_BMM150
7070
- name: INA2xx
7171
- name: SerialFlash
7272
- name: ArduinoBLE
@@ -78,7 +78,7 @@ jobs:
7878
libraries: |
7979
- name: ArduinoBLE
8080
- name: Arduino_LSM6DSOX
81-
- name: DFRobot_BMM150
81+
#- name: Arduino_BMI270_BMM150
8282
- name: INA2xx
8383
- name: SerialFlash
8484
sketch-paths: examples/ScienceKitR2/PhysicsLabFirmware

examples/ScienceKitR2/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ void loop() {
136136

137137
void updateSubscribedCharacteristics() {
138138
if (accelerationCharacteristic.subscribed()) {
139-
if (IMU.accelerationAvailable()) {
139+
if (IMU_SK.accelerationAvailable()) {
140140
float x, y, z;
141-
IMU.readAcceleration(x, y, z);
141+
IMU_SK.readAcceleration(x, y, z);
142142
float acceleration[3];
143143

144144
acceleration[0] = x;
@@ -148,9 +148,9 @@ void updateSubscribedCharacteristics() {
148148
}
149149
}
150150
if (gyroscopeCharacteristic.subscribed()) {
151-
if (IMU.gyroscopeAvailable()) {
151+
if (IMU_SK.gyroscopeAvailable()) {
152152
float x, y, z;
153-
IMU.readGyroscope(x, y, z);
153+
IMU_SK.readGyroscope(x, y, z);
154154
float gyroscope[3];
155155

156156
gyroscope[0] = x;
@@ -160,14 +160,17 @@ void updateSubscribedCharacteristics() {
160160
}
161161
}
162162

163-
if (magneticFieldCharacteristic.subscribed()) {// CHECK
164-
sBmm150MagData_t m = bmm150.getGeomagneticData();
165-
float magneticField[3];
166-
magneticField[0] = m.x;
167-
magneticField[1] = m.y;
168-
magneticField[2] = m.z;
169-
magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField));
170-
}
163+
if (magneticFieldCharacteristic.subscribed()) {
164+
float x, y, z;
165+
if (BME.magneticFieldAvailable()) {
166+
BME.readMagneticField(x, y, z);
167+
float magneticField[3];
168+
magneticField[0] = x;
169+
magneticField[1] = y;
170+
magneticField[2] = z;
171+
magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField));
172+
}
173+
}
171174

172175
if (temperatureCharacteristic.subscribed()) {
173176
float temperature = TempSens.getTemperature();

examples/ScienceKitR2/Nano33BLESenseFirmware/config.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ const int FlashChipSelect = 2;
1313
// IMU
1414
#include <Arduino_LSM6DSOX.h>
1515
// 3 axis magnetometer
16-
#include "DFRobot_BMM150.h"
16+
#include <BoschSensorClass.h>
1717
// INA
1818
#include <INA.h>
1919
#include <avr/dtostrf.h>
2020

2121

22-
DFRobot_BMM150_I2C bmm150(&Wire, I2C_ADDRESS_1);
22+
LSM6DSOXClass IMU_SK = LSM6DSOXClass(Wire,0x6A);
23+
BoschSensorClass BME = BoschSensorClass(Wire);
2324

2425
const uint32_t SHUNT_MICRO_OHM{100000}; ///< Shunt resistance in Micro-Ohm, e.g. 100000 is 0.1 Ohm
2526
const uint16_t MAXIMUM_AMPS{1}; ///< Max expected amps, clamped from 1A to a max of 1022A
@@ -51,24 +52,13 @@ void sensorsInit() {
5152
INA.alertOnBusOverVoltage(true, 5000); // Trigger alert if over 5V on bus
5253

5354
// bmm150
54-
while(bmm150.begin()){
55-
Serial.println("bmm150 init failed, Please try again!");
56-
delay(1000);
57-
} Serial.println("bmm150 init success!");
58-
Serial.println("bmm150 init success!");
59-
60-
// BMM150 init
61-
// Set sensor operation mode
62-
bmm150.setOperationMode(BMM150_POWERMODE_NORMAL);
63-
//Set preset mode
64-
bmm150.setPresetMode(BMM150_PRESETMODE_HIGHACCURACY);
65-
// Set the rate of obtaining geomagnetic data, the higher, the faster (without delay function)
66-
bmm150.setRate(BMM150_DATA_RATE_10HZ);
67-
// Enable the measurement at x-axis, y-axis and z-axis,
68-
bmm150.setMeasurementXYZ();
55+
if (!BME.begin()) {
56+
Serial.println("Failed to initialize IMU!");
57+
while (1);
58+
}
6959

7060
// LSM6DSOX init
71-
if (!IMU.begin()) {
61+
if (!IMU_SK.begin()) {
7262
Serial.println("Failed to initialize IMU!");
7363
while (1);
7464
}

examples/ScienceKitR2/PhysicsLabFirmware/PhysicsLabFirmware.ino

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ void updateSubscribedIMUCharacteristics() {
207207
if (millis() - imuTime > IMU_UPDATE_TIME) {
208208
imuTime = millis();
209209
if (accelerationCharacteristic.subscribed()) {
210-
if (IMU.accelerationAvailable()) {
210+
if (IMU_SK.accelerationAvailable()) {
211211
float x, y, z;
212-
IMU.readAcceleration(x, y, z);
212+
IMU_SK.readAcceleration(x, y, z);
213213
float acceleration[3];
214214

215215
acceleration[0] = x;
@@ -220,9 +220,9 @@ void updateSubscribedIMUCharacteristics() {
220220
}
221221

222222
if (gyroscopeCharacteristic.subscribed()) {
223-
if (IMU.gyroscopeAvailable()) {
223+
if (IMU_SK.gyroscopeAvailable()) {
224224
float x, y, z;
225-
IMU.readGyroscope(x, y, z);
225+
IMU_SK.readGyroscope(x, y, z);
226226
float gyroscope[3];
227227

228228
gyroscope[0] = x;
@@ -234,12 +234,15 @@ void updateSubscribedIMUCharacteristics() {
234234

235235

236236
if (magneticFieldCharacteristic.subscribed()) {
237-
sBmm150MagData_t m = bmm150.getGeomagneticData();
238-
float magneticField[3];
239-
magneticField[0] = m.x;
240-
magneticField[1] = m.y;
241-
magneticField[2] = m.z;
242-
magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField));
237+
float x, y, z;
238+
if (BME.magneticFieldAvailable()) {
239+
BME.readMagneticField(x, y, z);
240+
float magneticField[3];
241+
magneticField[0] = x;
242+
magneticField[1] = y;
243+
magneticField[2] = z;
244+
magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField));
245+
}
243246
}
244247
}
245248
}

examples/ScienceKitR2/PhysicsLabFirmware/config.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
// Flash memory
88
#include "SerialFlash.h"
99
#include <SPI.h>
10-
10+
#include <Wire.h>
1111
// IMU
1212
#include <Arduino_LSM6DSOX.h>
1313

1414
// BMM150
15-
#include "DFRobot_BMM150.h"
15+
#include <BoschSensorClass.h>
1616

1717
// INA
1818
#include <INA.h>
1919
#include <avr/dtostrf.h>
2020

21-
DFRobot_BMM150_I2C bmm150(&Wire, I2C_ADDRESS_1);
22-
21+
LSM6DSOXClass IMU_SK = LSM6DSOXClass(Wire,0x6A);
22+
BoschSensorClass BME = BoschSensorClass(Wire);
2323
const int FlashChipSelect = 2;
2424

2525
const uint32_t SHUNT_MICRO_OHM{100000}; ///< Shunt resistance in Micro-Ohm, e.g. 100000 is 0.1 Ohm
@@ -45,24 +45,13 @@ void sensorsInit() {
4545
INA.alertOnBusOverVoltage(true, 5000); // Trigger alert if over 5V on bus
4646

4747
// bmm150
48-
while(bmm150.begin()){
49-
Serial.println("bmm150 init failed, Please try again!");
50-
delay(1000);
51-
} Serial.println("bmm150 init success!");
52-
Serial.println("bmm150 init success!");
53-
54-
// BMM150 init
55-
// Set sensor operation mode
56-
bmm150.setOperationMode(BMM150_POWERMODE_NORMAL);
57-
//Set preset mode
58-
bmm150.setPresetMode(BMM150_PRESETMODE_HIGHACCURACY);
59-
// Set the rate of obtaining geomagnetic data, the higher, the faster (without delay function)
60-
bmm150.setRate(BMM150_DATA_RATE_10HZ);
61-
// Enable the measurement at x-axis, y-axis and z-axis,
62-
bmm150.setMeasurementXYZ();
48+
if (!BME.begin()) {
49+
Serial.println("Failed to initialize IMU!");
50+
while (1);
51+
}
6352

6453
// LSM6DSOX init
65-
if (!IMU.begin()) {
54+
if (!IMU_SK.begin()) {
6655
Serial.println("Failed to initialize IMU!");
6756
while (1);
6857
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Communication
88
url=https://github.com/arduino-libraries/Arduino_ScienceJournal
99
architectures=samd,nrf52,mbed,mbed_nano
1010
includes=ArduinoScienceJournal.h
11-
depends=Adafruit LSM9DS0 Library,Adafruit Zero PDM Library,Arduino_APDS9960,Arduino_HTS221,Arduino_LPS22HB,Arduino_LSM9DS1,ArduinoBLE,Arduino_CMSIS-DSP,Arduino_LSM6DSOX,SerialFlash,WiFiNINA,DFRobot_BMM150,INA2xx
11+
depends=Adafruit LSM9DS0 Library,Adafruit Zero PDM Library,Arduino_APDS9960,Arduino_HTS221,Arduino_LPS22HB,Arduino_LSM9DS1,ArduinoBLE,Arduino_CMSIS-DSP,Arduino_LSM6DSOX,SerialFlash,WiFiNINA,INA2xx

0 commit comments

Comments
 (0)