Wednesday, May 6, 2020

Installing ROS on a Raspberry Pi- Part 1

This spring I have been working with students in Barcelona on an autonomous vehicle project. They have been using a motorized car with an Arduino Uno and sensors, with a goal of upgrading to a Raspberry Pi and doing machine learning.
For cost reasons, they have selected the Raspberry Pi 3 Model A+; however I have some concerns about whether this has the performance needed for the project. As an early test case, I want to document what steps need to be taken to get ROS (Robot Operating System) running on the R-Pi.

What is ROS?

"The Robot Operating System (ROS) is a set of software libraries and tools that help you build robot applications. From drivers to state-of-the-art algorithms, and with powerful developer tools, ROS has what you need for your next robotics project. And it's all open source."

The latest release of ROS is "Melodic Morenia" and is built for Ubuntu Linux; it is also possible to install ROS onto Raspbian, which we will attempt here.

R-Pi Features and Limitations

The $25 Raspberry Pi 3 Model A+ ( has the following specs:
  • Extends the Raspberry Pi 3 range into the A+ board format.
  • Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz
  • 2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2/BLE
  • Extended 40-pin GPIO header
  • Full-size HDMI
  • Single USB 2.0 port
  • CSI camera port for connecting a Raspberry Pi Camera Module
  • DSI display port for connecting a Raspberry Pi Touch Display
  • 4-pole stereo output and composite video port
  • Micro SD port for loading your operating system and storing data
  • 5V/2.5A DC power input
The biggest limitations are the amount of SDRAM, followed by the ARMv8 performance. Also only having a single USB port will limit the peripherals we can connect without an external hub.

Our initial hardware components are:
  • Raspberry Pi 3 Model A+
  • 16GB Class 10 micro SD card
  • 5V/2.5A  micro-USB power supply
  • Video monitor
  • Wired USB keyboard
    • While it is possible to install using just a keyboard, a mouse makes life easier
    • You can use a keyboard with a built-in track pad
    • Connect a USB hub to the model A+ to add more ports
      • A keyboard with a USB port for a mouse
      • A monitor with a USB port to connect a keyboard and a mouse
      • A stand-alone hub with ports for more devices
  • The Model A+ has built-in WiFi which we will use to connect to the Internet

Installing Raspbian

In an earlier blog post, we walked through how to set up a Raspberry Pi as a headless system; in this article we will have a keyboard and display, and can use the Raspbian keyboard shortcuts instead of a mouse to access the desktop GUI.

Install the operating system image

Rather than downloading an OS image and using a third party app (e.g. Balena Etcher) to burn the image onto the SD card, we will instead use the Raspberry Pi Imager. This is easiest to use if you only want the OS latest release (in this case "buster") and want to overwrite files on the SD card without having to manually delete its existing disk partitions.
  • Download Raspberry Pi Imager
  • Insert  the micro-SD card into a card reader on your computer
  • Run the executable and under the 'Operating System" selection, choose
    • 'Erase' to format the SD card
    • 'Raspbian' to get the recommended Raspberry Pi Desktop
  • Close the Imager and eject the SD card

Setup the Pi

  • Insert the micro SD card that has the OS image on it into the Pi's card slot
  • Plug in your devices 
    • HDMI video cable
    • USB keyboard
    • Micro-USB power
  • Turn on the power
  • Once the system boots into the desktop GUI, follow the wizard's prompts to complete setup.
    • Select your country/language/timezone/keyboard
    • Change the 'pi' user password
    • Set up screen size if needed
    • Select a WiFi network
    • Enter the WiFi password and connect to the network
    • Update software
  • After updates complete, restart the Raspberry Pi and login to the GUI
  • If you did not successfully update the OS during installation, you can do so manually:
    • From the GUI, open a CLI terminal session: <CTRL> + <ALT> + t
    • Run the commands
$ sudo apt update
$ sudo apt dist-upgrade
$ sudo apt clean
  • Setup remote access for headless operation:
    • From the GUI, open a CLI terminal session: <CTRL> + <ALT> + t
    • Use 'sudo' to run 'raspi-config'
    • Change the user password if needed
    • Update network connection options
    • Select 'Interfacing Options' to
      • Enable SSH
      • Enable VNC
    • You can find the ip addess for the Raspberry Pi with the command 'hostname -I'
  • Since the Model A+ only has 512MB of ram, you will need to increase swap:
    • Check swap size by running the CLI command 'free -h'
    • Edit the /etc/dphys-swapfile to set CONF_SWAPSIZE=1024
    • Reboot the Raspberry Pi for this to take effect.
    • Confirm swap change by re-running 'free -h'

Installing ROS

ROS is originally targeted for Ubuntu, so we will need to build from source to run on Raspbian.
We will be working in our default directory "/home/pi" and following the steps detailed here: to install ROS Melodic on Raspbian Buster :
  • From the GUI
    • Open a CLI terminal session: <CTRL> + <ALT> + t
    • Execute the commands listed in the guide to:
      • Configure prerequisites
        • Setup ROS Repositories and keys
$ sudo sh -c 'echo "deb $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-key adv --keyserver hkp:// --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
$ sudo apt-get update
$ sudo apt-get upgrade
        • Install Bootstrap Dependencies
$ sudo apt install -y python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake
        • Initialize rosdep
$ sudo rosdep init
$ rosdep update
      • Install ROS
        • Create a catkin workspace
$ mkdir -p ~/ros_catkin_ws
$ cd ~/ros_catkin_ws
        • Fetch the core packages for either
          • ROS-Comm (a basic configuration that has been tested)
$ rosinstall_generator ros_comm --rosdistro melodic --deps --wet-only --tar > melodic-ros_comm-wet.rosinstall
$ wstool init src melodic-ros_comm-wet.rosinstall
          • ROS Desktop (GUI configuration)
$ rosinstall_generator desktop --rosdistro melodic --deps --wet-only --tar > melodic-desktop-wet.rosinstall
$ wstool init src melodic-desktop-wet.rosinstall
        • Resolve dependencies by running rosdep
$ cd ~/ros_catkin_ws
$ rosdep install -y --from-paths src --ignore-src --rosdistro melodic -r --os=debian:buster
        • Build the catkin workspace using 'catkin_make_isolated' with the '-j1' option to limit the number of CPU threads used on the ARMv8 core
$ sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/melodic -j1
        • Wait a long time for almost 200 packages to compile... :-)
        • Once the install is complete, configure your environment
$ source /opt/ros/melodic/setup.bash
        • You can also setup your bash shell to always have variables set correctly:
$ echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

Installing ROS on a Raspberry Pi- Part 2

In the previous post, we installed Raspbian 'buster' and ROS 'melodic' onto a Raspberry Pi; here we will test its functionality.

Login to the RPi

Since as part of the Raspbian install we enabled 'headless' mode, let's access its desktop using the 'VNC Viewer' client.
  • Download and install vnc viewer.
  • Find the IP address of your Raspberry Pi on your network.
    • Open a CMD or terminal window on your computer and run the command 'arp -a' and look for the Raspberyy Pi's physical MAC address that starts with 'b8-27-eb' (we can take advantage of the 'pipe' and 'findstr' commands in the Windows 10 Command Prompt to filter the results returned):
> arp -a | findstr " b8-27-eb-"         b8-27-eb-3b-f2-90     dynamic
  • Use the IP address found to login to the Raspberry Pi via VNC Viewer:
  • You will need to enter the password for the 'pi' user that you created as part of the Raspbian configuration steps you did in the first part of this series.

  • Now that we have access to the desktop on the headless system, we can use our local keyboard and mouse as if we were on the system itself. Note that when there is no physical display connected to the Raspberry Pi, it will default to a low-resolution desktop. To get a HD display, you will need to edit the /boot/config.txt file as follows:
    • Un-comment the following lines:
      • hdmi_force_hotplug=1
      • hdmi_group=1
      • hdmi_drive=2
    • Edit the following line to change the value from '1' to '16' to force display to 16:9 1080p
      • hdmi_mode=16
    • Comment out the following line:
      • dtoverlay=vc4-fkms-v3d

