n-elia / MAX30102-MicroPython-driver

A Maxim MAX30102 driver ported to MicroPython. It should also work for MAX30105.
MIT License
56 stars 21 forks source link

Having issues with a raspberry pi pico #10

Closed Ibrahim778 closed 2 years ago

Ibrahim778 commented 2 years ago

I'm using a Raspberry Pi Pico running micropython. I have the device attached on the hardware I2C pins and I pass through the instance just fine Sensor setup works. However I can't seem to read any actual data from it Using the example you have given I get strange errors, most are related to strings in the check function, for example:

Traceback (most recent call last):
  File "<stdin>", line 42, in <module>
  File "max30102.py", line 714, in safe_check
  File "max30102.py", line 668, in check
TypeError: ord() expected a character, !string of length 536990608 found

Other times, I get a few readings then it just freezes. I have tried with check() and safe_check() Both give the same result

Also the readings I get are like this:

22665 , 30041
22663 , 30040
22661 , 30038
22660 , 30039
22660 , 30041
22661 , 30044
22663 , 30052
22668 , 30063
22672 , 30073
22673 , 30075
22669 , 30070
22667 , 30068
22665 , 30068
22666 , 30071
22667 , 30074

Are they normal for this sensor?

n-elia commented 2 years ago

Hi Ibrahim, you're the first one with such a problem on the Pi Pico.

Are you using a genuine Maxim sensor?

The values seem ok, but keep in mind that their magnitude depend on the sensor's configuration, that you have to tune based on your use case.

Also, did you load your project on the board, or executed main.py "on the fly"? Please follow the instructions given in the README.md, here if you haven't before.

Ibrahim778 commented 2 years ago

I believe I am using a genuine sensor, is there anyway for me to tell? I am using code from main.py, yes, Also yes I am using the same as the example in the readme

n-elia commented 2 years ago

Do you have a link to a shop webpage?

Did you load your project on the board, or executed main.py "on the fly"? Have you tried ti simply reset the board with reset button?

Ibrahim778 commented 2 years ago

I run main.py 'on the fly', I use pico-go on vscode you see, it has a run button I can link you the sensor: https://hallroad.org/max30102-blood-oxygen-concentration-wrist-heart-rate-pulse-detection-heartbeat-sensor-module-stm32-sensor-in-pakistan.html

n-elia commented 2 years ago

Ok, I suggest you to upload the files as described in the README, and then to press the reset button. Otherwise, we can't be sure that everything is running well. (Using pico-go you should use the 'Upload' feature.)

The sensor seems a clone to me. You can check it by following these hints.

Ibrahim778 commented 2 years ago

I am having quite a bit of trouble doing so. Getting your example to work I mean Even after using the correct, hardware, I2C pins and things, after uploading it simply doesn't run I don't see any output either

Edit: Scratch that, I think I found the issue! Edit2: Can I ask what version of python you're using? I'm using the latest micropython for the pi pico Edit3: Well I'm baffled! It seems to work with your example, I have no idea why it wasn't working for me, I will require further help if you don't mind, I'll send you over my code tomorrow, Thanks!

n-elia commented 2 years ago

Hi,

I am using this driver since more than a year. I always used the latest micropython version, which now is 1.18.

Provided that you set the correct i2c pins, of you upload the main.py, boot.py and driver files into /lib folder, then the only thing you need is to reset the board with the onboard reset button. Then, it should work!

Feel free to ask anything, Bye, Nicola

Ibrahim778 commented 2 years ago

I just need to ask about one thing Your driver is for the MAX30102 but in the library code all references are to the MAX30105, just a little confused on that bit Also could you give a basic rundown on how it all works? I'm in the process of porting this to C, but I'm confused on why self._sample_avg etc exist

n-elia commented 2 years ago

Hi,

MAX30105 and MAX30102 are very similar; the 105 packs 3 LEDs (red, green, ir) while the 102 does not provide a green led.

This library is a port of MAX30105 library, and I had the chance to test it only on max30102 sensor. This is why you see references to max30105.

You're reinvent the wheel. If you reead the first lines of this repo's readme, you'll see that this is a port of a C driver. You should just use the sparkfun driver.

These drivers just interface with the sensor module through i2c. To understand how it works, you should take a look to Maxim MAX30102 datasheet.

I'll close this issue, have a nice day. Nicola