In October of 2022, the Connectivity Standards Alliance announced the release of the Matter 1.0 specification and SDK. With this release, anyone building on Arm will be able to produce and sell home automation services. The combination of the Matter protocol and Arm standards such as PSA certified, Project Cassini, and Project Centauri removes the fragmentation of devices from different suppliers. The race is on as Matter compliant devices have already been introduced into the market. The expectation is that a few billion Matter compliant devices will be sold over the next few years.
The next question is how to open this opportunity to all developers besides the established embedded experts. Python is one way to do so. The number of Python developers is increasing 20% per year and was estimated to be approximately 10 million in 2021. All we need now is a platform to run Matter and Python. What better choice than the ubiquitous Raspberry Pi Model B.
Spoiler alert, the output of this exercise is a Matter lighting home automation service created using Python. The service runs on a Raspberry Pi or a virtual Raspberry Pi in the cloud through Arm Virtual Hardware (AVH) as the same code runs on both as is. The service controls a LED that is connected to a Raspberry Pi and control is over the IP network.
To understand more about Matter and the Arm Virtual Hardware and its benefits, you can read my previous blog in this series here.
For the physical board
For the Arm Virtual Hardware Raspberry Pi 4 board
The first implementation will run the light service between two Raspberry Pi boards.
1. Use a breadboard and the jumper wires to connect the resistor and LED to the Raspberry Pi 4 board on GPIO17. Further information: https://www.raspberrypi.com/documentation/computers/os.html#gpio-pinout)
2. Insert the microSD card into the microSD card reader and connect it to your PC.
3. Using Raspberry Pi Imager tool to flash a microSD card with
a. Click the “Choose OS” button, then click on “Raspberry Pi OS (other)” -> “Raspberry Pi OS Lite (64-bit)”
b. Click the “Gear” icon in the bottom corner
c. Enter a name and set the username and password for SSH
d. Click the “Choose Storage” button and select the entry for the microSD card
e. Click the “Write” button
4. Insert the microSD card into the Raspberry Pi, connect the Ethernet cable to your network, and then connect power supply to the board to turn it on
5. SSH in to the Raspberry Pi using <username>@matter-light.local
6. Install build dependencies
sudo apt-get update
sudo apt-get install git gcc g++ python3 pkg-config libssl-dev libdbus-1-dev libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev python3-pip unzip libgirepository1.0-dev libcairo2-dev libreadline-dev
7. Clone Matter repo and submodules
git clone https://github.com/project-chip/connectedhomeip.git
git checkout db49235c39635582ea522929f9905af03e3114c7
./scripts/checkout_submodules.py --shallow --platform linux
8. Bootstrap the build
9. Build the Python and install the wheel
./scripts/build_python_device.sh --chip_detail_logging true
10. Activate Python virtual environment
11. Enable GPIO permissions
sudo usermod -a -G gpio <username>
12. Install the gpiozero package (recommended from here).
pip3 install gpiozero
13. Create a new file named lighting.py with the following:
from chip.server import (
from chip.exceptions import ChipStackError
from gpiozero import LED
led = LED(17)
if endpoint == 1:
if clusterId == 6 and attributeId == 0:
if len(value) >= 1 and value == 1:
print("[PY] light on")
print("[PY] light off")
chipLib = GetLibraryHandle(attributeChangeCallback)
input('Press enter to quit')
14. Start the application
To reset the device config:
1. Repeat steps 2-8 above, but using the name “matter-controller.local” in step 3c and 5.
2. Build and install the Device Controller wheel:
./scripts/build_python.sh -d true -i separate
3. Activate the Python virtual environment
In this section, the Raspberry Pi is replaced with an AVH Raspberry Pi. The same Python service code will run as above. The difference is that one can create 100 smart hubs as such and run 100 tests in parallel if necessary as opposed to creating a board farm.
1. Create new virtual Raspberry Pi device on AVH with the Raspberry Pi OS Lite OS option.
2. Using the console interface run steps 6-8 from “Setting up the Lighting device” section
3. Run steps 2-3 from “Setting up the Device Controller (physical) device” section
4. Download the AVH VPN profile to Lighting device
5. Install openvpn on lighting device
sudo apt-get install openvpn
6. Start a new SSH session and login using: <username>@matter-light.local
7. Start VPN connection
sudo openvpn --config 'app.avh.arm.com VPN - Default Project.ovpn'
8. Restart the Python lighting app in original SSH session.
1. On Device Controller device run (make sure you are in git project root!)
2. Discover commissionable devices
devices = devCtrl.DiscoverCommissionableNodes(filter=3840, stopOnFirst=True, timeoutSecond=20)
3. Commission the device setting node id to 233 and using code 20202021
4. Turn the light on:
await devCtrl.SendCommand(233, 1, Clusters.OnOff.Commands.On())
5. Turn off the light:
await devCtrl.SendCommand(233, 1, Clusters.OnOff.Commands.Off())
6. Toggle the light:
await devCtrl.SendCommand(233, 1, Clusters.OnOff.Commands.Toggle())
The age of true home automation starts now. The Matter protocol removes the last barrier for deployment. Arm and our ecosystem deliver the IP, tools, software services, and security frameworks to best address the wildly diverse nature of smart home devices. As such, Arm is the platform on which Matter-compliant devices will emerge first. There are many Arm-based platforms on the market today for developers to get started with, such as the Raspberry Pi and the NXP i.Mx8M based boards. The platform software is usually bundled with the hardware. The Matter SDK is open source from the Connectivity Standards Alliance (CSA). Any developer simply must create the automation service on top of the Matter platform. There is no limit to what is possible. If one can imagine it, then it can be created and deployed.
It only takes a few minutes to prepare a Matter platform and to start creating a home automation service using Python. Arm has even made the starting point so much easier by offering the Raspberry Pi on Arm Virtual Hardware. Developers can get started even when they do not yet have the hardware on their desk.
In an ideal scenario, anyone can create and test the service on a virtual Raspberry Pi and then deploy the code worldwide to a real Raspberry Pi because AVH and the real Raspberry Pi are binary compatible. The IoT runs on Arm, and we have a responsibility to create greater opportunities for innovation and scale by continually raising the bar on performance, simplified development, and software reuse. As such, we introduced Arm Virtual Hardware, a transformative offering, to enable software development in the cloud to empower developers to capture emerging market opportunities.
Explore what Arm Virtual Hardware can do for your team then:
Get started using this example by registering for the Arm Virtual Hardware private beta:
Register for Arm Virtual Hardware
Executing ./scripts/build/gn_bootstrap.sh give me the following error:
Setting up Python environment.....Traceback (most recent call last): File "/home/pi/connectedhomeip/third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/env_setup.py", line 795, in <module> sys.exit(main()) File "/home/pi/connectedhomeip/third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/env_setup.py", line 787, in main return EnvSetup(**vars(parse())).setup() File "/home/pi/connectedhomeip/third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/env_setup.py", line 457, in setup result = step(spin) File "/home/pi/connectedhomeip/third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/env_setup.py", line 606, in virtualenv if not virtualenv_setup.install( File "/home/pi/connectedhomeip/third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py", line 342, in install install_packages(gn_target) File "/home/pi/connectedhomeip/third_party/pigweed/repo/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py", line 310, in install_packages subprocess.check_call(gn_cmd, File "/usr/lib/python3.9/subprocess.py", line 368, in check_call retcode = call(*popenargs, **kwargs) File "/usr/lib/python3.9/subprocess.py", line 349, in call with Popen(*popenargs, **kwargs) as p: File "/usr/lib/python3.9/subprocess.py", line 951, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename)FileNotFoundError: [Errno 2] No such file or directory: 'gn'
The 'gn' binary can be build using the google page: https://gn.googlesource.com/gn/. This fixed the issue.