Loading...
Searching...
No Matches
arduino.py examples

Example scripts for the Phyduino Pico that use the Arduino-style functions in arduino.py (from arduino import *), in examples/arduino/. Each script has the shape of an Arduino sketch: setup() runs once, then loop() runs over and over, using pinMode(), digitalWrite(), analogRead() (0-1023), analogWrite() (0-255), delay() and millis(). The main() at the end of each file starts them; leave it as it is.

The examples are in folders named after the Arduino IDE's example categories, with board-specific ones in phyduino_pico/. Each example is a main.py in its own folder, because MicroPython runs main.py each time the board starts. Each page below explains what the script does, how to wire it and what it prints, followed by its source. The same examples written with phyduino.py are on the phyduino.py examples page.

With the Phyduino Pico firmware on the board, run a script from PyCharm, or with mpremote run examples/arduino/<folder>/<name>/main.py. To have it run every time the board starts, copy its main.py to the board: mpremote cp examples/arduino/<folder>/<name>/main.py :, then press RESET.

01_basics
Example What it shows
Bare Minimum The empty setup() and loop() to start a program from
Blink Blinking the on-board LED
Analog Read Serial All six analogue pins with analogRead(), 0-1023
Digital Read Serial Printing the state of a pushbutton
Fade Fading the on-board LED with analogWrite()
Read Analog Voltage All six analogue pins in millivolts
02_digital
Example What it shows
Blink Without Delay Timing with millis() instead of delay()
Button Lighting the LED while a pushbutton is pressed
Debounce Ignoring contact bounce so each press counts once
Digital Input Pullup A pushbutton with the pin's own pull-up resistor
State Change Detection Counting presses by detecting the edge
Tone Melody Playing a tune on a piezo buzzer
Tone Pitch Follower A pitch that follows an analogue input
03_analog
Example What it shows
Analog In Out Serial Setting LED brightness from a potentiometer
Calibration Learning a sensor's range at start-up
Smoothing A running average of the last 10 readings
04_communication
Example What it shows
ASCII Table Characters with their decimal, hex, octal and binary values
Graph Sending readings to a serial plotter
I2C Scanner Finding the devices on the I2C bus
Physical Pixel Switching the LED from the computer
UART Loopback Sending and receiving on UART0
phyduino_pico
Features of this board that the Arduino examples have no match for.
Example What it shows
Analog Averaging How the averaging setting steadies a reading
Analog Differential The voltage between two pins
VBUS Monitor The USB-C supply voltage and the CPU temperature
USB-PD Power Asking a USB-PD charger for a higher voltage