MAX30102 on Raspberry Pi Setup - jaredwhichard/Capstone-Website GitHub Wiki
In order to utilize the MAX30102 sensor, we need to properly configure the Raspberry Pi. For our testing we used a Raspberry Pi 4, but theoretically, the process should work with any Pi with GPIO pins.
- Raspberry Pi 4
- MAX30102 Breakout board
Table of Contents |
---|
Raspberry Pi Setup |
Physical Connection |
The Code |
1. Boot the device with the Raspberry Pi OS (former Raspbian).
2. Once running, open a terminal and update the device.
Pi must have an internet connection
- Download package information:
sudo apt update
- Install all available package upgrades:
sudo apt upgrade -y
3. Enable I2C on the Raspberry Pi
I2C is a protocol that will allow the Pi to be connected to peripherals through addressable pins, for our use, this is how the MAX30102 will communicate with the Pi.
💡 I2C peripherals are assigned 7-bit addresses
- Open the Raspberry Pi Software Configuration Tool:
sudo raspi-config
- Navigate to #3, Interface options and press
enter
- Navigate to #P5, I2C and press
enter
then select Yes when asked if you want the I2C interface to be enabled - Close the Raspberry Pi Software Configuration Tool by selecting
Finish
- Check to ensure that the I2C bus has been enabled: ` cat /boot/config.txt | grep "i2c"
- You may need to be sudo and you should see
dtparam=i2c_arm=on
- You may need to be sudo and you should see
The Raspberry Pi should now be prepared to communicate with the MAX30102, the next step is establishing a physical connection.
Now that the Raspberry Pi is ready to communicate with the MAX30102 breakout board using I2C as a communication protocol, we need to connect the board and the Pi.
The following connections are used for the first code we will utilize.
Our MAX30102 sensor has a slightly different layout then the one in the diagram below, however the connections will be the same.
- On the Raspberry Pi, you can run a command in the terminal to print the GPIO pin usage on the Pi:
pinout
Raspberry Pi | MAX30102 |
---|---|
3.3V (pin1) | VIN |
I2C_SDA1 (pin3; GPIO 2) | SDA |
I2C_SCL1 (pin5; GPIO 3) | SCL |
GND (pin9) | GND |
During this sprint we want to get the sensor operational with the Raspberry Pi, for the code we are utilize some of the great open source community work with the MAX30102, in particular, that of Doug Burrell.
- For the program to work we will need to download the numpy library for python:
sudo apt-get install build-essential python-dev python-pip python-smbus python-numpy git
- I also installed another library that is used for better gpio interfacing, although I'm not positive that was required:
sudo pip install RPi.GPIO
- Then we will use the repository from Doug Burrell:
sudo git clone https://github.com/doug-burrell/max30102
- Now navigate to the new repository
cd /max30102/
- Check the contents of the directory, there should be multiple files but main.py with operate the sensor:
ls
- And run the main.py file with python:
python main.py
Above is an example of the code running with the sensor. We can note a number of unusual results that ultimately make the data unreliable. However it provides us with good insights when moving forward. There are a number of issues that could be causing the sparatic results, one being sensor pressure and light interference. With a finger clip to attach the MAX30102 sensor to a finger securely we can keep solid pressure and block light from impacting the inferred sensor. We can also see how the current readout will not be suitable for our end product, but it will provide functions that will help us continue.