E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

Related tags

Hardware MagInkCal
Overview

MagInkCal

This repo contains the code needed to drive an E-Ink Magic Calendar that uses a battery powered (PiSugar2) Raspberry Pi Zero WH to retrieve events from a Google Calendar, format it into the desired layout, before pushing it to a Waveshare 12.48" tri-color E-Ink display. Note that the code has only been tested on the specific hardware mentioned, and customization of the code is necessary for it to work with other E-Ink displays or Battery/RTC add-ons. That said, enjoy working on your project and hopefully this helps to jump-start your magic calendar journey.

20210924_175459

Background

Back in 2019, I started a thread in Reddit to bounce an idea I had with the community: to replicate the Android Magic Calendar concept that inspired many DIY projects in the subsequent years. But specifically, I wanted it to run on battery so I could position it anywhere in house, and even hang it on the wall without a wire dangling beneath it. I also wanted the parts to be plug and play since I had neither the desire nor the steady hands needed to solder anything. After sitting on that idea for close to a year, I finally got my act together and ordered the parts I needed for this project. I posted another update to Reddit in 2020, but got overwhelmed with life/work so it took me almost another year before posting the full set of instructions and code here. An update was also posted on Reddit to share this with the community.

Hardware Required

How It Works

Through PiSugar2's web interface, the onboard RTC can be set to wake and trigger the RPi to boot up daily at a time of your preference. Upon boot, a cronjob on the RPi is triggered to run a Python script that fetches calendar events from Google Calendar for the next few weeks, and formats them into the desired layout before displaying it on the E-Ink display. The RPi then shuts down to conserve battery. The calendar remains displayed on the E-Ink screen, because well, E-Ink...

Some features of the calendar:

  • Battery life is the big question so I'll address it first. I'm getting around 3-4 weeks before needing to recharge the PiSugar2. I'm fairly happy with this but I'm sure this can be extended if I optimize the code further.
  • Since I had the luxury of using red for the E-Ink display, I used it to highlight the current date, as well as recently added/updated events.
  • I don't like having long bars that span across multiple days for multi-day events, so I chose to display only the start and end dates for those events, and adding small left/right arrows accordingly,
  • Given limited space (oh why are large E-Ink screens still so expensive!) and resolution on the display, I could only show 3 events per day and an indicator (e.g. 4 more) for those not displayed
  • The calendar always starts from the current week, and displays the next four (total 35 days). If the dates cross over to the new month, it's displayed in grey instead of black.

MagInkCal Basics

Setting Up Raspberry Pi Zero

  1. Start by flashing Raspberrypi OS Lite to a MicroSD Card.

  2. After setting up the OS, run the following commmand in the RPi Terminal, and use the raspi-config interface to setup Wifi connection, enable SSH, I2C, SPI, and set the timezone to your location.

sudo raspi-config
  1. Run the following commands in the RPi Terminal to setup the environment to run the Python scripts.
sudo apt update
sudo apt-get install python3-pip
sudo apt-get install chromium-chromedriver
pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
pip3 install pytz
pip3 install selenium
pip3 install Pillow
  1. Run the following commands in the RPi Terminal to install the libraries needed to drive the E-Ink display. See this page for more details.
sudo apt-get install python3-pil
sudo pip3 install RPi.GPIO
sudo pip3 install spidev
  1. Run the following commands in the RPi Terminal to install the web interface for PiSugar2 display. See this page for more details. After running the command, you would be able to access the web interface at http://your_raspberry_ip:8421 in your browser. From there you should be able specify when you wish to schedule the PiSugar2 boot up your RPi.
curl http://cdn.pisugar.com/release/Pisugar-power-manager.sh | sudo bash
  1. Download the over the files in this repo to a folder in your PC first.

  2. In order for you to access your Google Calendar events, it's necessary to first grant the access. Follow the instructions here on your PC to get the credentials.json file from your Google API. Don't worry, take your time. I'll be waiting here.

  3. Once done, copy the credentials.json file to the "gcal" folder in this project. Run the following command on your PC. A web browser should appear, asking you to grant access to your calendar. Once done, you should see a "token.pickle" file in your "gcal" folder.

