Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions HELPStat/Software/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# PlatformIO
.pio/
.pioenvs/
.piolibdeps/

# IDE
.vscode/
!.vscode/extensions.json
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@
SOFTWARE.
*/

#include <Arduino.h>
#include "HELPStat.h"
#include <vector>
#include <string>

/* 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 */
Expand Down
68 changes: 68 additions & 0 deletions HELPStat/Software/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions HELPStat/Software/lib/HELPStatLib/library.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
51 changes: 51 additions & 0 deletions HELPStat/Software/platformio.ini
Original file line number Diff line number Diff line change
@@ -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 <eigen.h> 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