From c19c7ac4ac4f795ca1168aeedc8589c19126931a Mon Sep 17 00:00:00 2001 From: thirdr Date: Fri, 9 Aug 2024 13:43:24 +0100 Subject: [PATCH] Pico Plus 2: new examples --- .../pico_plus_2/breakouts/bme68x-breakout.py | 20 ++++++++++++++ .../pico_plus_2/breakouts/scd41-breakout.py | 26 +++++++++++++++++++ micropython/examples/pico_plus_2/button.py | 13 ++++++++++ .../examples/pico_plus_2/onboard_led.py | 14 ++++++++++ 4 files changed, 73 insertions(+) create mode 100644 micropython/examples/pico_plus_2/breakouts/bme68x-breakout.py create mode 100644 micropython/examples/pico_plus_2/breakouts/scd41-breakout.py create mode 100644 micropython/examples/pico_plus_2/button.py create mode 100644 micropython/examples/pico_plus_2/onboard_led.py diff --git a/micropython/examples/pico_plus_2/breakouts/bme68x-breakout.py b/micropython/examples/pico_plus_2/breakouts/bme68x-breakout.py new file mode 100644 index 0000000..20429e9 --- /dev/null +++ b/micropython/examples/pico_plus_2/breakouts/bme68x-breakout.py @@ -0,0 +1,20 @@ +import time +from pimoroni_i2c import PimoroniI2C +from breakout_bme68x import BreakoutBME68X + +# SDA and SCL pins for the Pico Plus 2 QW/ST connector +PINS_PICO_PLUS_2 = {"sda": 4, "scl": 5} + +# Setup an instance of I2C and BME68X +i2c = PimoroniI2C(**PINS_PICO_PLUS_2) +bme = BreakoutBME68X(i2c) + +while True: + # Grab the readings + temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read() + + # Print the current temperature, pressure and humidity. You'll be able to see this in Thonny's shell + print("Temperature: {}°C\nPressure:{} Pa\nHumidity:{} %rH\n\n".format(temperature, pressure, humidity)) + + # Now we take a little nap before the next reading ZzzzZz + time.sleep(1) diff --git a/micropython/examples/pico_plus_2/breakouts/scd41-breakout.py b/micropython/examples/pico_plus_2/breakouts/scd41-breakout.py new file mode 100644 index 0000000..27c2ae7 --- /dev/null +++ b/micropython/examples/pico_plus_2/breakouts/scd41-breakout.py @@ -0,0 +1,26 @@ +import time +from pimoroni_i2c import PimoroniI2C +import breakout_scd41 + +# SDA and SCL pins for the Pico Plus 2 QW/ST connector +PINS_PICO_PLUS_2 = {"sda": 4, "scl": 5} + +# Setup an instance of I2C and BME68X +i2c = PimoroniI2C(**PINS_PICO_PLUS_2) +breakout_scd41.init(i2c) + +# Start the SCD41 sensor +breakout_scd41.start() + + +while True: + + # Grab the readings if the sensor is ready. + if breakout_scd41.ready(): + co2, temperature, humidity = breakout_scd41.measure() + + # Print the latest measurements, you'll be able to see this in Thonny's shell. + print("CO2: {} PPM\nTemperature: {}°C\nHumidity: {} %RH\n\n".format(co2, temperature, humidity)) + + # Now we take a little nap before the next reading ZzzzZz + time.sleep(3) diff --git a/micropython/examples/pico_plus_2/button.py b/micropython/examples/pico_plus_2/button.py new file mode 100644 index 0000000..44ceb8f --- /dev/null +++ b/micropython/examples/pico_plus_2/button.py @@ -0,0 +1,13 @@ +from machine import Pin + +# Setup the LED and Button pin. +led = Pin(25, Pin.OUT) +button = Pin(45, Pin.IN) + +# Light the LED when the button is presed! +while True: + + if button.value() == 0: + led.value(1) + else: + led.value(0) diff --git a/micropython/examples/pico_plus_2/onboard_led.py b/micropython/examples/pico_plus_2/onboard_led.py new file mode 100644 index 0000000..a47b952 --- /dev/null +++ b/micropython/examples/pico_plus_2/onboard_led.py @@ -0,0 +1,14 @@ +import time +from machine import Pin + +# Setup the LED pin. +led = Pin(25, Pin.OUT) + +# Blink the LED! +while True: + + led.value(1) + time.sleep(1) + + led.value(0) + time.sleep(1)