Platforms & Build
The firmware is built with PlatformIO using the Arduino framework. A single platformio.ini defines multiple environments — one per MCU family — so you can target any supported board without touching the source.
Quick Start
Section titled “Quick Start”- Install PlatformIO Core or the VS Code extension.
- Clone the firmware repository:
Terminal window git clone https://github.com/rpi-seism/reader.gitcd reader - Select your target environment and build:
Terminal window # STM32 (recommended)pio run -e stm32 -t upload# RP2040pio run -e rp2040 -t upload# ESP32pio run -e esp32 -t upload
platformio.ini Environments
Section titled “platformio.ini Environments”[env:stm32]platform = ststm32framework = arduinoboard = genericSTM32F103C8 ; Blue Pill — swap for your targetbuild_flags = -D PLATFORM_STM32 -D SERIAL_RX_BUFFER_SIZE=512lib_deps = robtillaart/CRC@^1.0.0Notes:
HAL_NVIC_SystemReset()is available on all STM32 families.- Hardware UART1 is used for RS-422; USB virtual COM is available for debug.
- The MAX490E DE/RE pins must be toggled around each transmission burst.
[env:rp2040]platform = raspberrypiframework = arduinoboard = picobuild_flags = -D PLATFORM_RP2040lib_deps = robtillaart/CRC@^1.0.0Notes:
- Programmable I/O (PIO) gives jitter-free SPI timing, ideal for the ADS1256.
- Use
Serial1for RS-422;Serial(USB) for debug. - Reset is via
watchdog_reboot(0, 0, 0)orrp2040.reboot().
[env:esp32]platform = espressif32framework = arduinoboard = esp32devbuild_flags = -D PLATFORM_ESP32lib_deps = robtillaart/CRC@^1.0.0Notes:
- Use
HardwareSerial Serial2(2)for RS-422. - Wi-Fi interference can add jitter to SPI — disable Wi-Fi if not needed.
ESP.restart()is the reset function.- OTA updates are possible via the Arduino OTA library.
[env:avr_uno]platform = atmelavrframework = arduinoboard = unolib_deps = robtillaart/CRC@^1.0.0Notes:
- Only 2 KB of SRAM — keep buffers minimal.
- Software Serial is required for RS-422 (hardware UART is used by USB).
- Recommended for prototyping only; timing jitter is higher than 32-bit targets.
- No hardware reset API; use the watchdog timer (
wdt.h).
[env:teensy40]platform = teensyframework = arduinoboard = teensy40lib_deps = robtillaart/CRC@^1.0.0Notes:
- 600 MHz ARM Cortex-M7 — handles >500 SPS without issue.
- Hardware SPI runs up to 40 MHz; use 4 MHz or lower for the ADS1256.
- Multiple hardware UARTs available; use
Serial1orSerial2for RS-422.
CRC-32 Library
Section titled “CRC-32 Library”The firmware uses robtillaart/CRC to compute the Ethernet/PKZip polynomial CRC-32, matching the daemon’s binascii.crc32():
#include "CRC32.h"
CRC32 crc;crc.reset();crc.add(packet_buffer, 14); // header + 3 × int32uint32_t checksum = crc.calc();memcpy(&packet_buffer[14], &checksum, 4);Dead-Client Detection
Section titled “Dead-Client Detection”If the RS-422 link goes down (daemon crash, cable fault), the UART TX FIFO eventually overflows. The firmware tracks consecutive TX failures. After a configurable threshold it calls the platform reset function to reinitialise the UART hardware:
// Platform-specific reset#if defined(PLATFORM_STM32) HAL_NVIC_SystemReset();#elif defined(PLATFORM_ESP32) ESP.restart();#elif defined(PLATFORM_RP2040) rp2040.reboot();#else wdt_enable(WDTO_15MS); // AVR watchdog while(1) {}#endifThe daemon detects the MCU’s absence through its own RX timeout and in_waiting heartbeat monitor — both sides recover independently.
SPI Wiring (ADS1256)
Section titled “SPI Wiring (ADS1256)”| ADS1256 Pin | MCU Pin | Signal |
|---|---|---|
| SCLK | SPI CLK | SPI Clock (1–4 MHz) |
| DIN | SPI MOSI | Data to ADC |
| DOUT | SPI MISO | Data from ADC |
| CS | GPIO (active low) | Chip Select |
| DRDY | GPIO (interrupt) | Data Ready (falling edge) |
| PDWN | 3.3 V | Always powered |
| RESET | GPIO or VCC | Pull high for normal operation |