post

Experiments and boards

A Raspberry Pi  or Arduino is a perfect companion for experiments, but you need some hardware support during development and deployment.

Here I show you the breadboard development tools I have first, followed by deployment boards.

Breadboard experimenters boards

Traditional extenders into a breadboard. From Adafruit and China, 26 pin (yes, that old) and 40 pin with a flatcable to the Pi. I do not like these very much.

Rasp.io Breadboard Pi Bridge – Pi Ports to Breadboard in Numerical Order. Nice setup, can be used with a Pi B or a Pi Zero. Easy to locate the pins with the descriptions on the PCB.
No Dupont wires required (except for +5V). .Blocks the power rows alas.


RasPiO Pro Hat Protect/Position Raspberry Pi Ports. Ideal if you fear damaging your Pi, has current limiting resistors on the GPIO pins.
Disadvantages are that these resistors may interfere e.g. I2C or SPI and the very small breadboard. Seldom used.

A simple and cheap Chinese breadboard solution. Requires Dupont wires and a printed pin layout required. Works fine, affordable Prototype comes close to deployment layout. Recommended.

The Wombat, a great experimenters board. Much I/O on board (serial to USB, ADC MCP3008, 2 button,s 4 output LEDs, power regulator for +3.3V. All jumpered.Well documented single in line I/O connector.
Large breadboard! The best board in my collection! From Gooligum Australia.

Sunfounder China, experiments Raspberry Pi and Arduino Uno or Mega. Solid, large breadboard, recommended.

Arduino Uno experimenters boards, acryl, from China.

Deployment boards

These boards are where the permanent circuit will be soldered on. Essential are the GPIO connector and enough solder islands.


Richard Saville aka AverageMan made a great collection of boards, I have many in use.

A Chinese (40 pin) and Adafruits board (26 pin, yes that old). The Chinese ones are affordable and great for deployment. Recommended!

Mini Mega deployment board. From China.

Itead 2.8 TFT Add-on V2.0 Touch

A small display, again one of those LCD screens attached via SPI. slow refresh, OS support frozen in time.

Instructions that worked for me, April 2020. 

https://www.itead.cc/blog/raspberry-pi-b-2-8-tft-add-on-v2-0-touch-function-realizing


Download Raspbian-2015-02-16.img into SD card, then launch Raspberry Pi B 
Its old Wheezy Debian, unsupported and outdated, so make sure you change to the legacy update, the official repository moved on. But there is a legacy repository!

Replace this line in /etc/apt/sources.list
deb http://legacy.raspbian.org/raspbian/ wheezy main contrib non-free rpi

Now you can do the 

sudo apt-get update

Do the usual raspi_config, add SPI support

sudo nano  /etc/modprobe.d/raspi-blacklist.conf
Comment the mask of spi out
#blacklist spi-bcm2708

Connect Raspberry Pi B+ 2.8 TFT Add-on V2.0 to Raspberry Pi B+ correctly

sudo apt-get install xinput evtest tslib libts-bin

Download the fbtft driver, and you may need to run the following command three times:
sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update

Finally get the codes:
*** Running pre-install script
Work around rpi-update issue #106
*** Updating firmware
*** Updating kernel modules
*** depmod 3.12.21+
*** Updating VideoCore libraries
*** Using HardFP libraries
*** Updating SDK
*** Running ldconfig
*** Storing current firmware revision
*** Running post-install script
/lib/firmware
*** Deleting downloaded files
*** Syncing changes to disk
*** If no errors appeared, your firmware was successfully updated to b77683205688d3f6ae2b32a3c7
f4e63de1c06a5d
*** A reboot is needed to activate the new firmware

By now,you need to reboot your Raspberry Pi B+
sudo reboot

sudo touch /usr/share/X11/xorg.conf.d/99-fbdev.conf

Configure the file /usr/share/X11/xorg.conf.d/99-fbdev.conf

sudo nano /usr/share/X11/xorg.conf.d/99-fbdev.conf

Section "Device"
  Identifier "itdb28"
  Driver "fbdev"
  Option "fbdev" "/dev/fb1"
EndSection

sudo modprobe fbtft_device name=itdb28 gpios=reset:5,dc:6,wr:12,cs:13,db00:20,db01:21,db02:22,d
b03:23,db04:24,db05:25,db06:26,db07:27 rotate=90 fps=50

Add the following contents to file /boot/config.txt
dtoverlay=ads7846,cs=1,speed=2000000,penirq=17,swapxy=1,xmin=230,xmax=3850,ymin=190,ymax=3850,p
max=255,xohms=100
startx &
 (you may have to reboot)

Load the touch driver
1.Add the following contents to file /boot/config.txt

dtoverlay=ads7846,cs=1,speed=2000000,penirq=17,swapxy=1,xmin=230,xmax=3850,ymin=190,ymax=3850,pmax=255,xohms=100
2.Reboot Raspberry Pi B+

sudo reboot
3.Load TFT display driver

sudo modprobe fbtft_device name=itdb28 gpios=reset:5,dc:6,wr:12,cs:13,db00:20,db01:21,db02:22,db03:23,db04:24,db05:25,db06:26,db07:27 rotate=90 fps=50
4.start up X Server

startx &
Adjust the X&Y directions of this touch screen
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 1
Test
·Check the event’s number which is in accord with the touch screen.

	cat /proc/bus/input/devices

This event’s number here is event3, then you need to execute the following command to do the calibration and test touch screen according to the event’s number you’ve got. When do calibrating, you’d better use touch pen to click the cross’s center unless you want a rough calibration result.

·Touch screen calibration

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event3 ts_calibrate

Hyperpixel 3.5 Pimoroni

3.5 inch touch screen. Superseeded by Hyperpixel 4.0

Reasonable quality, touch is, though it i capacitive, not too easy to use. Resistive screens an be handled with pens, not this one.

With current Buster not a perfect pair.

Two experiments:

Raspberry Pi 2 B V1.2 success

1 imaged a SD with current Buster (feb 2020)
2 booted on a Pi 4 1 GB
3 did the usual raspi-config things and update/upgrade
4 checked out the system, works as expected
5 curl https://get.pimoroni.com/hyperpixel | bash
6. rebooted , installed Hyperpixel

Result is a working display, HDMI whosw rainbow screen, touch is wrong, cursor moves opposite directions, axes mixed up.
So not too bad, but touch not configured correctly.

Fixed with, in a console window, the command

$ hyperpixel-rotate normal

which changed the orientation of the screen to what is aleady was, and changed the touch matrix to a working touch.

So far so good.

Raspberry Pi 4 1 GB failure

To check out the Pi4, current Buster (feb 2020) and Hyperpixel 3.5 I did the following:

1 imaged a SD with current Buster (feb 2020)
2 booted on a Pi 4 1 GB
3 did the usual raspi-config things and update/upgrade
4 checked out the system, works as expected
5 curl https://get.pimoroni.com/hyperpixel | bash
6. rebooted , installed Hyperpixel

Result is not a working Hyperpixel display, but reverse image on HDMI, Hyperpixel dead.
Which is the same effect as booting from the working Raspberry Pi 2 SD.
Maybe the curl https://get.pimoroni.com/hyperpixel | bash gets the old hyperpixel install and not the Pi 4 version? Looks like it.

So back to

1 imaged a SD with current Buster (feb 2020)
2 booted on a Pi 4 1 GB
3 did the usual raspi-config things and update/upgrade
4 checked out the system, works as expected
5 downloaded the Hyperpixel Pi 4 git repository
6. rebooted , installed Hyperpixel with ./setup.h

Result is Hyperpixel noise banner, HDMI shows normal screen

So install fails with the curl or setup, and instructions clearly wrong.Issue opened at Pimoroni.

Adafruit PITFT 2.8 resistive


Image Raspbian full if you want a desktop, else lite is sufficient for CLI.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get remove piwiz

sudo raspi-config
 - password
 - Boot to console autologon, no splash screen
 - localization time zone
 - Interfacing  - SSH SPI I2C Serial
 
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
chmod +x adafruit-pitft.sh
sudo ./adafruit-pitft.sh

Choose 1 tft 2.8 resistive
Choose 1 90 degrees
Console on tft Yes

reboot and console on tft visible

sudo sed -i "s+/dev/fb0+/dev/fb1+" /usr/share/X11/xorg.conf.d/99-fbturbo.conf
y       cat /usr/share/X11/xorg.conf.d/99-fbturbo.conf


sudo nano /usr/share/X11/xorg.conf.d/40-libinput.conf
At section touchscreen, add the following line
CODE: SELECT ALL
     Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"

This matrix fits for the 90° turned display (see rotate=90 at /boot/config.txt). In case you have turned the display 270, the line must be
CODE: SELECT ALL
     Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"

This design uses the hardware SPI pins (SCK, MOSI, MISO, CE0, CE1) as well as GPIO #25 and #24. All other GPIO are unused. Since we had a tiny bit of space, there's 4 spots for optional slim tactile switches wired to four GPIOs, that you can use if you want to make a basic user interface. For example, you can use one as a power on/off button.

We bring out GPIO #23, #22, #21, and #18 to the four switch locations!

The last known for-sure tested-and-working version is March 13, 2018 (https://downloads.raspberrypi.org/raspbian/images/raspbian-2018-03-14/) from https://downloads.raspberrypi.org/raspbian/images/

It works OK with recent Buster (Jan 2020), tested March 2020

Setting up the Touchscreen

Now that the screen is working nicely, we'll take care of the touchscreen. There's just a bit of calibration to do, but it isn't hard at all.

Before we start, we'll make a udev rule for the touchscreen. That's because the eventX name of the device will change a lot and its annoying to figure out what its called depending on whether you have a keyboard or other mouse installed.

Check if this already done

   sudo nano /etc/udev/rules.d/95-stmpe.rules

   to create a new udev file and copy & paste the following line in:
   SUBSYSTEM=="input", ATTRS{name}=="stmpe-ts", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen" 

   sudo rmmod stmpe_ts
   sudo modprobe stmpe_ts

Then type 
ls -l /dev/input/touchscreen

It should point to eventX where X is some number, that number will be different on different setups since other keyboards/mice/USB devices will take up an event slot

There are some tools we can use to calibrate & debug the touchscreen. Install the "event test" and "touchscreen library" packages with

sudo apt-get install evtest tslib libts-bin

Now you can use some tools such as

sudo evtest /dev/input/touchscreen

which will let you see touchscreen events in real time, press on the touchscreen to see the reports.

AutoMagic Calibration Script
If you rotate the display you need to recalibrate the touchscreen to work with the new screen orientation. You can manually run the calibration processes in the next section, or you can re-run the installer script and select a new rotation:

Try using this default calibration script to easily calibrate your touchscreen display. Note that the calibration values might not be exactly right for your display, but they should be close enough for most needs. If you need the most accurate touchscreen calibration, follow the steps in the next section to manually calibrate the touchscreen.
Manual Calibration
If the "automagic" calibration technique isn't working for you, or you have some other setup where you need to carefully calibrate you can do it 'manually'

You will want to calibrate the screen once but shouldn't have to do it more than that. We'll begin by calibrating on the command line by running

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate

follow the directions on the screen, touching each point. Using a stylus is suggested so you get a precise touch. Don't use something metal, plastic only!

Next you can run

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test

which will let you draw-test the touch screen. Go back and re-calibrate if you feel the screen isn't precise enough!

X Calibration
You can also calibrate the X input system but you have to use a different program called xtcal (xinput_calibrator no longer works)

You can do this if the calibration on the screen isn't to your liking or any time you change the rotate=XX module settings for the screen. Since the screen and touch driver are completely separated, the touchscreen doesn't auto-rotate

Download and compile it with the following:

 Download: fileCopy Code
sudo apt-get install libxaw7-dev libxxf86vm-dev libxaw7-dev libxft-dev
git clone https://github.com/KurtJacobson/xtcal
cd xtcal
make
You must be running PIXEL (the GUI) while calibrating.

Before you start the calibrator you will need to 'reset' the old calibration data so run

DISPLAY=:0.0 xinput set-prop "stmpe-ts" 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
Now you'll have to run the calibrator while also running X. You can do this by opening up the terminal program and running the the xtcal command (which is challenging to do on such a small screen) OR you can do what we do which is create an SSH/Terminal shell and then run the calibrator from the same shell, which requires the following command:

DISPLAY=:0.0 xtcal/xtcal -geometry 640x480
Note that the geometry may vary!

If you are using a 2.4"/2.8"/3.2" 320x240 display with landscape orientation, use 640x480. If you're in portrait, use 480x640.

If you are using a 3.5" display with landscape, use 720x480, portrait is 480x720

Follow the directions on screen

raspberry_pi_xinput.png
Once complete you'll get something like:
adafruit_products_testxtcal.png
Run sudo nano /usr/share/X11/xorg.conf.d/20-calibration.conf and copy the 9 numbers into the TransformationMatrix option so it looks like:

 Download: fileCopy Code
Section "InputClass"
        Identifier "STMPE Touchscreen Calibration"
        MatchProduct "stmpe"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "TransformationMatrix" "-0.000087 1.094214 -0.028826 -1.091711 -0.004364 1.057821 0 0 1"
EndSection
or whatever you got, into there.

You will want to reboot your Pi to verify you're do

Kedei 2 touch screen

Something I bought in 2015, 2 Kedei 2 lcd 3.5 inch touch screens. Worked, albeit slow.
With a Wheezy image, not to be updated due to the kernel doing its SPI thing to copy the framebuffer to the LCD screen via fbcopy.

March 2020, installed the Kedei screen on a Raspberry Pi V2 and inserted the archived SD card. It works!

Update? No, the official repository moved on. But there is a legacy repository!

Replace this line in /etc/apt/sources.list

deb http://legacy.raspbian.org/raspbian/ wheezy main contrib non-free rpi

and teh apt-get update works (be it with some warnings).

To test I installed MC and that went allright (be it with some warnings).

Screen quality is not too bad, screen refreshes are slow. In console mode it reminds me of the 9600 baud serial terminals!

Now I want autologon, no option in old raspiconfig!

From https://www.elinux.org/RPi_Debian_Auto_Login

sudo nano /etc/inittab
Scroll down to:

1:2345:respawn:/sbin/getty 115200 tty1
and change to

#1:2345:respawn:/sbin/getty 115200 tty1
Under that line add:

1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Auto StartX (Run LXDE)
In Terminal:

sudo nano /etc/rc.local
Scroll to the bottom and add the following above exit 0:

su -l pi -c startx

WD Pidrive

https://github.com/PiDrive/CommunityFoundationEdition

RTK.GPIO

RTK.GPIO protocol

The RTK.GPIO is a microprocessor system with a serial interface, and a RPi 40 pin GIO connector.

USB – CH340 UART – STM cpu – RPi GPIO 40 pin
– power 3.3V via voltage regulator for CH340, STM and RPi GPIO
– power 5V to RPi GPIO

The RPi is electrical identical to the RPi (all signals at 3.3V I/O).

Of the RPi connectors the following is supported:
– GPIO connector, layout identical to Raspberry
– GND, +5V, +3.3V
– GPIO 0-27 I/O set for read, write, pullup pulldown
– I2C on GPIO 2 and 3 100kHZ smbus subset
– No SPI, no ALT functions, no PWM, no edge triggered interrupts, no UART/T etc
– I2C also in separate 4 pin connector with +5V, unsure if 3.3V or 5V I2C signals
– UAR/T connector 4 pin undocumented
– PROG connector undocumented

Serial protocol (based upon studying the firmware source main.cpp version RTk-2016-01-05-FINAL)
A simple and not very robust protocol, no ACK’s, just one error message E1, no complete error checking,
version command returns string without CRLF

– ASCII character based
– The CH340 and STM communicate serial over 230400 baud, no hardware or software handshake
– no block I/O, all GPIO via separate commands
– just one error message ‘E 1 CR LF’
– all can be tested with a serial terminal emulator like Putty etc for GPIO, all is readable ASCII
– I2C commands are readable ASCII, but the data characters are interpreted as 8 bit numbers
(no software handshake allowed!)

Physical:
– GPIO numbers are the numbers on the RPi I/O connector.
– I2C is on GPIO2, GPIO3 with pullup resistors

After power on
– the RTK.GPIO sends the string ‘RTk.GPIO Ready’ (no CR LF!)
– all GPIO are Digital InOut

The RTK.GPIO accepts the following commands.

A command is one character followed by one or more characters as arguments, everything is in ASCII.

Flow:

main flow 

repeat
  read(command_char)
  if command char in [A..Z] then 
    read (param_char)
    do_command(command_char, param_char)
  else if command_char in [a..|] then
    read(gpio_char)
    gpio(command_char, gpio_char)
  else if command_char in {CR, LF)
    do nothing
  else
    send 'E' '1' CR LF
  until forever
  
do_commmand(command_char, param_char)


  case 
    V : send 'RTk.GPIO Ready' (note V requires a second char, can be any!)
	G : read(gpio_char)
	    do_GPIO(param_Char, GPIO_char)

    I : do_I2C(param_char)
	

gpio_command(pinc, cmdch)

GPIO Commands are two characters.
  <pinch> <cmdch>
 
pinch is the pin character (a..) where 'a' represents pin 0 (28 I/O's)
character is converted to number (nr = pin character - 'a'
cmdch is the command to perform on that pin:
  I: Set this pin to a digital input,        eg: aI
  O: Set this pin to a digital output,       eg: aO
  0: Write a digital low to this output,     eg: a0
  1: Write a digital high to this output,    eg: a1
  U: Write a pull input high,    eg: aU
  D: Write a pull input down,    eg: aD
  N: write a pull none           eg  aN
  ?: Read the state of this digital input,   eg: a?
     State is returned as pinch + state(0|1) 
     with CR LF added                        eg: a0 CR LF

 error if pin character out of range

do_I2C

in i2c all data chars are interpreted as integers, 
'0' is decimal i2c address 48 for example  
(make sure software handshake is off, otherwise the serial communication eats xon/xoff)

  read(i2c command)
  if i2c command = 'W' then
    read(i2C_address)
    read(length of i2c datastring)
    read all i2c datastring into i2c datablock array
    i2c.write(i2caddress, i2c datablock, lenght of i2c datablock)
  else if i2c command = 'R' then
    read(i2C_address)
    read(length of i2c datastring)
    read(first datablock data)
    i2c read(i2c addrss, i2c datablock, i2c datablock length)
    for all in i2c datablock do
      write datablock[count] to serial

RPI_HAL

rpi_hal from https://github.com/rudiratlos/rpi-hal is an incredible rich and uptodate unit for Freepascal to use the I/O of the Raspberry.

From Freepascal programs all works as expected when run as root. Otherwise accessing /dev/mem is causing real problems.

The unit can be used from Lazarus also (avoid the test procedures with writeln’ 😉 ) but also require root access and setting cthreads in the program heading.

For X apps  running as root is not possible with just sudo.
Seems I found a solution here: https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root

I applied method 2:

sudo nano /etc/profile

and added this line as last line

export XAUTHORITY=/home/pi/.Xauthority

Now i can do

$ sudo ./testinit (my simple test program with only the init line of rpi_hal)

and this worked without error, init succeeded.

If you want debugging the app in Lazarus, start Lazarus as root (and ignore all the warnings)

xhost +localhost
sudo /usr/bin/startlazarus

Original text from https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root

Method 2: Globally in /etc/profile
Add the following line to /etc/profile:

export XAUTHORITY=/home/username/.Xauthority
This will permanently allow root to connect to a non-root user’s X server.

Or, merely specify a particular app:

XAUTHORITY=/home/username/.Xauthority appname
where appname is the name of the particular app. (e.g. kwrite

Arduino on Raspberry

Install Arduino on Buster

  1. Arduino 1.8.12 (or higher) from arduino.cc – Software – Arduino ARM 32 bits
  2. Download to e.g. Downloads
  3. cd /Downloads
  4. tar -x -f arduino-1.8.5-linuxarm.tar.xz
  5. cd arduino-1.8.12
  6. sudo ./install.sh
  7. and Arduino appears in Home – Programming desktop

Autostart program like minicom at console at boot

Install minicom

sudo apt-get install minicom

setup your system to auto ;login into a commandline session
[use sudo raspi-config]

then at the end of .bashrc put in

if [ $(tty) == /dev/tty1 ]; then
   minicom -s  ##change this to be the thing you want or even a script [full path to]
fi

then reboot your rpi