Skip to content

Commit 89da746

Browse files
authored
Create i2c_SH1106_Basics.ino
Added basic example file for I2C oled displays with SH1106 chips.
1 parent 978bb56 commit 89da746

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//***********************************************************************************************
2+
// This example shows how to use the basic methods of the FluxGarage Robo Eyes library.
3+
//
4+
// Hardware: You'll need a breadboard, a microcontroller such as arduino nano v3 or better an esp32,
5+
// an I2C oled display with sh1106 chip and some jumper wires.
6+
//
7+
// Use the dedicated I2C pins of your microcontroller, on ESP32-WROOM-32 module use pin 22 for SCL and pin 21 for SDA.
8+
// Please note: This example turned out to have slow refresh rates on Arduino Uno. Did not find a fix yet.
9+
//
10+
// Published in January 2025 by Dennis Hoelscher, FluxGarage
11+
// www.youtube.com/@FluxGarage
12+
// www.fluxgarage.com
13+
//
14+
//***********************************************************************************************
15+
16+
#include <SPI.h>
17+
#include <Wire.h>
18+
#include <Adafruit_GFX.h>
19+
#include <Adafruit_SH110X.h>
20+
21+
/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
22+
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
23+
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
24+
25+
#define SCREEN_WIDTH 128 // OLED display width, in pixels
26+
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
27+
#define OLED_RESET -1 // QT-PY / XIAO
28+
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
29+
30+
#include <FluxGarage_RoboEyes.h>
31+
roboEyes roboEyes; // create RoboEyes instance
32+
33+
34+
void setup() {
35+
Serial.begin(9600);
36+
37+
delay(250); // wait for the OLED to power up
38+
display.begin(i2c_Address, true); // Address 0x3C default
39+
//display.setContrast (0); // dim display
40+
41+
// Startup robo eyes
42+
roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate
43+
44+
// Define some automated eyes behaviour
45+
roboEyes.setAutoblinker(ON, 3, 2); // Start auto blinker animation cycle -> bool active, int interval, int variation -> turn on/off, set interval between each blink in full seconds, set range for random interval variation in full seconds
46+
roboEyes.setIdleMode(ON, 2, 2); // Start idle animation cycle (eyes looking in random directions) -> turn on/off, set interval between each eye repositioning in full seconds, set range for random time interval variation in full seconds
47+
48+
// Define eye shapes, all values in pixels
49+
//roboEyes.setWidth(36, 36); // byte leftEye, byte rightEye
50+
//roboEyes.setHeight(36, 36); // byte leftEye, byte rightEye
51+
//roboEyes.setBorderradius(8, 8); // byte leftEye, byte rightEye
52+
//roboEyes.setSpacebetween(10); // int space -> can also be negative
53+
54+
// Cyclops mode
55+
//roboEyes.setCyclops(ON); // bool on/off -> if turned on, robot has only on eye
56+
57+
// Define mood, curiosity and position
58+
//roboEyes.setMood(DEFAULT); // mood expressions, can be TIRED, ANGRY, HAPPY, DEFAULT
59+
//roboEyes.setPosition(DEFAULT); // cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered)
60+
//roboEyes.setCuriosity(ON); // bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right
61+
62+
// Set horizontal or vertical flickering
63+
//roboEyes.setHFlicker(ON, 2); // bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels
64+
//roboEyes.setVFlicker(ON, 2); // bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels
65+
66+
// Play prebuilt oneshot animations
67+
//roboEyes.anim_confused(); // confused - eyes shaking left and right
68+
//roboEyes.anim_laugh(); // laughing - eyes shaking up and down
69+
70+
} // end of setup
71+
72+
73+
void loop() {
74+
roboEyes.update(); // update eyes drawings
75+
// Dont' use delay() here in order to ensure fluid eyes animations.
76+
// Check the AnimationSequences example for common practices.
77+
}
78+

0 commit comments

Comments
 (0)