I'm using a 4pin I2C 0.96 Inch 128X64 Oled Display, aliexpr link
wen I use it on a Arduino Leonardo It works fine,
But wen I want to use it on Nano or Pro Micro it will not work,
Using a address scanner sketch I find nothing on I2C.
I tried using different library's and sketches on the Leonardo everything works fine.
I use Leonardo R3 Atmega32u4
Pro Micro ATmega32U4 whit NRF24L01. aliexp link
Nano V3.0 ATMEGA328P whit NRF24L01. aliexpress link
This is how I wired everything
Oled - Leonardo
SCL - SCL
SDA - SDA
GND -GND
VCC - 3.3V
Oled - Pro Micro
SCL - 3
SDA - 2
GND -GND
VCC - VCC
Oled - Nano
SCL - 5
SDA - 4
GND -GND
VCC - 3v
This the sketch I like to get to work, just a simple Temp and Humility display
#include "DHT.h"
#define DHT11Pin 4
#define DHTType DHT22
//OLED
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
DHT HT(DHT11Pin,DHTType);
float tempC;
float humi;
//float tempF;
//OLED define
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
//For DHT11
HT.begin();
//For OLED I2C
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display(); //Display logo
delay(1000);
display.clearDisplay();
}
void loop() {
delay(1000);
tempC = HT.readTemperature();
humi = HT.readHumidity();
//tempF = HT.readTemperature(true);
Serial.print("Humidity:");
Serial.print(humi,0);
Serial.print("%");
Serial.print(" Temperature:");
Serial.print(tempC,1);
Serial.print("C ~ ");
// Serial.print(tempF,1);
// Serial.println("F");
display.clearDisplay();
oledDisplayHeader();
oledDisplay(2,0,0,tempC, "C");
oledDisplay(3,60,30, humi,"%");
// oledDisplay(2,70,44,tempF,"F");
display.display();
}
void oledDisplayHeader(){
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(20, 30);
display.print("RV ");
// display.setCursor(30, 0);
// display.print("Temperature");
}
void oledDisplay(int size, int x,int y, float value, String unit){
int charLen=12;
int xo=x+charLen*3.2;
int xunit=x+charLen*3.6;
int xval = x;
display.setTextSize(size);
display.setTextColor(WHITE);
if (unit=="%"){
display.setCursor(x, y);
display.print(value,0);
display.print(unit);
} else {
if (value>99){
xval=x;
} else {
xval=x+charLen;
}
display.setCursor(xval, y);
display.print(value,0);
display.drawCircle(xo, y+3, 3, WHITE); // print degree symbols ( )
display.setCursor(xunit, y);
display.print(unit);
}
}
I googled and did read a lot but nothing helped so far