From ff962de0eabb37cd757edbaeb7b4477b125faf01 Mon Sep 17 00:00:00 2001 From: TaylorJSharpe Date: Wed, 10 Jun 2026 12:18:43 -0600 Subject: [PATCH] Working on branching to a PlatformIO implementation --- HELPStat/Software/.gitignore | 9 +++ ...D594x_EIS_Demo.ino => AD594x_EIS_Demo.cpp} | 7 ++ HELPStat/Software/README.md | 68 +++++++++++++++++++ .../{ => lib}/HELPStatLib/HELPStat.cpp | 0 .../Software/{ => lib}/HELPStatLib/HELPStat.h | 0 .../{ => lib}/HELPStatLib/Impedance.c | 0 .../{ => lib}/HELPStatLib/Impedance.h | 0 .../Software/{ => lib}/HELPStatLib/README.md | 0 .../Software/{ => lib}/HELPStatLib/ad5940.c | 0 .../Software/{ => lib}/HELPStatLib/ad5940.h | 0 .../Software/{ => lib}/HELPStatLib/ad594x.cpp | 0 .../{ => lib}/HELPStatLib/constants.h | 16 +++-- .../Software/lib/HELPStatLib/library.json | 19 ++++++ .../Software/{ => lib}/HELPStatLib/lma.cpp | 0 HELPStat/Software/{ => lib}/HELPStatLib/lma.h | 0 HELPStat/Software/platformio.ini | 51 ++++++++++++++ 16 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 HELPStat/Software/.gitignore rename HELPStat/Software/AD594x_EIS_Demo/{AD594x_EIS_Demo.ino => AD594x_EIS_Demo.cpp} (93%) create mode 100644 HELPStat/Software/README.md rename HELPStat/Software/{ => lib}/HELPStatLib/HELPStat.cpp (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/HELPStat.h (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/Impedance.c (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/Impedance.h (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/README.md (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/ad5940.c (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/ad5940.h (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/ad594x.cpp (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/constants.h (50%) create mode 100644 HELPStat/Software/lib/HELPStatLib/library.json rename HELPStat/Software/{ => lib}/HELPStatLib/lma.cpp (100%) rename HELPStat/Software/{ => lib}/HELPStatLib/lma.h (100%) create mode 100644 HELPStat/Software/platformio.ini diff --git a/HELPStat/Software/.gitignore b/HELPStat/Software/.gitignore new file mode 100644 index 0000000..54f3227 --- /dev/null +++ b/HELPStat/Software/.gitignore @@ -0,0 +1,9 @@ +# PlatformIO +.pio/ +.pioenvs/ +.piolibdeps/ + +# IDE +.vscode/ +!.vscode/extensions.json +.idea/ diff --git a/HELPStat/Software/AD594x_EIS_Demo/AD594x_EIS_Demo.ino b/HELPStat/Software/AD594x_EIS_Demo/AD594x_EIS_Demo.cpp similarity index 93% rename from HELPStat/Software/AD594x_EIS_Demo/AD594x_EIS_Demo.ino rename to HELPStat/Software/AD594x_EIS_Demo/AD594x_EIS_Demo.cpp index 29a454e..382eabc 100644 --- a/HELPStat/Software/AD594x_EIS_Demo/AD594x_EIS_Demo.ino +++ b/HELPStat/Software/AD594x_EIS_Demo/AD594x_EIS_Demo.cpp @@ -29,10 +29,17 @@ SOFTWARE. */ +#include #include "HELPStat.h" #include #include +/* Forward declarations. + Unlike an .ino sketch (where the Arduino build auto-generates prototypes), a + .cpp must declare any function used before it is defined. blinkLED() is called + in loop() but defined at the bottom of the file. */ +void blinkLED(int cycles, bool state); + /* Reference constants for gain values - taken from AD5941.h library by Analog Devices */ //#define HSTIARTIA_200 0 /**< HSTIA Internal RTIA resistor 200 */ //#define HSTIARTIA_1K 1 /**< HSTIA Internal RTIA resistor 1K */ diff --git a/HELPStat/Software/README.md b/HELPStat/Software/README.md new file mode 100644 index 0000000..c9db71e --- /dev/null +++ b/HELPStat/Software/README.md @@ -0,0 +1,68 @@ +# HELPStat Firmware (PlatformIO) + +Firmware for the HELPStat potentiostat — an **Adafruit ESP32-S3 Feather** driving +an Analog Devices AD5941 for electrochemical impedance spectroscopy (EIS), with +BLE control, SD logging, and on-device Levenberg–Marquardt Randles-cell fitting. + +Originally an Arduino IDE sketch; this directory is now a self-contained +PlatformIO project. The sketch has been converted to a standard C++ translation +unit (`AD594x_EIS_Demo.cpp`) for clean PlatformIO compilation. + +## Layout + +| Path | Purpose | +|------|---------| +| [platformio.ini](platformio.ini) | PlatformIO build configuration | +| [AD594x_EIS_Demo/AD594x_EIS_Demo.cpp](AD594x_EIS_Demo/AD594x_EIS_Demo.cpp) | Main program (`src_dir`) | +| [lib/HELPStatLib/](lib/HELPStatLib/) | AD5941 driver, EIS logic, BLE/SD, LMA fitting | +| `App/` | Companion Android app (separate Gradle project) | + +## Prerequisites + +- [PlatformIO Core](https://platformio.org/install) (CLI) or the PlatformIO IDE + extension for VS Code. +- A native terminal. The ESP32 platform installer (pioarduino) **rejects + MSYS/MinGW/Git-Bash** — on Windows use **PowerShell** or **cmd**, not Git Bash. + +## Build / Upload / Monitor + +```sh +pio run # compile (default env: 4MB/2MB-PSRAM Feather) +pio run -t upload # flash over USB (auto-resets into the bootloader) +pio device monitor # serial monitor @ 115200 (native USB CDC) +pio run -t upload -t monitor # flash then monitor +``` + +If you have the **8MB no-PSRAM** Feather (Adafruit #5323) instead of the default +4MB/2MB-PSRAM board (#5477), append `-e adafruit_feather_esp32s3_nopsram` to the +`run` commands. + +In VS Code, use the PlatformIO toolbar (Build / Upload / Monitor) and pick the +environment from the status bar. + +The first build downloads the ESP32 toolchain and the `Eigen-Port` dependency, +so it takes a few minutes; later builds are fast. + +## Configuration notes + +- **Platform:** ESP32 Arduino core 3.x via the community + [pioarduino](https://github.com/pioarduino/platform-espressif32) fork. The + stock PlatformIO `espressif32` platform only ships core 2.x, which this + firmware predates. +- **Board:** Adafruit ESP32-S3 Feather. Two variants are provided as separate + environments — `adafruit_feather_esp32s3` (#5477, default) and + `adafruit_feather_esp32s3_nopsram` (#5323). These board definitions enable + native-USB Serial (`-DARDUINO_USB_CDC_ON_BOOT=1`), so prints appear on the USB + serial monitor with no extra wiring. The AD5941/SD pin map lives in + [lib/HELPStatLib/constants.h](lib/HELPStatLib/constants.h) and already matches + the Feather (SCK 36 / MOSI 35 / MISO 37). Two pins are deliberately reused: + GPIO21 (Feather NeoPixel power) for SD chip-select and GPIO7 (STEMMA-QT I2C + power) for the optional button — both fine since neither peripheral is used. +- **Partition:** the board default (1.4 MB app + OTA + UF2). The firmware is + ~0.75 MB, so it fits with room to spare and UF2 drag-drop updates still work. + SD logging is used for data, not SPIFFS. +- **Dependency:** `eigen.h` comes from + [LinnesLab/Eigen-Port](https://github.com/LinnesLab/Eigen-Port), declared in + both `platformio.ini` and `lib/HELPStatLib/library.json`. +- **`-Wno-error=return-type`** is set so the original sketch — which the Arduino + IDE accepted with only a warning — compiles unchanged. diff --git a/HELPStat/Software/HELPStatLib/HELPStat.cpp b/HELPStat/Software/lib/HELPStatLib/HELPStat.cpp similarity index 100% rename from HELPStat/Software/HELPStatLib/HELPStat.cpp rename to HELPStat/Software/lib/HELPStatLib/HELPStat.cpp diff --git a/HELPStat/Software/HELPStatLib/HELPStat.h b/HELPStat/Software/lib/HELPStatLib/HELPStat.h similarity index 100% rename from HELPStat/Software/HELPStatLib/HELPStat.h rename to HELPStat/Software/lib/HELPStatLib/HELPStat.h diff --git a/HELPStat/Software/HELPStatLib/Impedance.c b/HELPStat/Software/lib/HELPStatLib/Impedance.c similarity index 100% rename from HELPStat/Software/HELPStatLib/Impedance.c rename to HELPStat/Software/lib/HELPStatLib/Impedance.c diff --git a/HELPStat/Software/HELPStatLib/Impedance.h b/HELPStat/Software/lib/HELPStatLib/Impedance.h similarity index 100% rename from HELPStat/Software/HELPStatLib/Impedance.h rename to HELPStat/Software/lib/HELPStatLib/Impedance.h diff --git a/HELPStat/Software/HELPStatLib/README.md b/HELPStat/Software/lib/HELPStatLib/README.md similarity index 100% rename from HELPStat/Software/HELPStatLib/README.md rename to HELPStat/Software/lib/HELPStatLib/README.md diff --git a/HELPStat/Software/HELPStatLib/ad5940.c b/HELPStat/Software/lib/HELPStatLib/ad5940.c similarity index 100% rename from HELPStat/Software/HELPStatLib/ad5940.c rename to HELPStat/Software/lib/HELPStatLib/ad5940.c diff --git a/HELPStat/Software/HELPStatLib/ad5940.h b/HELPStat/Software/lib/HELPStatLib/ad5940.h similarity index 100% rename from HELPStat/Software/HELPStatLib/ad5940.h rename to HELPStat/Software/lib/HELPStatLib/ad5940.h diff --git a/HELPStat/Software/HELPStatLib/ad594x.cpp b/HELPStat/Software/lib/HELPStatLib/ad594x.cpp similarity index 100% rename from HELPStat/Software/HELPStatLib/ad594x.cpp rename to HELPStat/Software/lib/HELPStatLib/ad594x.cpp diff --git a/HELPStat/Software/HELPStatLib/constants.h b/HELPStat/Software/lib/HELPStatLib/constants.h similarity index 50% rename from HELPStat/Software/HELPStatLib/constants.h rename to HELPStat/Software/lib/HELPStatLib/constants.h index 6ccfd97..912e478 100644 --- a/HELPStat/Software/HELPStatLib/constants.h +++ b/HELPStat/Software/lib/HELPStatLib/constants.h @@ -14,22 +14,26 @@ // #define RESET 21 // #define ESP32_INTERRUPT 14 // INTERRUPT PIN FOR ESP32 -// // ESP32 S3 SPI / RESET / INT PINS +// Adafruit ESP32-S3 Feather (#5477 / #5323) - SPI / RESET / INT PINS +// SCK/MOSI/MISO below are the Feather's default hardware SPI pins. #define MOSI 35 -#define MISO 37 +#define MISO 37 #define SCK 36 -#define CS 11 -#define RESET 10 -#define ESP32_INTERRUPT 9 +#define CS 11 // D11 +#define RESET 10 // D10 +#define ESP32_INTERRUPT 9 // D9 // SD CARD PINS +// NOTE: on the Feather, GPIO21 is the onboard NeoPixel power pin. It is reused +// here as the SD chip-select; fine as long as the onboard NeoPixel is unused. #define CS_SD 21 // Need to make sure CLK doesn't exceed SD card maximum // Using the same clock is fine for this case #define SD_CLK 240000000 / 16 #define FILENAME "EISdata.csv" -/* USING SCL/SDA PINS AS LED DRIVERS FOR OUTPUT */ +/* Optional button/LED drivers. NOTE: on the Feather, GPIO7 is the STEMMA-QT + I2C power pin; reused here, fine as long as STEMMA-QT I2C is unused. */ #define LED1 6 #define LED2 7 diff --git a/HELPStat/Software/lib/HELPStatLib/library.json b/HELPStat/Software/lib/HELPStatLib/library.json new file mode 100644 index 0000000..3a56132 --- /dev/null +++ b/HELPStat/Software/lib/HELPStatLib/library.json @@ -0,0 +1,19 @@ +{ + "name": "HELPStat", + "version": "1.0.0", + "description": "Driver and EIS measurement library for the HELPStat potentiostat (Analog Devices AD5941) on the ESP32, with BLE control, SD logging, and Levenberg-Marquardt Randles-cell fitting.", + "keywords": "potentiostat, EIS, AD5941, AD594x, ESP32, impedance, BLE", + "authors": [ + { "name": "Kevin Alessandro Bautista", "email": "kbautis@purdue.edu" }, + { "name": "Shannon Riegle", "email": "sdriegle@iu.edu" } + ], + "license": "MIT", + "frameworks": "arduino", + "platforms": "espressif32", + "dependencies": [ + { + "name": "Bolder Flight Systems Eigen", + "version": "https://github.com/LinnesLab/Eigen-Port.git" + } + ] +} diff --git a/HELPStat/Software/HELPStatLib/lma.cpp b/HELPStat/Software/lib/HELPStatLib/lma.cpp similarity index 100% rename from HELPStat/Software/HELPStatLib/lma.cpp rename to HELPStat/Software/lib/HELPStatLib/lma.cpp diff --git a/HELPStat/Software/HELPStatLib/lma.h b/HELPStat/Software/lib/HELPStatLib/lma.h similarity index 100% rename from HELPStat/Software/HELPStatLib/lma.h rename to HELPStat/Software/lib/HELPStatLib/lma.h diff --git a/HELPStat/Software/platformio.ini b/HELPStat/Software/platformio.ini new file mode 100644 index 0000000..26e9b32 --- /dev/null +++ b/HELPStat/Software/platformio.ini @@ -0,0 +1,51 @@ +; PlatformIO project configuration for the HELPStat firmware. +; +; Target: Adafruit ESP32-S3 Feather, Arduino framework (core 3.x). +; The stock PlatformIO `espressif32` platform only ships Arduino core 2.x, so we +; use the community "pioarduino" fork, which packages Arduino-ESP32 3.x / IDF 5.x. +; +; The Feather has no USB-to-UART chip: Serial runs over native USB, which the +; Adafruit board definitions enable via -DARDUINO_USB_CDC_ON_BOOT=1. +; +; Build: pio run +; Upload: pio run -t upload (auto-resets into the bootloader) +; Monitor: pio device monitor (115200 baud) +; +; The default environment is the 4MB/2MB-PSRAM Feather (Adafruit #5477). If you +; have the 8MB no-PSRAM board (Adafruit #5323), build/upload with: +; pio run -e adafruit_feather_esp32s3_nopsram -t upload + +[platformio] +; The sketch folder is used as the source directory; it holds the main program +; AD594x_EIS_Demo.cpp (converted from the original .ino). +src_dir = AD594x_EIS_Demo +default_envs = adafruit_feather_esp32s3 + +; ---- Settings shared by every environment ---------------------------------- +[env] +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino +monitor_speed = 115200 + +; HELPStatLib (lib/HELPStatLib) is auto-discovered from lib/. +; Eigen-Port supplies used by the Levenberg-Marquardt fitting. +lib_deps = + https://github.com/LinnesLab/Eigen-Port.git + +build_flags = + -DCORE_DEBUG_LEVEL=0 + -DEIGEN_NO_DEBUG + ; The Arduino IDE treats a missing return in a non-void function as a + ; warning; the ESP32 platform's build promotes it to an error. Demote it + ; back so the original sketch compiles unchanged. + -Wno-error=return-type + +; ---- Adafruit ESP32-S3 Feather, 4MB Flash / 2MB PSRAM (Adafruit #5477) ------ +; Default board. The sketch's SPI/SD pins (lib/HELPStatLib/constants.h) already +; match this Feather: SCK 36, MOSI 35, MISO 37. +[env:adafruit_feather_esp32s3] +board = adafruit_feather_esp32s3 + +; ---- Adafruit ESP32-S3 Feather, 8MB Flash / No PSRAM (Adafruit #5323) ------- +[env:adafruit_feather_esp32s3_nopsram] +board = adafruit_feather_esp32s3_nopsram