This Fall, my Uni went back face-to-face, and I built a neat C02 RGB display project that displayed the C02 measurements of an Adafruit SCD-30 - NDIR CO2 Temperature and Humidity Sensor in a way that a whole classroom of students could see, read, and interpret. This project helped them feel comfortable spending 90 minutes indoors with others during the pandemic.
The success of this project made me want to create a smaller, more subtle version that I could carry with me to meetings. I holed to use the same sensor, an Adafruit Feather M0 logger (with micro-SD card), and a 128x64 OLED display. I soldered the display to the microprocessor using a set of headers, and the solders look pretty good. The CO2 sensor is connected with a cable to the microprocessor. And the processor is connected by a data USB cable to my computer (a Mac with Arduino IDE, v.1.8.16). I'm pretty certain I've installed all the libraries necessary to use these components, but my experience building the sketch has been rocky.
Using 'example' sketches with minimal modifications by my, I've verified that the CO2 sensor can write to the serial monitor. I've verified that I can write to the OLED display and the serial monitor, but my sketch is not doing what I expect it to be doing (or want it to do).
Below is the sketch I've been building. It is based off an 'example' sketch that prints to the OLED display when you press one of the buttons not he OLED board. I've been able to modify this to print to the serial monitor on a button press, too.
I need some pointers for resolving the following problems:
-
My microcontroller is connected to the port '/dev/cu.usbmodem1464301', but the Arduino IDE cannot reliably find it. Often, I get an error that the device can't be found. The third trick here (the double-click) has helped me, but it seems like a cludge. Is there something I'm doing that causes this serial communication problem?
-
When my sketch runs on my board, with my serial monitor running, I want to see (1) two test messages about the OLED, and (2) a "Button test" message in the serial monitor. Then I expect to see the OLED display message following by another message to the serial monitor. I'm seeing the messages on the OLED display but nothing in the serial monitor.
I've read the documentation about Serial.println() and I don't see what I'm doing wrong. other sketches with similar sketch statements seem to work properly, but adding the OLED display to the setup() function seems to be causing problems. And I don't know why.
Thanks in advance for any pointers people can offer to help me understand what I'm doing wrong.
// based on OLED_featherwing sketch
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
// OLED FeatherWing buttons map to different pins depending on board:
#if defined(ESP8266)
#define BUTTON_A 0
#define BUTTON_B 16
#define BUTTON_C 2
#elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
#define BUTTON_A 15
#define BUTTON_B 32
#define BUTTON_C 14
#elif defined(ARDUINO_STM32_FEATHER)
#define BUTTON_A PA15
#define BUTTON_B PC7
#define BUTTON_C PC5
#elif defined(TEENSYDUINO)
#define BUTTON_A 4
#define BUTTON_B 3
#define BUTTON_C 8
#elif defined(ARDUINO_NRF52832_FEATHER)
#define BUTTON_A 31
#define BUTTON_B 30
#define BUTTON_C 27
#else // 32u4, M0, M4, nrf52840, esp32-s2 and 328p
#define BUTTON_A 9
#define BUTTON_B 6
#define BUTTON_C 5
#endif
void setup() {
Serial.begin(115200);
Serial.println("128x64 OLED FeatherWing test");
display.begin(0x3C, true); // Address 0x3C default
Serial.println("OLED begun");
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(1000);
// Clear the buffer.
display.clearDisplay();
display.display();
display.setRotation(1);
Serial.println("Button test");
pinMode(BUTTON_A, INPUT_PULLUP);
pinMode(BUTTON_B, INPUT_PULLUP);
pinMode(BUTTON_C, INPUT_PULLUP);
// text display tests
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0,0);
display.print("Setting up CO2 detector and logger.\n");
display.print("TODO: disp CO2 #\n");
display.print("TODO: log CO2 #\n");
display.println("TODO: display/log # on push\n");
display.display(); // actually display all of the above
}
void loop() {
if(!digitalRead(BUTTON_A)) Serial.println("Button test A");
if(!digitalRead(BUTTON_B)) display.print("B");
if(!digitalRead(BUTTON_C)) display.print("C");
delay(500);
yield();
display.display();
}