Tuesday, December 29, 2020

Raspberry Pi/Python as Bluetooth classic client, bi-direction communication with ESP32

Raspberry Pi/Python act as GUI Bluetooth classic client, using tkinter/pybluez:
Connect to bluetooth classic server with hard-coded MAC.
User enter text to sent on bottom Text Frame, send to server.
Display the data received from server on upper Text frame.

The server side, run on ESP32 (NodeMCU ESP-32S), with SPI ST7735 IPS screen. It echo back received data. ESP32 (Arduino framework) code: Arduino-er: ESP-32S as Bluetooth classic Server, bi-direction communication with Raspberry Pi/Python.

Python code, pySPPClient.py.

import sys
from tkinter import *
from bluetooth import *
from threading import Thread
import time

rqsStopBtHandler = False

buf_size = 255

def btHandler():
    global rqsStopBtHandler
    rqsStopBtHandler = False
    
    print("btHandler Started")
    
    #Set sock.settimeout(),
    #to prevent program blocked by sock.recv()
    #and cannot end btHandler
    sock.settimeout(1.0)
    while rqsStopBtHandler!=True:
        try:
            datarx = sock.recv(buf_size)
            datarxToStr = datarx.decode("utf-8")
            print(datarxToStr)
            textCenter.insert(INSERT, datarxToStr)
        except Exception:
            continue
        
    print("btHandler End")
    
def startBtHandler():
    btThread = Thread(target=btHandler)
    btThread.start()
    
def close_window():
    global rqsStopBtHandler
    rqsStopBtHandler = True
    sock.close()
    print("Socket closed")
    print("Window closed")
    root.destroy()

def cmdSend():
    stringSent = textBottom.get(1.0, END)
    print(stringSent)
    sock.send(stringSent)
    #sock.send("\n")
    print("- Sent")
    
#===============================================
#Prepare Bluetooth Classic
print("Python version: ")
print(sys.version)
print("tkinter version: ", TkVersion)
print("=============================")
print("Connect to ESP32 Bluetooth Classic SPP Server")
#addr = "24:0A:C4:E8:0F:9A"
addr = "3C:71:BF:0D:DD:6A"
print(addr)
service_matches = find_service( address = addr )

if len(service_matches) == 0:
    print("couldn't find the ESP32 Bluetooth Classic SPP service")
    sys.exit(0)
    
for s in range(len(service_matches)):
    print("\nservice_matches: [" + str(s) + "]:")
    print(service_matches[s])
    
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]

port=1
print("connecting to \"%s\" on %s, port %s" % (name, host, port))

# Create the client socket
sock=BluetoothSocket(RFCOMM)
sock.connect((host, port))

print("connected")

#===============================================
#Prepare GUI
root = Tk()
root.configure(bg="darkgray") 
root.wm_title("SPP Client")
root.protocol("WM_DELETE_WINDOW", close_window)

rootFrame = Frame(root)
rootFrame.pack()

labelTitle = Label(root,
                   text="helloraspberrypi.blogspot.com",
                   font=("Helvetica", 18),
                   fg="White", bg="darkgray")
labelTitle.pack()

frameCenter = Frame(root, bg="lightgray")
frameCenter.pack()

textCenter= Text(frameCenter, width=26, height=10, font=("Helvetica", 18))
textCenter.pack(padx=10,pady=5)

frameBottom = Frame(root, bg="gray")
frameBottom.pack(expand=True, fill='both')

textBottom = Text(frameBottom, width=26, height=10, font=("Helvetica", 18))
textBottom.insert(INSERT, "Enter text here")
textBottom.pack(padx=10,pady=5)

buttonSend = Button(frameBottom, text="Send", command=cmdSend)
buttonSend.pack(padx=10,pady=5)

startBtHandler()

root.mainloop()

print("--- bye ---")

Related:

Friday, December 25, 2020

Raspberry Pi/Python remote control ESP32/Servos via Bluetooth Classic

Last exercise show how Python (on Raspberry Pi) Bluetooth communicate with ESP32 SerialToSerialBT, using pybluez. This exercise extended to send simple single character command to ESP32 via Bluetooth Classic, to control remote servos; with GUI using Tkinter.


