Last active
January 30, 2023 05:39
-
-
Save katsuyoshi/8cfe58c5cfe463f33643b0abd85cd23d to your computer and use it in GitHub Desktop.
M5Stamp picoで1.9inch Segment e-Paper Moduleのサンプルプログラムを試して見る。からの温湿度計に
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <stdlib.h> | |
#include "EPD_1in9.h" | |
//////////////////////////////////////full screen update LUT//////////////////////////////////////////// | |
unsigned char DSPNUM_1in9_on[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; // all black | |
unsigned char DSPNUM_1in9_off[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; // all white | |
unsigned char DSPNUM_1in9_WB[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; // All black font | |
unsigned char DSPNUM_1in9_W0[] = {0x00, 0xbf, 0x1f, 0xbf, 0x1f, 0xbf, 0x1f, 0xbf, 0x1f, 0xbf, 0x1f, 0xbf, 0x1f, 0x00, 0x00, }; // 0 | |
unsigned char DSPNUM_1in9_W1[] = {0xff, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, }; // 1 | |
unsigned char DSPNUM_1in9_W2[] = {0x00, 0xfd, 0x17, 0xfd, 0x17, 0xfd, 0x17, 0xfd, 0x17, 0xfd, 0x17, 0xfd, 0x37, 0x00, 0x00, }; // 2 | |
unsigned char DSPNUM_1in9_W3[] = {0x00, 0xf5, 0x1f, 0xf5, 0x1f, 0xf5, 0x1f, 0xf5, 0x1f, 0xf5, 0x1f, 0xf5, 0x1f, 0x00, 0x00, }; // 3 | |
unsigned char DSPNUM_1in9_W4[] = {0x00, 0x47, 0x1f, 0x47, 0x1f, 0x47, 0x1f, 0x47, 0x1f, 0x47, 0x1f, 0x47, 0x3f, 0x00, 0x00, }; // 4 | |
unsigned char DSPNUM_1in9_W5[] = {0x00, 0xf7, 0x1d, 0xf7, 0x1d, 0xf7, 0x1d, 0xf7, 0x1d, 0xf7, 0x1d, 0xf7, 0x1d, 0x00, 0x00, }; // 5 | |
unsigned char DSPNUM_1in9_W6[] = {0x00, 0xff, 0x1d, 0xff, 0x1d, 0xff, 0x1d, 0xff, 0x1d, 0xff, 0x1d, 0xff, 0x3d, 0x00, 0x00, }; // 6 | |
unsigned char DSPNUM_1in9_W7[] = {0x00, 0x21, 0x1f, 0x21, 0x1f, 0x21, 0x1f, 0x21, 0x1f, 0x21, 0x1f, 0x21, 0x1f, 0x00, 0x00, }; // 7 | |
unsigned char DSPNUM_1in9_W8[] = {0x00, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x1f, 0xff, 0x3f, 0x00, 0x00, }; // 8 | |
unsigned char DSPNUM_1in9_W9[] = {0x00, 0xf7, 0x1f, 0xf7, 0x1f, 0xf7, 0x1f, 0xf7, 0x1f, 0xf7, 0x1f, 0xf7, 0x1f, 0x00, 0x00, }; // 9 | |
unsigned char VAR_Temperature=20; | |
/****************************************************************************** | |
function : GPIO Init | |
parameter: | |
******************************************************************************/ | |
void GPIOInit(void) | |
{ | |
pinMode(EPD_BUSY_PIN, INPUT); | |
pinMode(EPD_RST_PIN, OUTPUT); | |
} | |
/****************************************************************************** | |
function : Software reset | |
parameter: | |
******************************************************************************/ | |
void EPD_1in9_Reset(void) | |
{ | |
digitalWrite(EPD_RST_PIN, 1); | |
delay(200); | |
digitalWrite(EPD_RST_PIN, 0); | |
delay(20); | |
digitalWrite(EPD_RST_PIN, 1); | |
delay(200); | |
} | |
/****************************************************************************** | |
function : send command | |
parameter: | |
Reg : Command register | |
******************************************************************************/ | |
void EPD_1in9_SendCommand(unsigned char Reg) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(Reg); | |
Wire.endTransmission(false); | |
} | |
/****************************************************************************** | |
function : send data | |
parameter: | |
Data : Write data | |
******************************************************************************/ | |
void EPD_1in9_SendData(unsigned char Data) | |
{ | |
Wire.beginTransmission(adds_data); | |
Wire.write(Data); | |
Wire.endTransmission(); | |
} | |
/****************************************************************************** | |
function : read command | |
parameter: | |
Reg : Command register | |
******************************************************************************/ | |
unsigned char EPD_1in9_readCommand(unsigned char Reg) | |
{ | |
unsigned char a; | |
Wire.beginTransmission(adds_com); | |
delay(10); | |
Wire.write(Reg); | |
a = Wire.read(); | |
Wire.endTransmission(); | |
return a; | |
} | |
/****************************************************************************** | |
function : read data | |
parameter: | |
Data : Write data | |
******************************************************************************/ | |
unsigned char EPD_1in9_readData(unsigned char Data) | |
{ | |
unsigned char a; | |
Wire.beginTransmission(adds_data); | |
delay(10); | |
Wire.write(Data); | |
a = Wire.read(); | |
Wire.endTransmission(); | |
return a; | |
} | |
/****************************************************************************** | |
function : Wait until the busy_pin goes LOW | |
parameter: | |
******************************************************************************/ | |
void EPD_1in9_ReadBusy(void) | |
{ | |
Serial.println("e-Paper busy"); | |
delay(10); | |
while(1) | |
{ //=1 BUSY; | |
if(digitalRead(EPD_BUSY_PIN)==1) | |
break; | |
delay(1); | |
} | |
delay(10); | |
Serial.println("e-Paper busy release"); | |
} | |
/* | |
# DU waveform white extinction diagram + black out diagram | |
# Bureau of brush waveform | |
*/ | |
void EPD_1in9_lut_DU_WB(void) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(0x82); | |
Wire.write(0x80); | |
Wire.write(0x00); | |
Wire.write(0xC0); | |
Wire.write(0x80); | |
Wire.write(0x80); | |
Wire.write(0x62); | |
Wire.endTransmission(); | |
} | |
/* | |
# GC waveform | |
# The brush waveform | |
*/ | |
void EPD_1in9_lut_GC(void) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(0x82); | |
Wire.write(0x20); | |
Wire.write(0x00); | |
Wire.write(0xA0); | |
Wire.write(0x80); | |
Wire.write(0x40); | |
Wire.write(0x63); | |
Wire.endTransmission(); | |
} | |
/* | |
# 5 waveform better ghosting | |
# Boot waveform | |
*/ | |
void EPD_1in9_lut_5S(void) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(0x82); | |
Wire.write(0x28); | |
Wire.write(0x20); | |
Wire.write(0xA8); | |
Wire.write(0xA0); | |
Wire.write(0x50); | |
Wire.write(0x65); | |
Wire.endTransmission(); | |
} | |
/* | |
# temperature measurement | |
# You are advised to periodically measure the temperature and modify the driver parameters | |
# If an external temperature sensor is available, use an external temperature sensor | |
*/ | |
void EPD_1in9_Temperature(void) | |
{ | |
Wire.beginTransmission(adds_com); | |
if( VAR_Temperature < 10 ) | |
{ | |
Wire.write(0x7E); | |
Wire.write(0x81); | |
Wire.write(0xB4); | |
} | |
else | |
{ | |
Wire.write(0x7E); | |
Wire.write(0x81); | |
Wire.write(0xB4); | |
} | |
Wire.endTransmission(); | |
delay(10); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xe7); // Set default frame time | |
// Set default frame time | |
if(VAR_Temperature<5) | |
Wire.write(0x31); // 0x31 (49+1)*20ms=1000ms | |
else if(VAR_Temperature<10) | |
Wire.write(0x22); // 0x22 (34+1)*20ms=700ms | |
else if(VAR_Temperature<15) | |
Wire.write(0x18); // 0x18 (24+1)*20ms=500ms | |
else if(VAR_Temperature<20) | |
Wire.write(0x13); // 0x13 (19+1)*20ms=400ms | |
else | |
Wire.write(0x0e); // 0x0e (14+1)*20ms=300ms | |
Wire.endTransmission(); | |
} | |
/* | |
# Note that the size and frame rate of V0 need to be set during initialization, | |
# otherwise the local brush will not be displayed | |
*/ | |
void EPD_1in9_init(void) | |
{ | |
unsigned char i = 0; | |
EPD_1in9_Reset(); | |
delay(100); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0x2B); // POWER_ON | |
Wire.endTransmission(); | |
delay(10); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xA7); // boost | |
Wire.write(0xE0); // TSON | |
Wire.endTransmission(); | |
delay(10); | |
EPD_1in9_Temperature(); | |
} | |
void EPD_1in9_Write_Screen( unsigned char *image) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xAC); // Close the sleep | |
Wire.write(0x2B); // turn on the power | |
Wire.write(0x40); // Write RAM address | |
Wire.write(0xA9); // Turn on the first SRAM | |
Wire.write(0xA8); // Shut down the first SRAM | |
Wire.endTransmission(); | |
Wire.beginTransmission(adds_data); | |
for(char j = 0 ; j<15 ; j++ ) | |
Wire.write(image[j]); | |
Wire.write(0x00); | |
Wire.endTransmission(); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xAB); // Turn on the second SRAM | |
Wire.write(0xAA); // Shut down the second SRAM | |
Wire.write(0xAF); // display on | |
Wire.endTransmission(); | |
EPD_1in9_ReadBusy(); | |
//delay(2000); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xAE); // display off | |
Wire.write(0x28); // HV OFF | |
Wire.write(0xAD); // sleep in | |
Wire.endTransmission(); | |
} | |
void EPD_1in9_Write_Screen1( unsigned char *image) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xAC); // Close the sleep | |
Wire.write(0x2B); // turn on the power | |
Wire.write(0x40); // Write RAM address | |
Wire.write(0xA9); // Turn on the first SRAM | |
Wire.write(0xA8); // Shut down the first SRAM | |
Wire.endTransmission(); | |
Wire.beginTransmission(adds_data); | |
for(char j = 0 ; j<15 ; j++ ) | |
Wire.write(image[j]); | |
Wire.write(0x03); | |
Wire.endTransmission(); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xAB); // Turn on the second SRAM | |
Wire.write(0xAA); // Shut down the second SRAM | |
Wire.write(0xAF); // display on | |
Wire.endTransmission(); | |
EPD_1in9_ReadBusy(); | |
//delay(2000); | |
Wire.beginTransmission(adds_com); | |
Wire.write(0xAE); // display off | |
Wire.write(0x28); // HV OFF | |
Wire.write(0xAD); // sleep in | |
Wire.endTransmission(); | |
} | |
void EPD_1in9_sleep(void) | |
{ | |
Wire.beginTransmission(adds_com); | |
Wire.write(0x28); // POWER_OFF | |
EPD_1in9_ReadBusy(); | |
Wire.write(0xAC); // DEEP_SLEEP | |
Wire.endTransmission(); | |
delay(2000); | |
// digitalWrite(EPD_RST_PIN, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _EPD_1in9_H_ | |
#define _EPD_1in9_H_ | |
#include <Arduino.h> | |
#include <Wire.h> | |
#include <stdlib.h> | |
// address | |
#define adds_com 0x3C | |
#define adds_data 0x3D | |
#define EPD_BUSY_PIN 19 | |
#define EPD_RST_PIN 18 | |
extern unsigned char DSPNUM_1in9_on[]; | |
extern unsigned char DSPNUM_1in9_off[]; | |
extern unsigned char DSPNUM_1in9_WB[]; | |
extern unsigned char DSPNUM_1in9_W0[]; | |
extern unsigned char DSPNUM_1in9_W1[]; | |
extern unsigned char DSPNUM_1in9_W2[]; | |
extern unsigned char DSPNUM_1in9_W3[]; | |
extern unsigned char DSPNUM_1in9_W4[]; | |
extern unsigned char DSPNUM_1in9_W5[]; | |
extern unsigned char DSPNUM_1in9_W6[]; | |
extern unsigned char DSPNUM_1in9_W7[]; | |
extern unsigned char DSPNUM_1in9_W8[]; | |
extern unsigned char DSPNUM_1in9_W9[]; | |
void GPIOInit(void); | |
void EPD_1in9_Reset(void); | |
void EPD_1in9_SendCommand(unsigned char Reg); | |
void EPD_1in9_SendData(unsigned char Data); | |
unsigned char EPD_1in9_readCommand(unsigned char Reg); | |
unsigned char EPD_1in9_readData(unsigned char Data); | |
void EPD_1in9_ReadBusy(void); | |
void EPD_1in9_lut_DU_WB(void); | |
void EPD_1in9_lut_GC(void); | |
void EPD_1in9_lut_5S(void); | |
void EPD_1in9_Temperature(void); | |
void EPD_1in9_init(void); | |
void EPD_1in9_Write_Screen(unsigned char *image); | |
void EPD_1in9_Write_Screen1(unsigned char *image); | |
void EPD_1in9_sleep(void); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include "EPD_1in9.h" | |
#include <M5Unified.h> | |
#include <Adafruit_Sensor.h> | |
#include <DHT.h> | |
#include <DHT_U.h> | |
#define I2C_SDA_PIN 21 | |
#define I2C_SCL_PIN 22 | |
#define DHTPIN 26 // Digital pin connected to the DHT sensor | |
#define DHTTYPE DHT11 // DHT 11 | |
#define INTERVAL_MS (30 * 1000) | |
DHT_Unified dht(DHTPIN, DHTTYPE); | |
uint32_t delayMS; | |
float temperature = 0.0; | |
float humidity = 0.0; | |
unsigned long wake_at; | |
void setup_epd_1in9() | |
{ | |
GPIOInit(); | |
EPD_1in9_init(); | |
EPD_1in9_lut_5S(); | |
EPD_1in9_Write_Screen(DSPNUM_1in9_off); | |
delay(500); | |
EPD_1in9_lut_GC(); | |
EPD_1in9_Write_Screen1(DSPNUM_1in9_on); | |
delay(500); | |
EPD_1in9_Write_Screen(DSPNUM_1in9_off); | |
delay(500); | |
EPD_1in9_lut_DU_WB(); | |
} | |
void setup_dht11() { | |
dht.begin(); | |
sensor_t sensor; | |
dht.temperature().getSensor(&sensor); | |
dht.humidity().getSensor(&sensor); | |
delayMS = sensor.min_delay / 1000; | |
} | |
void display_digit(unsigned char buff[], int digit, char num) { | |
static unsigned char *buffers[] = { | |
DSPNUM_1in9_W0, | |
DSPNUM_1in9_W1, | |
DSPNUM_1in9_W2, | |
DSPNUM_1in9_W3, | |
DSPNUM_1in9_W4, | |
DSPNUM_1in9_W5, | |
DSPNUM_1in9_W6, | |
DSPNUM_1in9_W7, | |
DSPNUM_1in9_W8, | |
DSPNUM_1in9_W9 | |
}; | |
if (digit == 0) { | |
switch (num) { | |
case '1': | |
buff[0] = buffers[num - '0'][0]; | |
break; | |
default: | |
buff[0] = 0x00; | |
break; | |
} | |
} else { | |
unsigned int loc = digit * 2 - 1; | |
switch (num) { | |
case '0': | |
case '1': | |
case '2': | |
case '3': | |
case '4': | |
case '5': | |
case '6': | |
case '7': | |
case '8': | |
case '9': | |
buff[loc] = buffers[num - '0'][loc]; | |
loc++; | |
buff[loc] = buffers[num - '0'][loc]; | |
break; | |
default: | |
buff[loc] = 0x00; | |
loc++; | |
buff[loc] = 0x00; | |
} | |
} | |
} | |
#define EPD_BUFF_SIZE 15 | |
void display() { | |
static unsigned char ex_buff[EPD_BUFF_SIZE] = {0}; | |
static unsigned char buff[EPD_BUFF_SIZE] = {0}; | |
char str[16] = {0}; | |
sprintf(str, "%5.1f%5.1f", temperature, humidity); | |
display_digit(buff, 0, str[0]); | |
display_digit(buff, 1, str[1]); | |
display_digit(buff, 2, str[2]); | |
display_digit(buff, 6, str[4]); | |
display_digit(buff, 3, str[6]); | |
display_digit(buff, 4, str[7]); | |
display_digit(buff, 5, str[9]); | |
/* dot & % */ | |
buff[2 * 2] |= 0x20; | |
buff[4 * 2] |= 0x20; | |
buff[5 * 2] |= 0x20; | |
/* c or f */ | |
buff[13] = 0x5; // Celsius | |
// buff[13] = 0x6; // Fahrenheit | |
/* bluetooth */ | |
buff[13] |= 0x08; | |
/* battery */ | |
buff[13] |= 0x10; | |
if (memcmp(ex_buff, buff, EPD_BUFF_SIZE) != 0) { | |
Serial.println("update"); | |
EPD_1in9_Write_Screen(buff); | |
delay(500); | |
memcpy(ex_buff, buff, EPD_BUFF_SIZE); | |
} | |
} | |
void awake() { | |
Serial.println("awake"); | |
wake_at = millis(); | |
} | |
void sleep() { | |
Serial.println("sleep"); | |
delay(100); | |
unsigned long now = millis(); | |
unsigned long past_mills = now - wake_at; | |
uint64_t sleep_us = (uint64_t)(INTERVAL_MS - past_mills) * (uint64_t)1000; | |
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); | |
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF); | |
esp_sleep_pd_config(ESP_PD_DOMAIN_MAX, ESP_PD_OPTION_OFF); | |
esp_sleep_enable_timer_wakeup(sleep_us); | |
esp_light_sleep_start(); | |
awake(); | |
} | |
void setup() { | |
auto cfg = M5.config(); | |
M5.begin(cfg); | |
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN); | |
setup_epd_1in9(); | |
setup_dht11(); | |
awake(); | |
} | |
void loop() { | |
// 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 { | |
Serial.print(F("Temperature: ")); | |
Serial.print(event.temperature); | |
Serial.println(F("°C")); | |
temperature = max(event.temperature, 0.0f); | |
} | |
// Get humidity event and print its value. | |
dht.humidity().getEvent(&event); | |
if (isnan(event.relative_humidity)) { | |
Serial.println(F("Error reading humidity!")); | |
} | |
else { | |
humidity = event.relative_humidity; | |
Serial.print(F("Humidity: ")); | |
Serial.print(event.relative_humidity); | |
Serial.println(F("%")); | |
display(); | |
sleep(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; PlatformIO Project Configuration File | |
; | |
; Build options: build flags, source filter | |
; Upload options: custom upload port, speed and extra flags | |
; Library options: dependencies, extra library storages | |
; Advanced options: extra scripting | |
; | |
; Please visit documentation for the other options and examples | |
; https://docs.platformio.org/page/projectconf.html | |
[env:m5stack-atom] | |
platform = espressif32 | |
board = m5stack-atom | |
framework = arduino | |
lib_deps = | |
m5stack/M5Unified@^0.1.1 | |
adafruit/DHT sensor library@^1.4.4 | |
monitor_speed = 115200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment