mirror of
				https://github.com/alexandrebobkov/ESP-Nodes.git
				synced 2025-11-04 10:49:53 +00:00 
			
		
		
		
	.
This commit is contained in:
		
							
								
								
									
										34
									
								
								ESP32-C3_ePaper/esp32c3_pins_arduino.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								ESP32-C3_ePaper/esp32c3_pins_arduino.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
#ifndef Pins_Arduino_h
 | 
			
		||||
#define Pins_Arduino_h
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "soc/soc_caps.h"
 | 
			
		||||
 | 
			
		||||
#define PIN_RGB_LED 8
 | 
			
		||||
// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino
 | 
			
		||||
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_RGB_LED;
 | 
			
		||||
#define BUILTIN_LED LED_BUILTIN  // backward compatibility
 | 
			
		||||
#define LED_BUILTIN LED_BUILTIN  // allow testing #ifdef LED_BUILTIN
 | 
			
		||||
// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API rgbLedWrite()
 | 
			
		||||
#define RGB_BUILTIN    LED_BUILTIN
 | 
			
		||||
#define RGB_BRIGHTNESS 64
 | 
			
		||||
 | 
			
		||||
static const uint8_t TX = 21;
 | 
			
		||||
static const uint8_t RX = 20;
 | 
			
		||||
 | 
			
		||||
static const uint8_t SDA = 8;
 | 
			
		||||
static const uint8_t SCL = 9;
 | 
			
		||||
 | 
			
		||||
static const uint8_t SS = 7;
 | 
			
		||||
static const uint8_t MOSI = 6;
 | 
			
		||||
static const uint8_t MISO = 5;
 | 
			
		||||
static const uint8_t SCK = 4;
 | 
			
		||||
 | 
			
		||||
static const uint8_t A0 = 0;
 | 
			
		||||
static const uint8_t A1 = 1;
 | 
			
		||||
static const uint8_t A2 = 2;
 | 
			
		||||
static const uint8_t A3 = 3;
 | 
			
		||||
static const uint8_t A4 = 4;
 | 
			
		||||
static const uint8_t A5 = 5;
 | 
			
		||||
 | 
			
		||||
#endif /* Pins_Arduino_h */
 | 
			
		||||
@@ -12,3 +12,6 @@
 | 
			
		||||
platform = espressif32
 | 
			
		||||
board = esp32-c3-devkitc-02
 | 
			
		||||
framework = arduino
 | 
			
		||||
lib_deps = 
 | 
			
		||||
	bodmer/TFT_eSPI@^2.5.43
 | 
			
		||||
	zinggjm/GxEPD2@^1.5.9
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +1,363 @@
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
 | 
			
		||||
// put function declarations here:
 | 
			
		||||
int myFunction(int, int);
 | 
			
		||||
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
 | 
			
		||||
 | 
			
		||||
// enable or disable GxEPD2_GFX base class
 | 
			
		||||
 | 
			
		||||
#define ENABLE_GxEPD2_GFX 0
 | 
			
		||||
 | 
			
		||||
#include <GxEPD2_BW.h>
 | 
			
		||||
 | 
			
		||||
#include <GxEPD2_3C.h>
 | 
			
		||||
 | 
			
		||||
#include <Fonts/FreeMonoBold9pt7b.h>
 | 
			
		||||
 | 
			
		||||
// ESP32-C3 SS=7,SCL(SCK)=4,SDA(MOSI)=6,BUSY=3,RST=2,DC=1
 | 
			
		||||
 | 
			
		||||
// 2.13'' EPD Module
 | 
			
		||||
 | 
			
		||||
GxEPD2_BW<GxEPD2_213_BN, GxEPD2_213_BN::HEIGHT> display(GxEPD2_213_BN(/*CS=5*/ SS, /*DC=*/ 1, /*RST=*/ 2, /*BUSY=*/ 3)); // DEPG0213BN 122x250, SSD1680
 | 
			
		||||
 | 
			
		||||
//GxEPD2_3C<GxEPD2_213_Z98c, GxEPD2_213_Z98c::HEIGHT> display(GxEPD2_213_Z98c(/*CS=5*/ SS, /*DC=*/ 1, /*RST=*/ 2, /*BUSY=*/ 3)); // GDEY0213Z98 122x250, SSD1680
 | 
			
		||||
 | 
			
		||||
// 2.9'' EPD Module
 | 
			
		||||
 | 
			
		||||
//GxEPD2_BW<GxEPD2_290_BS, GxEPD2_290_BS::HEIGHT> display(GxEPD2_290_BS(/*CS=5*/ SS, /*DC=*/ 1, /*RST=*/ 2, /*BUSY=*/ 3)); // DEPG0290BS 128x296, SSD1680
 | 
			
		||||
 | 
			
		||||
