Code used for Sensor Expo 2016 - Balloon Game. More details can be found here: https://github.com/ROHMUSDC/ROHM-SensorExpo2016-Pressure-Sensor-Demo/

Dependencies:   BLE_API mbed nRF51822

Fork of Nordic_UART_TEMPLATE_ROHM_SHLD1Update by ROHMUSDC

ROHM Balloon Game Demo Code featured at Sensors Expo 2016

This code was written to be used with the Nordic Semiconductor nRF51-DK.

This Code allows the user to configure two known pressure distances and save pressure readings onto the application. Then it will automatically extrapolate these values and allow the user to see the height of the board. When connected to a balloon, greater heights can be achieved and the board will return the current height of the board.

Additional information about the ROHM MultiSensor Shield Board can be found at the following link: https://github.com/ROHMUSDC/ROHM-SensorExpo2016-Pressure-Sensor-Demo/

For code example for the ROHM SENSORSHLD0-EVK-101, please see the following link: https://developer.mbed.org/teams/ROHMUSDC/code/ROHMSensorShield_BALOONGAME/

Operation

See Github Repositoy for additional information on how to operate this demo application.

Supported ROHM Sensor Devices

  • BM1383GLV Pressure Sensor

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:
3:c3ee9d663fb8
Parent:
2:c7b9d588c80f
Child:
4:eabae2996ecc
--- a/main.cpp	Wed Jul 22 01:05:56 2015 +0000
+++ b/main.cpp	Mon Jul 27 20:32:00 2015 +0000
@@ -36,9 +36,18 @@
 //#define AnalogALS   //BH1620    //Change 0: Remove this completely
 #define AnalogTemp  //BDE0600
 #define AnalogUV    //ML8511
-#define HallSensor  //BU52011   //Change 1: Change to use GPIO for BU52014
+#define HallSensor  //BU52011    //Change 1: Change to use GPIO for BU52014
 #define RPR0521     //RPR0521    //Change 2: Remove This and add in the RPR-0521
-                                //Change 3: Add Code For BH1745, KX022, BM1383GLV, KMX62
+#define KMX62                    //Change 3: Add Code For BH1745, KX022, BM1383GLV, KMX62
+                                
+//Devices To Add
+// PRessure Sensor
+// Accel Only - KX122
+// Check Functions for KMX62
+// Color Sensor
+
+// Gyro last...
+
 
 #include "mbed.h"
 #include "BLEDevice.h"
@@ -47,7 +56,7 @@
 #include "I2C.h"
 
 #define MAX_REPLY_LEN           (UARTService::BLE_UART_SERVICE_MAX_DATA_LEN)    //Actually equal to 20
-#define SENSOR_READ_INTERVAL_S  (2.0F) 
+#define SENSOR_READ_INTERVAL_S  (10.0F) 
 #define ADV_INTERVAL_MS         (1000UL)
 #define UART_BAUD_RATE          (19200UL)
 #define DEVICE_NAME             ("DEMO SENSOR") // This can be read AFTER connecting to the device.
@@ -109,6 +118,30 @@
 float       RPR0521_ALS_OUT = 0;
 #endif
 
+#ifdef KMX62
+int         KMX62_addr_w = 0x1C;          //7bit addr = 0x38, with write bit 0
+int         KMX62_addr_r = 0x1D;          //7bit addr = 0x38, with read bit 1
+
+char        KMX62_CNTL2[2] = {0x3A, 0x5F};
+char        KMX62_Addr_Accel_ReadData = 0x0A;
+char        KMX62_Content_Accel_ReadData[6];
+char        KMX62_Addr_Mag_ReadData = 0x10;
+char        KMX62_Content_Mag_ReadData[6];
+
+int         MEMS_Accel_Xout = 0;
+int         MEMS_Accel_Yout = 0;
+int         MEMS_Accel_Zout = 0;
+float       MEMS_Accel_Conv_Xout = 0;
+float       MEMS_Accel_Conv_Yout = 0;
+float       MEMS_Accel_Conv_Zout = 0;
+int         MEMS_Mag_Xout = 0;
+int         MEMS_Mag_Yout = 0;
+int         MEMS_Mag_Zout = 0;
+float       MEMS_Mag_Conv_Xout = 0;
+float       MEMS_Mag_Conv_Yout = 0;
+float       MEMS_Mag_Conv_Zout = 0;
+#endif
+
 /**
  * This callback is used whenever a disconnection occurs.
  */
