From 323d38d8eaa36ef4ce1f134e704f7d9665209455 Mon Sep 17 00:00:00 2001 From: sakluk Date: Thu, 14 May 2026 22:48:45 +0300 Subject: [PATCH 1/5] bug fixes: - lines 581-584: shifted wrong direction - line 685: wrong intendation - lines 214, 403, 410: confusing function name modified: max30102/__init__.py --- max30102/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/max30102/__init__.py b/max30102/__init__.py index 79fe6fb..c4ace2d 100644 --- a/max30102/__init__.py +++ b/max30102/__init__.py @@ -211,7 +211,7 @@ def setup_sensor(self, led_mode=2, adc_range=16384, sample_rate=400, # Set the LED brightness to the default value of 'low' self.set_pulse_amplitude_red(led_power) - self.set_pulse_amplitude_it(led_power) + self.set_pulse_amplitude_ir(led_power) self.set_pulse_amplitude_green(led_power) self.set_pulse_amplitude_proximity(led_power) @@ -400,14 +400,14 @@ def set_active_leds_amplitude(self, amplitude): if self._active_leds > 0: self.set_pulse_amplitude_red(amplitude) if self._active_leds > 1: - self.set_pulse_amplitude_it(amplitude) + self.set_pulse_amplitude_ir(amplitude) if self._active_leds > 2: self.set_pulse_amplitude_green(amplitude) def set_pulse_amplitude_red(self, amplitude): self.i2c_set_register(MAX30105_LED1_PULSE_AMP, amplitude) - def set_pulse_amplitude_it(self, amplitude): + def set_pulse_amplitude_ir(self, amplitude): self.i2c_set_register(MAX30105_LED2_PULSE_AMP, amplitude) def set_pulse_amplitude_green(self, amplitude): @@ -580,7 +580,8 @@ def bitmask(self, reg, slotMask, thing): def fifo_bytes_to_int(self, fifo_bytes): value = unpack(">i", b'\x00' + fifo_bytes) - return (value[0] & 0x3FFFF) >> self._pulse_width + # return (value[0] & 0x3FFFF) >> self._pulse_width # original (bug: shifts wrong direction) + return (value[0] & 0x3FFFF) >> (3 - self._pulse_width) # Returns how many samples are available def available(self): @@ -681,7 +682,7 @@ def check(self): self.fifo_bytes_to_int(fifo_bytes[6:9]) ) - return True + return True else: return False From 5c0c6b82d57065491c568f973c87c4b97d24b182 Mon Sep 17 00:00:00 2001 From: sakluk Date: Thu, 14 May 2026 23:00:24 +0300 Subject: [PATCH 2/5] modified example to use set_pulse_amplitude_ir() modified: README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45b4b8e..fc01956 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ LED_POWER = MAX30105_PULSEAMP_MEDIUM # MAX30105_PULSE_AMP_MEDIUM = 0x7F # 25.4mA - Presence detection of ~8 inch # MAX30105_PULSE_AMP_HIGH = 0xFF # 50.0mA - Presence detection of ~12 inch sensor.set_pulse_amplitude_red(LED_POWER) -sensor.set_pulse_amplitude_it(LED_POWER) +sensor.set_pulse_amplitude_ir(LED_POWER) sensor.set_pulse_amplitude_green(LED_POWER) # Set the LED brightness of all the active LEDs From 0c01c7e43fcc3e8e9d9db3519925d9c8085ec161 Mon Sep 17 00:00:00 2001 From: Nicola <62206011+n-elia@users.noreply.github.com> Date: Mon, 18 May 2026 21:53:33 +0200 Subject: [PATCH 3/5] Remove the bugfix comment --- max30102/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/max30102/__init__.py b/max30102/__init__.py index c4ace2d..9ed4835 100644 --- a/max30102/__init__.py +++ b/max30102/__init__.py @@ -580,7 +580,6 @@ def bitmask(self, reg, slotMask, thing): def fifo_bytes_to_int(self, fifo_bytes): value = unpack(">i", b'\x00' + fifo_bytes) - # return (value[0] & 0x3FFFF) >> self._pulse_width # original (bug: shifts wrong direction) return (value[0] & 0x3FFFF) >> (3 - self._pulse_width) # Returns how many samples are available From 50fe603651a5d3e5289c1650a1595e63d14cfe3f Mon Sep 17 00:00:00 2001 From: Nicola <62206011+n-elia@users.noreply.github.com> Date: Mon, 18 May 2026 21:54:59 +0200 Subject: [PATCH 4/5] Drain all queued samples from the queue instead of checking availability --- examples/basic_usage/main.py | 6 +++--- examples/heart_rate/main.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/basic_usage/main.py b/examples/basic_usage/main.py index 7e4452b..2d5cd82 100644 --- a/examples/basic_usage/main.py +++ b/examples/basic_usage/main.py @@ -93,11 +93,11 @@ def main(): while True: # The check() method has to be continuously polled, to check if # there are new readings into the sensor's FIFO queue. When new - # readings are available, this function will put them into the storage. + # readings are available, this function will put them into the storage queue. sensor.check() - # Check if the storage contains available samples - if sensor.available(): + # Drain all queued samples from the queue + while sensor.available(): # Access the storage FIFO and gather the readings (integers) red_reading = sensor.pop_red_from_storage() ir_reading = sensor.pop_ir_from_storage() diff --git a/examples/heart_rate/main.py b/examples/heart_rate/main.py index ff8cbe1..a47f50c 100644 --- a/examples/heart_rate/main.py +++ b/examples/heart_rate/main.py @@ -159,11 +159,11 @@ def main(): while True: # The check() method has to be continuously polled, to check if # there are new readings into the sensor's FIFO queue. When new - # readings are available, this function will put them into the storage. + # readings are available, this function will put them into the storage queue. sensor.check() - # Check if the storage contains available samples - if sensor.available(): + # Drain all queued samples from the queue + while sensor.available(): # Access the storage FIFO and gather the readings (integers) red_reading = sensor.pop_red_from_storage() ir_reading = sensor.pop_ir_from_storage() From a38a0f885200f27ad0ce823af857890634f64219 Mon Sep 17 00:00:00 2001 From: Nicola <62206011+n-elia@users.noreply.github.com> Date: Mon, 18 May 2026 21:58:36 +0200 Subject: [PATCH 5/5] Prepare for v0.5.0 release --- README.md | 11 +++++++++++ package.json | 2 +- setup.py | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc01956..0630abf 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,17 @@ resolution of 0.0625°C, but be aware that the accuracy is ±1°C. ## Changelog +- v0.5.0 + - **Breaking:** `set_pulse_amplitude_it()` renamed to `set_pulse_amplitude_ir()` to match the + actual LED (IR, not "IT"). Callers using the old name must update to the new one. + - **Breaking:** Fixed the bit-shift direction in `fifo_bytes_to_int()` (now `>> (3 - pulse_width)` + instead of `>> pulse_width`). Raw sample magnitudes will change whenever `pulse_width` is not 0; + downstream calibration (SpO2, HR thresholds) may need to be re-tuned. + - Fixed `check()` so it drains the entire sensor FIFO per call instead of returning after the + first sample. Callers polling `check()` in a tight loop should now iterate `pop_*_from_storage()` + with `while sensor.available()` instead of `if sensor.available()` to avoid leaving samples + queued between polls. The bundled examples have been updated accordingly. + - Thanks to @sakluk for the fixes (PR #26). - v0.4.2 - Added an heartrate estimation example. - Issued a new release to update the PyPi docs. diff --git a/package.json b/package.json index 2198371..f66de41 100644 --- a/package.json +++ b/package.json @@ -5,5 +5,5 @@ ], "deps": [ ], - "version": "0.4.2" + "version": "0.5.0" } \ No newline at end of file diff --git a/setup.py b/setup.py index 31a80ec..d795911 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="micropython-max30102", - version="0.4.2", + version="0.5.0", description="MAX30102 driver for micropython.", long_description=open("README.md").read(), long_description_content_type='text/markdown',