import time from collections import deque import Adafruit_ADS1x15 adc = Adafruit_ADS1x15.ADS1115() GAIN = 1 LSB = 4.096 / 32768.0 # show a slow breathing-friendly trace: # - "v" is instantaneous diff voltage # - "ac" is high-passed (removes slow drift) so breathing wiggles pop alpha = 0.995 # closer to 1 = slower drift removal dc = 0.0 buf = deque(maxlen=120) # ~8-10s at your ~14Hz t0 = time.time() print("Breathing monitor D01 (A0-A1). Ctrl+C to stop.") print("Tip: sit still 5s, then breathe deep/slow.") while True: raw = adc.read_adc_difference(0, gain=GAIN) # A0-A1 v = raw * LSB # simple DC tracker + high-pass dc = alpha*dc + (1-alpha)*v ac = v - dc buf.append(ac) # auto-scale bar peak = max(1e-6, max(abs(x) for x in buf)) width = 60 pos = int((ac/peak)* (width//2)) + width//2 pos = max(0, min(width-1, pos)) line = [" "] * width line[width//2] = "|" line[pos] = "*" if time.time() - t0 > 0.10: print(f"v={v:+0.3f}V ac={ac:+0.3f}V peak={peak:0.3f}V " + "".join(line), end="\r") t0 = time.time() time.sleep(0.01)