Problem with Waveshare E-Paper HAT on RPi

Hello community,

i’m not that good with python and normally using c on esp8266, but today i want to create an e-paper level indicator for the coffee pad dispenser at our office. the blynk server is running local on an rpi and i would like to use the same rpi for the e-paper display hat from waveshare. it works so far, but when i send the value “1” on virtual pin 1 an error occures

This is my code

import BlynkLib
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pic')
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
if os.path.exists(libdir):

import logging
from waveshare_epd import epd2in7
import time
from PIL import Image,ImageDraw,ImageFont
import traceback

logging.basicConfig(level=logging.DEBUG)"Starting Coffee Dispenser Display")
epd = epd2in7.EPD()

font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
font32 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 32)

# Initialize Blynk
blynk = BlynkLib.Blynk('xxxxxxxxx', server = "", port = 8080)

Limage ='1', (epd.height, epd.width), 255)  # 255: clear the frame 264x176
draw = ImageDraw.Draw(Limage)
draw.text((2, 0), 'Coffee Dispenser', font = font32, fill = 0)
draw.text((2, 37), 'Senseo Strong ', font = font24, fill = 0)
bmp =, 'bean.bmp'))
Limage.paste(bmp, (190,105))
# Register Virtual Pins
def my_write_handler(value):
    print('Current V1 value: {}'.format(value))    
    if value == 1:
        bmp =, 'battery_high.bmp'))
        bmp =, 'battery_empty.bmp'))
    Limage.paste(bmp, (2, 87))

while True:

And this is my error message:

Traceback (most recent call last):
  File "", line 53, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/", line 252, in run
  File "/home/pi/.local/lib/python3.7/site-packages/", line 207, in process
    self.emit("V"+args[1], args[2:])
  File "/home/pi/.local/lib/python3.7/site-packages/", line 95, in emit
    self.callbacks[evt](*a, **kv)
  File "", line 49, in my_write_handler
  File "/home/pi/coffee/lib/waveshare_epd/", line 421, in display
  File "/home/pi/coffee/lib/waveshare_epd/", line 162, in send_command
    epdconfig.digital_write(self.dc_pin, 0)
  File "/home/pi/coffee/lib/waveshare_epd/", line 53, in digital_write
    self.GPIO.output(pin, value)
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)

I’ve searched the internet but it seems i am the only one with that problem.
I also tried to set GPIO mode to GPIO.BCM, but it didn’t made any difference.
Thanks for your help!

I know nothing about Python, but this doesn’t look like it does what you said you are trying to achieve…

I would have expected two arguments, the virtual pin, and the value you’re sending to it.


VIRTUAL_WRITE() reads the virtual pins from the server. This is not a problem. The right value is also shown on cli


is the rough Python equivalent of this C++ function

int value = param.asInt();

@tailor.chris Your errors seem to imply something non-Blynk related… rather this line here seems to be the issue…

I would suggest first working out a test sketch without Blynk to confirm all other libraries and settings are working.

I’ve done this before and it worked perfectly

Don’t know what else you expect from us here… I don’t have any e-paper shields/hats to test your code with, and not too many others even use Python with Blynk.

So, what happens with this code (presumably runs if anything else but a 1 is sent… testable with a step or numeric input widget).

And on that note, both actions would rapidly occur on a button widget press (1 for press, 0 for release), so you need to determine which part is causing the issue, the press or release or simply running the display code???

I find it hard to understand how you successfully tested this exact code process (but without Blynk)

Hi, I had the same issue I have resolved by enabling the SPI interface here how to:

sudo raspi-config
Choose Interfacing Options → SPI → Yes to enable SPI interface
sudo reboot