Browse Source

first pdf and esp32 code

master
TeZ 3 years ago
parent
commit
8dd981dbab
  1. 193
      ESP32/D1-ESP32-DHT11-DISPLAY/D1-ESP32-DHT11-DISPLAY.ino
  2. 5655
      ESP32/D1-ESP32-DHT11-DISPLAY/fontdef.h
  3. 37
      ESP32/D1-ESP32-MotorTest/D1-ESP32-MotorTest.ino
  4. 51
      ESP32/D1-ESP32-Neopixel-Test/D1-ESP32-Neopixel-Test.ino
  5. 18
      ESP32/D1-ESP32-SIMPLESERVO/D1-ESP32-SIMPLESERVO.ino
  6. BIN
      TeZ-BioReactor_web.pdf

193
ESP32/D1-ESP32-DHT11-DISPLAY/D1-ESP32-DHT11-DISPLAY.ino

@ -0,0 +1,193 @@
// ----- TeZ ---- DHT Display on OLED screen -----
//* OLED DISPLAY 3.3V(VCC), GND, SCL (21), SDA (22) [ESP32]
//* model: SSD1306 Resolution: 128 x 64 (small = 128 x 32)
// FONTS >> in file OLEDdisplayFonts.h
// ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24
// SansSerif_plain_10, SansSerif_plain_12
// Dingbats__12
// Monospaced_plain_8, Monospaced_plain_10, Monospaced_plain_12, Monospaced_bold_10, Monospaced_bold_16, Monospaced_bold_24 //
// ceated with http://oleddisplay.squix.ch/
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
// https://learn.adafruit.com/dht/overview
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "fontdef.h"
//#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
#include "SSD1306Wire.h"
#include "OLEDDisplayUi.h"
#include <driver/adc.h>
// Initialize the OLED display using Wire library
SSD1306Wire display(0x3c, 21, 22);
// SSD1306 pinout for ESP32
// SDA >> 21
// SCL >> 22
// VCC >> Vin 5V
// GND >> GND
#define DHTPIN 25 // Digital pin connected to the DHT sensor
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
int wemosLEDpin = 02;
int SMOKETIME = 5000;
bool SMOKEFLAG = true;
///////////////////////////////////////////////////////
void setup() {
Serial.begin(115200);
pinMode(wemosLEDpin, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(4, true);
digitalWrite(wemosLEDpin, true);
// Initialising the OLED display
display.init();
display.flipScreenVertically();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.clear();
display.setFont(Monospaced_bold_16);
display.drawString(0, 0, "Hello Human!");
display.setFont(Monospaced_plain_12);
display.drawString(20, 30, "How are you");
display.drawString(40, 50, "today?");
display.display();
delay(3000);
// Initialize DHT device.
dht.begin();
Serial.println(F("DHTxx Unified Sensor Example"));
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.println(F("Temperature Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
Serial.println(F("------------------------------------"));
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println(F("Humidity Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
Serial.println(F("------------------------------------"));
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
///////////////////////////////////////////////////////
void loop() {
// FOG SWITCH
delay(SMOKETIME);
SMOKEFLAG = !(SMOKEFLAG);
digitalWrite(4, SMOKEFLAG);
digitalWrite(wemosLEDpin, SMOKEFLAG);
// SENSOR AND DISPLAY
display.clear();
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
display.setFont(Monospaced_bold_16);
display.drawString(0, 10, "Temp:");
display.drawString(50, 10, String(int(event.temperature)) + " c" );
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
display.setFont(Monospaced_bold_16);
display.drawString(0, 50, "Hum:");
display.drawString(50, 50, String(int(event.relative_humidity)) + " %");
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
display.display();
// printBuffer();
}
////////////////////////////////////////////
void printBuffer(void) {
// Initialize the log buffer
// allocate memory to store 8 lines of text and 30 chars per line.
display.setLogBuffer(5, 30);
// Some test data
const char* test[] = {
"Hello",
"World" ,
"----",
"Show off",
"how",
"the log buffer",
"is",
"working.",
"Even",
"scrolling is",
"working"
};
for (uint8_t i = 0; i < 11; i++) {
display.clear();
// Print to the screen
display.println(test[i]);
// Draw it to the internal screen buffer
display.drawLogBuffer(0, 0);
// Display it on the screen
display.display();
delay(500);
}
}

5655
ESP32/D1-ESP32-DHT11-DISPLAY/fontdef.h
File diff suppressed because it is too large
View File

37
ESP32/D1-ESP32-MotorTest/D1-ESP32-MotorTest.ino

@ -0,0 +1,37 @@
// WEMOS D1 MINI ESP32 // MOTOR TEST (with TIP 120) // TeZ 2022
#include <Arduino.h>
#include <analogWrite.h>
#define MOTORPIN 26
int powerStep = 1;
int power = 0;
/////////////////////////////////////////
void setup() {
// Set resolution for a specific pin
analogWriteResolution(MOTORPIN, 12);
for(int n=0; n<3; n++){
analogWrite(MOTORPIN, 200);
digitalWrite(2,HIGH);
delay(500);
analogWrite(MOTORPIN, 0);
digitalWrite(2,LOW);
delay(500);
}
}
/////////////////////////////////////////
void loop() {
power += powerStep;
if ( power == 0 || power == 255 ) {
powerStep = -powerStep;
}
analogWrite(MOTORPIN, power);
analogWrite(2, power);
delay(10);
}

51
ESP32/D1-ESP32-Neopixel-Test/D1-ESP32-Neopixel-Test.ino

@ -0,0 +1,51 @@
// WEMOS D1 MINI ESP32 // NEOPIXEL TEST (RGB) // TeZ 2022
#include <Adafruit_NeoPixel.h>
#define PIN 5 // data pin for neopixel
#define NUMPIXELS 8 // Max number of Leds
int rgbflag = 1;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
int ledPin = 2; // internal led D1 Mini esp32
//////////////////////////////////
void setup() {
pinMode(ledPin, OUTPUT);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
//////////////////////////////////
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
if(rgbflag == 1){
pixels.setPixelColor(i, pixels.Color(200, 0, 0)); // RED
}else if(rgbflag == 2){
pixels.setPixelColor(i, pixels.Color(0, 200, 0)); // GREEN
}else if(rgbflag == 3){
pixels.setPixelColor(i, pixels.Color(0, 0, 200)); // BLUE
}
pixels.show(); // Send the updated pixel colors to the hardware.
digitalWrite(ledPin, HIGH); // internal led ON
delay(DELAYVAL);
digitalWrite(ledPin, LOW); // internal led OFF
delay(DELAYVAL);
}
if(rgbflag < 3){
rgbflag ++;
}else{
rgbflag = 1;
}
}

18
ESP32/D1-ESP32-SIMPLESERVO/D1-ESP32-SIMPLESERVO.ino

@ -0,0 +1,18 @@
#include <ESP32Servo.h>
Servo myservo; // create servo object to control a servo
// Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
int servoPin = 23;
void setup() {
myservo.setPeriodHertz(50);
myservo.attach(servoPin);
}
void loop() {
myservo.write(0);
delay(2000);
myservo.write(180);
delay(2000);
}

BIN
TeZ-BioReactor_web.pdf

Loading…
Cancel
Save