├── MPU9250-master.zip ├── 3 LED blinking ├── es.jpg ├── led blinking.fzz ├── ESP32 pin mapping.jpg ├── LED blinking ESP32.png └── code │ └── code.ino ├── 10 i2c lcd ├── LiquidCrystal_I2C │ └── LiquidCrystal_I2C-master │ │ ├── README.md │ │ ├── library.json │ │ ├── library.properties │ │ ├── examples │ │ ├── HelloWorld │ │ │ └── HelloWorld.pde │ │ ├── SerialDisplay │ │ │ └── SerialDisplay.pde │ │ └── CustomChars │ │ │ └── CustomChars.pde │ │ ├── keywords.txt │ │ ├── LiquidCrystal_I2C.h │ │ └── LiquidCrystal_I2C.cpp ├── display_text │ └── display_text.ino └── FIND_ADDRESS │ └── FIND_ADDRESS.ino ├── 5 ADC ESP32 ├── ESP32 adc curve non linear.jpg ├── measure analog voltage ESP32.jpg └── code1.ino ├── 6 Touch Pins ESP32 ├── Touch sensor of ESP32.jpg ├── ESP32 touch sensor as button with Arduino IDE.jpg ├── TouchRead │ └── TouchRead.ino └── touchbutton │ └── touchbutton.ino ├── 8 PWM ESP32 ├── LED fading example ESP32 PWM.jpg ├── PWM with ESP32 with LED fading example.jpeg └── CODE.ino ├── 9 web server ESP32 ├── ESP32 Web server demo.jpg ├── ESP32 Web server demo 2.jpeg ├── accessing ESP32 webserver.jpg └── code │ └── code2.ino ├── 7 hall sensor ESP32 ├── hall sensor ESP32 position.jpg └── code │ └── code.ino ├── 4 Push Button interfacing ESP32 └── code.ino ├── README.md └── esp32-esp8266-micropyhton-mqtt-library /MPU9250-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/MPU9250-master.zip -------------------------------------------------------------------------------- /3 LED blinking/es.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/3 LED blinking/es.jpg -------------------------------------------------------------------------------- /3 LED blinking/led blinking.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/3 LED blinking/led blinking.fzz -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/README.md: -------------------------------------------------------------------------------- 1 | # LiquidCrystal_I2C 2 | 3 | LiquidCrystal Arduino library for I2C LCD displays 4 | -------------------------------------------------------------------------------- /3 LED blinking/ESP32 pin mapping.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/3 LED blinking/ESP32 pin mapping.jpg -------------------------------------------------------------------------------- /3 LED blinking/LED blinking ESP32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/3 LED blinking/LED blinking ESP32.png -------------------------------------------------------------------------------- /5 ADC ESP32/ESP32 adc curve non linear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/5 ADC ESP32/ESP32 adc curve non linear.jpg -------------------------------------------------------------------------------- /5 ADC ESP32/measure analog voltage ESP32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/5 ADC ESP32/measure analog voltage ESP32.jpg -------------------------------------------------------------------------------- /6 Touch Pins ESP32/Touch sensor of ESP32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/6 Touch Pins ESP32/Touch sensor of ESP32.jpg -------------------------------------------------------------------------------- /8 PWM ESP32/LED fading example ESP32 PWM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/8 PWM ESP32/LED fading example ESP32 PWM.jpg -------------------------------------------------------------------------------- /9 web server ESP32/ESP32 Web server demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/9 web server ESP32/ESP32 Web server demo.jpg -------------------------------------------------------------------------------- /9 web server ESP32/ESP32 Web server demo 2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/9 web server ESP32/ESP32 Web server demo 2.jpeg -------------------------------------------------------------------------------- /7 hall sensor ESP32/hall sensor ESP32 position.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/7 hall sensor ESP32/hall sensor ESP32 position.jpg -------------------------------------------------------------------------------- /9 web server ESP32/accessing ESP32 webserver.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/9 web server ESP32/accessing ESP32 webserver.jpg -------------------------------------------------------------------------------- /8 PWM ESP32/PWM with ESP32 with LED fading example.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/8 PWM ESP32/PWM with ESP32 with LED fading example.jpeg -------------------------------------------------------------------------------- /6 Touch Pins ESP32/ESP32 touch sensor as button with Arduino IDE.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalahmaddev/ESP32-projects-and-tutorials/HEAD/6 Touch Pins ESP32/ESP32 touch sensor as button with Arduino IDE.jpg -------------------------------------------------------------------------------- /7 hall sensor ESP32/code/code.ino: -------------------------------------------------------------------------------- 1 | 2 | int hall_sensor_value = 0; 3 | void setup() { 4 | Serial.begin(9600); 5 | } 6 | void loop() { 7 | hall_sensor_value = hallRead(); 8 | Serial.print("Hall sensor value = "); 9 | Serial.println(hall_sensor_value); 10 | delay(500); 11 | } 12 | -------------------------------------------------------------------------------- /5 ADC ESP32/code1.ino: -------------------------------------------------------------------------------- 1 | const int Analog_channel_pin= 15; 2 | int ADC_VALUE = 0; 3 | int voltage_value = 0; 4 | void setup() 5 | { 6 | Serial.begin(115200); 7 | } 8 | void loop() 9 | { 10 | ADC_VALUE = analogRead(Analog_channel_pin); 11 | Serial.print("ADC VALUE = "); 12 | Serial.println(ADC_VALUE); 13 | delay(1000); 14 | } 15 | -------------------------------------------------------------------------------- /6 Touch Pins ESP32/TouchRead/TouchRead.ino: -------------------------------------------------------------------------------- 1 | 2 | int touch_sensor_value=0; 3 | void setup() 4 | { 5 | Serial.begin(115200); 6 | Serial.println("Touch sensor tutorial ESP32"); 7 | } 8 | 9 | void loop() 10 | { 11 | 12 | touch_sensor_value = touchRead(T0); 13 | Serial.print("Touch0 value is = "); 14 | Serial.println( touch_sensor_value); 15 | delay(1000); 16 | } 17 | -------------------------------------------------------------------------------- /3 LED blinking/code/code.ino: -------------------------------------------------------------------------------- 1 | // We assigned a name LED pin to pin number 22 2 | const int LEDPIN = 22; 3 | 4 | void setup() 5 | { 6 | // This statement will declare pin 22 as digital output 7 | pinMode(LEDPIN, OUTPUT); 8 | 9 | } 10 | 11 | void loop() 12 | 13 | { 14 | 15 | digitalWrite(LEDPIN, HIGH); 16 | delay(1000); 17 | 18 | digitalWrite(LEDPIN, LOW); 19 | delay(1000); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LiquidCrystal_I2C", 3 | "keywords": "LCD, liquidcrystal, I2C", 4 | "description": "A library for DFRobot I2C LCD displays", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/marcoschwartz/LiquidCrystal_I2C.git" 9 | }, 10 | "frameworks": "arduino", 11 | "platforms": 12 | [ 13 | "atmelavr", 14 | "espressif8266" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /8 PWM ESP32/CODE.ino: -------------------------------------------------------------------------------- 1 | 2 | int PWM_FREQUENCY = 1000; 3 | int PWM_CHANNEL = 0; 4 | int PWM_RESOUTION = 8; 5 | int GPIOPIN = 15 ; 6 | 7 | void setup() 8 | { 9 | 10 | ledcSetup(PWM_CHANNEL, PWM_FREQUENCY, PWM_RESOUTION); 11 | ledcAttachPin(GPIOPIN, PWM_CHANNEL); 12 | 13 | 14 | } 15 | 16 | void loop() 17 | { 18 | 19 | for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) 20 | { 21 | ledcWrite(PWM_CHANNEL, dutyCycle); 22 | delay(100); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/library.properties: -------------------------------------------------------------------------------- 1 | name=LiquidCrystal_I2C 2 | version=1.1.4 3 | author=Frank de Brabander 4 | maintainer=Marco Schwartz 5 | sentence=A library for I2C LCD displays. 6 | paragraph= The library allows to control I2C displays with functions extremely similar to LiquidCrystal library. THIS LIBRARY MIGHT NOT BE COMPATIBLE WITH EXISTING SKETCHES. 7 | category=Display 8 | url=https://github.com/marcoschwartz/LiquidCrystal_I2C 9 | architectures=avr 10 | -------------------------------------------------------------------------------- /6 Touch Pins ESP32/touchbutton/touchbutton.ino: -------------------------------------------------------------------------------- 1 | #define touch_pin_numer T0 2 | const int LED_PIN_NUMBER = 22; 3 | const int VALUE_THRESHOLD = 20; 4 | int TOUCH_SENSOR_VALUE; 5 | void setup() 6 | { 7 | delay(1000); 8 | pinMode (LED_PIN_NUMBER, OUTPUT); 9 | } 10 | void loop(){ 11 | TOUCH_SENSOR_VALUE = touchRead(touch_pin_numer); 12 | Serial.print(TOUCH_SENSOR_VALUE); 13 | if(TOUCH_SENSOR_VALUE < VALUE_THRESHOLD) 14 | { 15 | digitalWrite(LED_PIN_NUMBER, HIGH); 16 | } 17 | else{ 18 | digitalWrite(LED_PIN_NUMBER, LOW); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/examples/HelloWorld/HelloWorld.pde: -------------------------------------------------------------------------------- 1 | //YWROBOT 2 | //Compatible with the Arduino IDE 1.0 3 | //Library version:1.1 4 | #include 5 | 6 | LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display 7 | 8 | void setup() 9 | { 10 | lcd.init(); // initialize the lcd 11 | // Print a message to the LCD. 12 | lcd.backlight(); 13 | lcd.setCursor(3,0); 14 | lcd.print("Hello, world!"); 15 | lcd.setCursor(2,1); 16 | lcd.print("Ywrobot Arduino!"); 17 | lcd.setCursor(0,2); 18 | lcd.print("Arduino LCM IIC 2004"); 19 | lcd.setCursor(2,3); 20 | lcd.print("Power By Ec-yuan!"); 21 | } 22 | 23 | 24 | void loop() 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /4 Push Button interfacing ESP32/code.ino: -------------------------------------------------------------------------------- 1 | // We assigned a name LED pin to pin number 22 2 | const int LEDPIN = 22; 3 | // this will assign the name PushButton to pin numer 15 4 | const int PushButton = 15; 5 | // This Setup function is used to initialize everything 6 | void setup() 7 | { 8 | // This statement will declare pin 22 as digital output 9 | pinMode(LEDPIN, OUTPUT); 10 | // This statement will declare pin 15 as digital input 11 | pinMode(PushButton, INPUT); 12 | } 13 | 14 | void loop() 15 | 16 | { 17 | // digitalRead function stores the Push button state 18 | // in variable push_button_state 19 | int Push_button_state = digitalRead(PushButton); 20 | // if condition checks if push button is pressed 21 | // if pressed LED will turn on otherwise remain off 22 | if ( Push_button_state == HIGH ) 23 | { 24 | digitalWrite(LEDPIN, HIGH); 25 | } 26 | else 27 | { 28 | digitalWrite(LEDPIN, LOW); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/examples/SerialDisplay/SerialDisplay.pde: -------------------------------------------------------------------------------- 1 | /* 2 | * Displays text sent over the serial port (e.g. from the Serial Monitor) on 3 | * an attached LCD. 4 | * YWROBOT 5 | *Compatible with the Arduino IDE 1.0 6 | *Library version:1.1 7 | */ 8 | #include 9 | #include 10 | 11 | LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display 12 | 13 | void setup() 14 | { 15 | lcd.init(); // initialize the lcd 16 | lcd.backlight(); 17 | Serial.begin(9600); 18 | } 19 | 20 | void loop() 21 | { 22 | // when characters arrive over the serial port... 23 | if (Serial.available()) { 24 | // wait a bit for the entire message to arrive 25 | delay(100); 26 | // clear the screen 27 | lcd.clear(); 28 | // read all the available characters 29 | while (Serial.available() > 0) { 30 | // display each character to the LCD 31 | lcd.write(Serial.read()); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /10 i2c lcd/display_text/display_text.ino: -------------------------------------------------------------------------------- 1 | /********* 2 | Rui Santos 3 | Complete project details at https://randomnerdtutorials.com 4 | *********/ 5 | 6 | #include 7 | 8 | // set the LCD number of columns and rows 9 | int lcdColumns = 16; 10 | int lcdRows = 2; 11 | 12 | // set LCD address, number of columns and rows 13 | // if you don't know your display address, run an I2C scanner sketch 14 | LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows); 15 | 16 | void setup(){ 17 | // initialize LCD 18 | lcd.init(); 19 | // turn on LCD backlight 20 | lcd.backlight(); 21 | } 22 | 23 | void loop(){ 24 | // set cursor to first column, first row 25 | lcd.setCursor(0, 0); 26 | // print message 27 | lcd.print("Hello, World!"); 28 | delay(1000); 29 | // clears the display to print new message 30 | lcd.clear(); 31 | // set cursor to first column, second row 32 | lcd.setCursor(0,1); 33 | lcd.print("Hello, World!"); 34 | delay(1000); 35 | lcd.clear(); 36 | } 37 | -------------------------------------------------------------------------------- /10 i2c lcd/FIND_ADDRESS/FIND_ADDRESS.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | Wire.begin(); 5 | Serial.begin(115200); 6 | Serial.println("\nI2C Scanner"); 7 | } 8 | 9 | void loop() { 10 | byte error, address; 11 | int nDevices; 12 | Serial.println("Scanning..."); 13 | nDevices = 0; 14 | for(address = 1; address < 127; address++ ) { 15 | Wire.beginTransmission(address); 16 | error = Wire.endTransmission(); 17 | if (error == 0) { 18 | Serial.print("I2C device found at address 0x"); 19 | if (address<16) { 20 | Serial.print("0"); 21 | } 22 | Serial.println(address,HEX); 23 | nDevices++; 24 | } 25 | else if (error==4) { 26 | Serial.print("Unknow error at address 0x"); 27 | if (address<16) { 28 | Serial.print("0"); 29 | } 30 | Serial.println(address,HEX); 31 | } 32 | } 33 | if (nDevices == 0) { 34 | Serial.println("No I2C devices found\n"); 35 | } 36 | else { 37 | Serial.println("done\n"); 38 | } 39 | delay(5000); 40 | } 41 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/keywords.txt: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Syntax Coloring Map For LiquidCrystal_I2C 3 | ########################################### 4 | 5 | ########################################### 6 | # Datatypes (KEYWORD1) 7 | ########################################### 8 | 9 | LiquidCrystal_I2C KEYWORD1 10 | 11 | ########################################### 12 | # Methods and Functions (KEYWORD2) 13 | ########################################### 14 | init KEYWORD2 15 | begin KEYWORD2 16 | clear KEYWORD2 17 | home KEYWORD2 18 | noDisplay KEYWORD2 19 | display KEYWORD2 20 | noBlink KEYWORD2 21 | blink KEYWORD2 22 | noCursor KEYWORD2 23 | cursor KEYWORD2 24 | scrollDisplayLeft KEYWORD2 25 | scrollDisplayRight KEYWORD2 26 | leftToRight KEYWORD2 27 | rightToLeft KEYWORD2 28 | shiftIncrement KEYWORD2 29 | shiftDecrement KEYWORD2 30 | noBacklight KEYWORD2 31 | backlight KEYWORD2 32 | autoscroll KEYWORD2 33 | noAutoscroll KEYWORD2 34 | createChar KEYWORD2 35 | setCursor KEYWORD2 36 | print KEYWORD2 37 | blink_on KEYWORD2 38 | blink_off KEYWORD2 39 | cursor_on KEYWORD2 40 | cursor_off KEYWORD2 41 | setBacklight KEYWORD2 42 | load_custom_character KEYWORD2 43 | printstr KEYWORD2 44 | ########################################### 45 | # Constants (LITERAL1) 46 | ########################################### 47 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/examples/CustomChars/CustomChars.pde: -------------------------------------------------------------------------------- 1 | //YWROBOT 2 | //Compatible with the Arduino IDE 1.0 3 | //Library version:1.1 4 | #include 5 | #include 6 | 7 | #if defined(ARDUINO) && ARDUINO >= 100 8 | #define printByte(args) write(args); 9 | #else 10 | #define printByte(args) print(args,BYTE); 11 | #endif 12 | 13 | uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4}; 14 | uint8_t note[8] = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0}; 15 | uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0}; 16 | uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0}; 17 | uint8_t duck[8] = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0}; 18 | uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0}; 19 | uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0}; 20 | uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4}; 21 | 22 | LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display 23 | 24 | void setup() 25 | { 26 | lcd.init(); // initialize the lcd 27 | lcd.backlight(); 28 | 29 | lcd.createChar(0, bell); 30 | lcd.createChar(1, note); 31 | lcd.createChar(2, clock); 32 | lcd.createChar(3, heart); 33 | lcd.createChar(4, duck); 34 | lcd.createChar(5, check); 35 | lcd.createChar(6, cross); 36 | lcd.createChar(7, retarrow); 37 | lcd.home(); 38 | 39 | lcd.print("Hello world..."); 40 | lcd.setCursor(0, 1); 41 | lcd.print(" i "); 42 | lcd.printByte(3); 43 | lcd.print(" arduinos!"); 44 | delay(5000); 45 | displayKeyCodes(); 46 | 47 | } 48 | 49 | // display all keycodes 50 | void displayKeyCodes(void) { 51 | uint8_t i = 0; 52 | while (1) { 53 | lcd.clear(); 54 | lcd.print("Codes 0x"); lcd.print(i, HEX); 55 | lcd.print("-0x"); lcd.print(i+15, HEX); 56 | lcd.setCursor(0, 1); 57 | for (int j=0; j<16; j++) { 58 | lcd.printByte(i+j); 59 | } 60 | i+=16; 61 | 62 | delay(4000); 63 | } 64 | } 65 | 66 | void loop() 67 | { 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32-projects-and-tutorials 2 | ESP32 projects and tutorials 3 | you can visit this webstie for more information about these tutorials with step by step guide 4 | https://microcontrollerslab.com/ 5 | 6 | Follow these tutorial in the given order to understand this course more better 7 | 1. Tutorial 1: Introduction to ESP32 development board 8 | https://microcontrollerslab.com/esp32-development-board/ 9 | 2. Tutorial 2: How to install ESP32 in Arduino IDE 10 | https://microcontrollerslab.com/install-esp32-arduino-ide/ 11 | 3. Tutorial 3: ESP32 pinout – How to use GPIO pins? 12 | https://microcontrollerslab.com/esp32-pinout-use-gpio-pins/ 13 | 4. Tutorial 4: GPIO pins of ESP32 – LED Blinking example 14 | https://microcontrollerslab.com/gpio-pins-esp32-led-blinking-example/ 15 | 5. Tutorial 5:Push button with ESP32 – GPIO pins as digital input 16 | https://microcontrollerslab.com/push-button-esp32-gpio-digital-input/ 17 | 6. Tutorial 6: How to use ADC of ESP32 – Measuring voltage example 18 | https://microcontrollerslab.com/adc-esp32-measuring-voltage-example/ 19 | 7. Tutorial 7: ESP32 touch sensor – How to use touch pins as a button 20 | https://microcontrollerslab.com/esp32-touch-sensor-button-example/ 21 | 8. Tutorial 8: ESP32 built in hall effect sensor with Arduino IDE 22 | https://microcontrollerslab.com/esp32-built-in-hall-effect-sensor-with-arduino-ide/ 23 | 9. Tutorial 9: Create ESP32 Web server in Arduino IDE : controlling LEDs 24 | https://microcontrollerslab.com/esp32-web-server-arduino-led/ 25 | 10. Tutorial number 10: ESP32 PWM with Arduino IDE – LED fading example 26 | https://microcontrollerslab.com/esp32-pwm-arduino-ide-led-fading-example/ 27 | 11. Tutorial 11 : I2C LCD interfacing with ESP32 28 | https://microcontrollerslab.com/esp32-esp8266-i2c-lcd-interfacing/ 29 | 12. Tutorial 12: interface dht11 dht22 with esp32 and display values on web server 30 | https://microcontrollerslab.com/esp32-dht11-dht22-web-server/ 31 | 13. Tutorial 13: ESP32 Password protected web server in Arduino IDE 32 | https://microcontrollerslab.com/esp32-password-protected-web-server-in-arduino-ide/ 33 | 14.Tutorial 14: Accessing ESP32 web server from anywhere in the world ( ESP8266 compatible) 34 | https://microcontrollerslab.com/accessing-esp32-web-server-anywhere-world-esp8266/ 35 | 15. Tutorial 15: ESP32 soft access point web server in Arduino IDE 36 | https://microcontrollerslab.com/esp32-soft-access-point-web-server-in-arduino-ide/ 37 | 16. Tutorial 16: ESP32 static/fix IP address 38 | https://microcontrollerslab.com/esp32-static-fix-ip-address/ 39 | 17. Tutorial 17: ESP32 Web Server Control Servo motor with Arduino IDE 40 | https://microcontrollerslab.com/esp32-servo-motor-web-server-arduino/ 41 | 42 | 18. Tutorial 18: ESP32 BMP180 Web Server using Arduino IDE 43 | https://microcontrollerslab.com/esp32-bmp180-web-server-arduino-ide/ 44 | 45 | 19. Tutorial 19: ADS1115 I2C external ADC with ESP32 in Arduino IDE 46 | https://microcontrollerslab.com/ads1115-external-adc-with-esp32/ 47 | 48 | 20. Tutorial 20: LM35 Temperature Sensor with ESP32 – Web Server 49 | https://microcontrollerslab.com/lm35-temperature-sensor-with-esp32-web-server/ 50 | 51 | 21.Tuoorial 21: ESP32 web server control relay and 220 volt lamp 52 | https://microcontrollerslab.com/esp32-web-server-control-relay-220-volt-lamp/ 53 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/LiquidCrystal_I2C.h: -------------------------------------------------------------------------------- 1 | //YWROBOT 2 | #ifndef LiquidCrystal_I2C_h 3 | #define LiquidCrystal_I2C_h 4 | 5 | #include 6 | #include "Print.h" 7 | #include 8 | 9 | // commands 10 | #define LCD_CLEARDISPLAY 0x01 11 | #define LCD_RETURNHOME 0x02 12 | #define LCD_ENTRYMODESET 0x04 13 | #define LCD_DISPLAYCONTROL 0x08 14 | #define LCD_CURSORSHIFT 0x10 15 | #define LCD_FUNCTIONSET 0x20 16 | #define LCD_SETCGRAMADDR 0x40 17 | #define LCD_SETDDRAMADDR 0x80 18 | 19 | // flags for display entry mode 20 | #define LCD_ENTRYRIGHT 0x00 21 | #define LCD_ENTRYLEFT 0x02 22 | #define LCD_ENTRYSHIFTINCREMENT 0x01 23 | #define LCD_ENTRYSHIFTDECREMENT 0x00 24 | 25 | // flags for display on/off control 26 | #define LCD_DISPLAYON 0x04 27 | #define LCD_DISPLAYOFF 0x00 28 | #define LCD_CURSORON 0x02 29 | #define LCD_CURSOROFF 0x00 30 | #define LCD_BLINKON 0x01 31 | #define LCD_BLINKOFF 0x00 32 | 33 | // flags for display/cursor shift 34 | #define LCD_DISPLAYMOVE 0x08 35 | #define LCD_CURSORMOVE 0x00 36 | #define LCD_MOVERIGHT 0x04 37 | #define LCD_MOVELEFT 0x00 38 | 39 | // flags for function set 40 | #define LCD_8BITMODE 0x10 41 | #define LCD_4BITMODE 0x00 42 | #define LCD_2LINE 0x08 43 | #define LCD_1LINE 0x00 44 | #define LCD_5x10DOTS 0x04 45 | #define LCD_5x8DOTS 0x00 46 | 47 | // flags for backlight control 48 | #define LCD_BACKLIGHT 0x08 49 | #define LCD_NOBACKLIGHT 0x00 50 | 51 | #define En B00000100 // Enable bit 52 | #define Rw B00000010 // Read/Write bit 53 | #define Rs B00000001 // Register select bit 54 | 55 | class LiquidCrystal_I2C : public Print { 56 | public: 57 | LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows); 58 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS ); 59 | void clear(); 60 | void home(); 61 | void noDisplay(); 62 | void display(); 63 | void noBlink(); 64 | void blink(); 65 | void noCursor(); 66 | void cursor(); 67 | void scrollDisplayLeft(); 68 | void scrollDisplayRight(); 69 | void printLeft(); 70 | void printRight(); 71 | void leftToRight(); 72 | void rightToLeft(); 73 | void shiftIncrement(); 74 | void shiftDecrement(); 75 | void noBacklight(); 76 | void backlight(); 77 | void autoscroll(); 78 | void noAutoscroll(); 79 | void createChar(uint8_t, uint8_t[]); 80 | void createChar(uint8_t location, const char *charmap); 81 | // Example: const char bell[8] PROGMEM = {B00100,B01110,B01110,B01110,B11111,B00000,B00100,B00000}; 82 | 83 | void setCursor(uint8_t, uint8_t); 84 | #if defined(ARDUINO) && ARDUINO >= 100 85 | virtual size_t write(uint8_t); 86 | #else 87 | virtual void write(uint8_t); 88 | #endif 89 | void command(uint8_t); 90 | void init(); 91 | void oled_init(); 92 | 93 | ////compatibility API function aliases 94 | void blink_on(); // alias for blink() 95 | void blink_off(); // alias for noBlink() 96 | void cursor_on(); // alias for cursor() 97 | void cursor_off(); // alias for noCursor() 98 | void setBacklight(uint8_t new_val); // alias for backlight() and nobacklight() 99 | void load_custom_character(uint8_t char_num, uint8_t *rows); // alias for createChar() 100 | void printstr(const char[]); 101 | 102 | ////Unsupported API functions (not implemented in this library) 103 | uint8_t status(); 104 | void setContrast(uint8_t new_val); 105 | uint8_t keypad(); 106 | void setDelay(int,int); 107 | void on(); 108 | void off(); 109 | uint8_t init_bargraph(uint8_t graphtype); 110 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end); 111 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end); 112 | 113 | 114 | private: 115 | void init_priv(); 116 | void send(uint8_t, uint8_t); 117 | void write4bits(uint8_t); 118 | void expanderWrite(uint8_t); 119 | void pulseEnable(uint8_t); 120 | uint8_t _Addr; 121 | uint8_t _displayfunction; 122 | uint8_t _displaycontrol; 123 | uint8_t _displaymode; 124 | uint8_t _numlines; 125 | bool _oled = false; 126 | uint8_t _cols; 127 | uint8_t _rows; 128 | uint8_t _backlightval; 129 | }; 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /9 web server ESP32/code/code2.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char* WIFI_NAME= "PTCL-BB"; 4 | const char* WIFI_PASSWORD = "5387c614"; 5 | WiFiServer server(80); 6 | 7 | String header; 8 | 9 | String LED_ONE_STATE = "off"; 10 | String LED_TWO_STATE = "off"; 11 | String LED_THREE_STATE = "off"; 12 | 13 | 14 | const int GPIO_PIN_NUMBER_22 = 22; 15 | const int GPIO_PIN_NUMBER_23 = 23; 16 | const int GPIO_PIN_NUMBER_15 = 15; 17 | 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | pinMode(GPIO_PIN_NUMBER_22, OUTPUT); 22 | pinMode(GPIO_PIN_NUMBER_23, OUTPUT); 23 | pinMode(GPIO_PIN_NUMBER_15, OUTPUT); 24 | 25 | digitalWrite(GPIO_PIN_NUMBER_22, LOW); 26 | digitalWrite(GPIO_PIN_NUMBER_23, LOW); 27 | digitalWrite(GPIO_PIN_NUMBER_15, LOW); 28 | 29 | 30 | Serial.print("Connecting to "); 31 | Serial.println(WIFI_NAME); 32 | WiFi.begin(WIFI_NAME, WIFI_PASSWORD); 33 | while (WiFi.status() != WL_CONNECTED) { 34 | delay(1000); 35 | Serial.print("Trying to connect to Wifi Network"); 36 | } 37 | Serial.println(""); 38 | Serial.println("Successfully connected to WiFi network"); 39 | Serial.println("IP address: "); 40 | Serial.println(WiFi.localIP()); 41 | server.begin(); 42 | } 43 | 44 | void loop(){ 45 | WiFiClient client = server.available(); 46 | if (client) { 47 | Serial.println("New Client is requesting web page"); 48 | String current_data_line = ""; 49 | while (client.connected()) { 50 | if (client.available()) { 51 | char new_byte = client.read(); 52 | Serial.write(new_byte); 53 | header += new_byte; 54 | if (new_byte == '\n') { 55 | 56 | if (current_data_line.length() == 0) 57 | { 58 | 59 | client.println("HTTP/1.1 200 OK"); 60 | client.println("Content-type:text/html"); 61 | client.println("Connection: close"); 62 | client.println(); 63 | 64 | if (header.indexOf("LED0=ON") != -1) 65 | { 66 | Serial.println("GPIO23 LED is ON"); 67 | LED_ONE_STATE = "on"; 68 | digitalWrite(GPIO_PIN_NUMBER_22, HIGH); 69 | } 70 | if (header.indexOf("LED0=OFF") != -1) 71 | { 72 | Serial.println("GPIO23 LED is OFF"); 73 | LED_ONE_STATE = "off"; 74 | digitalWrite(GPIO_PIN_NUMBER_22, LOW); 75 | } 76 | if (header.indexOf("LED1=ON") != -1) 77 | { 78 | Serial.println("GPIO23 LED is ON"); 79 | LED_TWO_STATE = "on"; 80 | digitalWrite(GPIO_PIN_NUMBER_23, HIGH); 81 | } 82 | if (header.indexOf("LED1=OFF") != -1) 83 | { 84 | Serial.println("GPIO23 LED is OFF"); 85 | LED_TWO_STATE = "off"; 86 | digitalWrite(GPIO_PIN_NUMBER_23, LOW); 87 | } 88 | if (header.indexOf("LED2=ON") != -1) 89 | { 90 | Serial.println("GPIO15 LED is ON"); 91 | LED_THREE_STATE = "on"; 92 | digitalWrite(GPIO_PIN_NUMBER_15, HIGH); 93 | } 94 | if(header.indexOf("LED2=OFF") != -1) { 95 | Serial.println("GPIO15 LED is OFF"); 96 | LED_THREE_STATE = "off"; 97 | digitalWrite(GPIO_PIN_NUMBER_15, LOW); 98 | } 99 | 100 | client.println(""); 101 | client.println(""); 102 | client.println(""); 103 | client.println(""); 108 | client.println("

