Heart rate sensor MAX30102


+ Reply to Thread
Results 1 to 24 of 24
  1. #1

    Default Heart rate sensor MAX30102

    Dear all,

    the covid-19 period, i have spent lots of time designing a 3D printed Adaptable medical Mask for covid-19. It was succesful using bio-compatible materials

    (here's the liink: https://www.linkedin.com/feed/update...6630277947393/)

    I have printed free of charge, for the kids in school about 50 of face shields in order to be safe inside the lectures.

    The same i did for the professional 3D printed Adaptable Medical Mask, for Hospitals. Just printed couple of those for testing.

    Now i would like to prepare a free of charge again low cost electronic heart rate circuit, for my sons classroom. Kids are in total 15 in class.


    As it is my first time using I2C protocol, i would like your help in order to establish a connection with the heart sensor MAX30102.

    If anyone have tried this sensor i would be much appreciated if you could share a part of your code.

    I have in front of me the manual of the MAX30102 and all the control and register modes. Actually i'm reading this 2 days now, and really as a newbie, cant understand where to start from.

    I will use the PIC18F26K22 at 16Mhz as from the PICBASIC manual I2C protocol needs to run up to 20MHZ using the I2CWRITE or I2CREAD software commands. (i hope i'm right)

    Next the following ports will be used.

    Code:
    LATC.1 for Data 
    LATC.2 for Clock 
    
    also reserved two more ports for external serial display
    
    LATC.6 for TX
    LATC.7 for RX
    Some MAX30102 registers

    Code:
    ;-------------------------------------------------------------|
    ;------------------------ max30102 registers------------------|
    ;-------------------------------------------------------------|
    define  I2C_WRITE_ADDR  $AE     ; b10101110
    define  I2C_READ_ADDR   $AF     ; b10101111
    define  I2C_ID_ADDR     $57     ; 7-bit version of the above
    ;define I2C_ID_ADDR  57h ; 7-bit version of the above
    
    ;//register addresses
    ;---------------------- STATUS REGISTER -----------------------
    define REG_INTR_STATUS_1   $00
    define REG_INTR_STATUS_2   $01
    
    define REG_INTR_ENABLE_1   $02
    define REG_INTR_ENABLE_2   $03
    
    ;----------------------- FIFO REGISTERS -----------------------
    define REG_FIFO_WR_PTR     $04   ; FIFO WRITE POINTER REG ADDR IS 0X04
    define REG_OVF_COUNTER     $05
    define REG_FIFO_RD_PTR     $06
    define REG_FIFO_DATA       $07
    
    ;---------------------- CONFIG REGISTER -----------------------
    define REG_FIFO_CONFIG     $08
    define REG_MODE_CONFIG     $09
    define REG_SPO2_CONFIG     $0A
    define REG_LED1_PA         $0C
    define REG_LED2_PA         $0D
    
    
    define REG_PILOT_PA        $10
    define REG_MULTI_LED_CTRL1 $11
    define REG_MULTI_LED_CTRL2 $12
    
    ;----------------------- TEMP REGISTER -------------------------
    define REG_TEMP_INTR       $1F
    define REG_TEMP_FRAC       $20
    define REG_TEMP_CONFIG     $21
    define REG_PROX_INT_THRESH $30
    
    ;----------------------- PART ID REGISTER ----------------------
    define REG_REV_ID          $FE
    define REG_PART_ID         $FF
    Now i'm trying to understand based on the manual how could i communicate with sensor and at least see it alive (any led light on the sensor)

    Really looking for your help.

  2. #2

    Default Re: Heart rate sensor MAX30102

    on the first post i think i made a mistake with Defines.

    Is this the correct way to assign a constant value to the name?

    Code:
    ;-------------------------------------------------------------|
    ;------------------------ max30102 registers------------------|
    ;-------------------------------------------------------------|
    I2C_WRITE_ADDR con  $AE     ; b10101110
    I2C_READ_ADDR con   $AF     ; b10101111
    I2C_ID_ADDR  con    $57     ; 7-bit version of the above
    ;I2C_ID_ADDR con  57h ; 7-bit version of the above
    
    ;//register addresses
    ;---------------------- STATUS REGISTER -----------------------
    REG_INTR_STATUS_1 con   $00
    REG_INTR_STATUS_2 con   $01
    
    REG_INTR_ENABLE_1 con   $02
    REG_INTR_ENABLE_2 con   $03
    
    ;----------------------- FIFO REGISTERS -----------------------
    REG_FIFO_WR_PTR con     $04   ; FIFO WRITE POINTER REG ADDR IS 0X04
    REG_OVF_COUNTER con     $05
    REG_FIFO_RD_PTR con     $06
    REG_FIFO_DATA con       $07
    
    ;---------------------- CONFIG REGISTER -----------------------
    REG_FIFO_CONFIG con     $08
    REG_MODE_CONFIG con     $09
    REG_SPO2_CONFIG con     $0A
    REG_LED1_PA con         $0C
    REG_LED2_PA con         $0D
    
    
    REG_PILOT_PA con        $10
    REG_MULTI_LED_CTRL1 con $11
    REG_MULTI_LED_CTRL2 con $12
    
    ;----------------------- TEMP REGISTER -------------------------
    REG_TEMP_INTR con       $1F
    REG_TEMP_FRAC con       $20
    REG_TEMP_CONFIG con     $21
    REG_PROX_INT_THRESH con $30
    
    ;----------------------- PART ID REGISTER ----------------------
    REG_REV_ID  con         $FE
    REG_PART_ID  con        $FF

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    LATC.1 for Data
    LATC.2 for Clock
    a recipe for failure in the making ?
    use of LATx ports in "highlevel" commands is incorrect and will not work as expected



    Is this the correct way to assign a constant value to the name?
    a quick little exercise trying to compile this will reveal the differences between defines and constants
    Code:
    reg var byte'#define bite_me 5     ;try one or the other of these two or niether 
    'bite_me con 5         ;                      "
    
    
    REG_INTR_STATUS_1 con   $00
    REG_INTR_STATUS_2 con   $01
    REG_INTR_STATUS_2 con   $07
    REG_INTR_STATUS_3 con   bite_me
    
    
    define REG_INTR_ENABLE_1   $02
    define REG_INTR_ENABLE_2  bite_me
    define REG_INTR_ENABLE_2  1
    
    
    #define REG_INTR_ENABLE_3   $02
    #define REG_INTR_ENABLE_4  bite_me
    #define REG_INTR_ENABLE_4  1
    
    
    loopy:
    
    
    reg =  bite_me
    reg = REG_INTR_ENABLE_3 
    reg = REG_INTR_ENABLE_1
    reg = REG_INTR_STATUS_1
    
    
    goto loopy
    This is more entertaining than Free to Air TV

  4. #4

    Default Re: Heart rate sensor MAX30102

    Thanks for the reply.

    do you mean that i cannot use the following format?

    Code:
    DataPin var LATC.1
    ClockPin var LATC.2

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    if that will become

    I2CREAD DataPin, ClockPin, Control,{Address,}[Var{,Var...}]{,Label}

    then yes that is not allowable and will cause difficult to determine bugs.
    you have to remember pbp is ancient technology, latx registers did not exist when it was created
    it never gets any significant updates
    Last edited by richard; - 17th August 2020 at 14:06.
    This is more entertaining than Free to Air TV

  6. #6

    Default Re: Heart rate sensor MAX30102

    It is a bit consfusing for me.

    But i will try to figure it out.

    My goal is to communicate with this heart sensor. First step is to send this command to light up the LED and then try to read the information needed.

    I have tried this I2C ping program http://www.picbasic.co.uk/forum/showthread.php?t=20185, in order to see if the sensor responds with the ACK. (i though that the sensor was dead)

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    this i2c sniffer will usually do the job


    Code:
      
    DEFINE I2C_SLOW 1    
          anselA=0        'dig i/o 
          ANSELC=0
          TRISC= %11111111
          TRISA= %11111110  
    
    
    SCL                 var Portc.1                     ' I2C Clock  PortA.3
    SDA                 var Portc.0                     ' I2C Data   PortA.2
    I                   VAR BYTE  
    addr                var byte
    rd                   var byte
    
        porta.0=1
        DEFINE DEBUG_REG PORTA
        DEFINE DEBUG_BIT 0      ;  if not used for pwr  
        DEFINE DEBUG_BAUD 38400
        DEFINE DEBUG_MODE 0     
        pause 2000
        Debug "Start",13 ,10
       addr=0
    
    
    for I = $02 to $fe step 2
    I2Cread SDA,SCL,i,addr,[rd] ; or I2Cread SDA,SCL,i,[rd] ;
    Debug "found addr ",#i , 13,10 
    nak:
    Next I
    end
    Last edited by richard; - 18th August 2020 at 00:32.
    This is more entertaining than Free to Air TV

  8. #8

    Default Re: Heart rate sensor MAX30102

    thanks for the book.

    on the other hand, i would like to continue with this project as it is important for me and the kids in school.

    I have done the first attempt to communicate with the sensor but no luck.

    Based on the Datasheet MAX30102, device address, or slave id: %1010111, consists of 7 bit, B7-B1,and the MSB-7 is transmitted first followed by the remaining bits. B0 is LSB which can be 0 if we write or 1 if we read.

    Then again from the manual explains that for the first write operation, we send the slave id as the first byte!....followed by the register address byte and then one or more data.

    From the PBP manual, and from this link http://www.picbasic.co.uk/forum/cont...-EEPROM-Part-1

    It is clear that I2CWRITE and I2CREAD command takes care of the write or read bit, also for the ACK.

    from max30102.png

    Now i have tried to send the following:

    if PBP and command I2CWRITE takes care of the 8th bit then how could i manage to correspond it in the code.

    Code:
    i2cwrite sda,scl,%1010111,$04,error ' this is slave id cosnist of 7 bits.
    If i send the above command nothing will happen, and the data line will be offset from the clock.

    wrong code.png

    Now using the following code:

    Code:
    i2cwrite sda,scl,%10101110,$04,error
    i get this on the scope:

    no ack.png

    then i tried the following:
    Code:
    i2cwrite sda,scl,%10101110,$04,error
    pause 100
    i2cwrite sda,scl,%10101110,$04,error
    and the result on the scope: it looks strange again.

    strange.png

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    did you try my i2c sniffer ?

    i2cwrite sda,scl,%10101110,$04,error
    how can that work ? you are attempting to write to the FIFO_WR_PTR yet providing no data to be written .

    i2cwrite sda,scl,$ae,$04,[1],error

    in general code snippets are a waste of time
    what pins , how are they set
    a schematic
    This is more entertaining than Free to Air TV

  10. #10

    Default Re: Heart rate sensor MAX30102

    Richard i havent used your sniffer code. Will do today it today.

    The breadboarding....i think is clear as schematic, if you like schematic i could also make one.

    breadboard.png

    SCL is set as input in TRISC

    Code:
    TRISC = %10000100 ' portc.7 and portc.2 set as input. 
    
    all other unused ports are configured as output and set to low. 
    
    SDA var portc.1
    SCL var portc.2
    Now regarding the FIFO_WR_PTR it is not clear to me in the manual what data to write to it.

    Register maps.png

    for example for the REG_MODE_CONFIG which is $09

    mode config.png

    there is a detailed info of the bits need to be set.

    mode.png

    For someone that is the first time working with a peripheral or a new method, it should be so many years a detailed info for configuration. At least a step by step guide.

    I'm not talking about you, but for all the others were in this forum for so many years. There were few guys were really helping. We lost a chief who was really made detailed explanations like talking to a baby.

    If we need to keep PBP alive, we need to start from 0. Here is not a plave to learn from skratch, and i agree. But if anyone loves PBP, we need to do that. Attract newbies like me, that would like to learn.

    Anyway, i will get in focus on this project, because it matters to me. If anyone would like to get involved and have in house a MAX30102, i would be really happy if could help me out as well.

    Richard i understand that you have no time and you have really other things to focus. Really appreciate your help, and i think you are one of the persons help in here.

    Many thanks.

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    The breadboarding....i think is clear as schematic, if you like schematic i could also make one
    not really , i looked at 3 modules the mikroe one is 3.3v only .the one mouser/e14 sell is 3.3 or 5v and has a logic level converter on board
    another provides no schematic and only vague spec no schema, i cannot identify your module

    by the look of your cro traces you are belting 5v in on the scl,sda pins , better hope its 5v tolerant

    TRISC = %10000100 ' portc.7 and portc.2 set as input.
    is wrong both must be input , the routine will switch tris as req
    if the module have 3.3 v pull ups might be better to use the open collector/drain method for i2c command
    [edit] forget that ,its open collecter by default.


    all other unused ports are configured as output and set to low.
    unnecessary


    SDA var portc.1
    SCL var portc.2
    conflicts with your tris statement anyway


    Now regarding the FIFO_WR_PTR it is not clear to me in the manual what data to write to it.
    me either but it will do something if everything else is correct
    Last edited by richard; - 21st August 2020 at 10:20.
    This is more entertaining than Free to Air TV

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    For someone that is the first time working with a peripheral or a new method, it should be so many years a detailed info for configuration. At least a step by step guide.


    I'm not talking about you, but for all the others were in this forum for so many years. There were few guys were really helping. We lost a chief who was really made detailed explanations like talking to a baby.


    If we need to keep PBP alive, we need to start from 0. Here is not a plave to learn from skratch, and i agree. But if anyone loves PBP, we need to do that. Attract newbies like me, that would like to learn
    if you are familiar with i2c protocol and the vagaries of the device you have studied and intend to use then the pbp manual
    tells you everything you need to know to communicate with your device with pbp's i2c commands.
    the pbp manual is not there to teach i2c protocol to a novice , its raison d'etre is to explain usage of pbp implementation.

    having said that you can always ask questions on forums but really the onus is on you to do the ground work. its your project.
    its a pretty tall order to expect a complete novice tutorial for every device you can pluck out of the air from unpaid volunteers
    there are still few here willing to have a go at helping but don't forget dt was paid support , that resource has never been replaced.
    leo will usually help but he has not ventured onto this forum for years and years afaik.
    Last edited by richard; - 21st August 2020 at 11:01.
    This is more entertaining than Free to Air TV

  13. #13

    Default Re: Heart rate sensor MAX30102

    Changed to input both portc.1 and portc.2

    This is the module.

    https://reedpaper.wordpress.com/2018...x-wrong-board/

    I have also following the "fix". Well module is 3.3V but i have never seen in all of the Arduino connections any note.

    I have changed the connections and used the 3.3V output from the Display to power the rest of the circuit.

    I dont beleive that i have burned the module as this is the result before i change the voltage supply from 5V to 3.3V.

    Code:
    i2cwrite sda,scl,$AE,$04
    pause 100
    This is the proof of ACK in 9th bit. As from the data sheet if the Id is the right one, the module pulls down the SDA during 9th bit to acknowledge receipt of data.

    ACK correct.png
    Last edited by astanapane; - 21st August 2020 at 12:16.

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    i2cwrite sda,scl,$AE,$04
    i see you're still torturing the device sending incomplete write resister i2c control messages at it
    This is more entertaining than Free to Air TV

  15. #15

    Default Re: Heart rate sensor MAX30102

    yes i havent send any data yet as i'm searching in the i2c how to do that corresponds to the max30102 manual.

    At least i know sensor is responded by pulling SDA down on 9th bit. This is something for me.

  16. #16

    Default Re: Heart rate sensor MAX30102

    i've done many tries. I just want to see if the red LED inside the sensor is alive. At least by sending a command to activate it.

    Code:
    This is as from the pseudo code the first step. I really do not know if that is the right way to send Device ID + write mode
    Then send the FIFO_WR_PTR (i still dont know what are the bits needs to be configured)
    REPEAT START
    
    addr = $04   ; FIFO WRITE POINTER REG ADDR IS 0X04
    i2cwrite  SDA,scl,contwr
    i2cwrite  SDA,scl,contwr,addr
    i2cwrite  SDA,scl,contwr
    i2cwrite  SDA,scl,contwr,addr
    
    Apart from pseudo code in the datasheet, Next i tried to send mode for the heart rate mode only
    
    addr = $09   ' mode configuration 
    i2cwrite  SDA,scl,contwr,addr,[modled],error ' ModLED = $02 as per data sheet heart rate mode only
    
    In the end i tried to send the led pulse amplitute. 
    
    addr = $0C   ' led pulse amplitute
    i2cwrite  SDA,scl,contwr,addr,[led1_pa],error' LED1_PA = $3F  , 12.6 mA
    no luck......keep walking.

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    given that you can buy these for < $20us delivered to your door i doubt its worth while making them other than as an intellectual exercise
    https://au.banggood.com/BOXYM-oFit-2...r_warehouse=CN
    i have tried the sparkfun arduino demos and was not particularly impressed with accuracy or stability of readings obtained
    {maybe my heart is inaccurate and unstable}
    the raspberrypi code goes about it quite differently&nbsp; with some dsp done on data collected in a fixed sampling period [not tried it].
    i have no experience with these things , i don't know if reverse engineering the arduino code is even worthwhile
    but no matter how you go about it the sort of digital signal processing needed will be lots and lots of hard work with pbp
    do you have a plan ? have you established optimal device settings to get the best readings ? how much data is needed and from where ?
    reading and writing to the device is child's play, setting it up to get meaningful data and being able to extract information from that data is another story
    This is more entertaining than Free to Air TV

  18. #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,991

    Default Re: Heart rate sensor MAX30102

    I double what Richard pointed.

    Ioannis

  19. #19

    Default Re: Heart rate sensor MAX30102

    Thanks both for your kind reply.

    I will find the way. I know it is quite difficult and options are limited to use Arduino.

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    i tried the arduino code again with the sensor attached to my finger with a rubber band , it works a bit better that way
    do you have a stl model for an enclosure ? . its difficult to make any sense of wildly unstable readings

    i'm thinking a ESP8285 M3 board would make a better platform and allow use of arduino libs if they can be proven to be adequate
    ESP8285's these cut down esp8266's are very cheap and still have more processing power than a bucket full of pic chips they are quite happy to run on two aaa batteries and consume little energy if wifi not engaged
    Last edited by richard; - 4th September 2020 at 10:24.
    This is more entertaining than Free to Air TV

  21. #21

    Default Re: Heart rate sensor MAX30102

    Hi Richard,

    once i have all the components (including the arduino board or ESP8285) then i will be ready to design the 3D cad model and printed.

    I will order some arduino and ESP and check them out.

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,991

    Default Re: Heart rate sensor MAX30102

    Use of such finger sensors need to have your finger cleaned from oil with alcohol (isoprop. alcohol or similar).

    It is necessary for the sensors to keep working with consistency.

    Ioannis

  23. #23
    Join Date
    May 2013
    Location
    australia
    Posts
    1,745

    Default Re: Heart rate sensor MAX30102

    thanks ioannis, with out the repeatable test conditions its all guess work

    i might see if i can print this
    https://www.thingiverse.com/thing:4395147
    This is more entertaining than Free to Air TV

  24. #24
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,991

    Default Re: Heart rate sensor MAX30102

    Interesting 3D print!

    Ioannis

Similar Threads

  1. New PIC failure rate
    By timmers in forum General
    Replies: 5
    Last Post: - 26th March 2009, 13:11
  2. Rf module baud rate
    By tazntex in forum Serial
    Replies: 4
    Last Post: - 5th August 2008, 18:47
  3. Replies: 6
    Last Post: - 18th January 2008, 09:17
  4. SHIFTOUT Clock rate
    By Brock in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th July 2006, 23:42
  5. Detect baud rate
    By Dick M in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd July 2005, 21:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts