PaPiRus e-ink display

The PaPiRus is an neat little e-ink display for the Raspberry Pi. It was developed through a Kickstarter project and can be fetched from PiSupply -https://www.pi-supply.com/product/papirus-epaper-eink-screen-hat-for-raspberry-pi-
Unfortunately, the software coming alongside with it is error prone and the documentation lacks some parts of the device.

Installation and fixing errors

There is a blog entry from Frederick Vandenbosch (http://frederickvandenbosch.be/?p=1483) describing the basic installation and how to fix the errors contained in the software delivered with the device. You should follow his guide to get your papirus screen up and running.
Thanks for your work Frederick !

Prepare I2C bus

Both the rtc and the temperature sensor make us of the i2c bus from the raspberry pi, so make sure it is activated on your device:

Activate the ic2 bus through raspi-config and load the kernel module i2c-dev:
sudo raspi-config (Advanced Options | I2C)
sudo modprobe i2c-dev


Install the i2c tools to better prepare the following steps:
 sudo apt-get install -y i2c-tools

Now we check, which devices we can see on the bus:
 sudo i2cdetect -y 1

If everything is setup correct, you should get the following reading (at address 0x48 the temperature sensor is found, 0x6f is used by the RTC)

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f
70: -- -- -- -- -- -- -- --

Using the temperature sensor

The sensor chip is an common LM75B. To read the temperature, just get the word value from register 0:
sudo i2cget -y 1 0x48 0x00 w
0xc020

Now the received values must be transferred a bit, so save the following script inside a file "readlm75.sh"

#!/bin/bash

while true;

do

i2cget -y 1 0x48 0x00 w |
awk '{printf("%.1f\n", (a=( \
(("0x"substr($1,5,2)substr($1,3,1))*0.0625)+0.1) \
)>128?a-256:a)}'

sleep 3

done
and execute it as root:

sudo bash -c "./readlm75.sh"
32.9
33.1


Using the real time clock

The RTC clock chip is a MCP7941, which is supported of the shelf through raspbian drivers.
As it is the same model used by the PiFace HAT, you could use their script to perform the installation -> https://github.com/piface/PiFace-Real-Time-Clock

Here are the basic steps:
To activate it, you must load the correct kernel module:


sudo modprobe i2c:mcp7941x
sudo bash -c "echo mcp7941x 0x6f > /sys/class/i2c-adapter/i2c-1/new_device"


Now check, if the clock is accessible:
sudo hwclock -r --debug

hwclock from util-linux 2.20.1
Using /dev interface to clock.
Last drift adjustment done at 1458046084 seconds after 1969
Last calibration done at 1458046084 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
/dev/rtc0 does not have interrupt functions. Waiting in loop for time from /dev/rtc0 to change
...got clock tick
Time read from Hardware Clock: 2016/03/16 07:17:41
Hw clock time : 2016/03/16 07:17:41 = 1458112661 seconds since 1969

And if all is ok, we set the correct time inside the RTC from our system time (make sure the pi has the correct time first !) :
sudo hwclock -w


Now to use the time from the RTC right at boot time, you must add a line at the end of the file /etc/modules:
sudo nano /etc/modules
 
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-dev
i2c:mcp7941x
and add the following lines to the file /etc/rc.local:

echo mcp7941x 0x6f > /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s
date

Just before the exit 0. Note: If you have a Rev 1 Pi, replace i2c-1 by i2c-0 above.

Using the Buttons

The PaPiRus optionally has 4 buttons which can be soldered on the board. These can be reached through the GPIO pins 36, 37, 38 and 40 from the Rasperry Pi (low enabled).

Here is an python example:

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
from papirus import PapirusText

GPIO.setmode(GPIO.BOARD)

text = PapirusText()

# Write text to the screen
text.write("PaPiRus Buttons")

# LM75 sensor
button1 = 36
button2 = 37
button3 = 38
button4 = 40

GPIO.setup(button1, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(button2, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(button3, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(button4, GPIO.IN, GPIO.PUD_DOWN)

while True:
    if GPIO.input(button1) == False:
        print("button1 pressed")
        text.write("PaPiRus Buttons  Button 1 pressed")
    if GPIO.input(button2) == False:
        print("button2 pressed")
        text.write("PaPiRus Buttons  Button 2 pressed")
    if GPIO.input(button3) == False:
        print("button3 pressed")
        text.write("PaPiRus Buttons  Button 3 pressed")
    if GPIO.input(button4) == False:
        print("button4 pressed")
        text.write("PaPiRus Buttons  Button 4 pressed")
        break

No comments:

Post a Comment