pyBTServoClient_20201226.py, for Python3.
import sys
from tkinter import *
from bluetooth import *

print("Python version: ")
print(sys.version)
print("tkinter version: ", TkVersion)
print("=============================");
print("Connect to ESP BT Servo Server")
addr = "24:0A:C4:E8:0F:9A"
print(addr)
service_matches = find_service( address = addr )

if len(service_matches) == 0:
    print("couldn't find the ESP32 BT Servo service")
    sys.exit(0)
    
for s in range(len(service_matches)):
    print("\nservice_matches: [" + str(s) + "]:")
    print(service_matches[s])
    
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]

port=1
print("connecting to \"%s\" on %s, port %s" % (name, host, port))

# Create the client socket
sock=BluetoothSocket(RFCOMM)
sock.connect((host, port))

print("connected")

def close_window():
    sock.close()
    print("Socket closed")
    print("Window closed")
    root.destroy()

#prepare GUI
root = Tk()
root.geometry("380x200")
root.configure(bg="lightgray") 
root.wm_title("Bluetooth Servo Client")
root.protocol("WM_DELETE_WINDOW", close_window)

CMD_ORG = 'O'
CMD_XDEC = 'A'
CMD_XDEC10 = 'B'
CMD_XINC = 'C'
CMD_XINC10 = 'D'
CMD_YDEC = 'E'
CMD_YDEC10 = 'F'
CMD_YINC = 'G'
CMD_YINC10 = 'H'

def cmdO():
    sock.send(CMD_ORG)
    print("0, 0")

def cmdXdec():
    sock.send(CMD_XDEC)
    print("X-")
    
def cmdXdec10():
    sock.send(CMD_XDEC10)
    print("X-10")

def cmdXinc():
    sock.send(CMD_XINC)
    print("X+")
    
def cmdXinc10():
    sock.send(CMD_XINC10)
    print("X+10")
    
def cmdYdec():
    sock.send(CMD_YDEC)
    print("Y-")
    
def cmdYdec10():
    sock.send(CMD_YDEC10)
    print("Y-10")

def cmdYinc():
    sock.send(CMD_YINC)
    print("Y+")
    
def cmdYinc10():
    sock.send(CMD_YINC10)
    print("Y+10")


ButtonO = Button(root, text="0", command = cmdO, width=6)
ButtonXdec = Button(root, text="X-", command = cmdXdec, width=6)
ButtonXinc = Button(root, text="X+", command = cmdXinc, width=6)
ButtonYdec = Button(root, text="Y-", command = cmdYdec, width=6)
ButtonYinc = Button(root, text="Y+", command = cmdYinc, width=6)
ButtonXdec10 = Button(root, text="X-10", command = cmdXdec10, width=6)
ButtonXinc10 = Button(root, text="X+10", command = cmdXinc10, width=6)
ButtonYdec10 = Button(root, text="Y-10", command = cmdYdec10, width=6)
ButtonYinc10 = Button(root, text="Y+10", command = cmdYinc10, width=6)

ButtonO.grid(row=2, column=2)
ButtonXdec.grid(row=2, column=1)
ButtonXinc.grid(row=2, column=3)
ButtonYdec.grid(row=3, column=2)
ButtonYinc.grid(row=1, column=2)
ButtonXdec10.grid(row=2, column=0)
ButtonXinc10.grid(row=2, column=4)
ButtonYdec10.grid(row=4, column=2)
ButtonYinc10.grid(row=0, column=2)

root.mainloop()

print("\n--- bye ---\n")
The ESP32 code (run on Arduino framework) is in my another blog's post: Arduino-er - ESP32 receive Bluetooth Classic command from Raspberry Pi/Python, to control Servos.

Next:

Saturday, December 19, 2020

Python (on Raspberry Pi) Bluetooth communicate with ESP32 SerialToSerialBT, using pybluez

It's a simple Python example using pybluez extension module, run on Raspberry Pi 4/Raspberry Pi OS, to communicate with ESP32 SerialToSerialBT example.