ESP32 Web server LED controlling example

"); 109 | client.println("

Web Server Example Microcontrollerslab.com

" ); 110 | client.println("

Press on button to turn on led and off button to turn off LED

"); 111 | client.println("
"); 112 | client.println("

LED one is " + LED_ONE_STATE + "

"); 113 | // If the PIN_NUMBER_22State is off, it displays the ON button 114 | client.println("
") ; 115 | client.println("

"); 116 | client.println("

LED two is " + LED_TWO_STATE + "

"); 117 | client.println(""); 118 | client.println("

"); 119 | client.println("

LED three is " + LED_THREE_STATE + "

"); 120 | client.println (""); 121 | client.println ("
"); 122 | client.println("
"); 123 | client.println(); 124 | break; 125 | } 126 | else 127 | { 128 | current_data_line = ""; 129 | } 130 | } 131 | else if (new_byte != '\r') 132 | { 133 | current_data_line += new_byte; 134 | } 135 | } 136 | } 137 | // Clear the header variable 138 | header = ""; 139 | // Close the connection 140 | client.stop(); 141 | Serial.println("Client disconnected."); 142 | Serial.println(""); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /esp32-esp8266-micropyhton-mqtt-library: -------------------------------------------------------------------------------- 1 | try: 2 | import usocket as socket 3 | except: 4 | import socket 5 | import ustruct as struct 6 | from ubinascii import hexlify 7 | 8 | class MQTTException(Exception): 9 | pass 10 | 11 | class MQTTClient: 12 | 13 | def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0, 14 | ssl=False, ssl_params={}): 15 | if port == 0: 16 | port = 8883 if ssl else 1883 17 | self.client_id = client_id 18 | self.sock = None 19 | self.server = server 20 | self.port = port 21 | self.ssl = ssl 22 | self.ssl_params = ssl_params 23 | self.pid = 0 24 | self.cb = None 25 | self.user = user 26 | self.pswd = password 27 | self.keepalive = keepalive 28 | self.lw_topic = None 29 | self.lw_msg = None 30 | self.lw_qos = 0 31 | self.lw_retain = False 32 | 33 | def _send_str(self, s): 34 | self.sock.write(struct.pack("!H", len(s))) 35 | self.sock.write(s) 36 | 37 | def _recv_len(self): 38 | n = 0 39 | sh = 0 40 | while 1: 41 | b = self.sock.read(1)[0] 42 | n |= (b & 0x7f) << sh 43 | if not b & 0x80: 44 | return n 45 | sh += 7 46 | 47 | def set_callback(self, f): 48 | self.cb = f 49 | 50 | def set_last_will(self, topic, msg, retain=False, qos=0): 51 | assert 0 <= qos <= 2 52 | assert topic 53 | self.lw_topic = topic 54 | self.lw_msg = msg 55 | self.lw_qos = qos 56 | self.lw_retain = retain 57 | 58 | def connect(self, clean_session=True): 59 | self.sock = socket.socket() 60 | addr = socket.getaddrinfo(self.server, self.port)[0][-1] 61 | self.sock.connect(addr) 62 | if self.ssl: 63 | import ussl 64 | self.sock = ussl.wrap_socket(self.sock, **self.ssl_params) 65 | premsg = bytearray(b"\x10\0\0\0\0\0") 66 | msg = bytearray(b"\x04MQTT\x04\x02\0\0") 67 | 68 | sz = 10 + 2 + len(self.client_id) 69 | msg[6] = clean_session << 1 70 | if self.user is not None: 71 | sz += 2 + len(self.user) + 2 + len(self.pswd) 72 | msg[6] |= 0xC0 73 | if self.keepalive: 74 | assert self.keepalive < 65536 75 | msg[7] |= self.keepalive >> 8 76 | msg[8] |= self.keepalive & 0x00FF 77 | if self.lw_topic: 78 | sz += 2 + len(self.lw_topic) + 2 + len(self.lw_msg) 79 | msg[6] |= 0x4 | (self.lw_qos & 0x1) << 3 | (self.lw_qos & 0x2) << 3 80 | msg[6] |= self.lw_retain << 5 81 | 82 | i = 1 83 | while sz > 0x7f: 84 | premsg[i] = (sz & 0x7f) | 0x80 85 | sz >>= 7 86 | i += 1 87 | premsg[i] = sz 88 | 89 | self.sock.write(premsg, i + 2) 90 | self.sock.write(msg) 91 | #print(hex(len(msg)), hexlify(msg, ":")) 92 | self._send_str(self.client_id) 93 | if self.lw_topic: 94 | self._send_str(self.lw_topic) 95 | self._send_str(self.lw_msg) 96 | if self.user is not None: 97 | self._send_str(self.user) 98 | self._send_str(self.pswd) 99 | resp = self.sock.read(4) 100 | assert resp[0] == 0x20 and resp[1] == 0x02 101 | if resp[3] != 0: 102 | raise MQTTException(resp[3]) 103 | return resp[2] & 1 104 | 105 | def disconnect(self): 106 | self.sock.write(b"\xe0\0") 107 | self.sock.close() 108 | 109 | def ping(self): 110 | self.sock.write(b"\xc0\0") 111 | 112 | def publish(self, topic, msg, retain=False, qos=0): 113 | pkt = bytearray(b"\x30\0\0\0") 114 | pkt[0] |= qos << 1 | retain 115 | sz = 2 + len(topic) + len(msg) 116 | if qos > 0: 117 | sz += 2 118 | assert sz < 2097152 119 | i = 1 120 | while sz > 0x7f: 121 | pkt[i] = (sz & 0x7f) | 0x80 122 | sz >>= 7 123 | i += 1 124 | pkt[i] = sz 125 | #print(hex(len(pkt)), hexlify(pkt, ":")) 126 | self.sock.write(pkt, i + 1) 127 | self._send_str(topic) 128 | if qos > 0: 129 | self.pid += 1 130 | pid = self.pid 131 | struct.pack_into("!H", pkt, 0, pid) 132 | self.sock.write(pkt, 2) 133 | self.sock.write(msg) 134 | if qos == 1: 135 | while 1: 136 | op = self.wait_msg() 137 | if op == 0x40: 138 | sz = self.sock.read(1) 139 | assert sz == b"\x02" 140 | rcv_pid = self.sock.read(2) 141 | rcv_pid = rcv_pid[0] << 8 | rcv_pid[1] 142 | if pid == rcv_pid: 143 | return 144 | elif qos == 2: 145 | assert 0 146 | 147 | def subscribe(self, topic, qos=0): 148 | assert self.cb is not None, "Subscribe callback is not set" 149 | pkt = bytearray(b"\x82\0\0\0") 150 | self.pid += 1 151 | struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic) + 1, self.pid) 152 | #print(hex(len(pkt)), hexlify(pkt, ":")) 153 | self.sock.write(pkt) 154 | self._send_str(topic) 155 | self.sock.write(qos.to_bytes(1, "little")) 156 | while 1: 157 | op = self.wait_msg() 158 | if op == 0x90: 159 | resp = self.sock.read(4) 160 | #print(resp) 161 | assert resp[1] == pkt[2] and resp[2] == pkt[3] 162 | if resp[3] == 0x80: 163 | raise MQTTException(resp[3]) 164 | return 165 | 166 | # Wait for a single incoming MQTT message and process it. 167 | # Subscribed messages are delivered to a callback previously 168 | # set by .set_callback() method. Other (internal) MQTT 169 | # messages processed internally. 170 | def wait_msg(self): 171 | res = self.sock.read(1) 172 | self.sock.setblocking(True) 173 | if res is None: 174 | return None 175 | if res == b"": 176 | raise OSError(-1) 177 | if res == b"\xd0": # PINGRESP 178 | sz = self.sock.read(1)[0] 179 | assert sz == 0 180 | return None 181 | op = res[0] 182 | if op & 0xf0 != 0x30: 183 | return op 184 | sz = self._recv_len() 185 | topic_len = self.sock.read(2) 186 | topic_len = (topic_len[0] << 8) | topic_len[1] 187 | topic = self.sock.read(topic_len) 188 | sz -= topic_len + 2 189 | if op & 6: 190 | pid = self.sock.read(2) 191 | pid = pid[0] << 8 | pid[1] 192 | sz -= 2 193 | msg = self.sock.read(sz) 194 | self.cb(topic, msg) 195 | if op & 6 == 2: 196 | pkt = bytearray(b"\x40\x02\0\0") 197 | struct.pack_into("!H", pkt, 2, pid) 198 | self.sock.write(pkt) 199 | elif op & 6 == 4: 200 | assert 0 201 | 202 | # Checks whether a pending message from server is available. 203 | # If not, returns immediately with None. Otherwise, does 204 | # the same processing as wait_msg. 205 | def check_msg(self): 206 | self.sock.setblocking(False) 207 | return self.wait_msg() 208 | -------------------------------------------------------------------------------- /10 i2c lcd/LiquidCrystal_I2C/LiquidCrystal_I2C-master/LiquidCrystal_I2C.cpp: -------------------------------------------------------------------------------- 1 | // Based on the work by DFRobot 2 | 3 | #include "LiquidCrystal_I2C.h" 4 | #include 5 | #if defined(ARDUINO) && ARDUINO >= 100 6 | 7 | #include "Arduino.h" 8 | 9 | #define printIIC(args) Wire.write(args) 10 | inline size_t LiquidCrystal_I2C::write(uint8_t value) { 11 | send(value, Rs); 12 | return 1; 13 | } 14 | 15 | #else 16 | #include "WProgram.h" 17 | 18 | #define printIIC(args) Wire.send(args) 19 | inline void LiquidCrystal_I2C::write(uint8_t value) { 20 | send(value, Rs); 21 | } 22 | 23 | #endif 24 | #include "Wire.h" 25 | 26 | 27 | 28 | // When the display powers up, it is configured as follows: 29 | // 30 | // 1. Display clear 31 | // 2. Function set: 32 | // DL = 1; 8-bit interface data 33 | // N = 0; 1-line display 34 | // F = 0; 5x8 dot character font 35 | // 3. Display on/off control: 36 | // D = 0; Display off 37 | // C = 0; Cursor off 38 | // B = 0; Blinking off 39 | // 4. Entry mode set: 40 | // I/D = 1; Increment by 1 41 | // S = 0; No shift 42 | // 43 | // Note, however, that resetting the Arduino doesn't reset the LCD, so we 44 | // can't assume that its in that state when a sketch starts (and the 45 | // LiquidCrystal constructor is called). 46 | 47 | LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows) 48 | { 49 | _Addr = lcd_Addr; 50 | _cols = lcd_cols; 51 | _rows = lcd_rows; 52 | _backlightval = LCD_NOBACKLIGHT; 53 | } 54 | 55 | void LiquidCrystal_I2C::oled_init(){ 56 | _oled = true; 57 | init_priv(); 58 | } 59 | 60 | void LiquidCrystal_I2C::init(){ 61 | init_priv(); 62 | } 63 | 64 | void LiquidCrystal_I2C::init_priv() 65 | { 66 | Wire.begin(); 67 | _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; 68 | begin(_cols, _rows); 69 | } 70 | 71 | void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { 72 | if (lines > 1) { 73 | _displayfunction |= LCD_2LINE; 74 | } 75 | _numlines = lines; 76 | 77 | // for some 1 line displays you can select a 10 pixel high font 78 | if ((dotsize != 0) && (lines == 1)) { 79 | _displayfunction |= LCD_5x10DOTS; 80 | } 81 | 82 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 83 | // according to datasheet, we need at least 40ms after power rises above 2.7V 84 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 85 | delay(50); 86 | 87 | // Now we pull both RS and R/W low to begin commands 88 | expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1) 89 | delay(1000); 90 | 91 | //put the LCD into 4 bit mode 92 | // this is according to the hitachi HD44780 datasheet 93 | // figure 24, pg 46 94 | 95 | // we start in 8bit mode, try to set 4 bit mode 96 | write4bits(0x03 << 4); 97 | delayMicroseconds(4500); // wait min 4.1ms 98 | 99 | // second try 100 | write4bits(0x03 << 4); 101 | delayMicroseconds(4500); // wait min 4.1ms 102 | 103 | // third go! 104 | write4bits(0x03 << 4); 105 | delayMicroseconds(150); 106 | 107 | // finally, set to 4-bit interface 108 | write4bits(0x02 << 4); 109 | 110 | 111 | // set # lines, font size, etc. 112 | command(LCD_FUNCTIONSET | _displayfunction); 113 | 114 | // turn the display on with no cursor or blinking default 115 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 116 | display(); 117 | 118 | // clear it off 119 | clear(); 120 | 121 | // Initialize to default text direction (for roman languages) 122 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 123 | 124 | // set the entry mode 125 | command(LCD_ENTRYMODESET | _displaymode); 126 | 127 | home(); 128 | 129 | } 130 | 131 | /********** high level commands, for the user! */ 132 | void LiquidCrystal_I2C::clear(){ 133 | command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero 134 | delayMicroseconds(2000); // this command takes a long time! 135 | if (_oled) setCursor(0,0); 136 | } 137 | 138 | void LiquidCrystal_I2C::home(){ 139 | command(LCD_RETURNHOME); // set cursor position to zero 140 | delayMicroseconds(2000); // this command takes a long time! 141 | } 142 | 143 | void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){ 144 | int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; 145 | if ( row > _numlines ) { 146 | row = _numlines-1; // we count rows starting w/0 147 | } 148 | command(LCD_SETDDRAMADDR | (col + row_offsets[row])); 149 | } 150 | 151 | // Turn the display on/off (quickly) 152 | void LiquidCrystal_I2C::noDisplay() { 153 | _displaycontrol &= ~LCD_DISPLAYON; 154 | command(LCD_DISPLAYCONTROL | _displaycontrol); 155 | } 156 | void LiquidCrystal_I2C::display() { 157 | _displaycontrol |= LCD_DISPLAYON; 158 | command(LCD_DISPLAYCONTROL | _displaycontrol); 159 | } 160 | 161 | // Turns the underline cursor on/off 162 | void LiquidCrystal_I2C::noCursor() { 163 | _displaycontrol &= ~LCD_CURSORON; 164 | command(LCD_DISPLAYCONTROL | _displaycontrol); 165 | } 166 | void LiquidCrystal_I2C::cursor() { 167 | _displaycontrol |= LCD_CURSORON; 168 | command(LCD_DISPLAYCONTROL | _displaycontrol); 169 | } 170 | 171 | // Turn on and off the blinking cursor 172 | void LiquidCrystal_I2C::noBlink() { 173 | _displaycontrol &= ~LCD_BLINKON; 174 | command(LCD_DISPLAYCONTROL | _displaycontrol); 175 | } 176 | void LiquidCrystal_I2C::blink() { 177 | _displaycontrol |= LCD_BLINKON; 178 | command(LCD_DISPLAYCONTROL | _displaycontrol); 179 | } 180 | 181 | // These commands scroll the display without changing the RAM 182 | void LiquidCrystal_I2C::scrollDisplayLeft(void) { 183 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 184 | } 185 | void LiquidCrystal_I2C::scrollDisplayRight(void) { 186 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 187 | } 188 | 189 | // This is for text that flows Left to Right 190 | void LiquidCrystal_I2C::leftToRight(void) { 191 | _displaymode |= LCD_ENTRYLEFT; 192 | command(LCD_ENTRYMODESET | _displaymode); 193 | } 194 | 195 | // This is for text that flows Right to Left 196 | void LiquidCrystal_I2C::rightToLeft(void) { 197 | _displaymode &= ~LCD_ENTRYLEFT; 198 | command(LCD_ENTRYMODESET | _displaymode); 199 | } 200 | 201 | // This will 'right justify' text from the cursor 202 | void LiquidCrystal_I2C::autoscroll(void) { 203 | _displaymode |= LCD_ENTRYSHIFTINCREMENT; 204 | command(LCD_ENTRYMODESET | _displaymode); 205 | } 206 | 207 | // This will 'left justify' text from the cursor 208 | void LiquidCrystal_I2C::noAutoscroll(void) { 209 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 210 | command(LCD_ENTRYMODESET | _displaymode); 211 | } 212 | 213 | // Allows us to fill the first 8 CGRAM locations 214 | // with custom characters 215 | void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) { 216 | location &= 0x7; // we only have 8 locations 0-7 217 | command(LCD_SETCGRAMADDR | (location << 3)); 218 | for (int i=0; i<8; i++) { 219 | write(charmap[i]); 220 | } 221 | } 222 | 223 | //createChar with PROGMEM input 224 | void LiquidCrystal_I2C::createChar(uint8_t location, const char *charmap) { 225 | location &= 0x7; // we only have 8 locations 0-7 226 | command(LCD_SETCGRAMADDR | (location << 3)); 227 | for (int i=0; i<8; i++) { 228 | write(pgm_read_byte_near(charmap++)); 229 | } 230 | } 231 | 232 | // Turn the (optional) backlight off/on 233 | void LiquidCrystal_I2C::noBacklight(void) { 234 | _backlightval=LCD_NOBACKLIGHT; 235 | expanderWrite(0); 236 | } 237 | 238 | void LiquidCrystal_I2C::backlight(void) { 239 | _backlightval=LCD_BACKLIGHT; 240 | expanderWrite(0); 241 | } 242 | 243 | 244 | 245 | /*********** mid level commands, for sending data/cmds */ 246 | 247 | inline void LiquidCrystal_I2C::command(uint8_t value) { 248 | send(value, 0); 249 | } 250 | 251 | 252 | /************ low level data pushing commands **********/ 253 | 254 | // write either command or data 255 | void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) { 256 | uint8_t highnib=value&0xf0; 257 | uint8_t lownib=(value<<4)&0xf0; 258 | write4bits((highnib)|mode); 259 | write4bits((lownib)|mode); 260 | } 261 | 262 | void LiquidCrystal_I2C::write4bits(uint8_t value) { 263 | expanderWrite(value); 264 | pulseEnable(value); 265 | } 266 | 267 | void LiquidCrystal_I2C::expanderWrite(uint8_t _data){ 268 | Wire.beginTransmission(_Addr); 269 | printIIC((int)(_data) | _backlightval); 270 | Wire.endTransmission(); 271 | } 272 | 273 | void LiquidCrystal_I2C::pulseEnable(uint8_t _data){ 274 | expanderWrite(_data | En); // En high 275 | delayMicroseconds(1); // enable pulse must be >450ns 276 | 277 | expanderWrite(_data & ~En); // En low 278 | delayMicroseconds(50); // commands need > 37us to settle 279 | } 280 | 281 | 282 | // Alias functions 283 | 284 | void LiquidCrystal_I2C::cursor_on(){ 285 | cursor(); 286 | } 287 | 288 | void LiquidCrystal_I2C::cursor_off(){ 289 | noCursor(); 290 | } 291 | 292 | void LiquidCrystal_I2C::blink_on(){ 293 | blink(); 294 | } 295 | 296 | void LiquidCrystal_I2C::blink_off(){ 297 | noBlink(); 298 | } 299 | 300 | void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){ 301 | createChar(char_num, rows); 302 | } 303 | 304 | void LiquidCrystal_I2C::setBacklight(uint8_t new_val){ 305 | if(new_val){ 306 | backlight(); // turn backlight on 307 | }else{ 308 | noBacklight(); // turn backlight off 309 | } 310 | } 311 | 312 | void LiquidCrystal_I2C::printstr(const char c[]){ 313 | //This function is not identical to the function used for "real" I2C displays 314 | //it's here so the user sketch doesn't have to be changed 315 | print(c); 316 | } 317 | 318 | 319 | // unsupported API functions 320 | #pragma GCC diagnostic push 321 | #pragma GCC diagnostic ignored "-Wunused-parameter" 322 | void LiquidCrystal_I2C::off(){} 323 | void LiquidCrystal_I2C::on(){} 324 | void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {} 325 | uint8_t LiquidCrystal_I2C::status(){return 0;} 326 | uint8_t LiquidCrystal_I2C::keypad (){return 0;} 327 | uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;} 328 | void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end){} 329 | void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end){} 330 | void LiquidCrystal_I2C::setContrast(uint8_t new_val){} 331 | #pragma GCC diagnostic pop 332 | 333 | --------------------------------------------------------------------------------