DEV Community

Mariano Martinez Peck
Mariano Martinez Peck

Posted on • Originally published at marianopeck.wordpress.com on

Getting started with Raspberry Pi and Smalltalk

In a previous post, I described why I personally believe that Smalltalk is a good fit for IoT. When we talk about IoT, there are millions of topics we can touch: SBC (single board computers), sensors, security, protocols, edge computing, GPIOs, AI, ML and so on… But one board in particular that changed the world is the Raspberry Pi.

You can read in many websites why the Raspberry Pi was a game changer. But what matters now is that it’s a SBC that fits in your hand, that could have 4 CPU cores (ARM), 1GB RAM, HDMI, 4 USBs, video, audio, Wi-Fi, Bluetooth, 40 GPIOs and all that in 35USD. Such board has power enough to perfectly run Linux. You can even run Docker containers in there!!

Obviously, by this time, Raspberry is not alone and there are plenty of boards out there as well: Pine64, BananaPi, ODROID-N2, just to name a few. There are new ones every day. They usually focus on different things: being cheap, AI, desktop replacement, being specially designed for clustering, etc.

However, most of them provide similar features:

  • ARM / ARM 64 processors (only a few others may have Intel or RISC-V).
  • Run a few given Linux distros either 32 or 64 bits (although some boards would also work with Windows 10 IoT).
  • Provide a number of GPIOs (most of the times, 40 pins) for general input output. Usually between 3.3v and 5.v. Not all boards provide GPIOs.
  • Implement some protocols to use over the GPIOs (UART, I2C, 1-Wire, SPI, etc).

What does Smalltalk (or any other language) need to run and take advantage of these boards?

The first obvious thing is that the Virtual Machine (VM) of the language must be compiled for ARM / ARM 64 (not x86 / x64). And it’s not just the VM but every third party library the VM depends on. Also, the VM may have some assumptions on the CPU architecture, like some Just In Time compilers that would only work in x86.

The second obvious thing is that such VM should work in Linux and most likely in any of the most commonly available distros: Raspbian, Armbian, Ubuntu, Debian, etc. This Linux must be a ARM-compiled version of the distro.

Finally, it would be almost mandatory that the language (Smalltalk in this case) has some functionality to be able to use the GPIOs. This is super important for sensors and all kind of devices that could be connected to the SBC. A common approach for high level languages like Smalltalk is to wrap via FFI (Foreign Function Interface) a third party C library that already takes care of that and all the related protocols (1-Wire, I2C, SPI, UART, etc). There are many libraries out there: pigpio, wiringpi, etc.

What’s the particular architecture of VASmalltalk?

The new VASmalltalk VM (starting with VA 9.1) was designed from scratch to be portable, performant and maintainable.

With that in mind, the VM was built using LLVM and libffi. LLVM supports many different target architectures, so VASmalltalk could eventually target RISC-V, WebAssembly or any other of their supported CPU arch, with relative small effort.

In fact, it took us only a small amount of hours to have the VM compiled to ARM and a few others to compile it for ARM 64 (aarch64).

For the Linux dependency itself, the VASmalltalk VM only depends on glibc (and if headfull, on motif), which is available on almost every Linux. So it’s quite likely it would work out of the box in any Linux. It also supports both, ARM and ARM 64 so it should work either bitness of Linux.

Finally, for the GPIO, VASmalltalk have a FFI binding for pigpio which allows you sensor data, pull pins up and down and implements most of the protocols already mentioned.

Show it to me!!

The procedure explained below on how to get started with VASmalltalk, Linux and ARM is quite similar for all devices and Linux flavors. For the purpose of this post I need to pick one, so I take the most common: Raspberry Pi (which could be any of the models) + Raspbian. The latter is a custom Debian OS specially made for the Raspberry Pi and the most commonly used and accepted.

At the time of this writing, the ARM version of VASmalltalk is only available through ECAP (Early Customer Access Program) releases. An ECAP release comes as a compresses file that you just uncompress wherever you want and everything is self contained. On Windows there is no further step to do than that. On Linux, you must be sure that the dependencies are installed. Note that his only happens with ECAP releases as VASmalltalk does provide regular .deb and .rpm installers for stable releases and those do install dependencies automatically.

Below is a script I normally use on a fresh Raspbian. Not all of the script is mandatory….just some of it:

#!/bin/sh

# Remove some stuff I normally don't use to free resources
sudo apt-get remove --purge --assume-yes \
  scratch* \
  libreoffice* \
  wolfram-engine \
  sonic-pi \
  minecraft-pi

# Lets update before installing
sudo apt-get update

# Basic tooling I like to have an all my Linuxes
sudo apt-get install --assume-yes \
  vim \
  tmux \
  htop \
  iotop \
  autocutsel \
  avahi-daemon \
  i2c-tools \
  netatalk \
  libnss-mdns \
  xrdp \
  curl

# Fix VNC issue https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=230779&p=1413648#p1413648
sudo apt-get install --assume-yes haveged
sudo update-rc.d haveged defaults


# Install pigpio (needed to use GPIO from VASmalltalk)
sudo apt-get install --assume-yes \
  pigpio \
  python-pigpio \
  python3-pigpio
cd $HOME
wget https://raw.githubusercontent.com/joan2937/pigpio/master/util/pigpiod.service
sudo cp pigpiod.service /etc/systemd/system/
sudo systemctl enable pigpiod
rm pigpiod.service

# Install RPI Monitor --- useful tool for monitoring status of the Pi
sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2C0D3C0F
sudo wget http://goo.gl/vewCLL -O /etc/apt/sources.list.d/rpimonitor.list
sudo apt-get update
sudo apt-get install rpimonitor

# Install VA Dependencies for running headless (esnx)
sudo apt-get install --assume-yes --no-install-recommends \
  libc6 \
  locales \

# Install VA Dependencies for running headfull and VA Environments tool
sudo apt-get install --assume-yes --no-install-recommends \
  libc6 \
  locales \
  xterm \
  libxm4 \
  xfonts-base \
  xfonts-75dpi \
  xfonts-100dpi

# Only necessary if we are using OpenSSL from Smalltalk
sudo apt-get install --assume-yes --no-install-recommends \
  libssl-dev 

# Generate locales
sudo su
echo en_US.ISO-8859-1 ISO-8859-1 >> /etc/locale.gen
echo en_US.ISO-8859-15 ISO-8859-15 >> /etc/locale.gen
locale-gen
exit

# Cleanup
sudo apt-get clean
sudo apt-get autoremove
Enter fullscreen mode Exit fullscreen mode

That bash script should be pretty clear on what I am doing and why. And as you can see, it is quite easy to adapt to other distros too. You can also see how to make a Docker image for VASmallalk and ARM here.

Once you have uncompressed the ECAP, all you need to do is go that directory, under /raspberryPi/ and run ./abt32.sh. That will bring the full VASmalltalk Unix IDE:

Screen Shot 2019-05-25 at 4.15.16 PM.png

Tips, tricks and recommendations to get started with Raspberry Pi

Below are just some recommendations if this is the first time you give Raspberry Pi a try:

  • Buy one of those kits (like Canakit or similar) that already comes with power supply, an already formatted microSD card and with NOOBS installed. NOOBS is a software that at boot (on the Pi), allows you to pick up an Operating System and install it in that very same running SD.
  • If you got the SD from somewhere else, I recommend using “SD Card Formatter” software (or similar) to be sure the SD is properly formatted for NOOBS. Then, download and put NOOBS in that SD, boot the Pi and finally install Raspbian.
  • I recommend starting with Raspbian Linux (default choice with NOOBS).
  • If you want to buy the SD separated I recommend, at least, UHS-1 Class 10 type.
  • Be sure to have a micro SD to SD adaptor or a USB card reader able to read micro SD.

Finally, if you want to know my top 10 gadgets for IoT, see below tweet. Although, I must say I have already new gadgets that should be added there!!

Conclusion

This post should give you an idea on how to get started with VASmalltalk on a ARM-Linux-powered single board computer. I have personally tried a few devices (Pi Zero W, Pi 3B+, Rock64) and many OSs (Raspbian, Raspbian Lite, Ubuntu Server 18.04, Armbian, etc). The procedure is quite similar with all of them.

In the upcoming posts, I will be showing how to access the GPIO from VASmalltalk, how to assembly and wrap specific sensors, how to transparently persist data on a remote GemStone, unique debugging capabilities, and much more.

Stay tuned!

Top comments (0)