For whatever reason, Raspberry Pis are still sold out everywhere, bar the Pi Pico. The issue with the Pi Pico is simple: it requires you to use your brain. Unlike the normal Pi, where you have a lot of I/O, you get one USB port, some holes to add wires to, and, if you buy the W variant, a chip for wireless.
My wireless dilemma#
I've had a Canon scanner for a long time now and recently threw it in the garage since it is:
- an eyesore,
- so friggin huge;
- easier for everyone to use in a common space.
The scanner is wireless with an Ethernet jack for wired connections. There aren't Ethernet cables running into the garage. As for our Wi-Fi, you'll be able to authenticate, but you won't be able to transfer any data. I'm not sure exactly why, but I'll just cite that the building is fairly old and, by that logic, isn't designed for radio waves.
I needed to either: (a) extend the current network so that it's minimal effort to use the scanner, or (b) use a small device to run a mini LAN to do scans with, adding a tiny bit of complexion.
Writing for the Pico#
There are a few conventional ways to add information to the Pico: MicroPython being used in a lot of examples, and what I decided to use. Their
network package has a useful "AP_IF" interface, or Access Point, that has a surprising amount of settings for an IoT device. It's relatively simple to set up, needing only four lines (L7 through L13 can be on one line).
After writing the code, I waited for my Picos to come in the mail. After, it sat on my desk for several weeks because I had something called life to do. Once Pico playtime had arrived, I realised that it isn't the most intuitive thing on Earth.
Flashing the Pico#
The first steps weren't too bad: install
micropython via Brew (or your package manager of choice). Connect the Pico while holding the
BOOTSEL button and add the firmware (renamed as
blink.uf2) to the device. On macOS, drag-and-drop hasn't worked for a while, so you have to use
cp. It's still a problem on Monterey as well, and yes, I'm aware I should update my Mac.
After flashing, it should restart on its own. You can run
ls /dev/tty to find the serial device (it'll look like
/dev/tty.usbmodem on macOS or
/dev/ttyACM on Linux) and run rshell to connect. It's nice to know the serial device in case you're using something else like minicom, the tool recommended in the Pico's docs and what I wasted too much time trying to use because you can't close and re-open it easily. I wouldn't recommend it.
In rshell, it's as simple as navigating to where your Python script is and using
cp to copy it to the board (
cp sensor.py /pyboard/main.py). The main reason why you rename it
main.py is so that it will run the script with the Pico when it boots. You could name it something else and use something like UART to get the script running without removing the power from the board, but it's easier to just keep the script locally. A quick note: don't copy to
boot.py, because that will break everything! You'll have to reflash your board for everything to work again. You can either hotplug the board so it runs itself or, since you may not know if the code works right away, use
repl, followed by
Ctrl-D to restart the board. If that works fine, you can use
Ctrl+X to leave
Ctrl+C to close out rshell like normal. There's also this script you could write, but it's not really necessary.
Woes that I have no solution for#
I could never really find out why I couldn't set a specific security setting, channel, or hide the (E)SSID. It simply wouldn't run on the Pico without me commenting those lines. Nothing was documented about it in the wiki for not working, no GitHub issues nor discussions, zero clue. Even looking at the source code, it's hard to know exactly what I should be putting for some attributes, like the Wi-Fi security. I cut my losses with the security since I was using WPA2 regardless and it seems to be the default.
It's not needed for this, but it would be cool to get it hooked up to the public Internet as well so that you could try using the Pico as a very low-budget AP. As far as I'm aware, you can't use AP mode and the normal Wi-Fi connection at the same time, which means no wireless extension. It would be nice to see that change in the future, but it's likely a limitation of the board itself.
It was fun experimenting with the Pico and making this tiny little AP. You can view the code that I used on GitHub if you need your own dedicated scanner network (for some reason). I'm not sure what I'll do with the other Pico yet, along with my non-W Picos, but I'd like to hear ideas.