Webserver on Raspberry

I would like to control my raspberry-robot from a web site.

I have chosen Node.js, since it should be easier to create interactive web sites.

To install Node.js and npm (Nodes package manager) I followed this gui

The code for controlling my Raspberry is written in C++, so I need to call a C++ library from Node.js.

I followed this example to learn the basic hello-world step.


Setup automatic switch from WiFi to Hotspot

My robot has and EdiMax WiFi adapter, and at startup it automatically connects to my home network, with a static ip.

But when I take the robot to a new location, It cannot automatically connect to a new WiFi, cause it doesn’t know the Network name and password.

Luckily someone has already solved this problem. At startup it checks and tries to connect to a known WiFi network.

If it cannot connect to a WiFi network, it setup a Hotspot.

This makes it possible to connect to the Robot without a wired connection or keyboard and a screen.

I used this guide to setup a Hotspot for the EdiMax WiFi adapter.

I used this guide to test at startup if it could connect to a known WiFi and otherwise setup a Hotspot.

Here are the files that I changed:
sudo nano /etc/default/isc-dhcp-server

# Defaults for isc-dhcp-server initscript
# sourced by /etc/init.d/isc-dhcp-server
# installed at /etc/default/isc-dhcp-server by the maintainer scripts

# This is a POSIX shell fragment

# Path to dhcpd’s config file (default: /etc/dhcp/dhcpd.conf).

# Path to dhcpd’s PID file (default: /var/run/dhcpd.pid).

# Additional options to start dhcpd with.
# Don’t use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. “eth0 eth1”.

sudo nano /etc/dhcp/dhcpd.conf
Only uncommented code is shown


subnet netmask {
option domain-name-servers,;
option domain-name “local”;
option routers;
option broadcast-address;
default-lease-time 600;
max-lease-time 7200;

sudo nano /etc/network/interfaces

auto lo wlan0

iface lo inet loopback

allow-hotplug eth0

iface eth0 inet dhcp

allow-hotplug wlan0

iface wlan0 inet static

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

#iface static_ip inet static
# address
# netmask
# gateway

up iptables-restore < /etc/iptables.ipv4.nat


sudo nano /etc/rc.local

Replace networkname with network it should try to connect to.

# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” “$_IP”

sudo mount -t cifs -o user=pi,password=raspberry,rw,file_mode=0777,dir_mode=0777 $

echo “Creating AccessPoint network”
echo “Attempting to start hostapd and dhcp server”
service hostapd start
service isc-dhcp-server start
echo “Accesspoint created”

echo “=================================”
echo “RPI Network conf bootstrapper 0.1”
echo “=================================”
echo “Scanning for known WIFI networks ”

if iwlist wlan0 scan | grep network-name > /dev/null
echo “WiFi in range has SSID: network-name
echo “Starting supplicant for WPA/WPA2”
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/$
echo “Obtaining IP from DHCP”
if dhclient -1 wlan0
echo “Connected to WiFi”
echo “DHCP server did not respond with an IP lease (DHCPOFFER)”
wpa_cli terminate
echo “Not in range, WiFi with SSID: Trevangsvej 197”

if ! $connected; then

exit 0

sudo nano /etc/sysctl.conf

I did not uncomment the line

# Uncomment the next line to enable packet forwarding for IPv4
# net.ipv4.ip_forward=1

My first successful Segway run

I have tried many different Segway configuration. Mindstorm direct to Gyro, Mindstorm with Arduino and Gyro, Raspberry pi and Arduino and Gyro.

I was not able to make them balance for more than a few seconds. But now I have a setup that can balance until the battery runs out.

The Segway configuration is:

Two Arduinos. One Arduino for the motorcontroller and encoder input from the motors, the second Arduino controls the gyro and accelerometer.

I have a Raspberry, connected to the Arduinos, but it is not envolved ind the Segway-balance routine.

IMG_6900 IMG_6902 IMG_6904

The Raspberry camera (with the red light) is for the Raspberry. Right now it has a face detection, and move the servo for the camera-

mount towards a face when it detects one.

The motor-gearing have som backlash, which is hard to compensate for.



Develop C++ project for Raspberry with Visual Studio and VisualGDB

I have tried different setup for writing and compiling my Raspberry C++ projects. Now I’m using Visual Studio (2013) with VisualGDB. It is possible to Compile with a raspberry Cross compiler, but I was not able to get all the Raspberry library copied over to the computer with Visual Studio. But even without the Cross compiler functionality, for me this is the best setup I have found yet. I’m used to working with C# in Visual Studio, so many things are already familiar to me.

In order to make the project work, the following things were done.

  • Output filename for static library where prefixed with ‘lib’
  • Include and Library output folders for linked files were added and set to the output folder for the project.

Raspberry Pi and WiFi with the EDIMAX-dongle

Setting up WiFi with the EDIMAX-dongle was not that difficult, except for one thing, disabling power safe mode.


Power safe

With EDIMAX-dongle power safe is default enabled. That means a ssh-session that has not been used for som minutes will be auto-closed!

Add the file /etc/modprobe.d/8191cu.conf with this

# Disable power saving
options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1


Static IP

Set a static ip (here called static_ip and fixed ip in /etc/network/interfaces with this

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

iface static_ip inet static


Use the static_ip setup in /etc/wpa_supplicant/wpa_supplicant.conf by writing this

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

ssid=”WiFi network name”
psk=”secret code”


Getting Raspberry PI 2 up and running

Upgrading from “Raspberry Pi B” to “Raspberry Pi 2 B”.
There are a lot of settings, tools and libraries to make the new RP 2 able to run the robot-code.  Heres a short list of what I needed to install.

  • OpenCV (v. 2.4.10)
  • RaspCam (v. 0.1.2)
  • Boost (v. 1.50)
  • Github workspace
    • Publish key to Github
  •  TightVNC
    • Enable TightVNC at startup




Connection MPU6050 Gyro with EV3 (Mindstorm)

I have tried to connect the MPU6050 with my EV3 using I2C connection.

The MPU6050 board needed bigger pull-up resistors. First I removed the resistors from the board,

and added 80k resistors (See picture).

After a lot of debugging I got it to work. I could read raw values from the MPU6050 with the EV3.

The raw values from the accelerometer values and the gyro-values are very noisy. To remove the noise a Kalman-filter is often used. But I would not use the EV3 processor for this filter-processing.

The MPU6050 has a buildt-in DMP (Digital Motion Processor).This processor can be programmed to make the filtering.

But in order to use the DMP, it had to be programmed after each power-on. A c-program has been written by I2CDevLib using reverse engineering. I have tried to translate the c-program to Java (LejOS) , but I could not get it to work.

I could get the MPU6050 and the Arduino connected and using the I2CDevLib programmed the DMP.

Now I tried to connect the MPU6050 to the Arduino using I2c and connected the Arduino with the EV3 using UART.

There is a Arduino library that emulates an EV3 sensor.

I now have a connection between EV3 and Arduino, and a connection between the Arduino and the MPU6050.

The Arduino work as a bridge between the EV3 and the MPU6050 sensor.

Here is a diagram of all the connections.