The code seems to run well, I can control any other aspect of the design, but I don’t get the text/pixels/etc. on the OLED display. I can see the printf’s debug results on my terminal.
I can see the original logo displayed on start, but it doesn’t look good.
After clear display it is gone, leaving a left over.
(is there a way to read back from the device? from the 1306 controller? I didn’t read yet it’s spec).
The WEMOS OLED display:
[0,66 inch OLED LED LCD Dispaly Schild Kompatibel für WEMOS D1 MINI ESP32 64X4 8 0,66 zoll Display 0.66 "oled modul IIC I2C|shield lcd|iic i2c lcdiic lcd - AliExpress]
Here is the code, including trials I have done, such as adding SPI lib (I am not using SPI bus), GFX lib (not needed to compile), same for wire.h (I assume it is included with the 1306 lib):
#include <Servo.h>
//#include <Wire.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h> // for the display
#include <Adafruit_GFX.h>
//#include <Arduino.h>
int servo_pin = 12; // D6
int echoPin = 13; // Echo Pin (D7)
int trigPin = 14; // Trigger Pin (D5)
int pos = 0; // variable to store the servo position
#define OLED_RESET -1 // GPIO0
//Adafruit_SSD1306 display(OLED_RESET);
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 48 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//Adafruit_SSD1306 display( OLED_RESET);
Servo servo_base; // create servo object to control a servo
int I2C_scanner(byte _dev); // scan I2C and return fist device found
int ultrasinic_measure();
int move_servo_and_read(int _pos);
void radar_search(int min_dist, int _max_dist);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo_base.attach(servo_pin); // attaches the servo on pin 9
Serial.begin(9600);
Wire.begin(); // for I2C
Serial.println("");
delay(2000); // for debug, to allow time to open terminal
byte oled_i2c_addr = 0x3c;
int i2C_dev = I2C_scanner(oled_i2c_addr); // the 3C Hex is 60 Dec.
Serial.print("Oled display detected address:");
Serial.println(i2C_dev, HEX);
if (i2C_dev==0) {
Serial.println("no I2C devices ");
}
else {
Serial.print("I2C device found: ");
Serial.println(i2C_dev, HEX);
}
// display
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
Serial.println("show logo");
display.display(); // logo of Adaftuit is loaded at start
delay(1000);
display.clearDisplay();
Serial.println("show pixel");
display.drawPixel(10, 10, SSD1306_WHITE);
display.display();
delay(1000);
// draw many lines
//estdrawline();
//display.display();
//delay(2000);
//display.clearDisplay();
// init done
Serial.print("SSD1306_LCDHEIGHT: ");
Serial.println(SSD1306_LCDHEIGHT);
Serial.print("display.width() ");
Serial.println(display.width());
Serial.print("display.height() ");
Serial.println(display.height());
delay(4000);
// Clear the buffer.
display.clearDisplay();
display.drawPixel(10, 10, SSD1306_WHITE);
display.drawPixel(20, 20, SSD1306_WHITE);
display.display();
Serial.println("setting pixles");
delay(1000);
display.clearDisplay();
display.writeFillRect(1,1,20,10,SSD1306_WHITE);
display.display();
Serial.println("Show Rect ");
delay(3000);
} // of setup
void loop() {
for (int i=1;i<=5;i++) {
digitalWrite(LED_BUILTIN, HIGH); // led OFF
display.clearDisplay();
Serial.print("cycle: ");
Serial.println(i);
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("ABC ");
display.println("... ");
display.println("123456 ");
//display.println(i);
display.display();
delay(5000);
digitalWrite(LED_BUILTIN, LOW); // led ON
delay(1000);
} // of for loop
return;
digitalWrite(LED_BUILTIN, HIGH); // led OFF
radar_search(20, 40); // TBD - use min & max to define a range of detection
delay(500);
digitalWrite(LED_BUILTIN, LOW); // led ON
} // of loop