Skip to content

Commit

Permalink
low power update mode added
Browse files Browse the repository at this point in the history
Enabled saving of framebuffer on external flash during power off
  • Loading branch information
RobPo committed Nov 19, 2020
1 parent 2e55e33 commit f57cb88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
38 changes: 17 additions & 21 deletions examples/06_WeatherForecast/06_WeatherForecast.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void setup(void) {
digitalWrite(SPI_FLASH_CS, HIGH); // to save power...

epd.begin(); // Turn ON & initialize 1.1" EPD
epd.loadFromFlash(ADDR_PIC1, 0); // Load an image from external flash
epd.loadFromFlash(ADDR_PIC1, 0); // Load an pic from external flash
epd.saveFBToFlash(ADDR_FRAMEBUFFER);// And save it to external framebuffer on flash
epd.update(); // Update EPD
epd.end(); // to save power...
digitalWrite(RFM_NSS, LOW); // to save power...
Expand All @@ -88,7 +89,7 @@ void loop(){
v_scap = analogRead(A7); // Measure V_scap
digitalWrite(SW_TFT, HIGH); // Turn OFF voltage divider

if (v_scap >= 640) { // Proceed only if (Vscap > 4,2V)--> DEFAULT!
if (v_scap >= 620) { // Proceed only if (Vscap > 4,0V)--> DEFAULT for 1.5F!
if (++app.Counter%2) { // Every two hours...
app.LoRaWAN_message_interval=58;

Expand All @@ -98,7 +99,6 @@ void loop(){

SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
//digitalWrite(RFM_NSS, HIGH);
epd.begin(false); // Turn ON EPD without refresh to save power
lorawan.init(); // Init the RFM95 module

Expand All @@ -107,7 +107,8 @@ void loop(){
lorawan.LORA_send_and_receive(); // LoRaWAN send_and_receive
if (lora.RX.Data[6] == 25) // Downlink data received?
ndr++; // if not increase nodatareceived (ndr) counter


epd.loadFromFlash(ADDR_FRAMEBUFFER); // Load last image to pre-buffer
epd.printText("Weather ", 1, 2, 1); // Header line

String leadingDay = "";
Expand Down Expand Up @@ -181,35 +182,30 @@ void loop(){
epd.fillRectLM(97 , 41, 4, 1, EPD_BLACK);
epd.fillRectLM(102, 41, 4, 1, EPD_BLACK);
epd.fillRectLM(107, 41, 4, 1, EPD_BLACK);
uint8_t r1 = uint8_t(lora.RX.Data[6]) / 5;
uint8_t r2 = uint8_t(lora.RX.Data[7]) / 5;
uint8_t r3 = uint8_t(lora.RX.Data[8]) / 5;
uint8_t r1 = uint8_t(lora.RX.Data[6]) / 5;
uint8_t r2 = uint8_t(lora.RX.Data[7]) / 5;
uint8_t r3 = uint8_t(lora.RX.Data[8]) / 5;
uint8_t r4 = uint8_t(lora.RX.Data[9]) / 5;
uint8_t r5 = uint8_t(lora.RX.Data[10]) / 5;
if(r1 > 20)
r1 = 20;
if(r2 > 20)
r2 = 20;
if(r3 > 20)
r3 = 20;
if(r4 > 20)
r4 = 20;
if(r5 > 20)
r5 = 20;

epd.fillRectLM(87 , 39, 4, r1, EPD_BLACK);
epd.fillRectLM(92 , 39, 4, r2, EPD_BLACK);
epd.fillRectLM(97 , 39, 4, r3, EPD_BLACK);
epd.fillRectLM(102, 39, 4, r4, EPD_BLACK);
epd.fillRectLM(107, 39, 4, r5, EPD_BLACK);

epd.printText("V " + String(v_scap*3.3/1023*2, 1), 115, 20, 1); // Plot last known voltage
epd.printText("U " + String(app.Counter/2+1) , 115, 30, 1); // Plot how many syncs have been tried
epd.printText("D " + String(app.Counter/2+1 - ndr), 115, 40, 1); // Plot how many downlinks were empty

epd.update(); // Send the framebuffer and do the update

epd.saveFBToFlash(ADDR_FRAMEBUFFER);
if (v_scap > 640)
epd.update(); // Trigger a 900ms default update (4GL)
else
epd.update(EPD_UPD_MONO); // Trigger a 450ms low power update (2GL)

epd.end(); // To save power...
digitalWrite(RFM_NSS, LOW); // To save power...
flash_power_down(); // To save power...
SPI.endTransaction(); // To save power...
SPI.end(); // To save power...
}
Expand Down
8 changes: 5 additions & 3 deletions examples/06_WeatherForecast/PL_microEPD44.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void PL_microEPD::begin(bool whiteErase) {
if (whiteErase)
WhiteErase(); //Start with a white refresh if TRUE
clear();

}

// ************************************************************************************
Expand Down Expand Up @@ -148,7 +149,7 @@ void PL_microEPD::update(int updateMode) {
case 2:
writeRegister(EPD_DRIVERVOLTAGE, 0x25, 0xFF, -1, -1); //Vgate=+17V/-25V, Vsource=+/-15V
writeRegister(EPD_PROGRAMMTP, 0x02, -1, -1, -1); //Use mono waveform
writeRegister(EPD_DISPLAYENGINE, 0x07, -1, -1, -1); //Only changing pixels updated
writeRegister(EPD_DISPLAYENGINE, 0x03, -1, -1, -1); //Only changing pixels updated
break;
case 3:
writeRegister(EPD_DRIVERVOLTAGE, 0x25, 0xFF, -1, -1); //Vgate=+15V/-20V, Vsource=+/-12V
Expand Down Expand Up @@ -341,10 +342,11 @@ void PL_microEPD::WhiteErase() {
}

void PL_microEPD::saveFBToFlash(int address) {
flash_eraseSector(0);
flash_eraseSector(address);
flash_eraseSector(address + 4096);
writeRegister(EPD_WRITEPXRECTSET, 0, 69, 0, 147);
writeRegister(EPD_PIXELACESSPOS, 0, 0, -1, -1);
for (int i=0; i<15; i++) {
for (int i=0; i<18; i++) {
digitalWrite(cs, LOW);
SPI.transfer(0x11 | EPD_REGREAD);
for (int j=0; j < sizeof(buffer); j++) //144 bytes
Expand Down

0 comments on commit f57cb88

Please sign in to comment.