A Matter Wi-Fi Light Bulb in Rust on the Raspberry Pi Pico 2 W
Posted by melastmohican 2 days ago
Comments
Comment by rdsubhas 2 days ago
But ultra low is not necessarily the same as battery powered, which itself doesn't necessarily mean coin-cell battery powered.
My experience with wifi modules I've built so far has been, they've all been "low" but not usually battery powerable.
I wish the README provides more info whether it's suitable for battery-powered operation, and if so how which.
Comment by surajrmal 2 days ago
Comment by happyopossum 1 day ago
Well, except for all the coin cell operated matter over WiFi smart buttons / remotes / switches you can buy from just about anywhere…
Comment by surajrmal 1 day ago
Comment by solid_fuel 1 day ago
Comment by everforward 1 day ago
I’m not sure I’d want a full second of latency on button presses. I would have figured Amazon used BTLE to the Alexa and used it as a BT to WiFi gateway
Comment by solid_fuel 21 hours ago
Comment by melastmohican 23 hours ago
Comment by teaearlgraycold 2 days ago
Comment by zxexz 2 days ago
Comment by ssl-3 2 days ago
Like: I suck at code. But I've known how to walk around in *nix systems and use things like bash to chain together commands like awk, grep, and sed for ~30 years. Maybe I'd even toss in some badly-cooked perl or python (or both!), when that seemed necessary.
For a very long time, I've been able to get some things done, but my skillset was focused on doing these things with real computers with live filesystems and real user interfaces, not MCUs.
So, some years ago: When I wanted to turn a window fan on and off based on some network-retrieved weather conditions, I didn't even consider an MCU. I didn't want to learn a new way of doing things; I just wanted a computer to get some data and decide whether to turn the fan on and off. And I wanted that done sooner instead of later.
I accomplished this with a Raspberry Pi Zero W -- with the whole OS. I didn't cross-compile anything. I didn't have to target some weird-looking external environment, or learn a new way of doing things.
Setting up the dev environment was very familiar: Dump a binary onto an SD card, boot it, get it onto the network, and use it.
I just SSH'd into that tiny little computer like I would any other Linux box and wrote my stupid little cobbled-up scripts right there, in-situ, on the final device that would be performing the work -- with a familiar interactive shell.
The end result worked very well. I'm not ashamed of any of this at all.
---
Later, I switched from networked weather reports to an RTL-SDR dongle and software decoding to listen for over-the-air broadcast reports from someone else's nearby APRS weather station, and used that as a source of weather data instead.
Can we even get that done in MCU land? (Should we even try to do so for just one window fan?)
Comment by teaearlgraycold 2 days ago
I get the familiar angle of using a Pi Zero. But don’t be intimidated by the Pico. Especially these days with the help of an LLM, you’re not slowed down too much. The version of Python they run feels very familiar. The tooling is good. They’re awesome!
Comment by ssl-3 2 days ago
And because I still suck at code: If I want to create something myself, then I still get to do that with a Linux box using unix methods.
That all said: I do enjoy working with RP2040 PIO assembler sometimes. The combination of its severe limitations and robustly resolute timing makes it both approachable, and fun. :)
Anyway, I think all methods are OK. There's no reason to judge them. (I think it's also OK to just use a computer to read Facebook, or as a porn machine, or to become an Amish leatherworker and leave all of this digital nonsense behind.)
Comment by teaearlgraycold 1 day ago
Party I am petitioning for passersby who might be wincing at the new prices for Pi 5s etc. for starter electronics/programming projects when they could save a ton of money with a Pico. I have to assume that a huge chunk of Pi 5 purchases from consumers end up with the computer either stuck in a drawer, having been used for a couple days, or running a workload they are completely overpowered for. Every time I see the new prices I wonder how much lower they would be if the consumers were better informed and demand was more appropriately redirected.
To give a specific example of a misused Pi, I've seen an RFID access system made by a hobbyist (low stakes, no need for professional/commercial solutions) running on a Pi 3. When the system glitches (another matter entirely - messy code) and needs to be rebooted you need to wait a minute or two for Linux to start up. I'm planning to replace this system with a Pico 2W. All it needs to do is handle a couple of buttons, a small LCD screen, and an RFID reader. We can handle all of that and a WiFi-accessible web admin interface using a microcontroller. Not only is it wasteful (for whatever that's worth) to have a quad core CPU, 1GB of RAM, and a whole Linux OS to perform such a trivial task. It's also leading to issues with complexity and performance.
Comment by ssl-3 1 day ago
Perhaps they'd cost even more if the ones sitting in drawers were never purchased at all.
And, I mean... I'm not here optimize anyone else's money. It's theirs, and they can spend it however they want.
As a specific example: Back before the literal-shortages several years ago, I'd see people buying 8GB Pi4s to run OpenWRT or Klipper. "I want the very best," they'd proclaim. "I don't want any bottlenecks."
I'd try to steer them to what I felt was a more-efficient path. "Yeah, but OpenWRT uses less than a hundred megs of RAM. And Klipper is pretty light, too -- that's kind of the whole point of this kind of software. The smallest [2GB] version is already complete and utter overkill for these purposes now, and will remain so in any future it is likely to ever see."
And what I found, over and over again, was that these folks didn't reason themselves into this position to begin with, and that they thus couldn't be reasoned out of it.
So I stopped trying to change their ways, and started accepting it instead. I'm happier this way.
Comment by teaearlgraycold 1 day ago
Comment by tzs 2 days ago
Consider common consumer wireless indoor/outdoor thermometers which have a temperature sensor you place outside and a display you place inside. Most of these use a much simpler radio protocol than WiFi or Bluetooth, and have nowhere near the compute power or memory resources to come anywhere near running Linux.
On the transmit side they typically have a fixed frequency oscillator (commonly near 433 MHz or a little over 900 MHz) connected to an antenna through a transistor. They send data by turning that transistor on and off. There are a variety of ways they might do this. Some might do it as pulses with different widths for 1 and 0. Some might do it by having have say 200 us on followed by 200 us off mean 1 and 200 us off followed by 200 us on mean 0. There are many more.
For home built stuff you can by cheap transmit modules to help with this, such as this one [1]. I'm linking to Sparkfun because they have good documentation, but you can find these all over the place.
On the receive side they use a simple receiver tuned to the same frequency (but with enough tolerance that it isn't a problem that both sides are probably using cheap oscillators that aren't very stable or accurate). Here a receiver module for home built stuff [2].
From what I've read the ways these work is that they automatically adjust the gain to have a constant high output level, but there is some lag in that. If there is nobody transmitting the output is just amplified background noise.
Then when someone starts transmitting the gain gets turned down so it is just enough for their signal to have max output. Let's say they are sending 1s as a pulse of 200 us on, 100 us off and 0s as 100 us on, 200 us off. With the gain set so the on level is at maximum output the off level will be quite a bit below that. As long as the gain adjustment is slow enough that it doesn't turn up the gain too much during that up to 200 us off, the next on will still be readily distinguished.
In that example the transmitter is sending 1 bit every 300 us. The firmware in the receiver can look for high/low and low/high transitions in the radio output, looking for the pattern of several consecutive 300 us intervals with 100 us on/200 us off or 200 us on/100 us off. Interpret that is a bit string, and make sure when you design your protocol your transmissions start with some kind of signature so you can tell you are actually listening to the right sender, and it should work. If you designed the radio protocol reasonably you should be able to do the recognition with some kind of efficient state machine.
[1] https://www.sparkfun.com/rf-link-transmitter-434mhz.html
[2] https://www.sparkfun.com/rf-link-receiver-4800bps-434mhz.htm...
Comment by teaearlgraycold 2 days ago
Comment by fundatus 2 days ago
Comment by stavros 2 days ago
Comment by psyonity 2 days ago
Comment by comfydragon 2 days ago
Comment by stavros 2 days ago
Comment by BluSyn 2 days ago
Few years ago I made a custom RGB LED rope light controller using ESP32 C3 DevKit and Rust embedded, connecting light to homeassistant via MQTT auto discovery. Was surprisingly easy to get started as someone who had limited experience with embedded programming, and only hobby Rust experience.
But the supported hardware in Rust crates was limited at the time and C3 dev kits weren’t widely available, so I never used it for anything. HAL support has only gotten better since then.
I may try to resurrect that project now with Pico 2 and Matter.
Comment by melastmohican 23 hours ago
Comment by bleepblap 2 days ago
Comment by RA2lover 2 days ago
Comment by melastmohican 23 hours ago
Comment by bleepblap 1 day ago
Comment by LoganDark 2 days ago
75.4% Linker Script
18.2% Rust
6.4% Shell
About sums up embedded development in Rust.
Comment by bschwindHN 2 days ago
rust-rpico2-embassy-examples $ tokei .
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Language Files Lines Code Comments Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Alex 2 330 280 0 50
Shell 1 25 13 3 9
TOML 2 76 58 7 11
─────────────────────────────────────────────────────────────────────────────────
Markdown 1 254 0 181 73
|- BASH 1 8 8 0 0
|- Shell 1 1 1 0 0
(Total) 263 9 181 73
─────────────────────────────────────────────────────────────────────────────────
Rust 10 1256 937 86 233
|- Markdown 10 340 8 263 69
(Total) 1596 945 349 302
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total 16 2290 1305 540 445
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
I guess "Alex" would be the linker scripts ending in .x?Comment by nevi-me 2 days ago
Comment by mkj 2 days ago
Comment by sli 2 days ago
Comment by kibwen 2 days ago
Comment by melastmohican 2 days ago
I’ve been experimenting with the new Raspberry Pi Pico 2 W (RP2350) and wanted to see how difficult it would be to build a fully compliant Matter smart device from scratch using Rust.
I put together a complete "Blinky" example using the rs-matter stack and the embassy async framework. It uses BLE for the initial commissioning phase and Wi-Fi for network connectivity. Once flashed, you can provision it directly into Apple Home, Google Home, or Home Assistant using your smartphone—no cloud accounts required. It exposes a standard Matter On/Off cluster that toggles a physical LED wired to the GPIO pins.
A few interesting technical notes from the build:
Bare Metal: It runs entirely no_std on bare metal using embassy-rp. Radio Coexistence: Getting the CYW43439 wireless chip to handle concurrent BLE (for commissioning) and Wi-Fi (for Matter IP traffic) on the RP2350 took some tweaking. We actually had to dial back the PIO SPI clock divider specifically because the RP2350's faster 150MHz core clock was causing bus corruption when the radio was saturated! Async Rust: The repo includes the full async CoEx (coexistence) runner setup to safely multiplex the radio between the Bluetooth and Wi-Fi stacks concurrently. If you’ve been wanting to build local-only smart home devices but felt intimidated by the massive official C++ Matter SDK, doing it in Rust is actually becoming incredibly approachable.
Would love to hear if anyone else is building custom smart home gear in Rust.
Comment by MrBuddyCasino 2 days ago
How do you even diagnose this?
Comment by melastmohican 2 days ago
Comment by mrlambchop 2 days ago
That sounds like the crate didn't have coexistence enabled or the defaults were really odd - so much boring stuff to write about BLE/WiFi Coex, but the short is "the default settings" are pretty good for low bandwidth IoT devices.
I'll peek at the code out of interest :)
Comment by mschuster91 2 days ago
> Turned out when slowed down SPI bus, it started working.
reeks of either RF interference issues or power rail issues. Power is not the strongest domain of anything RPi so that's where I'd look first.
Comment by taneq 2 days ago
Comment by DazWilkin 2 days ago
Comment by jkwang 2 days ago
Comment by ryanshrott 2 days ago
Comment by anya53 2 days ago