Skip to content

Commit

Permalink
change Bosch library used in example sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopi-tlt committed Oct 8, 2021
1 parent 466b796 commit 9758f4b
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 80 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ME310 0.0.0 - ????.??.??

ME310 2.5.0 - 2021.10.08
* Changed Bosch example to use BMA400-API library
* Minor code cleanup

ME310 2.4.0 - 2021.09.27
* Add SMS management in AT commands
* Add binary mode improvements for sockets data
Expand Down
216 changes: 141 additions & 75 deletions examples/Bosch_sensor_example/Bosch_sensor_example.ino
Original file line number Diff line number Diff line change
@@ -1,75 +1,141 @@
/*Copyright (C) 2020 Telit Communications S.p.A. Italy - All Rights Reserved.*/
/* See LICENSE file in the project root for full license information. */

/**
@file
ME310.cpp
string.h
stdio.h
@brief
Sample test of the use of AT commands via ME310 library
@details
In this example sketch, it is shown how to use BMA400 library of management the BMA400 accelerometer from Bosch Sensortec.
To run this sketch, it is necessary to download the Grove_3Axis_Digital_Accelerometer_BMA400 library from
https://github.com/Seeed-Studio/Grove_3Axis_Digital_Accelerometer_BMA400.
@version
2.0.0
@note
@author
Cristina Desogus
@date
29/04/2021
*/

#include <BMA400.h>

float x = 0, y = 0, z = 0;
float xACC = 0, yACC = 0, zACC = 0;
int16_t temperature = 0;
uint8_t idDev = 0;

void setup() {
Wire.begin();
Serial.begin(115200);
delay(1000);
Serial.println("Telit BMA400 test ");

Serial.println("Checking BMA400 connection");
delay(1000);
if(bma400.isConnection()) //Control of BMA400 connection is ON
{
bma400.initialize();
Serial.println("BMA400 is connected");
}
else
{
Serial.println("BMA400 is not connected");
}
delay(2000);
idDev = bma400.getDeviceID(); // Get id Device
Serial.println((String)"Device id: " + idDev);
}

void loop() {
bma400.getAcceleration(&x, &y, &z); // Get acceleration values x, y, z by reference
temperature = bma400.getTemperature(); // Get temperature value
xACC = bma400.getAccelerationX(); // Get acceleration value X
yACC = bma400.getAccelerationY(); // Get acceleration value Y
zACC = bma400.getAccelerationZ(); // Get acceleration value Z
Serial.println("Accelation values by getAcceleration function: ");
Serial.println((String)"X-> " + x + ", Y-> "+ y+ ", Z-> " +z);
Serial.println("Accelation value x by getAccelerationX : ");
Serial.println((String)"X-> " + xACC);
Serial.println("Accelation value y by getAccelerationY : ");
Serial.println((String)"Y-> "+ yACC);
Serial.println("Accelation value z by getAccelerationZ : ");
Serial.println((String)"Z-> " +zACC);
Serial.println((String)"Temperature: " + temperature);
delay(3000);
}
/*Copyright (C) 2021 Telit Communications S.p.A. Italy - All Rights Reserved.*/
/* See LICENSE file in the project root for full license information. */

/**
@file
ME310.cpp
string.h
stdio.h
@brief
Sample test of the use of AT commands via ME310 library
@details
In this example sketch, it is shown how to use BMA400 library of management the BMA400 accelerometer from Bosch Sensortec.
To run this sketch, it is necessary to download the telit BMA400-API library arduino porting from
https://github.com/telit/arduino-BMA400-API.
@version
2.1.0
@note
@author
Cristina Desogus
@date
29/04/2021
*/

#include <telit_bma400.h>

/* Earth's gravity in m/s^2 */
#define GRAVITY_EARTH (9.80665f)

/* 39.0625us per tick */
#define SENSOR_TICK_TO_S (0.0000390625f)


static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width);

struct bma400_dev bma;
struct bma400_sensor_conf conf;
struct bma400_sensor_data data;
struct bma400_int_enable int_en;
int8_t rslt;

float t, x, y, z;
int16_t temperature;
uint16_t int_status = 0;

static float lsb_to_ms2(int16_t accel_data, uint8_t g_range, uint8_t bit_width)
{
float accel_ms2;
int16_t half_scale;

half_scale = 1 << (bit_width - 1);
accel_ms2 = (GRAVITY_EARTH * accel_data * g_range) / half_scale;

return accel_ms2;
}

void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Telit BMA400 test ");

/* Interface reference is given as a parameter
* For I2C : BMA400_I2C_INTF
*/
rslt = bma400_interface_init(&bma, BMA400_I2C_INTF);

bma400_check_rslt("bma400_interface_init", rslt);

