Raspberry Pi Digital Clock, written in Python programming language

This was challenging for me to get into Python programming and setting Raspberry Pi to my own needs. I know this is overkill but also this is a path for future projects for example info display which can display time, the temperature in your place, and maybe turn on lights in the living room and the list goes on and on.

Hardware requirements:

Raspberry Pi
Waveshare 5inch HDMI LCD
MicroSD Card
PSU for Raspberry Pi

1. create micro sd card with raspberry pi os lite

Here we need to enter the path and name of the image we want to write to the sd card instead of “/ source_image_file” and instead of “/ destination_disk_drive” we need to enter the path and name of the disk we want to write to.

sudo dd if=/source_image_file of=/destination_disk_drive

2. enable SSH

To be able to access over SSH we need to create an empty file named SSH in the boot partition of our Micro SD card.

sudo touch /media/your_username/boot/SSH

3. setup hostname

sudo nano /media/ebaketa/rootfs/etc/hostname

4. edit the host’s file and replace “myhostname” with the desired hostname:

sudo nano /media/your_username/rootfs/etc/hosts

127.0.0.1	localhost
::1		localhost
127.0.1.1	myhostname.localdomain	myhostname

5. setup a static IP address

sudo nano /media/your_username/rootfs/etc/dhcpcd.conf

# Example static IP configuration:
interface eth0
static ip_address=192.168.x.xxx/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.x.x
static domain_name_servers=192.168.x.x 8.8.8.8 fd51:42f8:caae:d92e::1

6. edit Raspberry Pi OS configuration file config.txt

These lines below we need to add to “config.txt” to configure 5 inch HDMI LCD. The best is to add lines to the end of the file.

max_usb_current=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0
hdmi_drive=1

7. insert micro SD to the target machine, boot OS, and login over SSH

Now we can insert an SD card into Raspberry Pi, connect the power supply and boot into OS.

8. update Raspberry Pi OS

sudo apt update
sudo apt upgrade

9. reboot Raspberry Pi OS and login over SSH

10. start raspi-config tool

sudo raspi-config

change default password
set boot options -> console autologin
set language and regional settings
set keyboarad layout
set time zone

11. reboot Raspberry Pi OS and login over SSH

12. install xorg, xinit, x11-server-utils

sudo apt -y install --no-install-recommends xserver-xorg
sudo apt -y install --no-install-recommends xinit
sudo apt -y install x11-xserver-utils

13. install openbox, lxterminal, lxtask, lxappearance

sudo apt -y install openbox obconf obmenu lxterminal lxtask lxappearance

14. install PyGObject

sudo apt -y install python-gi python-gi-cairo python3-gi python3-gi-cairo gir1.2-gtk-3.0

15. create .bash_profile file and add a line below

touch ~/.bash_profile && sudo nano ~/.bash_profile

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then exec startx; fi

16. create openbox autostart file and add lines below

mkdir ~/.config && mkdir ~/.config/openbox && touch ~/.config/openbox/autostart && sudo nano ~/.config/openbox/autostart

# disable screen saver
xset s off &
xset s -dpms &
# run python digital clock
python ~/Projects/python/digital_clock/digital_clock.py

17. create directories for projects and get projects via wget

mkdir ~/Projects && mkdir ~/Projects/python && mkdir ~/Projects/python/digital_clock && cd ~/Projects/python/digital_clock

wget https://raw.githubusercontent.com/ebaketa/digital_clock/master/digital_clock.py

18. reboot Raspberry Pi OS

And that’s it with the next boot you should have a Raspberry Pi digital clock. If you find any mistakes in commands, please let me know, so I can correct them!

Github repo: https://github.com/ebaketa/digital_clock

Till the next time!

Install dmenu from source code on Raspberry Pi

So what is dmenu? dmenu is a dynamic menu for the X Window System and Raspberry Pi runs Linux. It is simple and can manage large numbers of user-defined menu items efficiently. And one more thing you need to install it from the source code so it is a good exercise to learn how to compile a program in Linux.

dmenu configured to show up in the middle of the screen


Software is freely available from suckless.org, and there is also “dwm” windows manager for X, “st” simple terminal, “surf” simple web browser, and more.
dmenu configured to show up on the top of the screen

First, we need to update the system and install dependencies:

sudo apt update
sudo apt install xorg-dev
sudo apt install build-essential
sudo apt install git

Clone dmenu git repo:

