Uploading Custom Firmware
The NeuroPawn Arduino library keeps EEG acquisition, packet generation, and host commands running while your sketch performs its own non-blocking work. The smallest complete firmware is:
#include <NeuroPawn.h>
void setup() { neuropawn.setup();}
void loop() { neuropawn.acquire_data();}Before Connecting Electrodes
Section titled “Before Connecting Electrodes”- Disconnect all electrodes and accessories while uploading firmware.
- Never connect mains-powered or non-isolated equipment while electrodes are in contact with a person.
- Use only an ATmega328P Arduino Nano target and keep the serial monitor at
115200baud. - Read the firmware resource and pin limits before adding peripherals.
Arduino IDE
Section titled “Arduino IDE”1. Install the library
Section titled “1. Install the library”In Arduino IDE, install NeuroPawn Knight Board from Library Manager. If you
downloaded a release archive instead, choose Sketch > Include Library > Add
.ZIP Library and select NeuroPawn-<version>-arduino.zip.
2. Create the sketch
Section titled “2. Create the sketch”Start with the minimal firmware above. To add application behavior, keep
neuropawn.acquire_data() at the start of every loop and schedule work with
millis():
#include <NeuroPawn.h>
unsigned long last_update = 0;
void setup() { neuropawn.setup(NP_DEFAULT);
if (NeuroPawnBoard::pin_available(5)) { pinMode(5, OUTPUT); }}
void loop() { neuropawn.acquire_data();
if (millis() - last_update >= 250) { last_update = millis(); digitalWrite(5, !digitalRead(5)); }}3. Select and upload
Section titled “3. Select and upload”- Connect the board directly by USB.
- Select Tools > Board > Arduino AVR Boards > Arduino Nano.
- Select the ATmega328P processor and the board’s serial port.
- Select Sketch > Upload.
After upload, the firmware begins streaming automatically. All EEG channels are
powered down after setup(); activate the required channels from the host with
the chon_<channel>_<gain> commands.
PlatformIO
Section titled “PlatformIO”Create a PlatformIO Arduino project with this platformio.ini:
[env:nanoatmega328]platform = atmelavrboard = nanoatmega328framework = arduinomonitor_speed = 115200
lib_deps = neuropawn/NeuroPawn@^1.0.0Put the minimal firmware in src/main.cpp, then run PlatformIO: Upload or:
pio run --target uploadBuild Firmware With IMU Data
Section titled “Build Firmware With IMU Data”IMU support is a build-time option. It adds about 13 kB of flash use and 640
bytes of RAM use, even before NP_IMU is selected at runtime.
PlatformIO IMU build
Section titled “PlatformIO IMU build”Add NEUROPAWN_IMU to the build flags and start the library in NP_IMU mode:
[env:nanoatmega328_imu]platform = atmelavrboard = nanoatmega328framework = arduinomonitor_speed = 115200build_flags = -DNEUROPAWN_IMU
lib_deps = neuropawn/NeuroPawn@^1.0.0#include <NeuroPawn.h>
void setup() { neuropawn.setup(NP_IMU);}
void loop() { neuropawn.acquire_data();}Arduino IDE IMU build
Section titled “Arduino IDE IMU build”Arduino IDE does not expose project build flags. In the installed library
folder, usually Documents/Arduino/libraries/NeuroPawn_Knight_Board/:
- Open
src/NeuroPawn.hand uncomment#define NEUROPAWN_IMUnear the top. - In
library.properties, change the linker setting toldflags=-lNeuroPawn_imu. - Restart Arduino IDE, then compile a sketch that calls
neuropawn.setup(NP_IMU).
To return to an EEG-only build, comment out the define and restore
ldflags=-lNeuroPawn.
Rules for Application Code
Section titled “Rules for Application Code”- Call
acquire_data()on every loop iteration. At 125 samples per second, blocking for roughly 8 ms can miss a sample. - Do not call
delay()or perform long blocking reads. Usemillis()-based scheduling and short state machines. - Never call
Serial.print()or write unrelated bytes toSerial; it is the binary data link. - Use only pins reported as available by
NeuroPawnBoard::pin_available(pin). - Keep interrupt service routines short.
Use neuropawn.quiet(true) before setup() when a host parser must receive only
binary data. See Knight Board Firmware for the API,
modes, status helpers, and complete hardware limits.
