I am "trying" to get a simple, piece of code working, but the net result is after 3 to 6 cycles the Nano stop responding. Not looping. During the few working cycles the OLED reads as expected. I have tried numerous Libraries, but no change. Any ideas?
#include "ssd1306.h"
#include <Adafruit_AHTX0.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define A4(SDA), A5(SCL)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_AHTX0 aht;
void setup() {
Serial.begin(9600);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_128x64_i2c_init();
ssd1306_positiveMode();
if (! aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
}
void loop() {
display.clearDisplay();
delay (200);
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
char charTemp[32];
dtostrf(temp.temperature, 8, 2, charTemp);
ssd1306_printFixed(0, 16, "Temperature (C)", STYLE_NORMAL);
ssd1306_printFixed(77, 30, charTemp, STYLE_NORMAL);
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degrees C");
char charHumi[32];
dtostrf(humidity.relative_humidity, 8, 2, charHumi);
ssd1306_printFixed(0, 42, "Humidity (%)", STYLE_NORMAL);
ssd1306_printFixed(77, 52, charHumi, STYLE_NORMAL);
Serial.print("Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println("%");
delay(3000);
}