Zephyr RTOS application for Arduino Portenta Machine Control that reads an AM2302 sensor and exposes the latest values through an open62541-based OPC UA server.
- Samples an AM2302 (DHT22) every 5 seconds.
- Publishes the latest temperature, humidity, and sensor-health values as OPC UA variables.
- Serves OPC UA over Ethernet on a fixed IPv4 address.
- Keeps local USB CDC logging active even if Ethernet or OPC UA startup fails.
Current validated runtime endpoint:
- Board IP:
192.168.1.50/24 - OPC UA endpoint:
opc.tcp://192.168.1.50:4840
Current exported node IDs:
ns=1;s=pmc.am2302.temperature_cns=1;s=pmc.am2302.humidity_rhns=1;s=pmc.am2302.sensor_ok
- Board: Arduino Portenta Machine Control
- MCU target:
arduino_portenta_h7/stm32h747xx/m7 - Sensor: ASAIR AM2302 / DHT22
- Network: Ethernet
AM2302 wiring used by this app:
| AM2302 pin | PMC pin | Notes |
|---|---|---|
+ |
3V3 |
Power |
out |
I2C SDA (PH8) |
Used as GPIO, not as I2C |
- |
GND |
Ground |
The devicetree overlay disables i2c3 because the Grove SDA pin is repurposed as the DHT data line.
This repository is the app/ manifest repository inside a west workspace. The intended layout is:
pmc-opcua/ <- west workspace root
+-- app/ <- this Git repository
+-- build/ <- west build directory (generated)
+-- zephyr/ <- west-managed Zephyr tree
+-- modules/ <- west-managed modules, including open62541
+-- tools/ <- west-managed tools
Important implications:
- Git root is
app/, not the workspace root. - Build and flash commands are run from the workspace root.
open62541is fetched as a separate west project intomodules/lib/open62541.- The app points Zephyr at the module through
EXTRA_ZEPHYR_MODULES=../modules/lib/open62541/arch.
- Python 3 with
venv - Git
- A Zephyr SDK installation with the
arm-zephyr-eabitoolchain dfu-utilfor flashing
Validated versions in the current project state:
- Zephyr:
v4.3.0 - open62541:
v1.5.0 - west:
v1.5.0 - Zephyr SDK:
0.17.4
Create a west workspace and clone this repository into app/:
mkdir pmc-opcua
cd pmc-opcua
git clone https://github.com/dongmin-dev/pmc-opcua app
python3 -m venv app/.venv
app/.venv/bin/pip install --upgrade pip west
app/.venv/bin/west init -l app
app/.venv/bin/west update --narrow -o=--depth=1
app/.venv/bin/west zephyr-export
app/.venv/bin/west packages pip --installMake sure the Zephyr SDK is installed and visible to the build environment, for example:
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR=$HOME/zephyr-sdk-0.17.4Install dfu-util with your platform package manager. On macOS:
brew install dfu-utilRun builds from the workspace root:
cd /path/to/pmc-opcua
app/.venv/bin/west build -p -b arduino_portenta_h7/stm32h747xx/m7 appThis board does not reliably enter DFU mode automatically from west flash.
Before flashing, manually press the reset button twice to enter DFU mode.
Then flash from the workspace root:
cd /path/to/pmc-opcua
app/.venv/bin/west flash -d buildUSB CDC logs are exposed through the board console. On macOS the device usually appears as /dev/cu.usbmodem*.
Example:
screen /dev/cu.usbmodem101 115200Expected runtime behavior:
- A shell-backed USB CDC prompt appears as
uart:~$. - The board logs AM2302 samples roughly every 5 seconds.
- The OPC UA server listens on port
4840.
Example log line:
[00:00:36.820,000] <inf> pmc_opcua: AM2302 temperature_c=24.90 humidity_rh=53.00
To verify network reachability from the host:
ping -c 3 192.168.1.50
nc -vz 192.168.1.50 4840Any OPC UA client can read the exported nodes. The project has been exercised with Python asyncua and standard desktop OPC UA clients such as UaExpert.
CONFIG_OPEN62541_NAMESPACE_ZERO="REDUCED"is required so the application variables can be added under the standard Objects folder.- open62541 allocations are routed to SDRAM to preserve SRAM headroom during USB and network bring-up.
- The Portenta flash layout is expanded in the board overlay by deleting
slot1_partitionand growingslot0_partition. CONFIG_PHY_INIT_PRIORITY=76, a PHY power-up delay, andno-resetin the overlay are currently required for reliable Ethernet bring-up on this board.- The repository carries an open62541 Zephyr compatibility patch at
patches/open62541-v1.5.0-zephyr-zsock-fd-set.patch.
- Put the board into DFU mode first with a double reset press.
- Re-run
app/.venv/bin/west flash -d buildafter the board re-enumerates.
- Check that the Ethernet cable is connected directly to the PMC.
- Put the host on the same subnet, for example
192.168.1.x/24. - Confirm the app booted cleanly over USB CDC before debugging the network path.
- Check AM2302 wiring.
- Confirm the sensor data line is on PMC Grove SDA (
PH8). - Watch USB CDC logs for
AM2302 read failed.