pybluez (or https://github.com/pybluez/pybluez)is a Python extension module allowing access to system Bluetooth resources.

Install pybluez for Python3, enter the command in Terminal:

$ sudo pip3 install pybluez

Copy and modify pybluez/examples/simple/rfcomm-client.py in Raspberry Pi Thonny.

It's my modified version, pyBTSimpleClient.py

from bluetooth import *

def input_and_send():
    print("\nType something\n")
    while True:
        data = input()
        if len(data) == 0: break
        sock.send(data)
        sock.send("\n")
        
def rx_and_echo():
    sock.send("\nsend anything\n")
    while True:
        data = sock.recv(buf_size)
        if data:
            print(data)
            sock.send(data)
            
#MAC address of ESP32
addr = "24:0A:C4:E8:0F:9A"
#uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
#service_matches = find_service( uuid = uuid, address = addr )
service_matches = find_service( address = addr )

buf_size = 1024;

if len(service_matches) == 0:
    print("couldn't find the SampleServer service =(")
    sys.exit(0)

for s in range(len(service_matches)):
    print("\nservice_matches: [" + str(s) + "]:")
    print(service_matches[s])
    
first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]

port=1
print("connecting to \"%s\" on %s, port %s" % (name, host, port))

# Create the client socket
sock=BluetoothSocket(RFCOMM)
sock.connect((host, port))

print("connected")

#input_and_send()
rx_and_echo()

sock.close()
print("\n--- bye ---\n")


How it run on Raspberry Pi 4/Raspberry Pi OS, communicate with ESP32 (ESP32-DevKitC V4) SerialToSerialBT example. The code in ESP32 side is in my another blog Arduino-er: ESP32 Bluetooth serial example.
 

Next:


ImportError: libbluetooth.so.3


If you reported with error of:
ImportError: libbluetooth.so.3: cannot open shared object file: No such file or directory

Install required library by entering the command in Terminal:
$ sudo apt install bluetooth bluez libbluetooth-dev


Wednesday, December 9, 2020

Install GIMP on Raspberry Pi OS

GIMP is a cross-platform image editor available for GNU/Linux, OS X, Windows and more operating systems.

To install GIMP on Raspberry Pi OS, simple enter the command in Terminal:

$ sudo apt-get install gimp


After installed, it's listed in System MENU > Graphics > GNU Image Manipulation Program




Display system info with neofetch

neofetch is a Terminal-based tools to displays information about your operating system, software and hardware in visual way.

To install neofetch to Raspberry Pi OS, enter the command:

$ sudo apt install neofetch



Tuesday, December 8, 2020

Raspberry Pi OS now support FAN control

With Raspberry Pi OS released December 2020, fan control is itroduced.


In Raspberry Pi Configuration, select Performance tab, there is a option of FAN. you can select the GPIO pin to which it is connected and set the temperature at which it turns on and off.  To control the new Raspberry Pi Case Fan.



Friday, December 4, 2020

Test network speed between Raspberry Pi using iPerf3

iPerf3 is a tool for active measurements of the maximum achievable bandwidth on IP networks. It supports tuning of various parameters related to timing, buffers and protocols (TCP, UDP, SCTP with IPv4 and IPv6). For each test it reports the bandwidth, loss, and other parameters.

This post show how to run iPerf3 on two Raspberry Pi to check the network speed between.

On both Raspberry Pi, install iPerf3 by entering command in Terminal:

$ sudo apt install iperf3
After installed.

In the service side, enter the command:
$ iperf3 -s
In the client side, enter command:
$ iperf3 -c <server ip>




Thursday, December 3, 2020

Raspberry Pi link to Bluetooth 5.0 headphones, using Blueman

Blueman is a lightweight, easy to use, Python based, and GPL licensed, GTK+ Bluetooth Manager.

Blueman is designed to provide a simple yet effective means for controlling the BlueZ API and simplifying Bluetooth tasks, such as:

  • Connecting to 3G/EDGE/GPRS via dial-up
  • Connecting to / Creating Bluetooth networks
  • Connecting to input devices
  • Connecting to audio devices
  • Sending / Receiving files via OBEX
  • Pairing

