Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the MAX30102 heart rate and blood oxygen sensor #4535

Merged
merged 2 commits into from Jan 31, 2022

Conversation

jclsn
Copy link

@jclsn jclsn commented Aug 18, 2021

I have created a device tree overlay for the above sensor with the help of PhilE from the forum. The sensor is now fully recognized. I updated the build config files for all models, though I am not sure about the correct naming there, as they seem to differ in every config. This should be verified.

@pelwell
Copy link
Contributor

pelwell commented Aug 18, 2021

As discussed on the Forum thread (https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=317957) I'll take this and merge it into the existing i2c-sensor overlay. In the process I'll change the config settings to make the driver a loadable module (=m instead of =y).

@jclsn
Copy link
Author

jclsn commented Aug 18, 2021 via email

pelwell pushed a commit to jclsn/linux that referenced this pull request Aug 18, 2021
See: raspberrypi#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
pelwell pushed a commit to jclsn/linux that referenced this pull request Aug 18, 2021
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@pelwell
Copy link
Contributor

pelwell commented Aug 18, 2021

Can you fetch your rpi-5.10.y branch again and test the new i2c-sensor overlay? You'll find that it's been force pushed - git reset --hard rpi-5.10.y should put you back on track.

@jclsn
Copy link
Author

jclsn commented Aug 18, 2021 via email

@jclsn
Copy link
Author

jclsn commented Aug 19, 2021 via email

pelwell pushed a commit to jclsn/linux that referenced this pull request Aug 19, 2021
See: raspberrypi#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
pelwell pushed a commit to jclsn/linux that referenced this pull request Aug 19, 2021
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@pelwell
Copy link
Contributor

pelwell commented Aug 19, 2021

There were two errors in the overlay - the sensor was being enabled by default, and the I2C interface wasn't being enabled for max30102. Try now.

@jclsn
Copy link
Author

jclsn commented Aug 19, 2021 via email

@jclsn
Copy link
Author

jclsn commented Aug 19, 2021

Sorry, my bad. I never figured you could commit to my fork and tried to build the master Pi kernel. I am still a bit new to Github. I am pulling the PR version now...

@jclsn
Copy link
Author

jclsn commented Aug 19, 2021 via email

@pelwell
Copy link
Contributor

pelwell commented Aug 19, 2021

There's no rush - take your time.

@pelwell pelwell added the Waiting for external input Waiting for a comment from the originator of the issue, or a collaborator. label Dec 2, 2021
@jclsn
Copy link
Author

jclsn commented Jan 21, 2022

I've been trying to compile the kernel again, but the Pi is somehow using 5.10.63 instead of 5.10.74. I then tried to upgrade the Pi kernel, fetch upstream sources to 5.10.92 and add the driver again, but when I booted almost no modules were loaded. Is there any way I can just add this module to the existing kernel without recompiling? I tried copying the max30102.ko into the right folder, but the module doesn't seem to be available.

Or how can I tell the Pi to boot the 5.10.74 kernel I compiled?

@jclsn
Copy link
Author

jclsn commented Jan 22, 2022

Seems there was the kmod binary missing when copying the modules to the rootfs. I can load the module with modprobe now, but it doesn't last until the next boot. I also can't see the device, although I am pretty sure that it is connected right.

Any idea why modprobe doesn't last until the next boot? I think last time I did not have to load the module manually. Just setting

dtoverlay=max30102,int_pin=4

was enough.

@pelwell
Copy link
Contributor

pelwell commented Jan 23, 2022

Any idea why modprobe doesn't last until the next boot?

Calls to modprobe are not persistent - modules will remain loaded until they are explicitly unloaded or the device is rebooted.

If you are asking why modprobe is necessary then it is probably because you haven't run depmod to update modules.alias. You can confirm whether the module is correctly registered with:

$ grep max30102 /lib/modules/`uname -r`/modules.alias

@jclsn
Copy link
Author

jclsn commented Jan 28, 2022

Hmm output is

alias i2c:max30105 max30102
alias i2c:max30102 max30102
alias of:N*T*Cmaxim,max30105C* max30102
alias of:N*T*Cmaxim,max30105 max30102
alias of:N*T*Cmaxim,max30102C* max30102
alias of:N*T*Cmaxim,max30102 max30102

so I guess it works. The sensor isn't appearing in the sysfs though

I realized that the first time I installed the modules on the SD card there was a notification that depmod was missing. I then installed the kmod package and ran it again without errors. Does it maybe not work if it failed the first time?

@jclsn
Copy link
Author

jclsn commented Jan 29, 2022

I also don't understand where the commits have gone. In my repository there is only the commit listed that I want to merge. I just wanted to fix the line in the readme you added, but I am a bit confused.

@jclsn
Copy link
Author

jclsn commented Jan 29, 2022

Yeah, I don't know. I've recompiled and pushed files again to SD card but it doesn't work. The module is added to module.dep

kernel/drivers/iio/health/max30102.ko: kernel/drivers/iio/buffer/kfifo_buf.ko kernel/drivers/iio/industrialio.ko kernel/drivers/base/regmap/regmap-i2c.ko

Actually this sensor isn't important to the project anymore. I just wanted to get it to work for the sake of completeness, but it is too time-consuming.

@jclsn
Copy link
Author

