Skip to content

Commit be31e11

Browse files
committed
Added sdCardSleep
1 parent 58aacfe commit be31e11

File tree

10 files changed

+81
-35
lines changed

10 files changed

+81
-35
lines changed

examples/Inkplate10/Advanced_Inkplate_Features/Inkplate_SD_Pictures/Inkplate_SD_Pictures.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Inkplate_SD_BMP example for Soldered Inkplate6
33
For this example you will need a micro USB cable, Inkplate6 and a SD card loaded with
44
image1.bmp and image2.bmp file that can be found inside folder of this example.
5-
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Select "Inkplate 10(ESP32)" or "Soldered Inkplate10" from Tools -> Board menu.
66
Don't have "Inkplate 10(ESP32)" option? Follow our tutorial and add it:
77
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
88
@@ -23,7 +23,7 @@
2323

2424
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
2525
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
26-
#error "Wrong board selection for this example, please select Inkplate 10 or Inkplate 10 V2 in the boards menu."
26+
#error "Wrong board selection for this example, please select Inkplate 10 or Soldered Inkplate10 in the boards menu."
2727
#endif
2828

2929
#include "Inkplate.h" //Include Inkplate library to the sketch
@@ -38,6 +38,7 @@ void setup()
3838
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
3939
display.clearDisplay(); // Clear frame buffer of display
4040
display.display(); // Put clear image on display
41+
display.setTextSize(5);
4142

4243
// Init SD card. Display if SD card is init propery or not.
4344
if (display.sdCardInit())
@@ -90,6 +91,7 @@ void setup()
9091
display.display();
9192
}
9293
display.display();
94+
display.sdCardSleep(); // Put sd card in sleep mode
9395
}
9496

9597
void loop()

examples/Inkplate10/Advanced_Inkplate_Features/Inkplate_SD_TXT_File/Inkplate_SD_TXT_File.ino

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Inkplate_SD_TXT example for Soldered Inkplate 10
33
For this example you will need only a micro USB cable, Inkplate 10 and a SD card
44
loaded with text.txt file that can be found inside folder of this example.
5-
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Select "Inkplate 10(ESP32)" or "Soldered Inkplate10" from Tools -> Board menu.
66
Don't have "Inkplate 10(ESP32)" option? Follow our tutorial and add it:
77
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
88
@@ -21,7 +21,7 @@
2121

2222
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
2323
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
24-
#error "Wrong board selection for this example, please select Inkplate 10 or Inkplate 10 V2 in the boards menu."
24+
#error "Wrong board selection for this example, please select Inkplate 10 or Soldered Inkplate10 in the boards menu."
2525
#endif
2626

2727
#include "Inkplate.h" //Include Inkplate library to the sketch
@@ -34,6 +34,7 @@ void setup()
3434
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
3535
display.clearDisplay(); // Clear frame buffer of display
3636
display.display(); // Put clear image on display
37+
display.setTextSize(5);
3738

