[PYTHON] Play with your Ubuntu desktop on your Raspberry Pi 4

Introduction

I've touched the Raspberry Pi a little before, but I heard that the Raspberry Pi 4 has 4GB of RAM and the Ubuntu desktop is officially supported in the fall, so I simply moved it and played with it. It is a memo of the time.

What I tried

Basically, I just ran the Ubuntu desktop (GNOME 3) on the Raspberry Pi 4. After that, I created a little programming environment so that it can be operated remotely.

What you prepared

I used Raspberry Pi 4 with 4GB of RAM. It may be easier to buy a starter kit that includes a case, heat sink, fan, power adapter, MicroSD card, and MicroHDMI-to-HDMI cable in addition to the main unit. Since the Raspberry Pi itself does not have a power button, it is convenient to have a power adapter with an ON/OFF switch. I used a 64GB microSD card. I also prepared a display to move the desktop environment. There are various 7-inch touch-compatible displays for Raspberry Pi, so I chose the cheap one and bought it. It's fun to see the GNOME screen on a small screen. In addition, prepare a USB-connected keyboard and mouse. This time, I bought a Raspberry Pi official keyboard and mouse to create an atmosphere. You can use the familiar red/white coloring to make it cute. I also wanted to see YouTube, so I prepared a small speaker with an earphone jack connection.

This time I used a normal Raspberry Pi 4, but there is also a Raspberry Pi 400 with an integrated keyboard.

Creating an OS image

Previously, OS images were written to SD cards using dd and Etcher, and SD cards were prepared using NOOBS, but now software called Raspberry Pi Imager is officially prepared. This time I use Ubuntu desktop instead of normal Raspberry Pi OS (Raspbian), but Ubuntu can also write to SD card using Raspberry Pi Imager. I created an SD card for an OS image using Raspberry Pi Imager on Windows. https://www.raspberrypi.org/software/ image.png Set the OS to write with Operationg System. Select Ubuntu Desktop 20.10 (RPi 4/400) from Other general purpose OS. You can also format the SD card by selecting Erase here. image.png Next, select the microSD card to write with SD Card. (Don't make a mistake!) image.png Finally, press the WRITE button to start writing to the SD card. Let's wait for a while. When the writing is completed, the SD card creation of the OS image is completed.

Setting up Ubuntu Desktop 20.10.

Insert the microSD card into the Raspberry Pi 4 main unit, connect the keyboard / mouse and display, and turn on the power to start the initial settings. The display has two micro-HDMI ports, but it seems good to connect it to HDMI0 on the USB Type-C side. Initial settings are completed when language settings, keyboard settings, Wi-Fi settings, regional settings, and user settings are made according to the procedure. Log in and you'll be taken to the familiar GNOME 3 desktop! It seems that the sunglasses are Raspberry Pi specifications. image.png First, start up the terminal and update the package.

$ sudo apt update && sudo apt upgrade -y

Japanese localization settings

Immediately after starting, the notation is not translated into Japanese. Right-click on an empty area on your desktop and select Settings. image.png If you select Manage Installed Languages from Region & Language, "Language support is not completely installed" will be displayed, so install from there. image.png If you restart after the installation is completed, the notation will change to Japanese.

Screen display settings

Since we are using a display as small as 7 inches this time, we will set the Dock to be automatically hidden in order to use the screen as widely as possible. image.png Also, I don't like to show the icon on the display, so I use the Tweak Tool to hide it.

$ sudo apt install gnome-tweak-tool

image.png

Watch youtube on Chromium

Firefox is installed by default in Ubuntu, but here we will install and use Chromium. Chromium can be installed with apt.

$ sudo apt install chromium-browser

I opened the YouTube site on Chromium. There is some lag until the thumbnails are displayed, but I think they will be displayed without waiting too long. Also, even if I played the video in full screen, it was displayed without any problem. I feel that it can be used enough. it's amazing! image.png The sound was output by inserting the speaker into the earphone jack of the Raspberry Pi. However, the volume was low with cheap speakers, so I increased the volume with the following settings. image.png

Remote connection setup

Up to this point, the display, keyboard, and mouse were connected to the Raspberry Pi for operation, but it is convenient for development and small operations if remote connection is possible.

SSH settings

You can install OpenSSH with the following command. After installation, the SSH server is running.

$ sudo apt install openssh-server
$ sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2020-12-30 13:19:15 JST; 28min ago

You can now connect with SSH.

$ ssh [email protected]
[email protected]'s password:
Welcome to Ubuntu 20.10 (GNU/Linux 5.8.0-1010-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 updates can be installed immediately.
0 of these updates are security updates.

Last login: Wed Dec 30 17:42:29 2020 from 192.168.1.7

VNC settings

Select Share from the settings screen to activate Screen Sharing. image.png You can now connect to VNC, but when you connect from a Windows VNC client (using VNC Viewer this time), an error occurs and you cannot connect. image.png In this case, you can solve it by making the following settings with dconf-editor. dconf-editor can be installed with apt.

$ sudo apt install dconf-editor

Turn off org/gnome/desktop/remote-access/require-encryption. image.png Also, in order to make a VNC connection without connecting a display to the Raspberry Pi, it is necessary to install a dummy graphic driver.

$ sudo apt install xserver-xorg-video-dummy

Save the display settings of the screen to be connected to VNC to a file.

$ sudo vi /usr/share/X11/xorg.conf.d/80-dummy.conf

80-dummy.conf


Section "Device"
    Identifier  "Configured Video Device"
    Driver      "dummy"
    VideoRam 256000
EndSection

Section "Monitor"
    Identifier  "Configured Monitor"
    HorizSync 5.0 - 1000.0
    VertRefresh 5.0 - 200.0
    # 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
    Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
EndSection

Section "Screen"
    Identifier  "Default Screen"
    Monitor     "Configured Monitor"
    Device      "Configured Video Device"
    DefaultDepth 24
    SubSection "Display"
        Depth 24
        Modes "1920x1080"
    EndSubSection
EndSection

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "jp,us"
    Option "XkbModel" "jp106"
    Option "XkbVariant" ",dvorak"
    Option "XkbOptions" "grp:alt_shift_toggle"
EndSection

The Modeline setting can be confirmed with the cvt command.

$ cvt 1920 1080
# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync

For VNC related, I referred to the following. http://rarak.jp/16022 https://kokufu.blogspot.com/2018/02/ubuntu-vino.html

Install Visual Studio Code

The ARM version is also released in Visual Studio Code, so install it on the Raspberry Pi and try it. To install, download the ARM 64 .deb file from the following page and install it. https://code.visualstudio.com/download image.png

$ sudo apt install libxss1
$ sudo dpkg -i code_1.52.1-1608136325_arm64.deb

It seems that it can be started and used without problems. Visual Studio Code has a remote function, but you can also run it directly on the Raspberry Pi like this. This is also amazing! image.png

Hello world in Python!

Let's run a simple programming on the Raspberry Pi. It seems that the Python3 environment was originally installed on Ubuntu, but here I will use pyenv to install and run the latest version of Python.

$ sudo apt install -y libsqlite3-dev libreadline-dev libgdbm-dev zlib1g-dev libbz2-dev sqlite3 tk-dev zip libssl-dev libffi-dev git
$ git clone https://github.com/yyuu/pyenv.git $HOME/.pyenv
$ export PYENV_ROOT=$HOME/.pyenv
$ export PATH=$PYENV_ROOT/bin:$PATH
$ eval "$(pyenv init -)"
$ pyenv install 3.9.1
$ pyenv global 3.9.1
$ python
Python 3.9.1 (default, Dec 30 2020, 15:30:40)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello, world!')
Hello, world!

I was able to run Python with pyenv without any problems. It seems that you can use any version of Python with this.

Hello world with Go!

Now let's use Go to run Hello world. However, this time, I will try to run the cross-compiled version on Windows with Raspberry Pi. Here is the version of Go used this time.

$ go version
go version go1.15.5 windows/amd64

Click here for the source code of the trial Hello world.

main.go


package main

import "fmt"

func main() {
	fmt.Println("Hello, world!")
}

Cross-compile is built by setting environment variables referring to the next page. https://golang.org/doc/install/source#environment

$ set GOOS=linux
$ set GOARCH=arm64
$ set GOARM=7
$ go build -o hello main.go

Transfer the built and generated hello file to Raspberry Pi with scp and execute it on Raspberry Pi. When you execute it, you will be given execute permission.

$ chmod a+x hello
$ ./hello
Hello, world!

I was able to execute it firmly. Go is convenient because it can be easily cross-compiled and can be run in a single binary.

As a bonus, Hello world with Rust!

I also tried cross-compiling with Rust, so it's a simple note. This time, it is a method using the command cross.

$ cargo init .
$ cargo run  #Hello world with cargo in it!Code is generated, so use it as it is this time
   Compiling hellors v0.1.0 (/tmp/hellors)
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/hellors`
Hello, world!
$ cargo install cross
$ rustup target list  #List of target environments
aarch64-apple-ios
aarch64-fuchsia
aarch64-linux-android
aarch64-pc-windows-msvc
aarch64-unknown-linux-gnu
:
$ cross build --release --target aarch64-unknown-linux-gnu

I also transferred the generated execution binary with scp and was able to execute it firmly on the Raspberry Pi.

$ chmod a+x hellors  #Add if you do not have execute permission
$ ./hellors
Hello, world!

in conclusion

I set up my Ubuntu desktop on my Raspberry Pi 4 as I wanted, and I was able to watch YouTube as if it were a normal computer. It's amazing how well it works with a palm-sized Raspberry Pi, and it's fun to touch it alone. Also, since the remote connection can be set up easily, it seems that the operation can be easily performed even in the operation where only the Raspberry Pi body is left on in the corner of the room. I'm also surprised that Visual Studio Code works as a development environment. I tried Python and Go this time, but I would like to move other things.

Recommended Posts

Play with your Ubuntu desktop on your Raspberry Pi 4
Power on / off your PC with raspberry pi
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Set swap space on Ubuntu on Raspberry Pi
Working with sensors on Mathematica on Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
GPGPU with Raspberry Pi
pigpio on Raspberry pi
Enjoy electronic work with GPIO on Raspberry Pi
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
DigitalSignage with Raspberry Pi
Cython on Raspberry Pi
Connect to MySQL with Python on Raspberry Pi
Record temperature and humidity with systemd on Raspberry Pi
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Control brushless motors with GPIOs on Raspberry Pi Zero
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Mutter plants with Raspberry Pi
SoftwareRAID 0 on SereneLinux (Ubuntu 18.04 Desktop)
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Build a server on Linux and local network with Raspberry Pi NextCloud and desktop sharing
Play with the Raspberry Pi Zero WH camera module Part 1
[Raspberry Pi] Stepping motor control with Raspberry Pi
Testing uart communication on Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Servo motor control with Raspberry Pi
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Serial communication with Raspberry Pi + PySerial
Install ghoto2 on Raspberry Pi (memo)
Draw Japanese with matplotlib on Ubuntu
Mount S3 on Ubuntu with goofys
OS setup with Raspberry Pi Imager
Try using ArUco on Raspberry Pi
Try L Chika with raspberry pi
OpenCV installation procedure on Raspberry Pi
Try moving 3 servos with Raspberry Pi
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
Play with Turtle on Google Colab
Using a webcam with Raspberry Pi
L Chika on Raspberry Pi C #
Control the motor with a motor driver using python on Raspberry Pi 3!
Let's access your Raspberry Pi from outside your home with VPN (WireGuard)
Cross-compile for Raspberry Pi Zero on Debian-Create your own shared library
How to play music (wav / mp3) files on Raspberry Pi python
Measure SIM signal strength with Raspberry Pi
Pet monitoring with Rekognition and Raspberry pi
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
Detect analog signals with A / D converter using python on Raspberry Pi 3!
USB boot on Raspberry Pi 4 Model B
Hello World with Raspberry Pi + Minecraft Pi Edition
Adafruit Python BluefruitLE works on Raspberry Pi.
Use python on Raspberry Pi 3 to light the LED with switch control!
Try tweeting arXiv's RSS feed on twitter from Raspberry Pi with python