jclsn commented Jan 30, 2022

Well, I guess something went wrong with my installation on the Pi. Actually I already tested this successfully, so I guess it is good to merge. If there are some improvements I can make another PR.

See: raspberrypi#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@pelwell pelwell merged commit 163aa02 into raspberrypi:rpi-5.10.y Jan 31, 2022
pelwell pushed a commit that referenced this pull request Jan 31, 2022
See: #4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@pelwell
Copy link
Contributor

pelwell commented Jan 31, 2022

I had to fix a last minute cut and paste error - the README referred to the MAX17040 rather than the MAX30102), but it's merged now.

@jclsn
Copy link
Author

jclsn commented Nov 7, 2022

Alright, I will see if the new sensor makes a difference when it arrives. I think I had a similar issue on Raspbian as well though. I mentioned that before the merge, but I was having a bad conscience, because I let this PR sit here for so long. I will ask the Yocto guys as well.

@timg236
Copy link
Contributor

timg236 commented Nov 8, 2022

If you are using buildroot then it might be worth using systemd or at least devtmpfs eudev rather than init scripts

@jclsn
Copy link
Author

jclsn commented Nov 8, 2022 via email

@timg236
Copy link
Contributor

timg236 commented Nov 8, 2022

Also check that the .dtbos on the sd card are up to date and match the ones from the kernel. It’s easy to end up with stale files. Just guesses though!

@jclsn
Copy link
Author

jclsn commented Nov 13, 2022

So I just installed a fresh copy of Raspian and added

dtparam=i2c1=on
dtparam=i2c_arm=on
dtoverlay=max30102,int_pin=4

to the config.txt

I have exactly the same issues as on the Yocto image. The module is not being populated under i2c or iio...

I also tried hooking up a new sensor in case the old one here was broken. Same thing.

@pelwell
Copy link
Contributor

pelwell commented Nov 14, 2022

I have one of these on order, but it will take about 3 weeks to arrive.

@jclsn
Copy link
Author

jclsn commented Nov 14, 2022 via email

@pelwell
Copy link
Contributor

pelwell commented Nov 14, 2022

It probably depends where you are. If you were to mark the item as a gift (which it would be) and of low value (also true) then it shouldn't be held up much, but if 3 weeks doesn't sound awful then it's better to wait.

@jclsn
Copy link
Author

jclsn commented Nov 15, 2022

It's fine. I will take care of other projects meanwhile. Thank you for taking care of it.

@pelwell
Copy link
Contributor

pelwell commented Dec 6, 2022

The max30102 I ordered has arrived. Once I soldered on the headers and wired it up, and the driver loaded and probed as expected.

The only relevant line in config.txt is:

dtoverlay=i2c-sensor,max30102

I didn't specify int_pin=4 because that is the default, but it still works if you do.

I do, however, get a kernel crash when I try to read from the device - the active_scan_mask is NULL in the interrupt handler. Even with a patched driver and it never seems to get any measurements, but perhaps that's because I've only connected the SDA, SCL, INT, VIN and GND pins.

@pelwell
Copy link
Contributor

pelwell commented Dec 7, 2022

Looking at the waveforms on a scope, the INT signal looks like a near clone of the SDA signal, as if there is coupling or even a short between the pins. As long as I keep the INT pin disconnected the driver seems to work. I'm putting this down to bad hardware or wiring - everything else seems to work as intended.

@jclsn
Copy link
Author

jclsn commented Dec 7, 2022

Hmm strange that it doesn't work for me then. Maybe my Pi has a problem. I should try another one. Will see if I can make it this weekend. Schedule is full though

@jclsn
Copy link
Author

jclsn commented Dec 11, 2022

Oh I just realized that I had the wrong line in config.txt

I had

dtoverlay=max30102

and not

dtoverlay=i2c-sensor, max30102

I am pretty sure that it used to be like that though. Weird. Anyway, I can now load the sensor and read from it without issues.

Thank your for the assistance! Glad we got it working.

@jclsn
Copy link
Author

jclsn commented Dec 11, 2022

Still no idea where to find the actual data buffer. I can turn the LEDs on and off, but no idea where to find the actual ADC reading...

it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Dec 17, 2022
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Dec 17, 2022
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Dec 17, 2022
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Dec 17, 2022
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Apr 20, 2023
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Apr 20, 2023
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request May 19, 2023
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request May 19, 2023
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Jun 20, 2023
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Jun 20, 2023
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
wanghao75 pushed a commit to gitee2github/raspberrypi-kernel that referenced this pull request Jul 13, 2023
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
wanghao75 pushed a commit to gitee2github/raspberrypi-kernel that referenced this pull request Jul 13, 2023
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Nov 29, 2023
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
it-is-a-robot pushed a commit to openeuler-mirror/raspberrypi-kernel that referenced this pull request Nov 29, 2023
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
jai-raptee pushed a commit to jai-raptee/iliteck1 that referenced this pull request Apr 30, 2024
See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
jai-raptee pushed a commit to jai-raptee/iliteck1 that referenced this pull request Apr 30, 2024
Add support for the MAX30102 heart rate and blood oxygen sensor to the
i2c-sensor overlay.

See: raspberrypi/linux#4535

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for external input Waiting for a comment from the originator of the issue, or a collaborator.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants