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.
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.
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.
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/
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.
Next, select the microSD card to write with SD Card
. (Don't make a mistake!)
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.
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. First, start up the terminal and update the package.
$ sudo apt update && sudo apt upgrade -y
Immediately after starting, the notation is not translated into Japanese. Right-click on an empty area on your desktop and select Settings
.
If you select Manage Installed Languages
from Region & Language
, "Language support is not completely installed" will be displayed, so install from there.
If you restart after the installation is completed, the notation will change to Japanese.
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. 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
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! 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.
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.
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
Select Share
from the settings screen to activate Screen Sharing
.
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.
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
.
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
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
$ 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!
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.
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.
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!
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