3839
// Init SD card. Display if SD card is init propery or not.
3940
if (display.sdCardInit())
@@ -46,6 +47,7 @@ void setup()
4647
{ // If it fails to open, send error message to display, otherwise read the file.
4748
display.println("File open error");
4849
display.display();
50+
display.sdCardSleep();
4951
}
5052
else
5153
{
@@ -54,16 +56,18 @@ void setup()
5456
char text[201]; // Array where data from SD card is stored (max 200 chars here)
5557
int len = file.fileSize(); // Read how big is file that we are opening
5658
if (len > 200)
57-
len = 200; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
58-
file.read(text, len); // Read data from file and save it in text array
59-
text[len] = 0; // Put null terminating char at the and of data
60-
display.print(text); // Print data/text
61-
display.display(); // Do a full refresh of display
59+
len = 200; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
60+
file.read(text, len); // Read data from file and save it in text array
61+
text[len] = 0; // Put null terminating char at the and of data
62+
display.print(text); // Print data/text
63+
display.display(); // Do a full refresh of display
64+
display.sdCardSleep(); // Put sd card in sleep mode
6265
}
6366
}
6467
else
6568
{ // If card init was not successful, display error on screen and stop the program (using infinite loop)
6669
display.println("SD Card error!");
70+
display.sdCardSleep();
6771
display.partialUpdate();
6872
while (true)
6973
;

examples/Inkplate6/Advanced_Inkplate_Features/Inkplate_SD_Pictures/Inkplate_SD_Pictures.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Inkplate_SD_BMP example for Soldered Inkplate6
33
For this example you will need a micro USB cable, Inkplate6 and a SD card loaded with
44
image1.bmp and image2.bmp file that can be found inside folder of this example.
5-
Select "Inkplate 6(ESP32)" from Tools -> Board menu.
5+
Select "Inkplate 6(ESP32)" or "Soldered Inkplate6" from Tools -> Board menu.
66
Don't have "Inkplate 6(ESP32)" option? Follow our tutorial and add it:
77
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
88
@@ -23,7 +23,7 @@
2323

2424
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
2525
#if !defined(ARDUINO_ESP32_DEV) && !defined(ARDUINO_INKPLATE6V2)
26-
#error "Wrong board selection for this example, please select Inkplate 6 or Inkplate 6 V2 in the boards menu."
26+
#error "Wrong board selection for this example, please select Inkplate 6 or Soldered Inkplate6 in the boards menu."
2727
#endif
2828

2929
#include "Inkplate.h" //Include Inkplate library to the sketch
@@ -62,7 +62,7 @@ void setup()
6262
}
6363
else
6464
{
65-
// If SD card init not success, display error on screen and stop the program (using infinite loop)
65+
// If SD card init not success, display error on screen, and stop the program (using infinite loop)
6666
display.println("SD Card error!");
6767
display.partialUpdate();
6868
while (true)
@@ -90,6 +90,7 @@ void setup()
9090
display.display();
9191
}
9292
display.display();
93+
display.sdCardSleep();
9394
}
9495

9596
void loop()

examples/Inkplate6/Advanced_Inkplate_Features/Inkplate_SD_TXT_File/Inkplate_SD_TXT_File.ino

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Inkplate_SD_TXT example for Soldered Inkplate 6
33
For this example you will need only a micro USB cable, Inkplate 6 and a SD card
44
loaded with text.txt file that can be found inside folder of this example.
5-
Select "Inkplate 6(ESP32)" from Tools -> Board menu.
5+
Select "Inkplate 6(ESP32)" or "Soldered Inkplate6" from Tools -> Board menu.
66
Don't have "Inkplate 6(ESP32)" option? Follow our tutorial and add it:
77
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
88
@@ -21,7 +21,7 @@
2121

2222
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
2323
#if !defined(ARDUINO_ESP32_DEV) && !defined(ARDUINO_INKPLATE6V2)
24-
#error "Wrong board selection for this example, please select Inkplate 6 or Inkplate 6 V2 in the boards menu."
24+
#error "Wrong board selection for this example, please select Inkplate 6 or Soldered Inkplate6 in the boards menu."
2525
#endif
2626

2727
#include "Inkplate.h" //Include Inkplate library to the sketch
@@ -43,8 +43,9 @@ void setup()
4343

4444
// Try to load text with max lenght of 200 chars.
4545
if (!file.open("/text.txt", O_RDONLY))
46-
{ // If it fails to open, send error message to display, otherwise read the file.
46+
{ // If it fails to open, send error message to display and put sd card in sleep mode, otherwise read the file.
4747
display.println("File open error");
48+
display.sdCardSleep();
4849
display.display();
4950
}
5051
else
@@ -54,16 +55,18 @@ void setup()
5455
char text[201]; // Array where data from SD card is stored (max 200 chars here)
5556
int len = file.fileSize(); // Read how big is file that we are opening
5657
if (len > 200)
57-
len = 200; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
58-
file.read(text, len); // Read data from file and save it in text array
59-
text[len] = 0; // Put null terminating char at the and of data
60-
display.print(text); // Print data/text
61-
display.display(); // Do a full refresh of display
58+
len = 200; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
59+
file.read(text, len); // Read data from file and save it in text array
60+
text[len] = 0; // Put null terminating char at the and of data
61+
display.print(text); // Print data/text
62+
display.sdCardSleep(); // Put sd card in sleep mode
63+
display.display(); // Do a full refresh of display
6264
}
6365
}
6466
else
6567
{ // If card init was not successful, display error on screen and stop the program (using infinite loop)
6668
display.println("SD Card error!");
69+
display.sdCardSleep();
6770
display.partialUpdate();
6871
while (true)
6972
;

examples/Inkplate6COLOR/Advanced_Inkplate_Features/Inkplate_SD_Pictures/Inkplate_SD_Pictures.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void setup()
7676
{
7777
Serial.println("Image error.");
7878
}
79+
80+
display.sdCardSleep(); // Put sd card in sleep mode
7981
}
8082

