Skip to content

Commit 1707762

Browse files
author
Nathan Seidle
committed
Add display testing
1 parent d7d6278 commit 1707762

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

Firmware/Display/Display.ino

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
MicroOLED_Clock.ino
3+
4+
Distributed as-is; no warranty is given.
5+
*/
6+
#include <Wire.h> // Include Wire if you're using I2C
7+
#include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library
8+
9+
#define PIN_RESET 9 // Connect RST to pin 9 (SPI & I2C)
10+
#define DC_JUMPER 1 // Set to either 0 (SPI, default) or 1 (I2C) based on jumper, matching the value of the DC Jumper
11+
MicroOLED oled(PIN_RESET, DC_JUMPER);
12+
13+
uint8_t Battery_0 [] = {
14+
0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01,
15+
0x0F, 0x08, 0xF8, 0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B,
16+
0x0B, 0x0B, 0x08, 0x0F, 0x01, 0x01,
17+
};
18+
19+
bool displayDetected = false;
20+
21+
void setup()
22+
{
23+
Wire.begin();
24+
Wire.setClock(400000);
25+
26+
Serial.begin(115200);
27+
delay(100);
28+
Serial.println("OLED example");
29+
30+
//0x3D is default on Qwiic board
31+
if (isConnected(0x3D) == true || isConnected(0x3C) == true)
32+
{
33+
Serial.println("Display detected");
34+
displayDetected = true;
35+
}
36+
else
37+
Serial.println("No display detected");
38+
39+
if (displayDetected)
40+
{
41+
oled.begin(); // Initialize the OLED
42+
oled.clear(PAGE); // Clear the display's internal memory
43+
oled.clear(ALL); // Clear the library's display buffer
44+
}
45+
}
46+
47+
void loop()
48+
{
49+
if (displayDetected)
50+
{
51+
oled.drawIcon(0, 0, 19, 16, Battery_0, sizeof(Battery_0), true);
52+
oled.display();
53+
54+
while(1);
55+
}
56+
57+
Serial.print(".");
58+
delay(100);
59+
}

Firmware/Display/DisplayHelper.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bool isConnected(uint8_t deviceAddress)
2+
{
3+
Wire.beginTransmission(deviceAddress);
4+
if (Wire.endTransmission() == 0)
5+
return true;
6+
return false;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bool isConnected(uint8_t deviceAddress)
2+
{
3+
Wire.beginTransmission(deviceAddress);
4+
if (Wire.endTransmission() == 0)
5+
return true;
6+
return false;
7+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Micro OLED Display Icon
3+
Nathan Seidle @ SparkFun Electronics
4+
Original Creation Date: November 15, 2020
5+
6+
Draw a variable sized icon anywhere on the display
7+
8+
This is helpful when you need a icon (GPS, battery, etc)
9+
on a certain part of the screen.
10+
11+
This code is beerware; if you see me (or any other SparkFun
12+
employee) at the local, and you've found our code helpful,
13+
please buy us a round!
14+
15+
Distributed as-is; no warranty is given.
16+
*/
17+
#include <Wire.h>
18+
#include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED
19+
20+
#define PIN_RESET 9
21+
#define DC_JUMPER 1 // Set to either 0 (SPI, default) or 1 (I2C) based on jumper, matching the value of the DC Jumper
22+
MicroOLED oled(PIN_RESET, DC_JUMPER);
23+
24+
//A 20 x 17 pixel image of a truck in a box
25+
//Use http://en.radzio.dxp.pl/bitmap_converter/ to generate output
26+
//Make sure the bitmap is n*8 pixels tall (pad white pixels to lower area as needed)
27+
//Otherwise the bitmap bitmap_converter will compress some of the bytes together
28+
uint8_t truck [] = {
29+
0xFF, 0x01, 0xC1, 0x41, 0x41, 0x41, 0x71, 0x11, 0x11, 0x11, 0x11, 0x11, 0x71, 0x41, 0x41, 0xC1,
30+
0x81, 0x01, 0xFF, 0xFF, 0x80, 0x83, 0x82, 0x86, 0x8F, 0x8F, 0x86, 0x82, 0x82, 0x82, 0x86, 0x8F,
31+
0x8F, 0x86, 0x83, 0x81, 0x80, 0xFF,
32+
};
33+
34+
int iconHeight = 17;
35+
int iconWidth = 20;
36+
37+
bool displayDetected = false;
38+
39+
void setup()
40+
{
41+
Wire.begin();
42+
Wire.setClock(2000000);
43+
44+
Serial.begin(115200);
45+
delay(100);
46+
Serial.println("Display Icon OLED example");
47+
48+
//0x3D is default on Qwiic board
49+
if (isConnected(0x3D) == true || isConnected(0x3C) == true)
50+
{
51+
Serial.println("Display detected");
52+
displayDetected = true;
53+
}
54+
else
55+
{
56+
Serial.println("No display detected. Freezing...");
57+
while(1);
58+
}
59+
60+
if (displayDetected)
61+
{
62+
oled.begin(); // Initialize the OLED
63+
oled.clear(PAGE); // Clear the display's internal memory
64+
oled.clear(ALL); // Clear the library's display buffer
65+
oled.display(); // Display what's in the buffer (splashscreen)
66+
67+
}
68+
}
69+
70+
int iconX = 0;
71+
int iconXChangeAmount = 1;
72+
int iconY = 0;
73+
int iconYChangeAmount = 1;
74+
75+
void loop()
76+
{
77+
if (displayDetected)
78+
{
79+
oled.drawIcon(iconX, iconY, iconWidth, iconHeight, truck, sizeof(truck), true);
80+
oled.display();
81+
82+
//Move the icon
83+
iconX += iconXChangeAmount;
84+
iconY += iconYChangeAmount;
85+
86+
if (iconX + iconWidth >= 64)
87+
iconXChangeAmount *= -1; //Change direction
88+
if (iconX == 0)
89+
iconXChangeAmount *= -1; //Change direction
90+
91+
if (iconY + iconHeight >= 48)
92+
iconYChangeAmount *= -1; //Change direction
93+
if (iconY == 0)
94+
iconYChangeAmount *= -1; //Change direction
95+
}
96+
}

0 commit comments

Comments
 (0)