git clone https://git.suckless.org/dmenu

Change directory:

cd dmenu

Build and install dmenu:

sudo make install

And we are ready to run dmenu from the terminal and use it. It shows up above on top of the panel. But it is smaller than the panel and there are fever patches that can help us to look better.

Remove compiler output files:

sudo make clean

Removing config.h file helps to apply patches:

sudo rm config.h

Download desired patch:

// numbers
wget https://tools.suckless.org/dmenu/patches/numbers/dmenu-numbers-4.9.diff
patch -p1 < dmenu-numbers-4.9.diff
sudo make install
sudo make clean
sudo rm config.h

// center
wget https://tools.suckless.org/dmenu/patches/center/dmenu-center-20200111-8cd37e1.diff
patch -p1 < dmenu-center-20200111-8cd37e1.diff
sudo make install
sudo make clean
sudo rm config.h

// highlight
wget https://tools.suckless.org/dmenu/patches/highlight/dmenu-highlight-20201211-fcdc159.diff
patch -p1 < dmenu-highlight-20201211-fcdc159.diff
sudo make install
sudo make clean
sudo rm config.h

// line height
wget https://tools.suckless.org/dmenu/patches/line-height/dmenu-lineheight-5.0.diff
patch -p1 < dmenu-lineheight-5.0.diff
sudo make install
sudo make clean
sudo rm config.h

// border
wget https://tools.suckless.org/dmenu/patches/border/dmenu-border-4.9.diff
patch -p1 < dmenu-border-4.9.diff
sudo make install
sudo make clean
sudo rm config.h

With this part of the setup, we are gonna create keybindings for an easy run as a top panel or in the middle of the screen.

Edit Raspberry Pi OS keybindings:

sudo nano /etc/xdg/openbox/lxde-pi-rc.xml

Add this lines in <keyboard> section:

<keybind key="C-S-space">
    <action name="Execute">
        <command>dmenu_run -h 36</command>
    </action>
</keybind>
<keybind key="C-space">
    <action name="Execute">
        <command>dmenu_run -h 30 -c -l 10</command>
    </action>
</keybind>

Now if we press a key combination SHIFT + CTRL + SPACE runs dmenu above the top panel and pressing CTRL + SPACE runs dmenu in the middle of the screen. And that all for this late-night adventure with Raspberry Pi.

Till the next time.

MiniPRO TL866xx universal programmer Linux installation.

The TL866A universal programmer is a chip programmer that allows us to write or read chip memory such as microcontrollers, EEPROM memory, etc. This very popular device, unfortunately, comes with software only for the Windows operating system. But there is an open-source alternative that allows the use of this device on the Linux operating system, thanks to David Griffith and his project on GitLab.



Installation:

Install build dependencies:

sudo apt install build-essential pkg-config git libusb-1.0-0-dev

Get source code:

git clone https://gitlab.com/DavidGriffith/minipro.git

Compile source code:

cd minipro
make

Install application:

sudo make install

Udev configuration:

