How to enable PiShop.nz 3.5" Touch Screen Monitor in Raspbian

We recommend you do the below commands via a SSH connection to allow copy & paste
Backup any important files before proceeding

Enable SPI and Screen (Required)

Edit boot config
sudo cp /boot/config.txt /boot/config.bu
sudo nano /boot/config.txt
Copy the below text to the bottom of the file
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0
dtparam=spi=on
dtoverlay=piscreen,rotate=90,speed=24000000
Save the file (CTRL-X then Y then ENTER).

Now reboot.
sudo reboot

Quick Test (optional)

Install fbi image viewer and test
sudo apt-get update && sudo apt-get -y install wget fbi
cd ~
wget http://pishop.nz/files/480x320.jpg
sudo fbi -noverbose -T 1 -a -d /dev/fb1 480x320.jpg
You should see the image on the 3.5" screen

Show Raspbian GUI on Screen (optional)

Edit X11 config file to send GUI to 3.5" screen
sudo cp /usr/share/X11/xorg.conf.d/99-fbturbo.conf /usr/share/X11/xorg.conf.d/99-fbturbo.bu
sudo sed -i 's/fb0/fb1/g' /usr/share/X11/xorg.conf.d/99-fbturbo.conf
sudo reboot
The Raspbian GUI should now show on the 3.5" screen

Show Raspbian Console on Screen (optional)

Edit boot config file to send console to 3.5" screen
sudo cp /boot/cmdline.txt /boot/cmdline.bu
sudo sed -i.bck '$s/$/ fbcon=map:10 fbcon=rotate:2 fbcon=font:ProFont6x11/' /boot/cmdline.txt
sudo reboot
The Raspbian console should now show on the 3.5" screen

Touch-screen Calibration (recommended)

If you need to calibrate the touch-screen, run the below commands in the Raspbian terminal.

Install the required packages
sudo apt-get update && sudo apt-get install -y xinput-calibrator
Run the calibration program
xinput_calibrator
If you are doing the commands via SSH, then use
DISPLAY=:0.0 xinput_calibrator
Copy the output of the program.
It should look similiar to this
Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
        Option  "Calibration"   "3905 232 263 3947"
EndSection
Now run the below commands to create and edit the file we need.
sudo mkdir -p /etc/X11/xorg.conf.d
sudo nano /etc/X11/xorg.conf.d/99-calibration.conf
Paste in the copied text and save the file (Ctrl-X, Y, ENTER).
Now reboot and the screen should be calibrated.
sudo reboot

Disable Screen Blanking (optional)

sudo sed -i 's/^BLANK_TIME=30/BLANK_TIME=0/' /etc/kbd/config
sudo sed -i 's/^POWERDOWN_TIME=30/POWERDOWN_TIME=0/' /etc/kbd/config
sudo reboot

Mirror HDMI Output to 3.5" Screen (optional)

Install cmake and build rpi-fbcp
sudo apt-get -y install cmake git
git clone https://github.com/tasanakorn/rpi-fbcp
cd rpi-fbcp/

mkdir build
cd build/
cmake ..
make

sudo install fbcp /usr/sbin/fbcp
Start mirroring
fbcp &
Stop mirroring
killall fbcp
Start mirroring on boot
sudo cp /etc/rc.local /etc/rc.local.bu
sudo sed -i 's/^exit 0/fbcp \&\nexit 0/g' /etc/rc.local
sudo reboot