# This example takes the temperature from the Pico's onboard temperature sensor, and displays it on Pico Explorer, along with a little pixelly graph. # It's based on the thermometer example in the "Getting Started with MicroPython on the Raspberry Pi Pico" book, which is a great read if you're a beginner! import machine import utime # Pico Explorer boilerplate import picoexplorer as display width = display.get_width() height = display.get_height() display_buffer = bytearray(width * height * 2) display.init(display_buffer) # reads from Pico's temp sensor and converts it into a more manageable number sensor_temp = machine.ADC(4) conversion_factor = 3.3 / (65535) i = 0 while True: # the following two lines do some maths to convert the number from the temp sensor into celsius reading = sensor_temp.read_u16() * conversion_factor temperature = round(27 - (reading - 0.706) / 0.001721) # this if statement clears the display once the graph reaches the right hand side of the display if i >= (width + 1): i = 0 display.set_pen(0, 0, 0) display.clear() # chooses a pen colour based on the temperature
import time import picoexplorer as explorer width = explorer.get_width() height = explorer.get_height() display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565) explorer.init(display_buffer) explorer.set_audio_pin(0) i = 1 while True: explorer.set_pen(120, 40, 60) explorer.clear() adc0 = int(explorer.get_adc(0) * 120) adc1 = int(explorer.get_adc(1) * 120) adc2 = int(explorer.get_adc(2) * 120) explorer.set_pen(255, 255, 255) explorer.text("ADC0:", 20, 20, 100) explorer.text("ADC1:", 20, 40, 100) explorer.text("ADC2:", 20, 60, 100) explorer.set_pen(adc0 * 2, 0, 0) explorer.circle(90 + adc0, 26, 10) explorer.set_pen(0, adc1 * 2, 0)
## This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful! import utime import picoexplorer as display # Set up and initialise Pico Explorer buf = bytearray(display.get_width() * display.get_height() * 2) display.init(buf) # From CPython Lib/colorsys.py def hsv_to_rgb(h, s, v): if s == 0.0: return v, v, v i = int(h * 6.0) f = (h * 6.0) - i p = v * (1.0 - s) q = v * (1.0 - s * f) t = v * (1.0 - s * (1.0 - f)) i = i % 6 if i == 0: return v, t, p if i == 1: return q, v, p if i == 2: return p, v, t if i == 3: return p, q, v if i == 4: return t, p, v if i == 5:
# Simple oscilloscope for a Raspberry Pi Pico # Press the buttons to toggle the traces # Designed for use with an pcio explorer board import picoexplorer as display import machine import utime # set up screen buffer and ADC WIDTH = display.get_width() HEIGHT = display.get_height() display_buffer = bytearray(WIDTH * HEIGHT * 2) display.init(display_buffer) # Clear screen and draw title display.set_pen(0, 0, 0) display.clear() display.set_pen(255, 0, 0) display.text("PicoScope", 0, 0, 0, 2) # Get 4 channels of Analogue to Digital converters adc = [] for i in range(4): adc.append(machine.ADC(i)) # Colours to display each ADC chanenl colors = [ (255, 0, 0), # Red, channel 0 (0, 255, 0), # Green, channel 1 (0, 0, 255), # Blue, channel 2 (0, 255, 255) ] # Cyan channel 3
# This example shows you how you can use Pico Explorer's onboard buzzer as a speaker to play different notes and string them together into a bleepy tune. # It uses code written by Avram Piltch - check out his Tom's Hardware article! https://www.tomshardware.com/uk/how-to/buzzer-music-raspberry-pi-pico # You'll need to connect a jumper wire between GPO and AUDIO on the Explorer Base to hear noise. import utime import picoexplorer as explorer # Set up and initialise Pico Explorer buf = bytearray(explorer.get_width() * explorer.get_height() * 2) explorer.init(buf) # tells Pico Explorer which pin you'll be using for noise explorer.set_audio_pin(0) # this handy list converts notes into frequencies, which you can use with the explorer.set_tone function tones = { "B0": 31, "C1": 33, "CS1": 35, "D1": 37, "DS1": 39, "E1": 41, "F1": 44, "FS1": 46, "G1": 49, "GS1": 52, "A1": 55, "AS1": 58, "B1": 62, "C2": 65, "CS2": 69,
import time, random import picoexplorer as explorer # set up screem WIDTH = explorer.get_width() HEIGHT = explorer.get_height() display_buffer = bytearray(WIDTH * HEIGHT * 2) # 2-bytes per pixel (RGB565) explorer.init(display_buffer) # main loop (forever) while True: # clear screen and display controle explorer.set_pen(0, 0, 0) explorer.rectangle(0, 0, WIDTH, HEIGHT) explorer.set_pen(0, 0, 255) explorer.text("A/B Motor 1", 0, 0, WIDTH, 4) explorer.text("X/Y Motor 2", 0, 50, WIDTH, 4) # Press A/B to control motor 1 if explorer.is_pressed(explorer.BUTTON_A): explorer.set_motor(0, 0, 1) explorer.text("Motor 1 Forwards", 0, 100, WIDTH, 2) elif explorer.is_pressed(explorer.BUTTON_B): explorer.set_motor(0, 1, 1) explorer.text("Motor 1 Backwards", 0, 100, WIDTH, 2) else: explorer.set_motor(0, 0, 0) # Press X/Y to control motor 2 if explorer.is_pressed(explorer.BUTTON_X): explorer.set_motor(1, 0, 1)
import time, random import picoexplorer as exp from machine import Pin width = exp.get_width() height = exp.get_height() display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565) exp.init(display_buffer) #exp.set_backlight(1.0) exp.set_audio_pin(0) green = exp.create_pen(0, 155, 0) red = exp.create_pen(155, 0, 0) blue = exp.create_pen(0, 0, 155) yellow = exp.create_pen(155, 155, 0) lit_green = exp.create_pen(0, 255, 0) lit_red = exp.create_pen(255, 0, 0) lit_blue = exp.create_pen(0, 0, 255) lit_yellow = exp.create_pen(255, 255, 0) white = exp.create_pen(200, 200, 200) black = 0 buttons = ["A", "B", "Y", "X"] half_width = width // 2 half_height = height // 2 leda = Pin(4, Pin.OUT) ledy = Pin(3, Pin.OUT) ledx = Pin(2, Pin.OUT) ledb = Pin(5, Pin.OUT)
def __init__(self): AbstractPlotter.__init__(self) width = display.get_width() height = display.get_height() self._display_buffer = bytearray(width * height * 2) display.init(self._display_buffer)