python3 quickstart.py
  1. Copy all the files over to your RPi using your preferred means.

  2. Run the following command in the RPi Terminal to open crontab.

crontab -e
  1. Specifically, add the following command to crontab so that the MagInkCal Python script runs each time the RPi is booted up.
@reboot cd /location/to/your/maginkcal && python3 maginkcal.py
  1. That's all! Your Magic Calendar should now be refreshed at the time interval that you specified in the PiSugar2 web interface!

PS: I'm aware that the instructions above may not be complete, especially when it comes to the Python libraries to be installed, so feel free to ping me if you noticed anything missing and I'll add it to the steps above.

Acknowledgements

  • Quattrocento Font: Font used for the calendar display
  • Bootstrap Calendar CSS: Stylesheet that adapted heavily for the calendar display
  • emagra: For adding in new features, such as 24hr display and multiple calendar selection.
  • /u/aceisace: For the tips on E-Ink development and the InkyCal repo (worth checking out even though I didn't use it for this project).

Contributing

I won't be updating this code much, since it has been serving me well. Nevertheless, feel free to fork the repo and modify it for your own purpose. At the same time, check out other similar projects, such as InkyCal. It's much more polished and also actively developed.

What's Next

Honestly, the cost of this project is way too high for a single purpose device. Personally, I've been looking at E-Ink tablets that emulate the experience of writing on paper, and allow the users to take notes on the go. Those familiar with this range of products would be aware of the reMarkable tablet, Ratta Supernote, Kobo Elipsa and many others. My next project is likely to enhance one of these devices such that the calendar will be displayed when it's not in use. While this is usually possible by manually setting the sleep screen image / screensaver, I'm looking to have the screensaver updated automatically on a daily basis, like how it was done in this project.

Comments
  • Multiple calendar, add ids in config.json

    Multiple calendar, add ids in config.json

    Hello there, I really liked this project and the idea. I have multiple calendar on my account so I tried to add multiple calendar without changing your code too much.

    opened by emagra 4
  • Long-lived gcal credential?

    Long-lived gcal credential?

    Hi!

    Thanks so much for sharing your project! It has inspired me to adapt it and build my own.

    I noticed that the google calendar credential expires after a couple days, do you know how to get a long-lived credential?

    Thanks again!

    Matt

    opened by mawise 2
  • Error 'NoneType' object has no attribute 'DEV_ModuleInit'

    Error 'NoneType' object has no attribute 'DEV_ModuleInit'

    Hello, firstly thank you very much about your work on this project!! I think it is a great project ;)

    My problem starts when it starts the phase of drawing in the ink waveshare 7.5 inches b, the logs I see are these:

    pi@raspberrypi:~/MagInkCal $ python3 maginkcal.py 
    /usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.7) or chardet (3.0.4) doesn't match a supported version!
      RequestsDependencyWarning)
    Starting daily calendar update
    Invalid time sync command
    Invalid battery output
    Battery level at start: -1.000
    Time synchronised to 2021-11-26 08:28:24.184037+01:00
    Retrieving events between 2021-11-22T00:00:00+01:00 and 2021-12-26T23:59:59.999999+01:00...
    Calendar events retrieved in 0:00:00.630859
    Screenshot captured and saved to file.
    Image colours processed. Extracted grayscale and red images.
    EPD init...
    'NoneType' object has no attribute 'DEV_ModuleInit'
    Completed daily calendar update
    Checking if configured to shutdown safely - Current hour: 8
    

    As you can see, I think the problem is on third to last line:

    'NoneType' object has no attribute 'DEV_ModuleInit'
    

    I inspect a little bit your code and the error occurs in the line 115 of epdconfig.py file : spi.DEV_ModuleInit

    I have searched on internet and this line should initialize the SPI module, but it does not work.

    I have followed your README.md 2 or 3 times to try to see what I could have missed and I am not able to resolve my problem by myself :(

    On the other way I have used the example python code from waveshare and it works correctly: epd_7in5b_V2_test.py

    @speedyg0nz: Could you help me solving this problem to run your project?

    By the way, I am using a Raspberry pi 4b and the SPI is enabled in my Raspberry pi 4b

    An other thing very curios that happens is:

    • When I reboot the raspberry the waveshare example works correctly
    • But if I have tried to run the python3 maginkcal.py before of running waveshare example, the waveshare example does not work, the screen does not show the images of example and the running apparently is the same but faster without waiting the ending of painting of the ink screen of each image.
    • Nevertheless, the python3 maginkcal.py always returns the output on this comment
    opened by popere 1
  • Some fix for sorting events time display and logger print statements

    Some fix for sorting events time display and logger print statements

    Hello there, I have made a new pull because the event was sorted per calendar list in conf file instead of hour. The event list shouldn't be too long (105 element 3 per day 35 days displayed) so I used sorted. Changed get_short_time to avoid useless char (0 in front of 09:00) Add handler in logger to print on STDOUT Feel free to give me feedback about this changes. Cheers!1

    opened by emagra 0
  • Multiple accounts?

    Multiple accounts?

    Any way to use multiple accounts within this project? All of them have CalDAV option (first acc is iCloud, two others are Gmail) Maybe some kind of CalDAV proxy? Before digging into the source code

    opened by leo150 0
  • Quickstart.py may need a current directory declaration

    Quickstart.py may need a current directory declaration

    Hey @speedyg0nz. Just wanted to let you know of an error I ran into and the method I used to fix it. For some reason running the quickstart.py as is returned an error.

    Adding this to line 22 CURR_DIR = os.path.dirname(os.path.realpath(__file__))

    and changing line 39-41 from this: flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', SCOPES) creds = flow.run_local_server(port=0)

    to this: credential_file=str(CURR_DIR)+'/credentials.json' flow = InstalledAppFlow.from_client_secrets_file( credential_file, SCOPES) creds = flow.run_local_server(port=0)

    That fixed the issue for me. Unfortunately, I'm having trouble replicating it now so I can't specify what the error it threw actually was. Apologies there. Starting from a fresh repo in a new environment doesn't have the issue at all. This is probably an edge case. I think this is an environment thing but thought it worth sharing regardless in case anyone else encounters it in the future.

    opened by pumodi 0
  • CalDav Calendar Integration

    CalDav Calendar Integration

    This PR allows users to pull calendar events from CalDav instead of Gcal. Almost all major calendar providers (gcal, nextcloud) offer a CalDav interface, so this is useful for custom integrations. In my case, I'm using this to sync Nextcloud calendar configs 😄

    I've tried to keep the same code standard that's currently used.

    Configuring to this instead of gcal is done through the config.json file's calendarSource parameter.

    opened by Ge0rg3 0
  • WIP: Add theming and month abbreviation

    WIP: Add theming and month abbreviation

    Work in Progress // yet not testet on mentioned hardware in README.md:

    • Add the possibility to change between a dark and a light theme/style.
      • Just copy the files (.css/.png) within render/stlye_light-folder or render/style_dark-folder
      • replace the existing files (.css/.png) in render-folder to switch between a dark and a light style of the calendar.
    • Add the possibility to use month abbreviation like 'JAN' instead of month number like '1' Adjustable via config.json: "isMonthAbbr": true --> month abrreviation like 'JAN' displays "isMonthAbbr": false --> default value, month number like '1' displays
    opened by christophbaur 1
Owner
null
Create a low powered, renewable generation forecast display with a Raspberry Pi Zero & Inky wHAT.

GB Renewable Forecast Display This Raspberry Pi powered eInk display aims to give you a quick way to time your home energy usage to help balance the g

Andy Brace 32 Jul 2, 2022
Raspberry Pi Power Button - Wake/Power Off/Restart(Double Press)

Control Raspberry pi with physically attached button. Wake, Power Off, and Restart (Double Press) . Python3 script runs as a service with easy installation.

Stas Yakobov 16 Oct 22, 2022
Python information display framework aimed at e-ink devices

My display, using a Raspberry Pi Zero W and Waveshare 6" e-paper hat infodisplay Modular information display framework aimed at e-ink devices. Built u

Niek Blankers 3 Apr 8, 2022
A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler.

Env-MCRO A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler. (btw this image is a bit outdated, some of the silkscreen

EnviousData 68 Oct 14, 2022
A battery pack simulation tool that uses the PyBaMM framework

Overview of liionpack liionpack takes a 1D PyBaMM model and makes it into a pack. You can either specify the configuration e.g. 16 cells in parallel a

PyBaMM Team 40 Jan 5, 2023
Get input from OLED Joystick, Runs command, Displays output on OLED Screen (Great for P4wnP1)

p4wnsolo-joyterm Gets text input from OLED Joystick Runs the command you typed Displays output on OLED Screen (Great for P4wnP1 - even better on Raspb

PawnSolo 7 Dec 19, 2022
A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.

distance sensor cube timer A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost. How to

null 3 Feb 21, 2022
This repository hosts the code for Stanford Pupper and Stanford Woofer, Raspberry Pi-based quadruped robots that can trot, walk, and jump.

This repository hosts the code for Stanford Pupper and Stanford Woofer, Raspberry Pi-based quadruped robots that can trot, walk, and jump.

Stanford Student Robotics 1.2k Dec 25, 2022
Mycodo is open source software for the Raspberry Pi that couples inputs and outputs in interesting ways to sense and manipulate the environment.

Mycodo Environmental Regulation System Latest version: 8.12.9 Mycodo is open source software for the Raspberry Pi that couples inputs and outputs in i

Kyle Gabriel 2.3k Dec 29, 2022
Designed a system that can efficiently sort recyclables and transfer them to corresponding bins using Python, a Raspberry Pi, and Quanser Labs.

System for Sorting and Recycling Containers - Project 3 Table of contents Overview The challenge Screenshot My process Built with Code snippets What I

Mit Patel 2 Dec 2, 2022
Code and build instructions for Snap, a simple Raspberry Pi and LED machine to show you how expensive the electricyty is at the moment

Code and build instructions for Snap, a simple Raspberry Pi and LED machine to show you how expensive the electricyty is at the moment. On row of LEDs shows the cost of the hour, the other row the cost of the day.

Johan Jonk Stenström 3 Sep 8, 2022
A global contest to grow and monitor your own food with Raspberry Pi

growlab A global contest to grow and monitor your own food with Raspberry Pi A capture from phototimer of my seed tray with a wide-angle camera positi

Alex Ellis 442 Dec 23, 2022
Raspberry Pi Pico and LoRaWAN from CircuitPython

Raspberry Pi Pico and LoRaWAN from CircuitPython Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040-based board using CircuitPython

Alasdair Allan 15 Oct 8, 2022
a weather application for the raspberry pi and the Pimorioni Inky pHAT.

raspi-weather a weather application for the raspberry pi and the Inky pHAT

Derek Caelin 59 Oct 24, 2022
A versatile program that uses the raspberry pi camera and provides it as a service

PiCameleon Is a daemon program meant to provide the RaspberryPi Camera as a service while running according to a configuration.

André Esser 52 Oct 16, 2022
Monorepo for my Raspberry Pi dashboard and GPS satellite listener.

?? pi dashboard My blog post: Listening to Satellites with my Raspberry Pi This is the monorepo for my Raspberry Pi dashboard!

Andrew Healey 27 Jun 8, 2022
KIRI - Keyboard Interception, Remapping, and Injection using Raspberry Pi as an HID Proxy.

KIRI - Keyboard Interception, Remapping and Injection using Raspberry Pi as a HID Proxy. Near limitless abilities for a keyboard warrior. Features Sim

Viggo Falster 10 Dec 23, 2022
Using a raspberry pi, we listen to the coffee machine and count the number of coffee consumption

A typical datarootsian consumes high-quality fresh coffee in their office environment. The board of dataroots had a very critical decision by the end of 2021-Q2 regarding coffee consumption.

dataroots 51 Nov 21, 2022
Automate gate/garage door opening via 433.92MHz emitter with Raspberry Pi, Home Assistant and Homekit.

Automate opening your garage door / gate Summary This project sums up how I automated opening my garage door using a Raspberry PI, a 433Mhz emitter, H

Julien Fouilhé 29 Nov 30, 2022