nexpaq development module demo for MAX3010x sensor

Dependencies:   MAX30105 nexpaq_mdk

Fork of ALS_Prox_Demo by nexpaq

Temp Prox Demo

MAX32625NEXPAQ development module

This project is a demonstration application for the MAX32625NEXPAQ development module and a MAX3010x sensor.

This project demonstrates polling the proximity sensor to use it like a button and also polling the temperature sensor and sending the information back to the application running on the phone, and the phone controlling the threshold for the proximity sensor and controlling the on board RGB LED to create different colors.

nexpaq App Tile Files

temp_prox_demo.zip

Revision:
14:6195f9b0bd1b
Parent:
10:a81682ee3e73
--- a/main.cpp	Sat Feb 04 03:31:29 2017 +0000
+++ b/main.cpp	Thu Feb 16 20:59:22 2017 +0000
@@ -1,19 +1,20 @@
 #include "mbed.h"
 #include "nexpaq_mdk.h"
-#include "MAX44000.h"
+#include "MAX30105.h"
 
-MAX44000 max44000(P1_6, P1_7);
 PwmOut ledR(P2_4);
 PwmOut ledG(P2_5);
 PwmOut ledB(P2_6);
 DigitalIn button(P0_1, PullUp);
+I2C i2c(P1_6, P1_7);
+MAX30105 max30105(i2c);
 
 /***** Definitions *****/
 #define		FUNCTION_TABLE_NUM					2
 #define		UUID_NUM							16			// UUID number is 16, don't change it
 #define     LOOP_DELAY                          100
 #define     PROX_THRESHOLD                      10
-#define     ALS_INTERVAL                        10          // about once per second
+#define     TEMP_INTERVAL                       10          // about once per second
 
 /***** Globals *****/
 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
@@ -23,7 +24,7 @@
     {0x2702, my_function_CMD_2702},		// Command -> function
 };
 
-int alsCnt = 0;
+int tempCnt = 0;
 int prxThrsh = PROX_THRESHOLD ;
 int lastPrx = 0;
 unsigned char prxPress = 0x02;
@@ -47,15 +48,24 @@
     np_api_upload(0x2703, &response, 1);
 }
 
-void sendALS()
+void sendTEMP()
 {
+    char dataBuf[2];
     unsigned char pData[3];
-    max44000.writeReg(MAX44000::REG_MAIN_CONFIG, 0x20);
     pData[0] = 10;
-    pData[1] = max44000.readReg(MAX44000::REG_ALS_DATA_HIGH);
-    pData[2] = max44000.readReg(MAX44000::REG_ALS_DATA_LOW);
+    pData[1] = 0xFF;
+    pData[2] = 0xFF;
+    if (max30105.readReg(MAX30105::REG_TEMP_CONFIG, dataBuf) == 0) {
+    	dataBuf[0] = MAX30105::REG_TEMP_INT;
+    	if (i2c.write(MAX30105_I2C_ADDR, dataBuf, 1) == 0) {
+	    	if (i2c.read(MAX30105_I2C_ADDR, dataBuf, 2) == 0) {
+	    		pData[1] = dataBuf[0];
+	    		pData[2] = dataBuf[1];
+    		}
+    	}
+    }
     np_api_upload(0x2800, pData, 3);
-    max44000.writeReg(MAX44000::REG_MAIN_CONFIG, 0x30);
+    max30105.writeReg(MAX30105::REG_TEMP_CONFIG, 0x01);
 }
 
 /******************************************************************************/
@@ -65,7 +75,12 @@
     if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
         // Register failed handle code
     }
-    max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_10);
+    max30105.softReset(); // reset the MAX30105
+    max30105.shutDown();  // shut down while configuring
+    max30105.enableIntr(MAX30105::INTR_PROX);  // enable proximity interrupt
+    max30105.setProx(0x40, PROX_THRESHOLD);    // set proximity pulse amplitude and threshold
+    max30105.setSingleLED();  // configure single LED mode to initiate proximity detection
+    max30105.wakeUp();        // exit shutdown to start sensing
     ledR = 1.0f;
     ledG = 1.0f;
     ledB = 1.0f;
@@ -73,11 +88,11 @@
 
 void app_loop()
 {
-    int proxData = max44000.readReg(MAX44000::REG_PRX_DATA);
-    if (proxData > prxThrsh) {
+    if (max30105.getIntr1() & MAX30105::INTR_PROX) { // if the proximity interrupt occurs
         if (!lastPrx) {
             np_api_upload(0x2800, &prxPress, 1);
         }
+        max30105.writeReg(MAX30105::REG_MODE_CONFIG, MAX30105::MODE_1LED); // go back into proximity detection
         lastPrx = 1;
     } else {
         lastPrx = 0;
@@ -88,10 +103,10 @@
     }
     lastBtn = button;
 
-    alsCnt += 1;
-    if (alsCnt > ALS_INTERVAL) {
-        sendALS();
-        alsCnt = 0;
+    tempCnt += 1;
+    if (tempCnt > TEMP_INTERVAL) {
+        sendTEMP();
+        tempCnt = 0;
     }
 }