Adding AUX GPIO mode to Sleepy Sensor Application

I’m building an enhanced version of the Cellular-Enabled Power Outage Detector (Cellular-Enabled Power Outage Detector w/ SMS Notifications - for monitoring houses in the winter when you are away.

The current hardware design uses a Notecarrier-F, ESP32 Feather, a temp/humidity sensor, battery% sensor, OLED screen and monitors the USB state (power from wall) through a digital input on the Feather.

I’m using the “Sleepy Sensor Application” Arduino sketch (Arduino Low power (with deep sleep) sample code for Notecard - #4 by zfields) to wake up the Feather every 30 minutes, take the 4 sensor readings (temp, humidity, battery% and power (0 or 1). This is sent to the Notehub through sensors.qo and then routed to to view the dashboard and to send SMS alerts.

The all works great except if the power goes out, it takes 30 minutes for the device to wake up and transmit this info to Notehub and onto SMS. I want the notification of a power outage to be fast.

Enter AUX GPIO mode to the rescue. I have connected F_USB to AUX1 on the Notecarrier. I want to configure this in a similar way to the “Cellular-Enabled Power Outage Detector” mentioned above by setting the following on the Notecarrier:


How do I add this AUX GPIO function to my device? Do I just run the above commands to the Notecarrier one time through a serial connection or add the info the the Arduino sketch such as in Problems “Setting GPIO mode with Notefile” from Feather ESP32

How and where do I integrate the power state in the notefile power-outage.qo with current one in sensors.qo? Do I just set up another route in Notehub to send the power state in power-outage.qo to the same feed at as the power state in sensors.qo and let it just get updated only when there is a change?

Do I need to change my Arduino code and remove the power object from sensors.qo? If I do this I’m not sure the intial power value will be send to Adafruit, just a change. It will also run every time the Feather reboots every 30 minutes.


I’m assuming F_USB is high and goes low when power is lost.

I do something similar putting the unit to sleep typically for 60 minutes, then wake up and take a reading, except when a button is pushed, then it wakes up immediately and takes a reading.

The only thing I see missing is the card.attn call that should look something like this:
“mode”:“sleep, auxgpio”,

auxgpio requires firmware 3.4.1 or above.

Just modify your Arduino code to include auxgpio in mode and then the unit should wake up every time power is lost.

Hope this helps.

I upgraded the firmware to 3.5.2 and added the “auxgpio” to my existing sleep command. Your idea to wake up the MCU and send all the sensor data including power state to Notehub on a power failure seems better than my original plan to just have the Notecard itself respond to the AUX1 going low during a power failure and updating just the power value as in the " Cellular-Enabled Power Outage Detector" that has no MCU.

Here is my current code that is not responding to AUX1 going low. (There must be a better way to add code than Blockquote.)

// Device monitors AC Power, Temp/Humidity and battery. Runs on battery when AC power is off
// Notecarrier-F, ESP32 Feather, Notecard, I2C sensors: HTU31-D Temp/Humidity sensor,
// LC709203F Lipo Battery Monitor & OLED Display
// FeatherPWR switch on Notecarrier in SWITCH position to enable ATTN sleep wakeup
// (eqivalent function of connecting Notecarrier ATTN pin to F_EN pin)
// Power monitoring: USB power connected to GPIO 14 on Feather with INPUT_PULLDOWN command
// AUX GPIO setup, USB also connected to AUX1 with 20K resistor with input-pulldown command
// OLED VCC is connected to USB so it shuts off when device is on battery during AC power outage
// Notecard Setup
#include <Notecard.h>
#define usbSerial Serial
#define productUID “”
Notecard notecard;
// Temp Sensor
#include <Wire.h>
#include “Adafruit_HTU31D.h”
Adafruit_HTU31D htu = Adafruit_HTU31D();
// Battery Monitor
#include “Adafruit_LC709203F.h”
Adafruit_LC709203F lc;
// OLED Setup
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
// This period controls the waking frequency of your host MCU,
static const size_t PERIOD_S = 1800; // 30 minutes
int powerPin = 14; //Input pin to monitor USB power; Feather GPIO14, Notecarrier F_D5
int powerValue = 0;
void setup() { // Runs on every reboot after power shut off during Sleep
// Initialize Display
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
// Initialize LC709203F Lipo Fuel Gauge
// Initialize Notecard
//initialize temp sensor
// Provide visual signal when the Host MCU is powered
digitalWrite(LED_BUILTIN, HIGH);
// // Power Sense pin - HIGH if USB power is on , 5V, no divider!
pinMode(powerPin, INPUT_PULLDOWN);
// Configure Notecard to synchronize with Notehub periodically, as well as
// adjust the frequency based on the battery level
J * req = notecard.newRequest(“hub.set”);
JAddStringToObject(req, “product”, productUID);
JAddStringToObject(req, “mode”, “periodic”);
JAddStringToObject(req, “vinbound”, “usb:60;high:120;normal:240;low:480;dead:0”);
JAddStringToObject(req, “voutbound”, “usb:30;high:60;normal:90;low:120;dead:0”);
//Read Power Pin
powerValue = digitalRead(powerPin); // 0=OFF, 1=ON // AC Power Sensor
//Read Temp/Humidity Sensor
sensors_event_t humidity, temp;
htu.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
// Set up Notecarrier AUX GPIO for monitoring USB power connected to AUX1
J *req = NoteNewRequest(“card.aux”);
JAddStringToObject(req, “mode”, “gpio”);
J pins = JAddArrayToObject(req, “usage”);
JAddItemToArray(pins, JCreateString(“input-pulldown”)); // AUX1
JAddItemToArray(pins, JCreateString(“off”)); // AUX2
JAddItemToArray(pins, JCreateString(“off”)); // AUX3
JAddItemToArray(pins, JCreateString(“off”)); // AUX4
JAddBoolToObject(req, “sync”, true);
JAddStringToObject(req, “file”, “powerstate.qo”); // is this necessary or should it be sensors.qo?
//Send sensor data to Notehub
usbSerial.println(“Sending data to Notehub”);
J * req = notecard.newRequest(“note.add”);
JAddStringToObject(req, “file”, “sensors.qo”);
JAddBoolToObject(req, “sync”, true);
J * body = JAddObjectToObject(req, “body”);
if (body)
JAddNumberToObject(body, “temp”, temp.temperature * 1.8 + 32);
JAddNumberToObject(body, “humidity”, humidity.relative_humidity);
JAddNumberToObject(body, “battery”,lc.cellPercent());
JAddNumberToObject(body, “power”, powerValue);
// Display Data on OLED.
if(powerValue == 1) {
display.setTextSize(2); // Draw 2X-scale text
1.8 + 32,0);
display.println(F(" F"));
display.print(F(“Hum :”));
display.println(F(" %“));
display.println(F(” %"));
display.print(F(“AC :”));
void loop() {
// Request sleep from loop to safeguard against tranmission failure, and
// ensure sleep request is honored so power usage is minimized.
// Create a “command” instead of a “request”, because the host
// MCU is going to power down and cannot receive a response.
J * req = NoteNewCommand(“card.attn”);
JAddStringToObject(req, “mode”, “sleep, auxgpio”); // added auxgpio
JAddNumberToObject(req, “seconds”, PERIOD_S);
// Wait 1s before retrying