To install Blueman on Raspberry Pi/Raspberry Pi OS, enter the command in Terminal:

$ sudo apt install bluetooth pi-bluetooth bluez blueman

After installed, reboot.

$ sudo reboot

After reboot, it's a shortcut on menu bar, and on MENU > Preferences > Bluetooth Manager.


This video show how to pair Bluetooth 5.0 headphones to Raspberry Pi/Raspberry Pi OS (32 bit) using Blueman. The devices tested are JBL TUNE 215BT + Raspberry Pi 4B/4 inch HDMI IPS Touch Display.



Tuesday, December 1, 2020

Check installed package in Raspberry Pi OS, using dpkg/dpkg-query

To list all installed packages, enter the command in Terminal:

$ dpkg -l

or

$ dpkg-query -l

To list about a specified package:

$ dpkg -l package-name-pattern

or

$ dpkg-query -l package-name-pattern



dpkg is a tool to install, build, remove and manage Debian packages. It can also be used as a front-end to dpkg-deb and dpkg-query. 

dpkg-query is a tool to show information about packages listed in the dpkg database.

With command "-l [package-name-pattern...]" list all known packages matching one or more patterns. If no package-name-pattern is given, list all packages in /usr/local/var/lib/dpkg/status, excluding the ones marked as not-installed (i.e.  those which have been previously purged).

The first three columns of the output show the desired action, the package status, and errors, in that order.

              Desired action:
                u = Unknown
                i = Install
                h = Hold
                r = Remove
                p = Purge

              Package status:
                n = Not-installed
                c = Config-files
                H = Half-installed
                U = Unpacked
                F = Half-configured
                W = Triggers-awaiting
                t = Triggers-pending
                i = Installed

              Error flags:
                <empty> = (none)
                R = Reinst-required




Monday, November 30, 2020

Waveshare 1.44 inch LCD HAT

Waveshare 1.44 inch LCD HAT on Raspberry Pi Zero W running Raspberry Pi OS (32 bit)


This is an LCD display HAT for Raspberry Pi, 1.44inch diagonal, 128x128 pixels, with embedded controller, communicating via SPI interface.

Features

  • Standard Raspberry Pi 40PIN GPIO extension header, supports Raspberry Pi series boards
  • 1x joystick (5-position), 3x pushbuttons, handy and useful
  • Comes with development resources and manual (examples for Raspberry Pi)

Specifications

  • Driver: ST7735S
  • Interface: SPI
  • Display color: RGB, 65K color
  • Resolution: 128x128
  • Backlight: LED
  • Operating voltage: 3.3V

details refer to Waveshare product page:
https://www.waveshare.net/wiki/1.44inch_LCD_HAT (Chinese)
https://www.waveshare.com/wiki/1.44inch_LCD_HAT (English)


Monday, November 23, 2020

Install CircuitPython to nanoESP32-S2, on Raspberry Pi.

 


MuseLab nanoESP32-S2 is a dev. board with a ESP32-S2 module. This board has 2 USB-C connector, one for Serial (ch340) and one for Native USB (esp32), is supported running CircuitPython.

Currently, nanoESP32-S2 support 4 module:

  • ESP32-S2-WROOM: PCB Antenna, no PSRAM.
  • ESP32-S2-WROOM-I: IPEX Antenna, no PSRAM.
  • ESP32-S2-WROVER: PCB Antenna, with PSRAM.
  • ESP32-S2-WROVER-I: IPEX Antenna, with PSRAM.

My sample is ESP32-S2-WROVER-I.

This video show the steps to flash CircuitPython (latest unstable release CircuitPython 6.1.0-beta.1) on museLab nanoESP32-S2, using Raspberry Pi 4B/8G running Raspberry Pi OS (32 bit).


Install esptool:
$ sudo pip install esptool
Download CircuitPython:
Visit https://circuitpython.org/board/muselab_nanoesp32_s2/ to download CircuitPython (.BIN) for nanoESP32-S2.

The full path of the downloaded file in my case is:
/home/pi/Downloads/adafruit-circuitpython-muselab_nanoesp32_s2-en_US-6.1.0-beta.1.bin

