Inkplate 6 FLICK einkOn/einkOff methods and battery percentage calculation

Customer:

I have two questions about the Inkplate 6 FLICK functionality:

  1. I see two new methods in the display class: einkOn() and einkOff(). What do they do and when should they be used?

  2. The display.readBattery() returns battery voltage, but I need to calculate the battery percentage or remaining capacity so users can see how much is left.

Originally submitted via email support on 28 September 2024. Migrated to the forum for community visibility.

Customer:

For the battery percentage, I found this formula online:

int percentage = ((voltage - 2.5) * 100.0) / 1.2;

I’m going to test this.

I’m also trying to create directories if they don’t exist, but I’m having trouble. Using SdFile it creates a file without an extension instead of a directory. Since Inkplate uses its own implementation of the SdFat library and there are no samples for checking (sub)directory existence, could you provide an example?

I need to:

  • Check if a directory tree exists on the SD card
  • Create directories top-level, one by one, not all at once before storing a file in the deepest directory

How do I do this?

Attachment omitted in migration: image001.png

Soldered Support:

Regarding einkOn() and einkOff(): you don’t actually need to use them - they’re used internally by the library at crucial times in refreshing the ePaper screen. This is used in the partialUpdate example but it’s not necessary when normally using partial update, as shown here: Inkplate-Arduino-library/examples/Inkplate6PLUS/Projects/Inkplate6PLUS_TicTacToe/Inkplate6PLUS_TicTacToe.ino at 2dd263f2f9548aadac8638413a143beddf068a64 · SolderedElectronics/Inkplate-Arduino-library · GitHub

For battery percentage, it will require experimentation. In my projects I’ve used:

#define FULL_VOLTAGE 4.2
#define EMPTY_VOLTAGE 3.0

int calculateBatteryPercentage(float voltage) {
  if (voltage >= FULL_VOLTAGE) {
    return 100;
  } else if (voltage <= EMPTY_VOLTAGE) {
    return 0;
  }
}

I usually set the low voltage value higher to ensure Inkplate can still power on when at low voltage, so you get the battery alert before power runs out. The initial update sequences and power-on cause current spikes, so 3.0 might not be enough.

Soldered Support:

I’ve tested checking for directory existence on the SD card here: #include "Inkplate.h" // Include Inkplate library to the sketchIn - Pastebin.com

It seems to work on my Inkplate. Can you check this code and use the snippet to implement folder creation if it doesn’t exist?

Customer:

The issue isn’t checking for existence, but actual creation. I tried sd.mkdir() and sd.chdir() but both crashed my program instantly.

I have two variables:

const char* nr = ;
const char* v = ;

The first variable is the top-level folder on the SD card, the second is the sublevel directory. I need both to be created if they don’t exist.

I saw in the original SdFat library that creating a file with a non-existing path should automatically create the directories, but that isn’t working either.

Attachment omitted in migration: ~WRD0000.jpg

Soldered Support:

Try this: #include "Inkplate.h" // Include Inkplate libraryInkplate display(INKPLATE_3B - Pastebin.com

This has worked for me - it checks if 123/voice1 exists and creates the folder on the SD card.

You should be able to use this code to create general functions which will create a file in a directory path and also create the folders if they don’t exist.

Attachment omitted in migration: image.png