This is the new Raspberry Pi Pico W. It's just like the original Pico, but it adds built-in
WiFi.
And it's six bucks.
Six bucks!
Once it hits store shelves, I guess I'll have to say I "Used to be Rich Last Sunday"!
It's just two bucks more than the normal Pico, and only a little more than what you'd pay
for an ESP32 or ESP8266, which are this thing's closest competition.
I'm gonna use this Pico W to build a wireless sensor for my garage door.
I know Linus over on LTT did a thing where he connected his garage doors up to Google,
but I'm not that trusting.
I don't want the cloud to control my garage.
And I certainly don't want voice control over something as potentially dangerous as closing
a garage door!
I just wanna see if the thing's open.
I'm already running Home Assistant, thanks to this Raspberry Pi in my rack.
And I've already set up some sensors for carbon dioxide levels in my house, but those are
using the ESP8266.
So how easy is it for me to build a wireless garage door sensor, but with the Pico W?
I put together a proof-of-concept at my desk using this rugged $20 garage door sensor.
I can connect these two wires to the Pico W, and I should be able to detect open or
closed states in software.
This sensor is a magnetic switch, and this part is a big magnet.
You mount the switch part to the garage door track, and the magnet to the door.
If the door is open, the switch stays "open", so these two wires won't be connected.
If the door is closed, the switch closes, so these wires pass through current so the
Pi can detect the door is closed.
I could solder on some headers like these and put the Pico on a breadboard.
But in this case, I'll just use friction while I'm testing out the circuit.
I'll stick one wire through pin 3, which is a ground pin, and one through pin 1, which
is GPIO pin 0.
You can see a quick reference for all the pins on the bottom of the Pico W, or go online
for a full reference chart.
To program the Pico W, I'm gonna use Thonny.
It's a code editor built for microcontrollers.
It should already support the Pico W, or if not by the time you're watching this, it should
soon.
Raspberry Pi has a really nice getting started guide, so if you haven't used Thonny before,
go check that out.
I put this code into a script called sensor.py.
I configured the sensor on GPIO pin 0, which is physical pin 1 on the Pico.
To control the LED on the Pico W, it's actually a little different than the regular Pico.
The Pico's LED is just hanging out on GPIO pin 25.
But on the Pico W, the LED is controlled through the WiFi chip.
So on the Pico W, you use the special 'LED' pin, like this.
The main loop of this script is simple: If the sensor's high, I turn on the LED, and
if it changed from last time I checked, I print out a debug message, "Garage door is
open."
If the sensor's low, meaning the magnet is close by, I turn off the LED, and if that's
different than the last time I checked, I print out "Garage door's closed."
Later on, we can add in the wireless bits to make this work from my garage, but right
now I just wanna validate the hardware works.
So I hit the Run button, and Thonny will launch the script on the Pico W.
And right now, since the magnet's far away, the LED is on, and Thonny reports the Garage
door's open.
And if I move that magnet closer...
there!
The LED turns off, and Thonny reports that the garage door's closed.
Moving the magnet back and forth, things seem to be working.
Now, one quick note: the first time I tested this out, the sensor would work for a while--
then it wouldn't--and then it would again.
And that was because I had forgotten to add this little "PULLUP" part in the code.
That tells the Pico to activate what's called a "pull-up resistor" on the GPIO pin.
Without it, the digital input can get into a funky state where it doesn't really have
a good reference for what's on or off.
So we can connect through a resistor to the Pi's internal voltage, and that makes the
signal a lot clearer.
And it seems to be working well!
The next step is to get the garage door status available over WiFi.
But--
I'm actually going to leave that part for a future video. Why?
Because I was in the hospital!
Well, actually I am in the hospital right now, but I won't be by the time you're seeing
this.
This is something like what the code'll look like, and I promise I'll have it all up on
GitHub soon, I just didn't have the time to get it all ready this week.
[sarcastically] Thank you, Crohn's disease!
And because of that hospital visit, I also didn't get time to finish testing something
else I'm really excited about.
And that's ESPHome support for the Pico.
I posted a short blog post demoing the feature, and soon that support will be in a stable
release.
That means for a garage door sensor like this, instead of writing a bunch of MicroPython
code to connect it to Home Assistant, I could just write a short YAML file instead.
ESPHome can flash all the firmware to the Pico W and make integrating it super easy.
So I'll cover that, too, in the future, but let's get back to testing WiFi on the Pico
W. One of the easiest ways to demonstrate Pico's
new WiFi skill is to run a tiny MicroPython web server on it.
And it's surprisingly easy!
This little script serves up a tiny web page from the Pico, and I flashed it using Thonny.
I grabbed the IP address that was printed in the console, and ran it through apachebench
to see how many requests per second I could get it to serve up.
Only 4, but heck, this thing only has like a quarter meg of RAM, it's not gonna break
any records.
And since it can run MicroPython, I can also use micropip to install micro iperf3, and
do a bandwidth test—I get about 9 megabits per second near my access point, and 6 megabit
out at the far side of my house.
That's decent speed for embedded WiFi, and it's been stable so far.
But I haven't had enough time to do long-term stability tests yet.
That's one thing that bites people on ESP devices sometimes.
WiFi can just kinda drop out after long periods, and that gets really annoying.
I'll have more data on stability in my next video.
Two other things you should know if you pick up a Pico W--you can also use lightweight
IP [lwIP] if you use the Pico's C SDK.
And if you're using MicroPython, you can turn off powersaving mode with this line, if you
need the WiFi to be a little more responsive.
Powersaving is on by default, and that makes response times a bit jittery, but not terrible.
If I turn off powersaving, you can see response times are much more stable.
So yeah, you're not gonna be serving up Wordpress on a Pico W, but it's got just enough memory
to serve up some text, a status page, and things like that.
I also wanted to do some more work on power benchmarking, but that'll have to wait until
my next video too.
So the Pico W is six bucks, should be available today in quantity, and it's a great alternative
to ESP devices like the ESP8266 I used in my air quality sensors!
There are other RP2040 devices with WiFi that came before, like the Wio RP2040 by Seeed
Studios, or the Arduino Nano RP2040 Connect, with 8 times the flash storage.
But the Pico W is a great choice for most projects, unless you need specialized features
built into other boards.
Besides WiFi, the best feature of the Pico W is still the RP2040.
It has features like Programmable IO, or PIO, that makes the chip able to be kind of a lightweight
FPGA.
What does that mean?
Well, it can be programmed to interact with lotsa different interfaces.
Heck, Konrad Beckmann got a Pico to work as a programmable game cartridge in a Nintendo 64!
Check out his PicoCart64 project for more on that.
I asked Konrad what motivated him to work on that project, and he said he just wanted
to see if it was possible.
It was a great way to test out his hardware hacking skills, and the Pico was cheap, easy
to get, and well-documented.
And that's the thing.
Raspberry Pi accidentally had perfect timing with their RP2040 microprocessor.
In the midst of the chip shortages, they have the one thing many competitors are lacking:
availability.
I can drive to Micro Center here in Saint Louis and pick up a Pico today.
Some microcontrollers have been unavailable for months, and it's anybody's guess when
they'll be back in stock.
Couple that with the community, extensive public documentation, and the low price even
in single-unit quantities, and Raspberry Pi kinda hit a grand slam!
The Pico W, and the ecosystem around it, continues to make microcontroller programming more approachable,
and I'm here for it.
Until next time, I'm Jeff Geerling.
This is what the shirt says,
in case you were wondering.