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

Connection Error #6

Open
batulaiko opened this issue Sep 17, 2020 · 4 comments
Open

Connection Error #6

batulaiko opened this issue Sep 17, 2020 · 4 comments

Comments

@batulaiko
Copy link

Hi i wrote a simpel code to check is it work or not. when m=max30102.MAX30102(), it prints (Channel = 1 , Address 87)
and stucks in red, ir = m.read_sequential part.
I checked in i2cdetect -y 1 , it shows the address 57. But in code, it is 87. The connections are true by the way.

I have 7 pin version but I think it doesn't matter it is 5 or 7 pin.

Do you have any idea about that?

Have a nice day.

@vrano714
Copy link
Owner

Hi, batulaiko.

Initialization of the sensor is written here:

class MAX30102():
    # by default, this assumes that physical pin 7 (GPIO 4) is used as interrupt
    # by default, this assumes that the device is at 0x57 on channel 1
    def __init__(self, channel=1, address=0x57, gpio_pin=7):
        print("Channel: {0}, address: {1}".format(channel, address))
        self.address = address
        self.channel = channel

As you can see, the address to be printed is decimal format, because no formatting is set here.
Therefore, 0x57 is shown as 87. (0x57 = 5x 16 + 7 = 87)
I guess the connection is successful.


Sensor reading is as:

    def read_sequential(self, amount=100):
        """
        This function will read the red-led and ir-led `amount` times.
        This works as blocking function.
        """
        red_buf = []
        ir_buf = []
        for i in range(amount):
            while(GPIO.input(self.interrupt) == 1):
                # wait for interrupt signal, which means the data is available
                # do nothing here
                pass

            red, ir = self.read_fifo()

            red_buf.append(red)
            ir_buf.append(ir)

        return red_buf, ir_buf

This code waits until the data becomes available and availability is notified via interrupt pin.
Please ensure that 5 pins (Vin, SDA,SCL, INT, GND) of your HR sensor are correctly connected to corresponding RaspberryPi pins.
(I do not have 7pin version, so I do not know its pin assign. sorry)

@vrano714
Copy link
Owner

FYI: I updated max30102.py to show hex address (commit 8a80db7).

@batulaiko
Copy link
Author

batulaiko commented Sep 23, 2020

I can use max30100.py in another respiratory. I can get values from them. I am using 5 pin actually. There are 7 pins but I am using Vin, SDA,SCL, INT, GND pins. It shows me address is 0x57 now but still stucks in data reading.

image

This is the code which I am using. I put some prints for being sure the function which makes stucking this code.

I can use max30100.py in other respiratory but I need to figure the HR calculation function out.

Simply, for calculation, I need a list which contaions 100 data which appended 25 sample rate, am I right?

If I change sample rate, is the fuction be affected because of it?

@vrano714
Copy link
Owner

Your code looks good.

Can you see red light from the sensor?
Working sensor should emit red light (and IR light, which we cannot see).
If yes, I cannot figure out why. Sorry.

This repository contains a modified version of max30102 to free from INT pin.
I do not know whether this works, but if you are interested, please try it.
https://github.com/doug-burrell/max30102


Simply, for calculation, I need a list which contaions 100 data which appended 25 sample rate, am I right?

Yes. hrcalc.py do some peak detection on its input signal to calc heart rate.
You can use the data recorded by other (similar) sensors.

If I change sample rate, is the fuction be affected because of it?

Yes. hrcalc.py has the following constants: SAMPLE_FREQ and BUFFER_SIZE.
If you feed the data with different frequency than 25 Hz, please set appropriate values on them.

SAMPLE_FREQ is just a sampling frequency. For example set 100 if you feed 100 Hz data.
BUFFER_SIZE should be set to 4*SAMPLE_FREQ.
(I just follow the original Arduino code. I do not know why, however it seems that 4-sec data is needed, not 100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants