Raspberry Pi 4 & Raspberry Pi Pico
Picked up a couple of Raspberry Pi's this weekend to play around with. One is about the most minimal Pi there is, the Raspberry Pi Pico WH (with only 256k ram, but with WiFi/Bluetooth), and the other about the most maxed out Pi, the Raspberry Pi 4 Model B, with 8gb ram, 128GB MicroSD, and also with WiFi/Bluetooth.
The Pi 4 was pretty easy to setup. I initially set it up with the full GUI enabled, and plugged into a monitor\keyboard\mouse, but this was just for the setup phase. I installed OpenSSH on it so that I could connect to it via the terminal, and I enabled VNC Server on it. Once those two pieces were enabled, I made it headless (and turned off the desktop on startup) so that it's no longer tied down to a monitor. I also installed ZeroTier VPN on it and added it to my Home VPN.
Here's how I got the very first bit of code running on the Pi Pico..
Held down the button on the pi pico as I plugged in the usb cable, once the cable was plugged in, I let go of the button, this puts the pico into usb drive mode
Downloaded the MicroPython firmware and dragged/dropped it onto the pi pico usb drive. This automatically installs the firmware, disconnects the usb drive, and reboots the pico
After reboot, the pi pico is now available thru a virtual serial port that can be found with
ls -l /dev/ttyACM*
, (/dev/attyACM0 on mine)
# installed software to talk to pi thru virtual serial port, and connected..
sudo apt install minicom
# joined group that allows access to virtual port
sudo usermod -a -G dialout <my id> # add myself to dialout group
# ..and connected to python repl/console
sudo minicom -o -D /dev/ttyACM0 # after joining 'dialout'/rebooting, don't need 'sudo'
# copy/pasted this python code onto the console
from machine import Pin
led = Pin("LED", Pin.OUT)
led.value(1) # led on
#led.value(0) # led off
#led.toggle() # on/off..
..and led on the pico pi lit up!
..finally a slightly more complex example with 3 led's wired up and flashing a pattern determined by this very simple MicroPython code:
from machine import Pin
import time
# GP15 -> 220Ω -> yellow led -> GRND
# GP16 -> 220Ω -> red led -> GRND
# GP13 -> 220Ω -> blue led -> GRND
Green_LED = Pin(15, Pin.OUT)
Red_LED = Pin(16, Pin.OUT)
Blue_LED = Pin(13, Pin.OUT)
def process_yellow():
Green_LED.value(1)
time.sleep(1)
Green_LED.value(0)
time.sleep(1)
Green_LED.value(1)
time.sleep(1)
Green_LED.value(0)
def process_red():
Red_LED.value(1)
time.sleep(1)
Red_LED.value(0)
def process_blue():
Blue_LED.value(1)
time.sleep(.25)
Blue_LED.value(0)
time.sleep(.25)
Blue_LED.value(1)
time.sleep(.25)
Blue_LED.value(0)
while True:
process_yellow()
process_red()
process_blue()