Skip to content

Commit 1dd51ed

Browse files
committed
Updated examples using the SSD1306-based 64x48 OLED displays for new setup API.
1 parent ed8181d commit 1dd51ed

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

examples/04.Shields/Ambient_Light_Shield(BH1750)/BH1750_OLED_test/BH1750_OLED_test.ino

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1+
//Install [claws/BH1750 Library](https://github.com/claws/BH1750) first.
2+
13
#include <Wire.h>
24
#include <Adafruit_GFX.h>
35
#include <Adafruit_SSD1306.h>
46
#include <BH1750.h>
57

8+
#define SCREEN_WIDTH 64 // OLED display width, in pixels
9+
#define SCREEN_HEIGHT 48 // OLED display height, in pixels
10+
11+
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
12+
// SCL GPIO5
13+
// SDA GPIO4
614
#define OLED_RESET 0 // GPIO0
7-
Adafruit_SSD1306 display(OLED_RESET);
15+
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
16+
17+
/*
18+
19+
BH1750 can be physically configured to use two I2C addresses:
20+
- 0x23 (most common) (if ADD pin had < 0.7VCC voltage)
21+
- 0x5C (if ADD pin had > 0.7VCC voltage)
22+
23+
Library uses 0x23 address as default, but you can define any other address.
24+
If you had troubles with default value - try to change it to 0x5C.
825
26+
*/
927
BH1750 light(0x23);
1028

1129
void setup() {
1230

1331
Serial.begin(115200);
1432

15-
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
33+
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
34+
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)); // Address 0x3C for 64x48
1635

1736
}
1837

examples/04.Shields/Barometric_Pressure_HP303B_Shield/HP303B_OLED_TEST/HP303B_OLED_TEST.ino

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
//Install [LOLIN_HP303B_Library](https://github.com/wemos/LOLIN_HP303B_Library.git) first.
2+
13
#include <Wire.h>
24
#include <Adafruit_GFX.h>
35
#include <Adafruit_SSD1306.h>
46
#include <LOLIN_HP303B.h>
57

68
LOLIN_HP303B HP303B;
79

10+
#define SCREEN_WIDTH 64 // OLED display width, in pixels
11+
#define SCREEN_HEIGHT 48 // OLED display height, in pixels
12+
13+
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
14+
// SCL GPIO5
15+
// SDA GPIO4
816
#define OLED_RESET -1
9-
Adafruit_SSD1306 display(OLED_RESET);
17+
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
1018

1119
void setup()
1220
{
1321

14-
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
22+
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
23+
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)); // Address 0x3C for 64x48
1524
display.setTextColor(WHITE);
1625

1726
//Address of the HP303B (0x77 or 0x76)

examples/04.Shields/Barometric_Pressure_HP303B_Shield/simple/simple.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//Install [LOLIN_HP303B_Library](https://github.com/wemos/LOLIN_HP303B_Library.git) first.
2+
13
#include <LOLIN_HP303B.h>
24

35
LOLIN_HP303B HP303B;

0 commit comments

Comments
 (0)