Following Anthropic's Claude Code best practices: - CLAUDE.md: 504 → 121 lines Keep concise: commands, code style, critical rules. Move detailed specs to /opt/repos/docs/reference/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2.7 KiB
2.7 KiB
ClearGrow Probe Firmware
nRF52840 wireless sensor node with Thread networking and code-based pairing.
Commands
# Setup
source ~/ncs/.venv/bin/activate
source ~/ncs/zephyr/zephyr-env.sh
cd /opt/repos/probe
# Build and flash
west build -b nrf52840dk_nrf52840
west flash
# Clean rebuild
rm -rf build && west build -b nrf52840dk_nrf52840
# Memory reports
west build -t rom_report
west build -t ram_report
# Monitor (RTT recommended)
JLinkRTTClient
# Or serial
minicom -D /dev/ttyACM0 -b 115200
Code Style
- Zephyr style: 4-space indent,
snake_case - Logging:
LOG_MODULE_REGISTER(name, LOG_LEVEL_INF), thenLOG_INF(),LOG_WRN(),LOG_ERR() - Timing:
k_sleep(K_MSEC(100)), never raw ticks
Critical Rules
DO NOT use Zephyr PM framework - nRF52840 lacks HAS_PM support. Use Nordic HAL directly:
#include <hal/nrf_power.h>
nrf_power_system_off(NRF_POWER); // <1µA, does NOT return
Thread role is MTD-SED (Sleepy End Device) - poll period 1 second
CoAP operations are blocking - never call from time-critical contexts
Architecture
src/
├── main.c # Entry point, state machine
├── sensor_manager.c # I2C sensor drivers
├── thread_node.c # Thread + CoAP client
├── power_manager.c # Battery, sleep modes
└── pairing_code.c # PSKd generation
Key APIs
// Sensors
sensor_manager_init();
sensor_manager_get_data(&data);
// Thread
thread_node_init();
thread_node_send_sensors(&data);
// Power
power_manager_get_battery_percent();
power_manager_set_state(POWER_STATE_SLEEP);
// Pairing
pairing_code_get_pskd(); // Returns 6-char code
Sensors (I2C)
| Sensor | Addr | Measures |
|---|---|---|
| SHT4x | 0x44 | Temp, humidity |
| MLX90614 | 0x5A | Leaf temp (IR) |
| ADS1115 | 0x48 | Soil moisture, EC, pH |
| SCD4x | 0x62 | CO2 |
| VEML7700 | 0x10 | PAR/PPFD, DLI |
Power States
| State | Current | Use |
|---|---|---|
| Active | 10-15mA | Not commissioned |
| Idle | 6-8mA | Normal operation (SED) |
| Sleep | 3-5mA | Low battery |
| System OFF | <1µA | Critical/shipping |
Pairing
- PSKd: 6-character code printed on device label
- Format:
A3F2K7(excludes I, O, Q, Z) - Auto-joiner: Retries with backoff, 10-min timeout for battery protection
Debugging
# Check Thread SED mode
grep "MTD-SED" build/zephyr/zephyr.dts
# Log levels
LOG_MODULE_REGISTER(thread_node, LOG_LEVEL_DBG);
Common issues:
- Won't join: Check PSKd, verify controller in pairing mode
- High power: Verify SED mode, check poll period
- Sensor fails: Check I2C pull-ups (4.7k), verify address
Documentation
Full docs: /opt/repos/docs/reference/firmware/probe/