I'm trying to make a PM2.5 sensor which displays the PM2.5 concentration and corresponding EPA recommendation onto an e-paper display.
When I try to upload my sketch, the IDE warns me:
Sketch uses 21154 bytes (65%) of program storage space. Maximum is 32256 bytes.
Global variables use 1779 bytes (86%) of dynamic memory, leaving 269 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.
I have several debugging Serial.println() statements throughout the code, but the serial monitor never shows a single output, and the TX and RX pins never light either. The display doesn't even so much as flash. As far as I can tell, once I upload the sketch absolutely nothing happens.
When I comment out the sensor part of the sketch and pass the display functions dummy values, everything works fine. When I comment out the display part of the sketch and just print PM2.5 concentrations to serial, everything works fine. It's only when I try putting them both together that I run into this issue.
I'm using an Arduino Uno, Nova PM sds011, and Waveshare 1.54-inch v2 e-Paper display. I've wired everything to a breadboard and powered it with an old Sony phone charger, rated for 5V 0.5mA, which should be more than enough current for my project. I've got a 1mF aluminum electrolytic capacitor set across the positive and negative rails of my breadboard to control ripple voltage from my source. I've attached my sketch to this post.
I'm still learning Arduino and still getting familiar with these forums. Please let me know if there's somewhere else I should post this, or whether there's more information I should include. Any help is much appreciated!
Edit: my apologies, the original sketch I'd attached was an outdated version with unused code commented out. I've reattached a more complete version. Here's the newer version in code tags:
/*
PM2.5 Smoke Concentration Sensor and Display
Based off of the examples GXEPD2_minimumExample
from the GXEPD2 library (https://github.com/ZinggJM/GxEPD2) and
queryReportingMode from the Nova Fitness SDS dust sensors library
(https://github.com/lewapek/sds-dust-sensors-arduino-library)
Uses Waveshare 1.54inch E-Paper display, Arduino Uno, and Nova PM SDS011 Air Quality Sensor.
Last updated 4/9/21
*/
//#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#define MAX_DISPLAY_BUFFER_SIZE 800
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_154_D67, MAX_HEIGHT(GxEPD2_154_D67)> display(GxEPD2_154_D67(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEH0154D67
#include "SdsDustSensor.h"
SdsDustSensor sds(3, 5); //rx pin, tx pin
void setup() {
Serial.begin(9600);
Serial.println("setting up...");
delay(1000);
sds.begin();
display.init();
display.fillScreen(GxEPD_WHITE);
display.fillScreen(GxEPD_BLACK);
display.fillScreen(GxEPD_WHITE);
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
}
void loop() {
Serial.println("Waking up sensor");
sds.wakeup();
Serial.println("Waiting...");
delay(30000);
Serial.println("Getting PM values");
checkSensor();
Serial.println("Sensor going back to sleep\n");
sds.sleep();
delay(60000);
}
void checkSensor() {
PmResult pm = sds.queryPm();
display.firstPage();
do
{
Serial.println("PM2.5 = ");
Serial.print(pm.pm25);
display.fillScreen(GxEPD_WHITE);
display.setCursor((display.width() - 200) / 2, display.height() / 8);
display.println("PM2.5 Conc.[µg/m^3]: ");
display.println(pm.pm25);
display.setCursor(0, display.height() * 1 / 2);
display.println("Caution: 100% of \nthose who breathe O2 die.\n");
//^^ this is stand-in: later I want custom messages for different PM2.5 concentrations
}
while (display.nextPage());
}
sensor_test_v8.ino (2.15 KB)