Check the ROS installation

  • Open a terminal session and create a catkin workspace in your home directory:
$ mkdir -p ~/catkin_ws/src  
$ cd ~/catkin_ws/  
$ catkin_make
$ source devel/setup.bash
  • Run 'roscore' to check the install:
$ roscore
... logging to /home/pi/.ros/log/8e91c8a2-8fdf-11ea-a15e-b827eb3bf290/roslaunch-rospi-8768.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://rospi:35989/
ros_comm version 1.14.5


 * /rosdistro: melodic
 * /rosversion: 1.14.5


auto-starting new master
process[master]: started with pid [8778]

setting /run_id to 8e91c8a2-8fdf-11ea-a15e-b827eb3bf290
process[rosout-1]: started with pid [8790]
started core service [/rosout]
  • Use <CTL>- C to exit roscore
  • Continue on with these ROS tutorials.

Sunday, February 16, 2020

Raspbian SD card checksum errors.

I have an aging Dell Latitude 6410 that I use for lab development, and in order to extend it's usable life, I upgraded it with a 512 GB SSD and moved from Windows 7 to Windows 10. 

After re-installing Balena Etcher to flash Raspbian images to microSD cards, I kept getting an error message during the final card validation:
  • "Source and destination checksums do not match".
This appears to be a Windows 10 issue with external USB memory devices described here:
The problem is caused by Windows 10 writing a new System Volume Information folder to the SD card containing IndexerVolumeGuid and WPSettings.dat files

While this does not affect the operation of the SD card in a Raspberry Pi, ignoring the checksum error could mask real image corruption problems. There is a simple workaround to prevent Windows from writing that SVI folder, described here:

Friday, April 27, 2018

Installing software onto the Raspberry Pi- Part 2

Finally here's where we install the Linux software for monitoring the Smart Meter!
Based on the previous work done for the testing on a Windows PC, we are going to need:
  • rtl-sdr drivers
  • rtl-tcp server
  • rtlamr decoder
But instead of Windows sources, we are going to need the ones for Raspbian.


The following post was extremely helpful in setting up the rtlsdr software on the RPi:

  • First we need to install some packages required by the rtl-sdr dongle server:
  • Instead of going to the NooElec website for pre-compiled Windows drivers, we will get the sources from:

    Fortunately 'git' is already included with the installed OS, so we can execute the following directly in /home/pi to get the rtl-sdr code:
