Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test - Sensors #5

Merged
merged 7 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions LKExp-mbed-sensors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ HTS221
* `DevI2C.h` come from [X\_NUCLEO\_COMMON](https://os.mbed.com/teams/ST/code/X_NUCLEO_COMMON/), it adapts i2c of mbed to i2c to manage i2c devices proposed by ST.
* `Component.h`, `GyroSensor.h`, `HumiditySensor.h`, `MagneticSensor.h`, `MotionSensor.h` and `TempSensor.h` come from [ST\_INTERFACES](https://os.mbed.com/teams/ST/code/ST_INTERFACES/) are abstract classes to build specific drivers.

## Execution









* Plug X\_NUCLEO\_IKS01A2 and STEVAL\_MKI197V1 on Arduino conenctors
* If an error occurs, LED1 turns on (after flash)
25 changes: 25 additions & 0 deletions LKExp-mbed-sensors/src/board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "board.h"

Board::Board(PinName sda, PinName scl) {
dev_i2c = new DevI2C(sda, scl);
ladislas marked this conversation as resolved.
Show resolved Hide resolved
ht_sensor = new HTS221Sensor(dev_i2c);
magneto = new LSM303AGRMagSensor(dev_i2c);
acc_gyro = new LSM6DSOXSensor(dev_i2c, LSM6DSOX_I2C_ADD_L);

ht_sensor->init(NULL);
magneto->init(NULL);
acc_gyro->init(NULL);

DigitalOut LSM6DSOX_INT1 (PIN_LSM6DSOX_INT1, 0); //Set to 1 to disable I2C and enable only I3C on LSM6DSOX
}

void Board::check_id() {
uint8_t id;

ht_sensor->read_id(&id);
if (id != HTS221_WHO_AM_I_VAL) _errorLED = 1; //(0xBC expected)
magneto->read_id(&id);
if (id != LSM303AGR_MAG_WHO_AM_I) _errorLED = 1; //(0x40 expected)
acc_gyro->read_id(&id);
if (id != LSM6DSOX_ID) _errorLED = 1; //(0x6C expected)
}
27 changes: 27 additions & 0 deletions LKExp-mbed-sensors/src/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Pin definition ------------------------------------------------------------*/
#define PIN_I2C_SDA (D14)
#define PIN_I2C_SCL (D15)
#define PIN_LSM6DSOX_INT1 (A5)

/* Includes ------------------------------------------------------------------*/
#include "mbed.h"
#include "HTS221Sensor.h"
#include "LSM303AGRMagSensor.h"
#include "LSM6DSOXSensor.h"
#include "DevI2C.h"

/* Static variables ----------------------------------------------------------*/
static DigitalOut _errorLED(LED1);

class Board {
public:
Board(PinName sda=PIN_I2C_SDA, PinName scl=PIN_I2C_SCL);
~Board(void);

void check_id();

DevI2C *dev_i2c;
HTS221Sensor *ht_sensor;
LSM303AGRMagSensor *magneto;
LSM6DSOXSensor *acc_gyro;
};
6 changes: 5 additions & 1 deletion LKExp-mbed-sensors/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "mbed.h"
#include "board.h"

Board *board = new Board();
ladislas marked this conversation as resolved.
Show resolved Hide resolved

int main(void) {
return 0;
printf("--- Starting new run ---\r\n");
board->check_id();
ladislas marked this conversation as resolved.
Show resolved Hide resolved
}