8183
void loop()

examples/Inkplate6COLOR/Advanced_Inkplate_Features/Inkplate_SD_TXT_File/Inkplate_SD_TXT_File.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,19 @@ void setup()
5656
char text[3001]; // Array where data from SD card is stored (max 200 chars here)
5757
int len = file.fileSize(); // Read how big is file that we are opening
5858
if (len > 3000)
59-
len = 3000; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
60-
file.read(text, len); // Read data from file and save it in text array
61-
text[len] = 0; // Put null terminating char at the and of data
62-
display.print(text); // Print data/text
63-
display.display(); // Do a full refresh of display
59+
len = 3000; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
60+
file.read(text, len); // Read data from file and save it in text array
61+
text[len] = 0; // Put null terminating char at the and of data
62+
display.print(text); // Print data/text
63+
display.sdCardSleep(); // Put sd card in sleep mode
64+
display.display(); // Do a full refresh of display
6465
}
6566
}
6667
else
67-
{ // If card init was not successful, display error on screen and stop the program (using infinite loop)
68+
{ // If card init was not successful, display error on screen, put sd card in sleep mode, and stop the program
69+
// (using infinite loop)
6870
display.println("SD Card error!");
71+
display.sdCardSleep();
6972
display.display();
7073
while (true)
7174
;

examples/Inkplate6PLUS/Advanced_Inkplate_Features/Inkplate_SD_Pictures/Inkplate_SD_Pictures.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Inkplate_SD_BMP example for Soldered Inkplate 6PLUS
33
For this example you will need a micro USB cable, Inkplate 6PLUS and a SD card loaded with
44
image1.bmp and image2.bmp file that can be found inside folder of this example.
5-
Select "Inkplate 6PLUS(ESP32)" from Tools -> Board menu.
5+
Select "Inkplate 6PLUS(ESP32)" or "Soldered Inkplate 6Plus" from Tools -> Board menu.
66
Don't have "Inkplate 6PLUS(ESP32)" option? Follow our tutorial and add it:
77
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
88
@@ -23,7 +23,8 @@
2323

2424
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
2525
#if !defined(ARDUINO_INKPLATE6PLUS) && !defined(ARDUINO_INKPLATE6PLUSV2)
26-
#error "Wrong board selection for this example, please select Inkplate 6PLUS or Inkplate 6PLUS V2 in the boards menu."
26+
#error \
27+
"Wrong board selection for this example, please select Inkplate 6PLUS or Soldered Inkplate 6Plus V2 in the boards menu."
2728
#endif
2829

2930
#include "Inkplate.h" //Include Inkplate library to the sketch
@@ -76,6 +77,8 @@ void setup()
7677
display.drawBitmapFromSd(&file, 0, 0);
7778
display.display();
7879
}
80+
81+
display.sdCardSleep(); // Put sd card in sleep mode
7982
}
8083

8184
void loop()