Identify the COM port to attached to ESP32-S2 board, using dmesg:

Before connect to ESP32-S2 board:

Enter the command to clear dmesg buffer:
$ sudo dmesg -c

Connect ESP32-S2 USB marked "ch340".

Enter the command to check the latest attached port:
$ dmesg

found:
ch341-uart converter now attached to ttyUSB0

The COM port is: /dev/ttyUSB0

Erase and Flash ESP32-S2:

Erase:
$ esptool.py --chip auto --port <COM PORT> erase_flash
Flash with downloaded CircuitPython:
$ esptool.py --chip auto --port <COM PORT> -b 460800 --before=default_reset \
--after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 4MB 0x0000 \
<DOWNLOADED FILE>
Done!
After flashed with CircuitPython, you can now disconnect and reconnect the ESP32-S2 board to the another USB connector marked "esp32".

A new driver name "CIRCUITPY" is attached.


Install Mu:

Mu is a Python Editor, and is suggested to program CircuitPython.

To install Mu on Raspberry Pi OS:
Click the Menu >> Preferences >> Recommmended Software
>> Programing >> Mu

With Mu installed, you can try something with CircuitPython REPL. Refer to the video.


For more exercise related to CircuitPython/ESP32-S2, refer to my another blog posts Embedded things > Hello nanoESP32-S2/CircuitPython

Install esptool on Raspberry Pi OS