(Note that in order for certificates to work for https access, you must have your OS set to the correct date and time !!
  • We can now run the following (note it may take some time to complete):
  • Before we can install the rtl-sdr USB dongle, we need to setup a 'blacklist' file to prevent the standard USB Radio/TV drivers from loading. Create the file 
         and add the following lines to it: 
  • You can now reboot the RPi, install the rtl-sdr dongle, and run rtl_test  
(use Ctrl+C to exit the test):


  • Before we can download and build rtlamr, we need to install the go build environment

(since this is for the RPi, we will need to get the version that runs on the ARM processor;  
as of this posting, the latest go release is 1.10):

  • If all has run successfully, you can now check the go version:
  • We can now download and build bemasher's rtlamr from

  • You can now start up rtl_tcp in a terminal session:
  • And then start up rtlamr in a different terminal:
Next steps:
  • Configuring the meter reader software

Thursday, April 26, 2018

Installing software onto the Raspberry Pi- Part 1

Now that the Raspberry Pi can access the internet, we can begin adding and configuring software.
One of the first things to do is log into the the RPi via SSH and run raspi-config:

We will:
  • Update raspi-config
  • Set Localization options
    • Change Locale to 'en_US.UTF-8 UTF-8'
    • Change Timezone to US-Eastern
    • Change Keyboard Layout to match the new locale
    • Change Wi-fi Country to 'US United States'
  • Under Advanced Options
    •  Expand Filesystem to use the entire microSD card
Now that we have plenty of space on the system disk, we can start installing software.
But how? Some options:
  • From the RPi SSH terminal command line
  • By downloading software packages onto the laptop and transferring them to the RPi for installation (WinSCP is good for this):
  • Installing via the Rasperry Pi Desktop's Applications Menu -> Preferences -> Add/Remove Software.
    • But we are running headless and there's no Desktop GUI!
While the first two options can be followed immediately, let's figure out how to get access to the RPi  Desktop. We want to use VNC (Virtual Network Computing) for graphical desktop sharing:

On your Raspberry Pi, run the following commands to make sure you have the latest versions of software, including VNC Connect:

Now, enable VNC Server by running raspi-config and doing the following:
  • Navigate to Interfacing Options.
  • Scroll down and select VNC > Yes.

On the laptop you will need to download and install VNC Viewer so you can connect to VNC Server that is running on the RPi:

Once it is installed, we can start VNC Viewer on the laptop, direct it to the IP address of the RPi and login with our default credentials:

 And we are in!:

Next steps: 

Wednesday, April 25, 2018

Sharing your laptop's internet connection with your Raspberry Pi

In the previous post, we set up a headless Raspberry Pi and connected to it via a PuTTY SSH terminal session running over the local NIC. In order to update and install software onto the RPi, we will need to give it access to the Internet and all of its code respositories. For example, you will need this when you run 'sudo raspi-config' and need to select Option 8 to update to the latest script version:

Since it is the Windows laptop that has access to the global network, we will enable Internet Connection Sharing between the global interface and the local NIC so the RPi can route through the laptop to the web. I found a couple of references on how to do this, but encountered differences in behavior on Windows 7 and Windows 10. 

 To get it working on the Windows 10 laptop:
  • Go to the NIC that is connected to the outside world (in my case, this was my laptop's WiFi adapter) and enable Internet Connection Sharing:
  • When ICS is enabled, the wired NIC will automatically be assigned an IP address of '' with subnet ''.
  • Use PuTTY to login to the RPi at the IP address you found using Wireshark and edit the file /etc/dhcpcd.conf  to set a new static IP address and DNS server:
interface eth0
static ip_address=
static routers=
static domain_name_servers=
  • Reboot the RPi and login over SSH again using the new static IP address ( You should be able to run 'sudo apt-get update' to download RPi updates from the global repository:

Next steps:

Tuesday, April 24, 2018

Setting up a headless Raspberry Pi

At the end of my previous post on reading my Smart Meter, I said I wanted to move the monitoring hardware and software off of the PC and onto a dedicated Raspberry Pi. Since I wasn't getting to this task at home, I thought I would try to do it during lunch at the office. Unfortunately, I don't have access to as much equipment there, but then that's part of the challenge.

In the office I just have my laptop, with keyboard and monitors tethered to other systems.  I was planning on following the steps in this post on configuring the RPi without those devices, and only using a PuTTY SSH to establish a serial terminal connection:

However, I also do not have open access to the corporate network or router and am running Windows instead of Linux. There were some more tips here for a direct ethernet cable connection:

but the problem is I do not have a good way to determine the IP address that the RPi self-assigns when it boots. Then I remembered that I run the Wireshark protocol analyzer on my Linux systems, and there is also a Windows version available!

So here's the steps:
  • On the Windows laptop, download the latest version of Raspian and burn the image to a microSD card.
  • From a Windows command prompt, create a dummy file named 'ssh' and place it in the Linux boot directory located on the card (in this case, the card reader has assigned drive E to it).
    • copy /b NUL ssh
    • move ssh e:
  • Eject the the microSD card and install it into the RPi.
  • Connect the laptop and the RPi together with a standard ethernet cable.
  • Power up the RPi and wait a couple of minutes for it to self-assign an IP address.
  • On your laptop, start Wireshark and select the Ethernet interface to analyze:

  • Examine the first few lines of the analysis to see what IP address the RPi is broadcasting from (in this case

  • Now that I know the IP address, I can log into the RPi using PuTTY:

  • And we are in!!

    Next steps:
    •  Configure the RPi's network settings (e.g., set a static IP address)
    •  Set up internet connection sharing on my laptop so I can update the RPi with the RTLSDR software: