Merge pull request #1 from pimoroni/examples/new_products
Examples/new products
This commit is contained in:
commit
967b010709
@ -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)
|
||||||
26
micropython/examples/pico_plus_2/breakouts/scd41-breakout.py
Normal file
26
micropython/examples/pico_plus_2/breakouts/scd41-breakout.py
Normal file
@ -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)
|
||||||
13
micropython/examples/pico_plus_2/button.py
Normal file
13
micropython/examples/pico_plus_2/button.py
Normal file
@ -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)
|
||||||
14
micropython/examples/pico_plus_2/onboard_led.py
Normal file
14
micropython/examples/pico_plus_2/onboard_led.py
Normal file
@ -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)
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
import plasma
|
||||||
|
from plasma import plasma2040
|
||||||
|
from pimoroni_i2c import PimoroniI2C
|
||||||
|
from breakout_trackball import BreakoutTrackball
|
||||||
|
|
||||||
|
# SDA and SCL pins for the Tiny 2350 QW/ST connector
|
||||||
|
PINS_PLASMA_2350 = {"sda": 20, "scl": 21, "baudrate": 100000}
|
||||||
|
|
||||||
|
# Create an I2C instance and setup the trackball breakout
|
||||||
|
i2c = PimoroniI2C(**PINS_PLASMA_2350)
|
||||||
|
trackball = BreakoutTrackball(i2c)
|
||||||
|
|
||||||
|
# Set how many LEDs you have
|
||||||
|
NUM_LEDS = 100
|
||||||
|
|
||||||
|
# APA102 / DotStar™ LEDs
|
||||||
|
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)
|
||||||
|
|
||||||
|
# WS2812 / NeoPixel™ LEDs
|
||||||
|
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT, rgbw=True)
|
||||||
|
|
||||||
|
# Start updating the LED strip
|
||||||
|
led_strip.start()
|
||||||
|
|
||||||
|
# Clear any previously lit LEDs
|
||||||
|
led_strip.clear()
|
||||||
|
|
||||||
|
position = 0
|
||||||
|
sensitivity = 1
|
||||||
|
hue = 0.0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
# Read the trackball data
|
||||||
|
state = trackball.read()
|
||||||
|
|
||||||
|
# Increase/Decrease the number of LEDs lit when moving the trackball Up/Down
|
||||||
|
if state[BreakoutTrackball.UP] > sensitivity:
|
||||||
|
if position < NUM_LEDS:
|
||||||
|
position += 1
|
||||||
|
if state[BreakoutTrackball.DOWN] > sensitivity:
|
||||||
|
if position > 0:
|
||||||
|
position -= 1
|
||||||
|
|
||||||
|
# Change the hue when moving the trackball Left/Right
|
||||||
|
if state[BreakoutTrackball.LEFT] > sensitivity:
|
||||||
|
hue += 0.02
|
||||||
|
if state[BreakoutTrackball.RIGHT] > sensitivity:
|
||||||
|
hue -= 0.02
|
||||||
|
|
||||||
|
# Set the LEDs
|
||||||
|
for i in range(position):
|
||||||
|
led_strip.set_hsv(i, hue, 1.0, 1.0)
|
||||||
|
|
||||||
|
# Clear the LEDs we're not using at the moment
|
||||||
|
for i in range(position, NUM_LEDS):
|
||||||
|
led_strip.set_rgb(i, 0, 0, 0)
|
||||||
16
micropython/examples/plasma_2350/buttons.py
Normal file
16
micropython/examples/plasma_2350/buttons.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import time
|
||||||
|
import machine
|
||||||
|
|
||||||
|
# Setup for the button pins
|
||||||
|
user_button = machine.Pin(22, machine.Pin.IN)
|
||||||
|
a_button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if user_button.value() == 0:
|
||||||
|
print("USER BUTTON PRESSED!")
|
||||||
|
|
||||||
|
if a_button.value() == 0:
|
||||||
|
print("A BUTTON PRESSED!")
|
||||||
|
|
||||||
|
time.sleep(0.2)
|
||||||
27
micropython/examples/plasma_2350/rainbow.py
Normal file
27
micropython/examples/plasma_2350/rainbow.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import plasma
|
||||||
|
from plasma import plasma2040
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Set how many LEDs you have
|
||||||
|
NUM_LEDS = 50
|
||||||
|
|
||||||
|
# APA102 / DotStar™ LEDs
|
||||||
|
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)
|
||||||
|
|
||||||
|
# WS2812 / NeoPixel™ LEDs
|
||||||
|
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)
|
||||||
|
|
||||||
|
# Start updating the LED strip
|
||||||
|
led_strip.start()
|
||||||
|
|
||||||
|
offset = 0.0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
offset += float(10) / 2000.0
|
||||||
|
|
||||||
|
for i in range(NUM_LEDS):
|
||||||
|
hue = float(i) / NUM_LEDS
|
||||||
|
led_strip.set_hsv(i, offset, 1.0, 1.0)
|
||||||
|
|
||||||
|
time.sleep(1.0 / 60)
|
||||||
15
micropython/examples/plasma_2350/rgb_led.py
Normal file
15
micropython/examples/plasma_2350/rgb_led.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from pimoroni import RGBLED
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
# Setup the RGB Led
|
||||||
|
led = RGBLED(16, 17, 18)
|
||||||
|
|
||||||
|
# Cycle through RGB
|
||||||
|
|
||||||
|
while True:
|
||||||
|
led.set_rgb(255, 0, 0)
|
||||||
|
sleep(1)
|
||||||
|
led.set_rgb(0, 255, 0)
|
||||||
|
sleep(1)
|
||||||
|
led.set_rgb(0, 0, 255)
|
||||||
|
sleep(1)
|
||||||
22
micropython/examples/plasma_2350/single_colour.py
Normal file
22
micropython/examples/plasma_2350/single_colour.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import plasma
|
||||||
|
from plasma import plasma2040
|
||||||
|
|
||||||
|
# Set how many LEDs you have
|
||||||
|
NUM_LEDS = 50
|
||||||
|
|
||||||
|
# APA102 / DotStar™ LEDs
|
||||||
|
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)
|
||||||
|
|
||||||
|
# WS2812 / NeoPixel™ LEDs
|
||||||
|
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)
|
||||||
|
|
||||||
|
# Start updating the LED strip
|
||||||
|
led_strip.start()
|
||||||
|
|
||||||
|
# Set each LED in the strip
|
||||||
|
for i in range(NUM_LEDS):
|
||||||
|
led_strip.set_rgb(i, 100, 0, 100)
|
||||||
|
|
||||||
|
# We've told the LEDs which colour to display and now we just want to keep the program running!
|
||||||
|
while True:
|
||||||
|
pass
|
||||||
37
micropython/examples/tiny_2350/breakouts/bme688-breakout.py
Normal file
37
micropython/examples/tiny_2350/breakouts/bme688-breakout.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import time
|
||||||
|
from pimoroni import RGBLED
|
||||||
|
from pimoroni_i2c import PimoroniI2C
|
||||||
|
from breakout_bme68x import BreakoutBME68X
|
||||||
|
|
||||||
|
# SDA and SCL pins for the Tiny 2350 QW/ST connector
|
||||||
|
PINS_TINY_2350 = {"sda": 12, "scl": 13}
|
||||||
|
|
||||||
|
# Setup an instance of I2C and BME68X
|
||||||
|
i2c = PimoroniI2C(**PINS_TINY_2350)
|
||||||
|
bme = BreakoutBME68X(i2c)
|
||||||
|
|
||||||
|
# Setup the RGB Led
|
||||||
|
led = RGBLED(18, 19, 20)
|
||||||
|
|
||||||
|
# Values for high (red) and low (blue) temperature. Adjust these if you like :)
|
||||||
|
HIGH = 24
|
||||||
|
LOW = 18
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Grab the readings
|
||||||
|
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()
|
||||||
|
|
||||||
|
# Print the current temperature, you'll be able to see this in Thonny's shell
|
||||||
|
print(temperature)
|
||||||
|
|
||||||
|
# Set the LED based on the latest temperature reading
|
||||||
|
if temperature >= HIGH:
|
||||||
|
led.set_rgb(255, 0, 0)
|
||||||
|
elif temperature <= LOW:
|
||||||
|
led.set_rgb(0, 0, 255)
|
||||||
|
else:
|
||||||
|
led.set_rgb(0, 255, 0)
|
||||||
|
|
||||||
|
# Now we take a little nap before the next reading ZzzzZz
|
||||||
|
time.sleep(1)
|
||||||
40
micropython/examples/tiny_2350/breakouts/scd41-breakout.py
Normal file
40
micropython/examples/tiny_2350/breakouts/scd41-breakout.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import time
|
||||||
|
from pimoroni import RGBLED
|
||||||
|
from pimoroni_i2c import PimoroniI2C
|
||||||
|
import breakout_scd41
|
||||||
|
|
||||||
|
# SDA and SCL pins for the Tiny 2350 QW/ST connector
|
||||||
|
PINS_TINY_2350 = {"sda": 12, "scl": 13}
|
||||||
|
|
||||||
|
# Setup an instance of I2C and SCD41
|
||||||
|
i2c = PimoroniI2C(**PINS_TINY_2350)
|
||||||
|
breakout_scd41.init(i2c)
|
||||||
|
|
||||||
|
# Setup the RGB Led and then turn it off
|
||||||
|
led = RGBLED(18, 19, 20)
|
||||||
|
led.set_rgb(0, 0, 0)
|
||||||
|
|
||||||
|
# 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 CO2 measurement, you'll be able to see this in Thonny's shell
|
||||||
|
print(co2)
|
||||||
|
|
||||||
|
# Change the onboard LED based on the current CO2 levels
|
||||||
|
|
||||||
|
if co2 < 1000:
|
||||||
|
led.set_rgb(0, 255, 0)
|
||||||
|
elif co2 >= 1000 and co2 <= 2000:
|
||||||
|
led.set_rgb(255, 165, 0)
|
||||||
|
elif co2 > 2000:
|
||||||
|
led.set_rgb(255, 0, 0)
|
||||||
|
|
||||||
|
# Now we take a little nap before the next reading ZzzzZz
|
||||||
|
time.sleep(3)
|
||||||
11
micropython/examples/tiny_2350/buttons.py
Normal file
11
micropython/examples/tiny_2350/buttons.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import time
|
||||||
|
import machine
|
||||||
|
|
||||||
|
user_button = machine.Pin(23, machine.Pin.IN)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if user_button.value() == 0:
|
||||||
|
print("BUTTON PRESSED!")
|
||||||
|
|
||||||
|
time.sleep(0.2)
|
||||||
15
micropython/examples/tiny_2350/rgb_led.py
Normal file
15
micropython/examples/tiny_2350/rgb_led.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from pimoroni import RGBLED
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
# Setup the RGB Led
|
||||||
|
led = RGBLED(18, 19, 20)
|
||||||
|
|
||||||
|
# Cycle through RGB
|
||||||
|
|
||||||
|
while True:
|
||||||
|
led.set_rgb(255, 0, 0)
|
||||||
|
sleep(1)
|
||||||
|
led.set_rgb(0, 255, 0)
|
||||||
|
sleep(1)
|
||||||
|
led.set_rgb(0, 0, 255)
|
||||||
|
sleep(1)
|
||||||
Loading…
Reference in New Issue
Block a user