esptool.py is a Python-based, open source, platform independent, utility to communicate with the ROM bootloader in Espressif ESP8266 & ESP32 chips. ESP32-S2 is supported started from Version 3.0 (https://github.com/espressif/esptool/releases).

To install esptool on Raspberry Pi OS, enter the command in Terminal:

$ sudo pip install esptool
remark:

In my trial on Raspberry Pi OS, if I install without "sudo", I cannot run it without specify the full path.

Because the esptool.py executable is installed to the hidden directory ~/local/.bin directory. Have to set PATH to esptool, otherwise it cannot be run directly. So I install esptool with "sudo".

To check the version of installed esptool using pip:
$ pip show esptool



Next:
Install CircuitPython to nanoESP32-S2, on Raspberry Pi

Sunday, November 22, 2020

Remote access Raspberry Pi using xrdp/Microsoft Remote Desktop

How to remote control Raspberry Pi from Android/Windows 10 with xrdp installed.

Microsoft Remote Desktop Protocol (RDP) provides remote display and input capabilities over network connections for Windows-based applications running on a server. RDP is designed to support different types of network topologies and multiple LAN protocols.

xrdp is an open source RDP server, provides a graphical login to remote machines using Microsoft Remote Desktop Protocol (RDP). xrdp accepts connections from a variety of RDP clients: FreeRDP, rdesktop, NeutrinoRDP and Microsoft Remote Desktop Client (for Windows, Mac OS, iOS and Android).

Install xrdp:

In Raspberry Pi, install xrdp by entering the command in Terminal:

$ sudo apt install xrdp

Remote access Raspberry Pi from Android using Microsoft Remote Desktop App:

With Microsoft Remote Desktop app installed on Android devices, you can access remote Raspberry Pi running xrdp. There are two version available in Google Play Store: Remote Desktop and Remote Desktop 8. In my trial, Remote Desktop 8 is more stable, so I show how to for using it.




Remote access Raspberry Pi from Windows 10 using Remote Desktop Connection:

With xrdp installed, you can also remote access your Raspberry Pi from Windows 10 using Remote Desktop Connection. Just search and run "Remote Desktop Connection".


Check in the video:



Saturday, November 21, 2020

Record screen action on Raspberry Pi, SimpleScreenRecorder

SimpleScreenRecorder is a Linux program that I've created to record programs and games. To install it on Raspberry Pi OS:

MENU > Preferences > Add/Remove Software
Search and install simplescreenrecorder

Friday, November 20, 2020

Install Virtual Keyboard(matchbox-keyboard) on Raspberry Pi

 Matchbox-keyboard is an on screen 'virtual' or 'software' keyboard. To install on Raspberry Pi:

$ sudo apt-get install matchbox-keyboard

Tested on Raspberry Pi 4B/8G with 4" 800x480 HDMI IPS Touch Screen running Raspberry Pi OS (32 bit).

Wednesday, November 18, 2020

Setup 4 inch HDMI IPS Touch Display on Raspberry Pi 4B/8G (Raspberry Pi OS 32 bit)

This video show how to setup 4" HDMI Display-C (XPT2046 Touch Controller/800x480 Pixel) on Raspberry Pi 4B/8G (Raspberry Pi OS 32 bit).

Visit http://www.lcdwiki.com/4inch_HDMI_Display-C, follow the steps, enter the command in Terminal:

Install the Display/Touch driver:
$ sudo rm -rf LCD-show
$ git clone https://github.com/goodtft/LCD-show.git
$ chmod -R 755 LCD-show
$ cd LCD-show/
$ sudo ./MPI4008-show



Calibrate the touch screen of 4 inch 800x480 HDMI Display for Raspberry Pi 


Actually, the touch is calibrated very well after driver installed.

To calibrate the touch screen:
download How_to_calibrate_the_resistance_touch_screen-V1.2 below Download Resources,
follow the steps.

With driver installed,
Enter the commands in Terminal:
$ cd LCD-show/
$ sudo dpkg -i -B xinput-calibrator_0.7.5-1_armhf.deb

Execute the touch calibration command:
$ DISPLAY=:0.0 xinput_calibrator

Touch the four calibration points with the touch pen

New touch parameters will be displayed after calibration

Edit /etc/X11/xorg.conf.d/99-calibration.conf,
update with new touch parameters.
$ sudo nano /etc/X11/xorg.conf.d/99-calibration.conf

Save and exit:
- Ctrl-X
- Y
- Enter

$ sudo reboot



Next:
~ Install Virtual Keyboard(matchbox-keyboard) on Raspberry Pi

Remark@2021-07-15:
By default without installing driver, the screen will display in vertical (portrait). With Raspberry Pi OS Screen Configuration Orientation feature, I can change screen direction.

For sure, without installing driver, it cannot detect touch. Normally I use wireless keyboard with mouse pad, so no need touch function.


My board, Raspberry Pi 4B/8G v1.4

 Just received my new board, Raspberry Pi 4B/8G v1.4.








Setup 4 inch HDMI Display-C on Raspberry Pi 4B/8G (Raspberry Pi OS 32 bit)

Friday, November 13, 2020

Install 64 bit Arduino IDE on 64 bit Ubuntu for Raspberry Pi

Steps to download and install 64 bit Arduino IDE on 64 bit Ubuntu for Raspberry Pi, tested on Raspberry Pi 4B/4G.


download the option of Linux ARM 64 bits.

Extract the downloaded file, and run the install script in Terminal:
$ sudo ./install.sh


Remark:
If you fail when upload to board caused by Permission denied by USB port, enter the command in Terminal.
$ sudo usermod -a -G dialout <username>
$ sudo chmod a+rw <port>

where <username> is your user name in Ubuntu, <port> is the attached USB port.














Thursday, November 12, 2020

Program Arduino using VSCode/PlatformIO/Ubuntu for Raspberry Pi

With Visual Studio Code/PlatformIO IDE installed on Ubuntu for Raspberry Pi, this video show steps to program Arduino Uno using Visual Studio Code + PlatformIO IDE on 64 bit Ubuntu Desktop for Raspberry Pi, tested on Raspberry Pi 4B/4G).


Remark:
At 6:15 in the video, a+w is mis-entered, it work as expected. Anyway a+rw is suggested.

Wednesday, November 11, 2020

Install 64 bit Visual Studio Code/PlatformIO IDE on Ubuntu for Raspberry Pi

To install 64 bit Visual Studio Code on Ubuntu Desktop for Raspberry Pi, visit https://code.visualstudio.com/, download Linux .deb of ARM 64 build.

Open Terminal, run the command:

$ sudo apt install ./<file>.deb

After Visual Studio Code installed, you can search and run it in Activities, or enter "code" in Terminal.

Install Extension of PlatformIO IDE to Visual Studio Code:

