B4R Code Snippet MAX30100 interfacing with WEMOS using inline C...

Dear friends,
Here is the code to interface MAX30100 (Heart Rate and SPO2 sensor) breakout with WEMOS D1 mini using inline C.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Public HR, SPO2,TEMP As Double
    Dim LastReport, reportPeriod As Long
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    reportPeriod=1000
    RunNative("setup",Null)
    AddLooper("Looper1")
End Sub
          
Sub Looper1
    RunNative("update",Null)
    If Millis -LastReport >reportPeriod Then
        RunNative("read",Null)
        Log("Heart rate:",HR,"   ","SPO2:",SPO2,"    ","TEMP:",TEMP)
        LastReport=Millis
    End If
End Sub

#if C
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
PulseOximeter pox;
void setup(B4R::Object* o){
pox.begin();
pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
}
void update(B4R::Object*o) {
pox.update();
}  
void read (B4R::Object* o) {
  
   b4r_main::_hr = pox.getHeartRate();
   b4r_main::_spo2 =pox.getSpO2();
    b4r_main::_temp =pox.getTemperature();
}

#End if
Attached along with is the Arduino library.
Enjoy.
IMPORTANT: Use 4.7K resistors for pull-up on lines SCL and SDA! The breakout does not work without those!
 

Attachments

  • Arduino-MAX30100-master.zip
    99.2 KB · Views: 491
Top