`Hi I've been trying to use an transparent OLED screen for my project and the code won't make it turn on. I don't actually see any lights on this OLED screen: Transparent OLED screen
This is my code using the Adafruit_GFX and Adafruit_SSD1306 libraries:
//PLEASE PUT THE COLONS AFTER EVERY LINE IN SETUP AND LOOP IF NOT YOU JUST WASTED A LOT OF TIME
//Library for Arduino code
#include <Arduino.h>
//Library for Arduino SPI transparent OLED
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//Library for Arduino Nano 33 BLE Sense REV2's Temperature and Humidity Sensor
#include <Arduino_HS300x.h>
//Defining the Pins and actual Module for the SPI OLED
#define ScreenWidth 128
#define ScreenHeight 64
#define OLED_DIN 3
#define OLED_CLK 2
#define OLED_DC 4
#define OLED_CS 5
#define OLED_RST 6
//Button Pin
#define buttonPin 9
//Cofigure and calibrate the Arduino Transparent OLED
Adafruit_SSD1306 display(ScreenWidth, ScreenHeight, OLED_DC, OLED_CS, OLED_RST);
void setup() {
// put your setup code here, to run once:
HS300x.begin();
display.begin();
//define the pinmode for the button
pinMode(buttonPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly
//Define the two integers of the HS300x module
float temperature = HS300x.readTemperature();
float humidity = HS300x.readHumidity();
// Read the value of the input. It can either be 1 or 0
int buttonValue = digitalRead(buttonPin);
// If button is pushed then turn on and print the temperature and humidity on the OLED
//if (buttonValue == HIGH) {
display.setCursor(0,0);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("Hello world");
//}
}
What are you running the code in. How is it connected to the display. How is it powered. Posting an annotated schematic would help a lot. Links to technical information on each of the hardware parts will also help.
The constructor in the posted code is a constructor for hardware SPI where the MOSI and SCK pins are known. The pins depend on the processor that is in use (Arduino board).
No, you do not change the library. Just use the proper constructor with the pin numbers that you want. Look at the examples that come with the library. They show the difference between a constructor for hardware and software SPI. I posted an example of the constructor for software SPI. Just change the pins.
Try this code with the constructor for softwate SPI. Not tested.
//PLEASE PUT THE COLONS AFTER EVERY LINE IN SETUP AND LOOP IF NOT YOU JUST WASTED A LOT OF TIME
//Library for Arduino code
#include <Arduino.h>
//Library for Arduino SPI transparent OLED
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//Library for Arduino Nano 33 BLE Sense REV2's Temperature and Humidity Sensor
#include <Arduino_HS300x.h>
//Defining the Pins and actual Module for the SPI OLED
#define ScreenWidth 128
#define ScreenHeight 64
#define OLED_DIN 3
#define OLED_CLK 2
#define OLED_DC 4
#define OLED_CS 5
#define OLED_RST 6
//Button Pin
#define buttonPin 9
//Cofigure and calibrate the Arduino Transparent OLED
//Adafruit_SSD1306 display(ScreenWidth, ScreenHeight, OLED_DC, OLED_CS, OLED_RST);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, OLED_DIN, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);
void setup()
{
// put your setup code here, to run once:
HS300x.begin();
display.begin();
//define the pinmode for the button
pinMode(buttonPin, INPUT);
}
void loop()
{
// put your main code here, to run repeatedly
//Define the two integers of the HS300x module
float temperature = HS300x.readTemperature();
float humidity = HS300x.readHumidity();
// Read the value of the input. It can either be 1 or 0
int buttonValue = digitalRead(buttonPin);
// If button is pushed then turn on and print the temperature and humidity on the OLED
//if (buttonValue == HIGH) {
display.setCursor(0, 0);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("Hello world");
//}
}