@@ -165,7 +198,7 @@
         else
         {
             len = snprintf((char*) buf, MAX_REPLY_LEN, "ERROR");
-        }
+    `    }
 
         m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
 
@@ -213,7 +246,6 @@
         
         len = snprintf((char*) buf, MAX_REPLY_LEN, "Temp = %.2f C", BDE0600_output);
         m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
-
     }
 #endif
 
@@ -281,8 +313,76 @@
     }
 #endif
 
+#ifdef KMX62
     if (m_ble.getGapState().connected) {
-        len = snprintf((char*) buf, MAX_REPLY_LEN, "                ");         //Print and Extra Line to show new data
+        //Read Accel Portion from the IC
+        i2c.write(KMX62_addr_w, &KMX62_Addr_Accel_ReadData, 1, RepStart);
+        i2c.read(KMX62_addr_r, &KMX62_Content_Accel_ReadData[0], 6, NoRepStart);
+
+        //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte.
+        //      However, because we need the signed value, we will adjust the value when converting to "g"
+        MEMS_Accel_Xout = (KMX62_Content_Accel_ReadData[1]<<8) | (KMX62_Content_Accel_ReadData[0]);
+        MEMS_Accel_Yout = (KMX62_Content_Accel_ReadData[3]<<8) | (KMX62_Content_Accel_ReadData[2]);
+        MEMS_Accel_Zout = (KMX62_Content_Accel_ReadData[5]<<8) | (KMX62_Content_Accel_ReadData[4]);
+          
+        //Note: Conversion to G is as follows:
+        //      Axis_ValueInG = MEMS_Accel_axis / 1024
+        //      However, since we did not remove the LSB previously, we need to divide by 4 again
+        //      Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB
+        MEMS_Accel_Conv_Xout = (float)MEMS_Accel_Xout/4096/2;
+        MEMS_Accel_Conv_Yout = (float)MEMS_Accel_Yout/4096/2;
+        MEMS_Accel_Conv_Zout = (float)MEMS_Accel_Zout/4096/2;
+
+        //Read MAg portion from the IC
+        i2c.write(KMX62_addr_w, &KMX62_Addr_Mag_ReadData, 1, RepStart);
+        i2c.read(KMX62_addr_r, &KMX62_Content_Mag_ReadData[0], 6, NoRepStart);
+
+        //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte.
+        //      However, because we need the signed value, we will adjust the value when converting to "g"
+        MEMS_Mag_Xout = (KMX62_Content_Mag_ReadData[1]<<8) | (KMX62_Content_Mag_ReadData[0]);
+        MEMS_Mag_Yout = (KMX62_Content_Mag_ReadData[3]<<8) | (KMX62_Content_Mag_ReadData[2]);
+        MEMS_Mag_Zout = (KMX62_Content_Mag_ReadData[5]<<8) | (KMX62_Content_Mag_ReadData[4]);
+        
+        //Note: Conversion to G is as follows:
+        //      Axis_ValueInG = MEMS_Accel_axis / 1024
+        //      However, since we did not remove the LSB previously, we need to divide by 4 again
+        //      Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB
+        MEMS_Mag_Conv_Xout = (float)MEMS_Mag_Xout*0.146;
+        MEMS_Mag_Conv_Yout = (float)MEMS_Mag_Yout*0.146;
+        MEMS_Mag_Conv_Zout = (float)MEMS_Mag_Zout*0.146;
+
+        len = snprintf((char*) buf, MAX_REPLY_LEN, "KMX61SensorData:");
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+
+        len = snprintf((char*) buf, MAX_REPLY_LEN, " AccX= %0.2f g", MEMS_Accel_Conv_Xout);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+        
+        len = snprintf((char*) buf, MAX_REPLY_LEN, " AccY= %0.2f g", MEMS_Accel_Conv_Yout);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+        
+        len = snprintf((char*) buf, MAX_REPLY_LEN, " AccZ= %0.2f g", MEMS_Accel_Conv_Zout);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+        
+        len = snprintf((char*) buf, MAX_REPLY_LEN, " MagX= %0.2f g", MEMS_Mag_Conv_Xout);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+        
+        len = snprintf((char*) buf, MAX_REPLY_LEN, " MagY= %0.2f g", MEMS_Mag_Conv_Yout);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+        
+        len = snprintf((char*) buf, MAX_REPLY_LEN, " MagZ= %0.2f g", MEMS_Mag_Conv_Zout);
+        m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
+        wait_ms(1000);
+    }
+#endif
+
+    if (m_ble.getGapState().connected) {
+        len = snprintf((char*) buf, MAX_REPLY_LEN, "               ");         //Print and Extra Line to show new data
         m_ble.updateCharacteristicValue(m_uart_service_ptr->getRXCharacteristicHandle(), buf, len);
     }
 }
@@ -339,6 +439,11 @@
     i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false);
 #endif
 
+#ifdef KMX62
+  // 1. CNTL2 (0x3A), write (0x5F): 4g, Max RES, EN temp mag and accel
+    i2c.write(KMX62_addr_w, &KMX62_CNTL2[0], 2, false);
+#endif
+
 //Start BTLE Initialization Section
     m_ble.init();
     m_ble.onDisconnection(disconnectionCallback);