//GxEPD2_3C<GxEPD2_290_C90c, GxEPD2_290_C90c::HEIGHT> display(GxEPD2_290_C90c(/*CS=5*/ SS, /*DC=*/ 1, /*RST=*/ 2, /*BUSY=*/ 3)); // GDEM029C90 128x296, SSD1680
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  pinMode(8, OUTPUT);
 | 
			
		||||
 | 
			
		||||
  digitalWrite(8, HIGH);
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
 | 
			
		||||
  display.init(115200,true,50,false);
 | 
			
		||||
 | 
			
		||||
  helloWorld();
 | 
			
		||||
 | 
			
		||||
  helloFullScreenPartialMode();
 | 
			
		||||
 | 
			
		||||
  delay(1000);
 | 
			
		||||
 | 
			
		||||
  if (display.epd2.hasFastPartialUpdate)
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    showPartialUpdate();
 | 
			
		||||
 | 
			
		||||
    delay(1000);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  display.hibernate();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char HelloWorld[] = "Hello World!";
 | 
			
		||||
 | 
			
		||||
const char HelloWeACtStudio[] = "WeAct Studio";
 | 
			
		||||
 | 
			
		||||
void helloWorld()
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  display.setRotation(1);
 | 
			
		||||
 | 
			
		||||
  display.setFont(&FreeMonoBold9pt7b);
 | 
			
		||||
 | 
			
		||||
  display.setTextColor(GxEPD_BLACK);
 | 
			
		||||
 | 
			
		||||
  int16_t tbx, tby; uint16_t tbw, tbh;
 | 
			
		||||
 | 
			
		||||
  display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
 | 
			
		||||
 | 
			
		||||
  // center the bounding box by transposition of the origin:
 | 
			
		||||
 | 
			
		||||
  uint16_t x = ((display.width() - tbw) / 2) - tbx;
 | 
			
		||||
 | 
			
		||||
  uint16_t y = ((display.height() - tbh) / 2) - tby;
 | 
			
		||||
 | 
			
		||||
  display.setFullWindow();
 | 
			
		||||
 | 
			
		||||
  display.firstPage();
 | 
			
		||||
 | 
			
		||||
  do
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    display.fillScreen(GxEPD_WHITE);
 | 
			
		||||
 | 
			
		||||
    display.setCursor(x, y-tbh);
 | 
			
		||||
 | 
			
		||||
    display.print(HelloWorld);
 | 
			
		||||
 | 
			
		||||
    display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
 | 
			
		||||
 | 
			
		||||
    display.getTextBounds(HelloWeACtStudio, 0, 0, &tbx, &tby, &tbw, &tbh);
 | 
			
		||||
 | 
			
		||||
    x = ((display.width() - tbw) / 2) - tbx;
 | 
			
		||||
 | 
			
		||||
    display.setCursor(x, y+tbh);
 | 
			
		||||
 | 
			
		||||
    display.print(HelloWeACtStudio);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  while (display.nextPage());
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void helloFullScreenPartialMode()
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  //Serial.println("helloFullScreenPartialMode");
 | 
			
		||||
 | 
			
		||||
  const char fullscreen[] = "full screen update";
 | 
			
		||||
 | 
			
		||||
  const char fpm[] = "fast partial mode";
 | 
			
		||||
 | 
			
		||||
  const char spm[] = "slow partial mode";
 | 
			
		||||
 | 
			
		||||
  const char npm[] = "no partial mode";
 | 
			
		||||
 | 
			
		||||
  display.setPartialWindow(0, 0, display.width(), display.height());
 | 
			
		||||
 | 
			
		||||
  display.setRotation(1);
 | 
			
		||||
 | 
			
		||||
  display.setFont(&FreeMonoBold9pt7b);
 | 
			
		||||
 | 
			
		||||
  if (display.epd2.WIDTH < 104) display.setFont(0);
 | 
			
		||||
 | 
			
		||||
  display.setTextColor(GxEPD_BLACK);
 | 
			
		||||
 | 
			
		||||
  const char* updatemode;
 | 
			
		||||
 | 
			
		||||
  if (display.epd2.hasFastPartialUpdate)
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    updatemode = fpm;
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  else if (display.epd2.hasPartialUpdate)
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    updatemode = spm;
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  else
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    updatemode = npm;
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // do this outside of the loop
 | 
			
		||||
 | 
			
		||||
  int16_t tbx, tby; uint16_t tbw, tbh;
 | 
			
		||||
 | 
			
		||||
  // center update text
 | 
			
		||||
 | 
			
		||||
  display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
 | 
			
		||||
 | 
			
		||||
  uint16_t utx = ((display.width() - tbw) / 2) - tbx;
 | 
			
		||||
 | 
			
		||||
  uint16_t uty = ((display.height() / 4) - tbh / 2) - tby;
 | 
			
		||||
 | 
			
		||||
  // center update mode
 | 
			
		||||
 | 
			
		||||
  display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
 | 
			
		||||
 | 
			
		||||
  uint16_t umx = ((display.width() - tbw) / 2) - tbx;
 | 
			
		||||
 | 
			
		||||
  uint16_t umy = ((display.height() * 3 / 4) - tbh / 2) - tby;
 | 
			
		||||
 | 
			
		||||
  // center HelloWorld
 | 
			
		||||
 | 
			
		||||
  display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
 | 
			
		||||
 | 
			
		||||
  uint16_t hwx = ((display.width() - tbw) / 2) - tbx;
 | 
			
		||||
 | 
			
		||||
  uint16_t hwy = ((display.height() - tbh) / 2) - tby;
 | 
			
		||||
 | 
			
		||||
  display.firstPage();
 | 
			
		||||
 | 
			
		||||
  do
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    display.fillScreen(GxEPD_WHITE);
 | 
			
		||||
 | 
			
		||||
    display.setCursor(hwx, hwy);
 | 
			
		||||
 | 
			
		||||
    display.print(HelloWorld);
 | 
			
		||||
 | 
			
		||||
    display.setCursor(utx, uty);
 | 
			
		||||
 | 
			
		||||
    display.print(fullscreen);
 | 
			
		||||
 | 
			
		||||
    display.setCursor(umx, umy);
 | 
			
		||||
 | 
			
		||||
    display.print(updatemode);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  while (display.nextPage());
 | 
			
		||||
 | 
			
		||||
  //Serial.println("helloFullScreenPartialMode done");
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void showPartialUpdate()
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  // some useful background
 | 
			
		||||
 | 
			
		||||
  helloWorld();
 | 
			
		||||
 | 
			
		||||
  // use asymmetric values for test
 | 
			
		||||
 | 
			
		||||
  uint16_t box_x = 10;
 | 
			
		||||
 | 
			
		||||
  uint16_t box_y = 15;
 | 
			
		||||
 | 
			
		||||
  uint16_t box_w = 70;
 | 
			
		||||
 | 
			
		||||
  uint16_t box_h = 20;
 | 
			
		||||
 | 
			
		||||
  uint16_t cursor_y = box_y + box_h - 6;
 | 
			
		||||
 | 
			
		||||
  if (display.epd2.WIDTH < 104) cursor_y = box_y + 6;
 | 
			
		||||
 | 
			
		||||
  float value = 13.95;
 | 
			
		||||
 | 
			
		||||
  uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
 | 
			
		||||
 | 
			
		||||
  display.setFont(&FreeMonoBold9pt7b);
 | 
			
		||||
 | 
			
		||||
  if (display.epd2.WIDTH < 104) display.setFont(0);
 | 
			
		||||
 | 
			
		||||
  display.setTextColor(GxEPD_BLACK);
 | 
			
		||||
 | 
			
		||||
  // show where the update box is
 | 
			
		||||
 | 
			
		||||
  for (uint16_t r = 0; r < 4; r++)
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    display.setRotation(r);
 | 
			
		||||
 | 
			
		||||
    display.setPartialWindow(box_x, box_y, box_w, box_h);
 | 
			
		||||
 | 
			
		||||
    display.firstPage();
 | 
			
		||||
 | 
			
		||||
    do
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
      display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
 | 
			
		||||
 | 
			
		||||
      //display.fillScreen(GxEPD_BLACK);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while (display.nextPage());
 | 
			
		||||
 | 
			
		||||
    delay(2000);
 | 
			
		||||
 | 
			
		||||
    display.firstPage();
 | 
			
		||||
 | 
			
		||||
    do
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
      display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while (display.nextPage());
 | 
			
		||||
 | 
			
		||||
    delay(1000);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  //return;
 | 
			
		||||
 | 
			
		||||
  // show updates in the update box
 | 
			
		||||
 | 
			
		||||
  for (uint16_t r = 0; r < 4; r++)
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
 | 
			
		||||
    display.setRotation(r);
 | 
			
		||||
 | 
			
		||||
    display.setPartialWindow(box_x, box_y, box_w, box_h);
 | 
			
		||||
 | 
			
		||||
    for (uint16_t i = 1; i <= 10; i += incr)
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
      display.firstPage();
 | 
			
		||||
 | 
			
		||||
      do
 | 
			
		||||
 | 
			
		||||
      {
 | 
			
		||||
 | 
			
		||||
        display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
 | 
			
		||||
 | 
			
		||||
        display.setCursor(box_x, cursor_y);
 | 
			
		||||
 | 
			
		||||
        display.print(value * i, 2);
 | 
			
		||||
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      while (display.nextPage());
 | 
			
		||||
 | 
			
		||||
      delay(500);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    delay(1000);
 | 
			
		||||
 | 
			
		||||
    display.firstPage();
 | 
			
		||||
 | 
			
		||||
    do
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
      display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while (display.nextPage());
 | 
			
		||||
 | 
			
		||||
    delay(1000);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  // put your setup code here, to run once:
 | 
			
		||||
  int result = myFunction(2, 3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  // put your main code here, to run repeatedly:
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// put function definitions here:
 | 
			
		||||
int myFunction(int x, int y) {
 | 
			
		||||
  return x + y;
 | 
			
		||||
  // put your main code here, to run repeatedly:
 | 
			
		||||
 | 
			
		||||
  digitalWrite(8, HIGH);
 | 
			
		||||
 | 
			
		||||
  delay(1000);
 | 
			
		||||
 | 
			
		||||
  digitalWrite(8, LOW);
 | 
			
		||||
 | 
			
		||||
  delay(1000);  
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user