Jean-Marc,
Thank you for your work making the waveshare e-papers more accessible with your library and spending so much time on here answering questions.
I'm using a Waveshare 2.9 B/W/Red display on a custom ESP32-based PCB. The display works perfectly but I am having a problem where after initializing the display, digitalWrite on pin 19 no longer works. I have a function that enables a voltage divider, takes a voltage reading, and outputs it to the screen.
I was trying to figure out why the getVbat function worked perfect in a standalone project but not at all in my epaper project so I inserted a bunch of labeled test points to determine when it stopped working. Here is the condensed applicable sections of code (link to full code at the bottom):
#include <Adafruit_LIS3DH.h>
#include <SPI.h>
//#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <EEPROM.h>
#include <Wire.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
#include <Preferences.h>
#include <Fonts/Roboto8.h> //Roboto_Regular8pt7b
#include <Fonts/SpecialElite10.h> //SpecialElite_Regular10pt7b
Preferences preferences;
//Initialize display:
//GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
#define VOLTS 34
#define VBAT_EN 19
#define V_CAL_A 0.003578
#define V_CAL_B 0//0.3827
void getVbat(){
int V1raw;
digitalWrite(VBAT_EN,HIGH);
V1raw=analogRead(VOLTS);
Vbat=((float)V1raw)*V_CAL_A+V_CAL_B;
Serial.print(VBAT_EN);Serial.print("=");
Serial.print(digitalRead(VBAT_EN));Serial.print(" ");
Serial.print(" Vraw=");Serial.print(V1raw);
Serial.print(" Vbat=");Serial.print(Vbat);
digitalWrite(VBAT_EN,LOW);
Serial.print(" ");Serial.print(VBAT_EN);Serial.print("=");
Serial.println(digitalRead(VBAT_EN));
}
void setup() {
analogReadResolution(11);
analogSetPinAttenuation(VOLTS, ADC_11db); //6db range 0-2.2v
pinMode(VOLTS, INPUT);
pinMode(VBAT_EN, OUTPUT);
Serial.begin(115200);
Serial.print("A "); getVbat();
// Initialize SPIFFS
if(!SPIFFS.begin(true)){
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
Serial.print("B "); getVbat();
btStop();
WiFi.mode(WIFI_OFF);
//SERVER SETUP
Serial.print("C "); getVbat();
// Route for root / web page
server.on("/wifi.html", HTTP_GET, [](AsyncWebServerRequest *request){
Serial.println("/wifi.html");
//... LOTS OF WEB SERVER CODE OMITTED
Serial.print("K "); getVbat();
display.init(); //Initialize e-paper
Serial.print("L "); getVbat();
//Setup LIS3DH Accelerometer:
lis.begin(0x19);
lis.setRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
lis.setDataRate(LIS3DH_DATARATE_100_HZ); //1,10,25,50,100,200,400,LIS3DH_DATARATE_POWERDOWN
lis.setClick(2, CLICKTHRESHHOLD, TIMELIMIT, TIMELATENCY, TIMEWINDOW);
Serial.print("M "); getVbat();
loadData(); //Load data from SPIFFS
Serial.print("N "); getVbat();
refreshDisplay();
WakeTime=millis();
}
The console output looks like this:
ets Jun 8 2016 00:22:57
rst:0x5 (DEEPSLEEP_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10088
load:0x40080400,len:6380
entry 0x400806a4
A 19=1 Vraw=967 Vbat=3.46 19=0
B 19=1 Vraw=967 Vbat=3.46 19=0
C 19=1 Vraw=965 Vbat=3.45 19=0
D 19=1 Vraw=967 Vbat=3.46 19=0
E 19=1 Vraw=966 Vbat=3.46 19=0
F 19=1 Vraw=967 Vbat=3.46 19=0
G 19=1 Vraw=966 Vbat=3.46 19=0
H 19=1 Vraw=967 Vbat=3.46 19=0
I 19=1 Vraw=967 Vbat=3.46 19=0
J 19=1 Vraw=967 Vbat=3.46 19=0
K 19=1 Vraw=967 Vbat=3.46 19=0
L 19=0 Vraw=0 Vbat=0.00 19=0
M 19=0 Vraw=0 Vbat=0.00 19=0
Reading data from EEPROM...
Read cycle time: [E][Preferences.cpp:354] getUInt(): nvs_get_u32 fail: cycleTime NOT_FOUND
N 19=0 Vraw=0 Vbat=0.00 19=0
Starting to refresh display.
Loading image '/logo1.bmp'
File size: 19062
Image Offset: 118
Header size: 40
Bit Depth: 4
Image size: 128x296
loaded in 68 ms
Done refreshing display.
If you notice, between battery reads "K" and "L" the VOLTS_EN pin (19) is no longer HIGH. The only thing that happens in the code between K and L is initializing the display:
Serial.print("K "); getVbat();
display.init(); //Initialize e-paper
Serial.print("L "); getVbat();
Link to full code: here
Am I doing something wrong?