#raspberrypipico

3 posts
Replying to @michael
michael
@michael
Public en edited
Photo of Raspberry Pi Pico connected to CozIR Ambient CO2 sensor with jumper wires
Photo of Raspberry Pi Pico connected to CozIR Ambient CO2 sensor with jumper wires

@michael

MicroPython version of CozIR Ambient demo script:

from machine import UART, Pin
import time

uart1 = UART(1, baudrate=9600, tx=Pin(4), rx=Pin(5))

uart1.write(b'K 2\r\n')
uart1.flush()
time.sleep(1)
print("COZIR CO2 sensor ready\n")

uart1.write(b'Z\r\n')
time.sleep_ms(100)
discard = uart1.read(10)

while True:
    uart1.write(b'Z\r\n')
    time.sleep_ms(10)
    resp = uart1.read(10)
    resp = resp[:8]
    fltCo2 = int(resp[2:])
    print("CO2 (ppm) = " + str(fltCo2))
    time.sleep(1)

Upload script to Pico and run:

(.venv) $ mpremote pico cp cozir.py :cozir.py + exec "import cozir.py" 
cp cozir.py :cozir.py
COZIR CO2 sensor ready

CO2 (ppm) = 802
CO2 (ppm) = 802
CO2 (ppm) = 810
CO2 (ppm) = 808
^C(.venv) $ 

#MicroPython #RaspberryPiPico #CO2 #sensor

Photo of CozIR Ambient CO2 sensor, Raspberry Pi Pico 2 W on a breadboard and a plastic box with jumper wires, all placed on a laminated pinout diagram
Photo of CozIR Ambient CO2 sensor, Raspberry Pi Pico 2 W on a breadboard and a plastic box with jumper wires, all placed on a laminated pinout diagram

Using mpremote with Raspberry Pi Pico, OpenBSD edition

The mpremote command line tool provides an integrated set of utilities to remotely interact with, manage the filesystem on, and automate a MicroPython device over a serial connection.

On my laptop, the USB serial device is found at /dev/ttyU0. Make sure that you're member of the dialer group before proceeding.

Start by installing python3 and pip3:

$ doas pkg_add python-3.14.9 py3-pip

Create virtual environment and activate it:

$ python3 -m venv .venv
$ . .venv/bin/activate

Update pip3 and install mpremote

(.venv) $ pip3 install --upgrade pip
(.venv) $ pip3 install mpremote

The device path on OpenBSD isn't among the pre-defined shortcuts. To make connections easier to establish, create a config file for mpremote similar to this:

(.venv) $ cat ~/.config/mpremote/config.py                                                                  
commands = {
    "pico": "connect /dev/ttyU0"
}

Run a demo script on the device:

(.venv) $ mpremote pico exec "import hello" 
Hello from MicroPython

#MicroPython #mpremote #RaspberryPiPico #OpenBSD

https://ifx-micropython.readthedocs.io/en/latest/reference/mpremote.html

Load older posts