examples/Inkplate6PLUS/Advanced_Inkplate_Features/Inkplate_SD_TXT_File/Inkplate_SD_TXT_File.ino

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Inkplate_SD_TXT example for Soldered Inkplate 6PLUS
33
For this example you will need only a micro USB cable, Inkplate 6PLUS and a SD card
44
loaded with text.txt file that can be found inside folder of this example.
5-
Select "Inkplate 6PLUS(ESP32)" from Tools -> Board menu.
5+
Select "Inkplate 6PLUS(ESP32)" or "Soldered Inkplate 6Plus" from Tools -> Board menu.
66
Don't have "Inkplate 6PLUS(ESP32)" option? Follow our tutorial and add it:
77
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
88
@@ -21,7 +21,8 @@
2121

2222
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
2323
#if !defined(ARDUINO_INKPLATE6PLUS) && !defined(ARDUINO_INKPLATE6PLUSV2)
24-
#error "Wrong board selection for this example, please select Inkplate 6PLUS or Inkplate 6PLUS V2 in the boards menu."
24+
#error \
25+
"Wrong board selection for this example, please select Inkplate 6PLUS or Soldered Inkplate 6Plus in the boards menu."
2526
#endif
2627

2728
#include "Inkplate.h" //Include Inkplate library to the sketch
@@ -46,26 +47,30 @@ void setup()
4647
if (!file.open("/text.txt", O_RDONLY))
4748
{ // If it fails to open, send error message to display, otherwise read the file.
4849
display.println("File open error");
50+
display.sdCardSleep();
4951
display.display();
5052
}
5153
else
5254
{
5355
display.clearDisplay(); // Clear everything that is stored in frame buffer of epaper
5456
display.setCursor(0, 0); // Set print position at the begining of the screen
55-
char text[3001]; // Array where data from SD card is stored (max 200 chars here)
57+
char text[3001]; // Array where data from SD card is stored (max 200 chars here)
5658
int len = file.fileSize(); // Read how big is file that we are opening
5759
if (len > 3000)
58-
len = 3000; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
60+
len = 3000; // If it's more than 200 bytes (200 chars), limit to max 200 bytes
5961
file.read(text, len); // Read data from file and save it in text array
6062
text[len] = 0; // Put null terminating char at the and of data
6163
display.setTextSize(2);
62-
display.print(text); // Print data/text
63-
display.display(); // Do a full refresh of display
64+
display.print(text); // Print data/text
65+
display.sdCardSleep(); // Put sd card in sleep mode
66+
display.display(); // Do a full refresh of display
6467
}
6568
}
6669
else
67-
{ // If card init was not successful, display error on screen and stop the program (using infinite loop)
70+
{ // If card init was not successful, display error on screen, put sd card in sleep mode, and stop the program
71+
// (using infinite loop)
6872
display.println("SD Card error!");
73+
display.sdCardSleep();
6974
display.partialUpdate();
7075
while (true)
7176
;

src/include/System.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ int16_t System::sdCardInit()
169169
return getSdCardOk();
170170
}
171171

172+
/**
173+
* @brief sdCardSleep turns off the P-MOS which powers the sd card to save energy in deep sleep
174+
*/
175+
void System::sdCardSleep()
176+
{
177+
#if defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE10V2) || defined(ARDUINO_INKPLATE6PLUSV2) || \
178+
defined(ARDUINO_INKPLATECOLOR)
179+
// Set SPI pins to input to reduce power consumption in deep sleep
180+
pinMode(12, INPUT);
181+
pinMode(13, INPUT);
182+
pinMode(14, INPUT);
183+
pinMode(15, INPUT);
184+
185+
// And also disable uSD card supply
186+
pinModeInternal(IO_INT_ADDR, ioRegsInt, 13, OUTPUT);
187+
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 13, HIGH);
188+
#else
189+
pinModeInternal(IO_INT_ADDR, ioRegsInt, 13, OUTPUT);
190+
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, 13, HIGH);
191+
#endif
192+
}
193+
172194
/**
173195
* @brief getSdFat gets sd card object
174196
*

src/include/System.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class System : public Esp,
118118
void setSdCardOk(int16_t s);
119119
int16_t getSdCardOk();
120120
int16_t sdCardInit();
121+
void sdCardSleep();
121122

122123
SdFat getSdFat();
123124
SPIClass *getSPIptr();

0 commit comments

Comments
 (0)