rslt = bma400_soft_reset(&bma);
bma400_check_rslt("bma400_soft_reset", rslt);

rslt = bma400_init(&bma);
bma400_check_rslt("bma400_init", rslt);

/* Select the type of configuration to be modified */
conf.type = BMA400_ACCEL;

/* Get the accelerometer configurations which are set in the sensor */
rslt = bma400_get_sensor_conf(&conf, 1, &bma);
bma400_check_rslt("bma400_get_sensor_conf", rslt);

/* Modify the desired configurations as per macros
* available in bma400_defs.h file */
conf.param.accel.odr = BMA400_ODR_100HZ;
conf.param.accel.range = BMA400_RANGE_2G;
conf.param.accel.data_src = BMA400_DATA_SRC_ACCEL_FILT_1;

/* Set the desired configurations to the sensor */
rslt = bma400_set_sensor_conf(&conf, 1, &bma);
bma400_check_rslt("bma400_set_sensor_conf", rslt);

rslt = bma400_set_power_mode(BMA400_MODE_NORMAL, &bma);
bma400_check_rslt("bma400_set_power_mode", rslt);

int_en.type = BMA400_DRDY_INT_EN;
int_en.conf = BMA400_ENABLE;

rslt = bma400_enable_interrupt(&int_en, 1, &bma);
bma400_check_rslt("bma400_enable_interrupt", rslt);

}

void loop() {

Serial.print("\nGet accel data - BMA400_DATA_SENSOR_TIME\n");

while ((rslt == BMA400_OK))
{
rslt = bma400_get_interrupt_status(&int_status, &bma);

if (int_status & BMA400_ASSERTED_DRDY_INT)
{
rslt = bma400_get_accel_data(BMA400_DATA_SENSOR_TIME, &data, &bma);

/* 12-bit accelerometer at range 2G */
x = lsb_to_ms2(data.x, 2, 12);
y = lsb_to_ms2(data.y, 2, 12);
z = lsb_to_ms2(data.z, 2, 12);
t = (float)data.sensortime * SENSOR_TICK_TO_S;

/*temperature is returned in celsius degrees tenths, as an integer*/
rslt = bma400_get_temperature_data(&temperature, &bma);

Serial.println("");
Serial.println("Accelation values by bma400_get_accel_data function: ");
Serial.print((String)"X-> " + x + ", Y-> "+ y+ ", Z-> " +z);
Serial.print(", t(s) : ");
Serial.println(t);

/*Convert temperature in celsius degrees*/
float c_temp = (float)(temperature / 10.0);
Serial.println((String)"Temperature: " + c_temp + " \xB0" +"C");
delay(3000);
}
}
}
4 changes: 2 additions & 2 deletions examples/LWM2M_example/LWM2M_example_2G/LWM2M_example_2G.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const char *resp;
#define ON_OFF 6 /*Select the GPIO to control ON_OFF*/
#endif
/*
* If a Telit-Board Charlie is not in use, the ME310 class needs the Uart Serial instance in the constructor, that will be used to communicate with the modem.\n
* If a Telit-Board Charlie is not in use, the ME310 class needs the Uart Serial instance in the constructor, that will be used to communicate with the modem.\n
* Please refer to your board configuration in variant.h file.
* Example:
* Uart Serial1(&sercom4, PIN_MODULE_RX, PIN_MODULE_TX, PAD_MODULE_RX, PAD_MODULE_TX, PIN_MODULE_RTS, PIN_MODULE_CTS);
* ME310 myME310 (Serial1);
* ME310 myME310 (Serial1);
*/
ME310 myME310;

Expand Down
4 changes: 2 additions & 2 deletions examples/LWM2M_example/LWM2M_example_4G/LWM2M_example_4G.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ const char *resp;
#endif

/*
* If a Telit-Board Charlie is not in use, the ME310 class needs the Uart Serial instance in the constructor, that will be used to communicate with the modem.\n
* If a Telit-Board Charlie is not in use, the ME310 class needs the Uart Serial instance in the constructor, that will be used to communicate with the modem.\n
* Please refer to your board configuration in variant.h file.
* Example:
* Uart Serial1(&sercom4, PIN_MODULE_RX, PIN_MODULE_TX, PAD_MODULE_RX, PAD_MODULE_TX, PIN_MODULE_RTS, PIN_MODULE_CTS);
* ME310 myME310 (Serial1);
* ME310 myME310 (Serial1);
*/
ME310 myME310;

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ME310G1
version=2.4.0
version=2.5.0
author=Telit
maintainer=Telit <[email protected]>
sentence=Allows communication with ME310G1 Telit module.
Expand Down

0 comments on commit 9758f4b

Please sign in to comment.