What was the old method to enabled PiScreen drivers?

1. Edit /boot/config.txt

pi@raspberrypi ~ $ sudo nano /boot/config.txt

Add;

dtparam=spi=on

2. Edit /etc/modules

pi@raspberrypi ~ $ sudo nano /etc/modules

Copy and paste the code below into this file;

flexfb width=320 height=480 regwidth=16 init=-1,0xb0,0x0,-1,0x11,-2,250,-1,0x3A,0x55,-1,0x36,0x28,-1,0xC2,0x44,-1,0xC5,0x00,0x00,0x0,0x0,-1,0xE0,0x0F,0x1F,0x1C,0x0C,0x0F,0x08,0x48,0x98,0x37,0x0A,0x13,0x04,0x11,0x0D,0x00,-1,0xE1,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0xE2,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0x11,-1,0X29,-3
fbtft_device debug=3 rotate=90 name=flexfb speed=16000000 gpios=reset:25,dc:24,led:22
ads7846_device gpio_pendown=17 verbose=3 x_plate_ohms=100 pressure_max=255 swap_xy=1

How do I rotate the display on PiScreen?

Rotating the display on PiScreen to portrait mode can be done by editing /boot/config.txt and adding the optional rotation parameter after the overlay statement

dtoverlay=piscreen2r,rotate=90

The values, 0, 90, 180, 270 are supported.

 

How do I Change DPI for X Windows?

The DPI can be set when starting X windows. Changing the DPI can give you a bit more screen real-estate.

pi@raspberrypi ~ $ sudo FRAMEBUFFER=/dev/fb1 startx — -dpi 60

To make a permanent change;
edit /usr/bin/startx as root and enter in some default server arguments.

defaultserverargs=”-dpi 60”
serverargs=”-dpi 60”

How do I use python to display information on PiScreen?

You will need to use the pygame module to display information on PiScreen with Python.

And before you call pygame.init(), you need to set the environment variable to point the output to PiScreen. (/dev/fb1).

Example code;

import pygame, sys, os
from pygame.locals import *
os.putenv('SDL_FBDEV', '/dev/fb1')
pygame.init()
# set up the window
DISPLAYSURF = pygame.display.set_mode((480, 320))

# set up the colors
BLACK = (  0,   0,   0)
WHITE = (255, 255, 255)
RED   = (255,   0,   0)
GREEN = (  0, 255,   0)
BLUE  = (  0,   0, 255)
# draw on the surface object
DISPLAYSURF.fill(WHITE)
pygame.draw.polygon(DISPLAYSURF, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(DISPLAYSURF, BLUE, (120, 60), (60, 120))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 120), (120, 120), 4)
pygame.draw.circle(DISPLAYSURF, BLUE, (300, 50), 20, 0)
pygame.draw.ellipse(DISPLAYSURF, RED, (300, 200, 40, 80), 1)
pygame.draw.rect(DISPLAYSURF, RED, (200, 150, 100, 50))
pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[380][280] = BLACK
pixObj[382][282] = BLACK
pixObj[384][284] = BLACK
pixObj[386][286] = BLACK
pixObj[388][288] = BLACK
del pixObj
# run the game loop
while True:
    for event in pygame.event.get():
            if event.type == QUIT:
                        pygame.quit()
                        sys.exit()
    pygame.display.update()

How do I use PiScreen with XBMC?

PiScreen isnt supported on XBMC.  However there is a work around to copy what is display on the HDMI port(fb0) to the PiScreen.

 

To do this, we will need Framebuffer Copy.

pi@raspberrypi ~ $ sudo apt-get install cmake
pi@raspberrypi ~ $ git clone https://github.com/tasanakorn/rpi-fbcp
pi@raspberrypi ~ $ cd rpi-fbcp/
pi@raspberrypi ~ $ mkdir build
pi@raspberrypi ~ $ cmake ..
pi@raspberrypi ~ $ make
pi@raspberrypi ~ $ sudo install fbcp /usr/local/bin/fbcp

To use Framebuffer Copy the console needs to be on fb0. If it isnt already there, you can change it to fb0 using this command;

pi@raspberrypi ~ $ con2fbmap 1 0

The run framebuffer copy in the background

pi@raspberrypi ~ $ fbcp &

You should now have fb0 mirrored onto fb1(PiScreen).

How to rotate the touchscreen on a PiScreen

If you rotate the display on the TFT, you will also need to rotate the touchscreen.

If you haven’t already done so, install xinput.

pi@raspberrypi ~ $ sudo apt-get install xinput -y

Open up the X init script

pi@raspberrypi ~ $ sudo nano /etc/X11/xinit/xinitrc

And add these lines;

DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axes Swap' 1
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 1 1

before;

. /etc/X11/Xsession

You may need to change the values at the end of the each line;

Evdev Axes Swap
Swap X & Y
1 for yes and 0 for no
Evdev Axis Inversion
Swap the direction on the X or Y plane.
1 for yes and 0 for no. A number is needed for each plane

You may also need to re-calibrate the touch screen for X windows. This can be done by deleting the file below and then rebooting;

pi@raspberrypi ~ $ sudo rm /etc/pointercal.xinput

How to Re-calibrate the Touchscreen input for X Windows

The calibration script runs every time X Windows starts

It first checks for the calibration file and if it is present it then loads this data into X windows.

If the calibration data is not present, it will then start the calibration program.

To rerun the calibration program, delete /etc/pointercal.xinput

No console out of the HDMI port.

When the console is moved to the PiScreen, no console will appear out the HDMI port.

The console can be moved back to the HDMI port by deleting the text below from /boot/cmdline.txt

fbcon=map:10 fbcon=rotate:2 fbcon=font:ProFont6x11

This can be down from a Windows or Mac PC.

You can always leave the console on the HDMI and manually swing it over to piscreen with

con2fbmap 1 1

and back to the HDMI with

con2fbmap 1 0

This will have to be done every time the Pi is booted.