Skip to content

Commit fd7812f

Browse files
authored
New examples added
1 parent 39fa8e1 commit fd7812f

File tree

2 files changed

+228
-0
lines changed

2 files changed

+228
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Example testing sketch for various DHT humidity/temperature sensors
2+
// Written by ladyada, public domain
3+
4+
// REQUIRES the following Arduino libraries:
5+
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
6+
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
7+
8+
//***********************************************************************************************
9+
// Adafruit's example has been extended for being used with the FluxGarage RoboEyes,
10+
// showing different robot face expressions and animations in relation to the temperature
11+
// variable "t". Beside the DHT22 sensor, add an I2C SSD1306 OLED display to get started.
12+
//
13+
// Published in August 2025 by Dennis Hoelscher, FluxGarage
14+
// www.youtube.com/@FluxGarage
15+
// www.fluxgarage.com
16+
//
17+
//***********************************************************************************************
18+
19+
#include "DHT.h"
20+
21+
#define DHTPIN 2 // Digital pin connected to the DHT sensor
22+
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
23+
// Pin 15 can work but DHT must be disconnected during program upload.
24+
25+
// Uncomment whatever type you're using!
26+
//#define DHTTYPE DHT11 // DHT 11
27+
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
28+
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
29+
30+
// Connect pin 1 (on the left) of the sensor to +5V
31+
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
32+
// to 3.3V instead of 5V!
33+
// Connect pin 2 of the sensor to whatever your DHTPIN is
34+
// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
35+
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins)
36+
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
37+
38+
// Initialize DHT sensor.
39+
// Note that older versions of this library took an optional third parameter to
40+
// tweak the timings for faster processors. This parameter is no longer needed
41+
// as the current DHT reading algorithm adjusts itself to work on faster procs.
42+
DHT dht(DHTPIN, DHTTYPE);
43+
44+
45+
#include <Adafruit_SSD1306.h>
46+
47+
#define SCREEN_WIDTH 128 // OLED display width, in pixels
48+
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
49+
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
50+
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
51+
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
52+
53+
#include <FluxGarage_RoboEyes.h> // https://github.com/FluxGarage/RoboEyes
54+
roboEyes roboEyes; // create RoboEyes instance
55+
56+
// EVENT TIMER
57+
unsigned long eventTimer; // will save the timestamps
58+
59+
void setup() {
60+
Serial.begin(9600);
61+
62+
// Startup OLED Display
63+
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
64+
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C or 0x3D
65+
Serial.println(F("SSD1306 allocation failed"));
66+
for(;;); // Don't proceed, loop forever
67+
}
68+
69+
// Startup dht sensor lib
70+
dht.begin();
71+
//Serial.println(F("DHTxx test!"));
72+
73+
// Startup robo eyes
74+
roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate
75+
roboEyes.setPosition(DEFAULT); // eye position should be middle center
76+
roboEyes.setAutoblinker(ON, 3, 2); // start auto blinker
77+
78+
display.setRotation(2); // Rotate the display by 180 degrees - this makes sense if your display is mounted upside down
79+
80+
eventTimer = millis(); // start event timer from here
81+
82+
}
83+
84+
void loop() {
85+
roboEyes.update(); // update eyes drawings
86+
// dont' use delay() here in order to ensure fluid eyes animations
87+
88+
// Measure temperature every 5 seconds
89+
if(millis() >= eventTimer+5000){
90+
// Reading temperature or humidity takes about 250 milliseconds!
91+
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
92+
float h = dht.readHumidity();
93+
// Read temperature as Celsius (the default)
94+
float t = dht.readTemperature();
95+
// Read temperature as Fahrenheit (isFahrenheit = true)
96+
float f = dht.readTemperature(true);
97+
98+
// Check if any reads failed and exit early (to try again).
99+
if (isnan(h) || isnan(t) || isnan(f)) {
100+
Serial.println(F("Failed to read from DHT sensor!"));
101+
return;
102+
}
103+
104+
// Compute heat index in Fahrenheit (the default)
105+
float hif = dht.computeHeatIndex(f, h);
106+
// Compute heat index in Celsius (isFahreheit = false)
107+
float hic = dht.computeHeatIndex(t, h, false);
108+
109+
/*Serial.print(F("Humidity: "));
110+
Serial.print(h);
111+
Serial.print(F("% Temperature: "));
112+
Serial.print(t);
113+
Serial.print(F("°C "));
114+
Serial.print(f);
115+
Serial.print(F("°F Heat index: "));
116+
Serial.print(hic);
117+
Serial.print(F("°C "));
118+
Serial.print(hif);
119+
Serial.println(F("°F"));
120+
*/
121+
Serial.println(t);
122+
123+
if (t < 15){
124+
// Robot is freezing if temperature is below 15° Celsius
125+
roboEyes.setMood(TIRED);
126+
roboEyes.setHFlicker(ON, 2);
127+
}
128+
else if (t > 25){
129+
// Robot is sweating if temperature is above 25° Celsius
130+
roboEyes.setMood(TIRED);
131+
roboEyes.setSweat(ON);
132+
roboEyes.setPosition(S);
133+
}
134+
else {
135+
// Robot's comfort zone: temperature is between 15° and 25° Celsius
136+
roboEyes.setMood(DEFAULT); // neutral face expression
137+
roboEyes.setPosition(DEFAULT); // eye position: middle center
138+
roboEyes.setHFlicker(OFF);
139+
roboEyes.setSweat(OFF);
140+
}
141+
142+
eventTimer = millis(); // reset timer
143+
}
144+
} // end of main loop
145+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 micro controller such as ESP32, an SPI oled display
5+
// with 1322 chip and some jumper wires.
6+
//
7+
// Published in may 2025 by Dennis Hoelscher, FluxGarage
8+
// www.youtube.com/@FluxGarage
9+
// www.fluxgarage.com
10+
//
11+
//***********************************************************************************************
12+
13+
#include <SSD1322_for_Adafruit_GFX.h> // -> Display driver, download here: https://github.com/venice1200/SSD1322_for_Adafruit_GFX
14+
15+
// Used for software SPI
16+
#define OLED_CLK 4
17+
#define OLED_MOSI 6
18+
19+
// Used for software or hardware SPI
20+
#define OLED_CS 7
21+
#define OLED_DC 9
22+
23+
// Used for I2C or SPI
24+
#define OLED_RESET 8
25+
26+
// hardware SPI
27+
Adafruit_SSD1322 display(256, 64, &SPI, OLED_DC, OLED_RESET, OLED_CS);
28+
29+
#include <FluxGarage_RoboEyes.h>
30+
roboEyes roboEyes; // create RoboEyes instance
31+
#define SCREEN_WIDTH 256 // OLED display width, in pixels
32+
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
33+
34+
35+
void setup() {
36+
Serial.begin(9600);
37+
//while (! Serial) delay(100);
38+
Serial.println("SSD1327 OLED test");
39+
40+
if ( ! display.begin(0x3D) ) {
41+
Serial.println("Unable to initialize OLED");
42+
while (1) yield();
43+
}
44+
45+
// Startup robo eyes
46+
roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 100); // screen-width, screen-height, max framerate
47+
roboEyes.setDisplayColors(0x00, 0x0F); // Most dark/bright values for grayscale oleds, such as the SSD1322
48+
49+
// Define some automated eyes behaviour
50+
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
51+
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
52+
53+
// Define eye shapes, all values in pixels
54+
//roboEyes.setWidth(36, 36); // byte leftEye, byte rightEye
55+
//roboEyes.setHeight(36, 36); // byte leftEye, byte rightEye
56+
//roboEyes.setBorderradius(8, 8); // byte leftEye, byte rightEye
57+
//roboEyes.setSpacebetween(10); // int space -> can also be negative
58+
59+
// Cyclops mode
60+
//roboEyes.setCyclops(ON); // bool on/off -> if turned on, robot has only on eye
61+
62+
// Define mood, curiosity and position
63+
//roboEyes.setMood(DEFAULT); // mood expressions, can be TIRED, ANGRY, HAPPY, DEFAULT
64+
//roboEyes.setPosition(DEFAULT); // cardinal directions, can be N, NE, E, SE, S, SW, W, NW, DEFAULT (default = horizontally and vertically centered)
65+
//roboEyes.setCuriosity(ON); // bool on/off -> when turned on, height of the outer eyes increases when moving to the very left or very right
66+
67+
// Set horizontal or vertical flickering
68+
//roboEyes.setHFlicker(ON, 2); // bool on/off, byte amplitude -> horizontal flicker: alternately displacing the eyes in the defined amplitude in pixels
69+
//roboEyes.setVFlicker(ON, 2); // bool on/off, byte amplitude -> vertical flicker: alternately displacing the eyes in the defined amplitude in pixels
70+
71+
// Play prebuilt oneshot animations
72+
//roboEyes.anim_confused(); // confused - eyes shaking left and right
73+
//roboEyes.anim_laugh(); // laughing - eyes shaking up and down
74+
75+
} // end of setup
76+
77+
78+
void loop() {
79+
roboEyes.update(); // update eyes drawings
80+
// Dont' use delay() here in order to ensure fluid eyes animations.
81+
// Check the AnimationSequences example for common practices.
82+
}
83+

0 commit comments

Comments
 (0)