Click Extension tab, search and install PlatformIO IDE.

Related:
Install official Visual Studio Code (ver 1.5) and PlatformIO IDE on Raspberry Pi OS (32 bit), basically the same steps, but 32 bit for current Raspberry Pi OS.

Next:
Program Arduino using VSCode/PlatformIO/Ubuntu for Raspberry Pi



Sunday, November 8, 2020

Run vcgencmd on Ubuntu for Raspberry Pi, fix "VCHI initialization failed"

vcgencmd is a command line utility that can get various pieces of information from the VideoCore GPU on the Raspberry Pi. Much of the information available is only of use to Raspberry Pi engineers, but there are a number of very useful options available to end users that will be described here.

In my trial on Ubuntu Desktop for Raspberry Pi, vcgencmd is installed by default. But fail with error of "VCHI initialization failed".

To fix it, add the video group to your user:

$ sudo usermod -aG video <username>


After log-out and log-in.



Thursday, November 5, 2020

psutil, process and system utilities for Python

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. 

In my trial on Ubuntu Desktop for Raspberry Pi, it's installed by default.

Links:
- GitHub - giampaolo /psutil
- psutil documentation



Install Thonny on Ubuntu for Raspberry Pi

Thonny is a very great cross-platform Python IDE. 

To install Thonny on Ubuntu Desktop for Raspberry Pi, simple enter the command in Terminal:

$ sudo apt install thonny

After installed, you can enter "thonny" in Terminal, or search "thonny" in Activities.


Thursday, October 29, 2020

Check disks on Ubuntu Desktop for Raspberry Pi


Disk Usage Analyzer is a graphical tool to analyze disk usage. It is pre-loaded in Ubuntu Desktop for Raspberry Pi.

Search and run Disk Usage Analyzer in Accessories:





Test the performance of disk on Ubuntu Desktop for Raspberry Pi using Disks(gnome-disk-utility)

Disks(gnome-disk-utility) is a GNOME utility for dealing with storage devices.

To test the performance of disk on Ubuntu Desktop for Raspberry Pi, open Disks from Activities.

This video show how:


Tuesday, October 27, 2020

Check system usage using System Monitor, on Ubuntu for Raspberry Pi

To check system status, system loading and disk usage on Ubuntu for Raspberry, you can use System Monitor.

Search and run "System Monitor" in Activities.


In System Monitor, you can checkProcesses, Resources and File systems.





related:

Tuesday, October 13, 2020

Install official Visual Studio Code (ver 1.5) and PlatformIO IDE on Raspberry Pi OS (32 bit)


With Visual Studio Code now support Raspberry Pi officially, just tried to install on Raspberry Pi 4B/4GB. As straightforward as stated in Visual Studio Code doc.

Install official Visual Studio Code (ver 1.5) and PlatformIO IDE on Raspberry Pi OS (32 bit):

Install VS Code:

Visit: https://code.visualstudio.com/
Scroll down and download ".deb" of "ARM" build for 32 bit Raspberry Pi OS.

Open Terminal, run the command:
$ sudo apt install ./<file>.deb

Where <file> is the file downloaded.

Install Extension of PlatformIO IDE to Visual Studio Code:

Click Extension tab, search and install PlatformIO IDE

Related:
~ Current Raspberry Pi OS officially 32 bit only. If you want 64 bit Visual Studio Code, you can try Ubuntu Desktop for Raspberry Pi (64 bit), and Install Visual Studio Code/PlatformIO IDE on Ubuntu for Raspberry Pi.


Updated@2021-03-24:

Sunday, October 11, 2020

Visual Studio Code now support Raspberry Pi officially

 Visual Studio Code is a free, open source code editor from Microsoft. With its release of version 1.50 (September 2020) it support Raspberry Pi officiaally.


  • Visual Studio Code is a free, open source code editor from Microsoft.
  • It's available cross-platform on Linux and Mac, and also Chromebooks that support Linux apps.
  • Official ARM support for Linux now brings the application to ARM based Chromebooks, Linux machines like the PineBook Pro and the Raspberry Pi.