sudo cp udev/*.rules /etc/udev/rules.d/
sudo udevadm trigger

Add regular user to the plugdev group:

sudo usermod -a -G plugdev YOUR-USER

Reboot your system.

Basic usage:

Show all available options:

minipro

Show version information:

minipro -V

Read from the device and save to a file:

minipro -p W29C020C -r test_w29c020c.bin

Erase the device:

minipro -p W29C020C -E

Blank check:

minipro -p W29C020C -b

Write from file to the device:

minipro -p W29C020C -w test_w29c020c.bin

I am very pleased with this installation, everything went without a single problem and the universal programmer works flawlessly. Many thanks to the open-source community and fingers up for David’s project on GitLab.

Stay healthy and safe till the next time!

Basic commands and using PICkit 2 on Linux!

Now that we have the software installed and ready to use, it is time to get familiar with the basic commands to successfully load the program into the microcontroller. So let’s get started!

Checking version:

pk2cmd -?V

# Returned output:

Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   2.32.00


Operation Succeeded

Auto-detect PIC:

pk2cmd -P

# Returned output:
Auto-Detect: Found part PIC16F887.


Operation Succeeded

Erase a device:

pk2cmd -P -E

# Returned output:
Auto-Detect: Found part PIC16F887.

Erasing Device...

Operation Succeeded

Blank check:

pk2cmd -P -C

# Returned output:
Auto-Detect: Found part PIC16F887.

Device is blank

Operation Succeeded

Program a device:

pk2cmd -PPIC16F887 -J -M -Ftest_write.hex

# Returned output:
PICkit 2 Program Report       
2-1-2021, 1:17:27
Device Type: PIC16F887

Program Succeeded.

Operation Succeeded

Power a device and release reset:

pk2cmd -P -A5 -T -R

# Returned output:
Auto-Detect: Found part PIC16F887.


Operation Succeeded

Read a device:

pk2cmd -PPIC16F887 -J -R -GFtest_read.hex

# Returned output:
Read successfully.            

Operation Succeeded
I believe this is enough to get started with PICkit 2 Development Programmer / Debugger on Linux OS.
Stay healthy and safe till the next time!

Install PICkit 2 Development Programmer / Debugger on Raspberry Pi OS.

To install PICkit 2 Development Programmer / Debugger on Raspberry Pi OS, we are gonna first prepare our system by installing dependencies, download source code for PICkit 2 command-line application, compile it, and at the end verify test installation.

So for that, we are gonna use these commands as follows:

Update and Install dependencies:

sudo apt update
sudo apt install build-essential libusb-dev

Download and unpack the source files:

wget https://ww1.microchip.com/downloads/en/DeviceDoc/pk2cmdv1.20LinuxMacSource.tar.gz
tar xzvf pk2cmdv1.20LinuxMacSource.tar.gz
cd pk2cmdv1.20LinuxMacSource

Building the application:

make linux

Installing the application:

make install

Adding device file location to PATH:

echo 'export PATH="$PATH:/usr/share/pk2"' >> ~/.bashrc

Reboot system and test installation:

pk2cmd -?v

# PICki2 not connected
Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   PICkit 2 not found

# PICkit2 connected
Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   2.32.00

Uninstall pk2cmd:

Remove file pk2cmd from /usr/local/bin:
sudo rm -R /usr/local/bin/pk2cmd

Remove all files from /usr/share/pk2/:
sudo rm /usr/share/pk2/*

Remove folder /usr/share/pk2/:
sudo rm -R /usr/share/pk2

Edit file .bashrc:
sudo nano ~/.bashrc

Find and Remove line :
export PATH="$PATH:/usr/share/pk2"

Stay healthy and safe till the next time!

Install PICkit 2 Development Programmer / Debugger on Debian 10 Buster 64-bit.

To install PICkit 2 Development Programmer / Debugger on Debian 10 Buster 64-bit, we need to install library packages for i386 architecture. That we can do with Multiarch. What is Multiarch? Multiarch lets us install library packages from multiple architectures on the same machine.

So for that, we are gonna use a couple of commands to print current architecture, check foreign architecture, and add a new architecture.

The first command is gonna print the current machine architecture:

dpkg --print-architecture
amd64

The second command is gonna print foreign machine architecture. If print nothing, means we don’t have foreign machine architecture added to our system:

dpkg --print-foreign-architectures

The next step is a way to add foreign machine architecture to our system:

dpkg --add-architecture i386

So now if we do check for other available architectures, it should print i386:

dpkg --print-foreign-architectures
i386

Now we need to install dependencies for compiling our source files:

sudo apt update
sudo apt install build-essential libusb-dev

That’s all for preparing the system. The next step is downloading and unpacking the source files:

wget https://ww1.microchip.com/downloads/en/DeviceDoc/pk2cmdv1.20LinuxMacSource.tar.gz
tar xzvf pk2cmdv1.20LinuxMacSource.tar.gz
cd pk2cmdv1.20LinuxMacSource

Building the application:

make linux

Installing the application:

make install

Adding device file location to PATH:

echo 'export PATH="$PATH:/usr/share/pk2"' >> ~/.bashrc

Reboot system and test installation:

pk2cmd -?v

# PICki2 not connected
Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   PICkit 2 not found

# PICkit2 connected
Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   2.32.00

Uninstall pk2cmd:

Remove file pk2cmd from /usr/local/bin:
sudo rm -R /usr/local/bin/pk2cmd

Remove all files from /usr/share/pk2/:
sudo rm /usr/share/pk2/*

Remove folder /usr/share/pk2/:
sudo rm -R /usr/share/pk2

Edit file .bashrc:
sudo nano ~/.bashrc

Find and Remove line :
export PATH="$PATH:/usr/share/pk2"

Stay healthy and safe till the next time!