This is sample code for interfacing ROHM's SENSORSHLD1-EVK-101 with Nordic Semiconductor's nRF51-DK Development Kit Host BTLE Board
Dependencies: BLE_API mbed nRF51822
Fork of Nordic_UART_TEMPLATE_ROHM by
Code Example for ROHM Mutli-Sensor Shield on the Nordic Semiconductor nRF51-DK
This code was written to be used with the Nordic Semiconductor nRF51-DK.
This is the basic example code for interfacing ROHM's Multi-sensor Shield Board onto this board.
Additional information about the ROHM MultiSensor Shield Board can be found at the following link: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield
For code example for the ROHM SENSORSHLD0-EVK-101, please see the following link: https://developer.mbed.org/teams/ROHMUSDC/code/Nordic_UART_TEMPLATE_ROHM/
Operation
Ultimately, this code will initialize all the sensors on the Multi-sensor shield board and then poll the sensors. The sensor data will then be returned to the BTLE COM port link and will be view-able on any BTLE enabled phone that can connect to the Nordic UART Application.
Supported ROHM Sensor Devices
- BDE0600G Temperature Sensor
- BM1383GLV Pressure Sensor
- BU52014 Hall Sensor
- ML8511 UV Sensor
- RPR-0521 ALS/PROX Sensor
- BH1745NUC Color Sensor
- KMX62 Accel/Mag Sensor
- KX122 Accel Sensor
- BM1422 MI Magnetometer Sensor
- KXG03 Gyro/Accel Sensor
Updates from SHLD0 to SHLD1
- Pressure Sensor Changes: Fixed Register Map Changes for BM1383AGLV, See Pressure Sensor Datasheet for more details - TEMP and PRES output switched
- Added new #ifdef section for Magnetometer
- Changed Gyro Device Address (7bit addr now 0x4F, not 0x4E)
Sensor Applicable Code Sections
- Added a Section in "Main" to act as initialization
- Added to the "Periodic Callback" to read sensor data and return to Phone/Host
Questions/Feedback
Please feel free to let us know any questions/feedback/comments/concerns on the ROHM shield implementation by contacting the following e-mail:
Revision 9:878e7fad5347, committed 2016-09-15
- Comitter:
- kbahar3
- Date:
- Thu Sep 15 20:53:01 2016 +0000
- Parent:
- 8:2a19622864c2
- Child:
- 10:5e4819579d0b
- Commit message:
- Added References to BM1383 (Non-A) for use with yellow sticker-ed boards
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jun 08 18:20:30 2016 +0000
+++ b/main.cpp Thu Sep 15 20:53:01 2016 +0000
@@ -59,7 +59,8 @@
#define KMX62 //KMX61, Accel/Mag Sensor
#define Color //BH1745, Color Sensor
#define KX122 //KX122, Accelerometer Sensor
-#define Pressure //BM1383, Barometric Pressure Sensor
+//#define BM1383A //BM1383A, Barometric Pressure Sensor (NON-YELLOW STICKERED BOARDS)
+#define BM1383 //BM1383, Barometric Pressure Sensor (YELLOW STICKERED BOARDS)
#define Magnetometer //BM1422GMV, MI Magnetometer Sensor
#define KXG03 //KXG03, Gyroscopic Sensor
@@ -210,7 +211,32 @@
int KX122_Accel_Z_HB = 0;
#endif
-#ifdef Pressure
+#ifdef BM1383A
+int Press_addr_w = 0xBA;
+int Press_addr_r = 0xBB;
+
+char PWR_DOWN[2] = {0x12, 0x01};
+char SLEEP[2] = {0x13, 0x01};
+char Mode_Control[2] = {0x14, 0xC4};
+
+char Press_Content_ReadData[6];
+char Press_Addr_ReadData =0x1A;
+
+int BM1383_Temp_highByte;
+int BM1383_Temp_lowByte;
+int BM1383_Pres_highByte;
+int BM1383_Pres_lowByte;
+int BM1383_Pres_leastByte;
+
+short int BM1383_Temp_Out;
+float BM1383_Temp_Conv_Out;
+float BM1383_Pres_Conv_Out;
+
+float BM1383_Var;
+float BM1383_Deci;
+#endif
+
+#ifdef BM1383
int Press_addr_w = 0xBA;
int Press_addr_r = 0xBB;
@@ -378,7 +404,7 @@
//transmit data
len = snprintf((char*) buf, MAX_REPLY_LEN, "Color Sensor:");
m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
- wait_ms(20);
+ wait_ms(20);
len = snprintf((char*) buf, MAX_REPLY_LEN, " Red= %d ADC", BH1745_Red);
m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
@@ -607,7 +633,7 @@
i++;
}
else if (i == 8){
- #ifdef Pressure
+ #ifdef BM1383A
if (m_ble.getGapState().connected) {
//Read color Portion from the IC
i2c.write(Press_addr_w, &Press_Addr_ReadData, 1, RepStart);
@@ -619,9 +645,9 @@
BM1383_Var = (Press_Content_ReadData[0]<<3) | (Press_Content_ReadData[1] >> 5);
BM1383_Deci = ((Press_Content_ReadData[1] & 0x1f) << 6 | ((Press_Content_ReadData[2] >> 2)));
BM1383_Deci = (float)BM1383_Deci* 0.00048828125; //0.00048828125 = 2^-11
- BM1383_Pres_Conv_Out = (BM1383_Var + BM1383_Deci); //question pending here...
+ BM1383_Pres_Conv_Out = (BM1383_Var + BM1383_Deci);
- len = snprintf((char*) buf, MAX_REPLY_LEN, "Pressure Sensor:");
+ len = snprintf((char*) buf, MAX_REPLY_LEN, "BM1383A Sensor:");
m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
wait_ms(20);
@@ -633,7 +659,36 @@
m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
wait_ms(20);
}
- #endif
+ #endif
+
+ #ifdef BM1383
+ if (m_ble.getGapState().connected) {
+ //Read color Portion from the IC
+ i2c.write(Press_addr_w, &Press_Addr_ReadData, 1, RepStart);
+ i2c.read(Press_addr_r, &Press_Content_ReadData[0], 6, NoRepStart);
+
+ BM1383_Temp_Out = (Press_Content_ReadData[0]<<8) | (Press_Content_ReadData[1]);
+ BM1383_Temp_Conv_Out = (float)BM1383_Temp_Out/32;
+
+ BM1383_Var = (Press_Content_ReadData[2]<<3) | (Press_Content_ReadData[3] >> 5);
+ BM1383_Deci = ((Press_Content_ReadData[3] & 0x1f) << 6 | ((Press_Content_ReadData[4] >> 2)));
+ BM1383_Deci = (float)BM1383_Deci* 0.00048828125; //0.00048828125 = 2^-11
+ BM1383_Pres_Conv_Out = (BM1383_Var + BM1383_Deci);
+
+ len = snprintf((char*) buf, MAX_REPLY_LEN, "BM1383 Sensor:");
+ m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+ wait_ms(20);
+
+ len = snprintf((char*) buf, MAX_REPLY_LEN, " Temp= %0.2f C", BM1383_Temp_Conv_Out);
+ m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+ wait_ms(20);
+
+ len = snprintf((char*) buf, MAX_REPLY_LEN, " Pres= %0.2f hPa", BM1383_Pres_Conv_Out);
+ m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+ wait_ms(20);
+ }
+ #endif
+
i++;
}
@@ -849,7 +904,7 @@
#ifdef RPR0521
// 1. Mode Control (0x41), write (0xC6): ALS EN, PS EN, 100ms measurement for ALS and PS, PS_PULSE=1
// 2. ALS_PS_CONTROL (0x42), write (0x03): LED Current = 200mA
- // 3. PERSIST (0x43), write (0x20): PS Gain x4
+ // 3. PERSIST (0x43), write (0x20): PS Gain x4
i2c.write(RPR0521_addr_w, &RPR0521_ModeControl[0], 2, false);
i2c.write(RPR0521_addr_w, &RPR0521_ALSPSControl[0], 2, false);
i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false);
@@ -876,7 +931,13 @@
i2c.write(KX122_addr_w, &KX122_Accel_CNTL2[0], 2, false);
#endif
- #ifdef Pressure
+ #ifdef BM1383A
+ i2c.write(Press_addr_w, &PWR_DOWN[0], 2, false);
+ i2c.write(Press_addr_w, &SLEEP[0], 2, false);
+ i2c.write(Press_addr_w, &Mode_Control[0], 2, false);
+ #endif
+
+ #ifdef BM1383
i2c.write(Press_addr_w, &PWR_DOWN[0], 2, false);
i2c.write(Press_addr_w, &SLEEP[0], 2, false);
i2c.write(Press_addr_w, &Mode_Control[0], 2, false);