reference:
- Windows Central > Microsoft Visual Studio Code now supports Raspberry Pi and ARM Chromebooks
- Visual Studio Code > September 2020 (version 1.50)

Next:
Install official Visual Studio Code (ver 1.5) and PlatformIO IDE on Raspberry Pi OS (32 bit)



Updated@2021-03-24:

Saturday, October 10, 2020

Watch CPU frequency of Raspberry Pi: adding menu item of CPUFreq frontend and using vcgencmd.

This video show how to watch CPU frequency of Raspberry Pi running Rspberry Pi OS (tested on Raspberry Pi 4):
- adding menu item of CPUFreq frontend
- or using vcgencmd. 

vcgencmd is a command line utility that can get various pieces of information from the VideoCore GPU on the Raspberry Pi, details refer to Raspberry Pi Document of vcgencmd.

To get the actual speed of ARM cores, enter the command in Terminal:

$ vcgencmd measure_clock arm

You can also keep watching vcgencmd result in Terminal using the watch command.

$ watch -n 1 vcgencmd measure_clock arm

Alternatively, you can also check it in the file /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq, where cpu0 can be cpu0~4 for Raspberry Pi 4 with 4 core. Read HERE.


Sunday, September 13, 2020

Install Putty on Raspberry Pi OS

To install Putty on Raspberry Pi OS, enter command:
$ sudo apt install putty
After installed, Putty located at menu > Internet > Putty SSH client


Monday, August 24, 2020

Wio Terminal: Read Light Sensor and display on LCD graphically


The light sensor on Wio Terminal uses Analog interface and you can simply read the surrounding Light sensor values via reading its pin.

This exercise run on Wio Terminal (using Arduino framework) to read the built-in light sensor in 10ms interval, and display on the LCD screen graphically.

Also, the time to perform the job is displayed as info for reference.

Wio_LightSensor.ino

#include <SPI.h>
#include <TFT_eSPI.h>

TFT_eSPI tft = TFT_eSPI();

#define FrameOx 5
#define FrameOy 5
#define FrameWidth  300
#define FrameHeight 200

#define Title   "Wio Terminal Light Sensor"
#define TitleX  FrameOx
#define TitleY  210
#define InfoX   FrameOx
#define InfoY   230

#define BUFFER_SIZE 300
#define MAX_VAL 200
int BufferSensorVal[BUFFER_SIZE];

int sampling;

// interval at which to sample light sensor (milliseconds)
const long interval = 10;
unsigned long previousMillis = 0;

void drawFrame(){
  tft.fillRect(FrameOx, FrameOy, FrameWidth, FrameHeight, TFT_DARKGREY);
  tft.drawRect(FrameOx-1, FrameOy-1, FrameWidth+2, FrameHeight+2, TFT_LIGHTGREY);
}

void setup() {
  pinMode(WIO_LIGHT, INPUT);
  
  tft.init();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);

  tft.drawString(Title,TitleX,TitleY);

  for(int i=0; i<BUFFER_SIZE;i++)
  {
    int v = map(i, 0, BUFFER_SIZE, 0, MAX_VAL);
    BufferSensorVal[i] = 0;
  }

  sampling = 0;

}

void loop() {
  unsigned long currentMillis = millis();
  unsigned long startMicros = micros();

  if (currentMillis - previousMillis >= interval) {

    if(sampling == 0){
      drawFrame();
    }
    
    previousMillis = currentMillis;

    //Read Light Sensor and map to value suitable for display
    int light = analogRead(WIO_LIGHT);
    int lightVal = map(light, 0, 1024, 0, MAX_VAL);
    BufferSensorVal[sampling] = lightVal;

    tft.drawLine(sampling+FrameOx, FrameOy+MAX_VAL, 
          sampling+FrameOx,FrameOy+MAX_VAL-lightVal, TFT_WHITE);
    
    sampling++;
    if(sampling == BUFFER_SIZE){
      sampling = 0;
    }

    //How long to perform the drawing, 
    //for information only,in microsecond
    String strInfo = String(micros()-startMicros);
    tft.drawString("     ", InfoX, InfoY);
    tft.drawString(strInfo, InfoX, InfoY);

  }
}