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')
print(picdir)
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
print(libdir)
if os.path.exists(libdir):
    sys.path.append(libdir)

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

logging.basicConfig(level=logging.DEBUG)


logging.info("Starting Coffee Dispenser Display")
epd = epd2in7.EPD()
epd.init()
epd.Clear(0xFF)

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 = "127.0.0.1", port = 8080)

Limage = Image.new('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 = Image.open(os.path.join(picdir, 'bean.bmp'))
Limage.paste(bmp, (190,105))
epd.display(epd.getbuffer(Limage))
epd.sleep()
# Register Virtual Pins
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
    print('Current V1 value: {}'.format(value))    
    if value == 1:
        bmp = Image.open(os.path.join(picdir, 'battery_high.bmp'))
    else:
        bmp = Image.open(os.path.join(picdir, 'battery_empty.bmp'))
    Limage.paste(bmp, (2, 87))
    epd.display(epd.getbuffer(Limage))
    epd.sleep()

while True:
    blynk.run()

And this is my error message:

Traceback (most recent call last):
  File "coffee02.py", line 53, in <module>
    blynk.run()
  File "/home/pi/.local/lib/python3.7/site-packages/BlynkLib.py", line 252, in run
    self.process(data)
  File "/home/pi/.local/lib/python3.7/site-packages/BlynkLib.py", line 207, in process
    self.emit("V"+args[1], args[2:])
  File "/home/pi/.local/lib/python3.7/site-packages/BlynkLib.py", line 95, in emit
    self.callbacks[evt](*a, **kv)
  File "coffee02.py", line 49, in my_write_handler
    epd.display(epd.getbuffer(Limage))
  File "/home/pi/coffee/lib/waveshare_epd/epd2in7.py", line 421, in display
    self.send_command(0x10)
  File "/home/pi/coffee/lib/waveshare_epd/epd2in7.py", line 162, in send_command
    epdconfig.digital_write(self.dc_pin, 0)
  File "/home/pi/coffee/lib/waveshare_epd/epdconfig.py", 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.

Pete.

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

@PeteKnight

is the rough Python equivalent of this C++ function

BLYNK_WRITE(V1) {   
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