Investigating Node.js for Raspberry Pi Robotic Vehicle

I’ve been looking at alternatives to WebIOPi since it is no longer maintained. I have successfully built a few, small vehicles running WebIOPi but it seems that the project is no longer supported. I was also never satisfied with the latency when moving the vehicle or servos attached to it.

I’ve worked with Node.js before but was not aware that you could use it to create the PWM signals that I normally use to control the motors on my vehicles. I have developed larger vehicles now, with tank tracks, that use 12 volt drill motors. I use Radio Controlled ESC’s (Electronic Speed Controllers) to handle the increased voltage and amperage. This is a small tracked vehicle I built controlled by Node.js, Johnny-five and Raspi-io. I deploy an ad-hoc network on the bot for a connection.

Just a side note. I built this vehicle from spare parts and junk I had in the garage. The frame is made from crutches. The track wheels are from an old set of roller blades. The tracks themselves were made from rubber tarp straps. I cut the metal ends off and spliced them together. I then screwed metal stitching plates used in construction between the two straps. Topped them off with strips of rubber that I cut up from a spare BMX tire. Motors are cheap drill 12V. I bought two 30amp RC ESC’s on Ebay for the connection between the Raspberry Pi and the motors. I used PWM signals to make them go forward, backward and define the speed.  I built my own dashboard to control it. Using the extensions of Node called Express & Socket.io to do this through a browser.

These are my notes so far while installing Node.js and other components.

  1. Intall Node using the ARM package
  2. Install the Pi-blaster daemon
  3. [sudo git clone https://github.com/sarfata/pi-blaster]
  4. [sudo apt-get install autoconf]
  5. [cd pi-blaster]
  6. [sudo ./autogen.sh]
  7. [sudo ./configure]
  8. [sudo make]
  9. [sudo make install]
  10. [cd ..]

Create a folder for your project.

Install the node modules that you need. Express, socket etc..

 

 

 

 

 

quick2wire-gpio-admin

If you are using quick2wire-gpio-admin, you’ll need to make a few changes to make it work.

https://github.com/quick2wire/quick2wire-gpio-admin/pull/6

In src/gpio-admin.c

Change this line 30  int size = snprintf(path, PATH_MAX, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
To this --          int size = snprintf(path, PATH_MAX, "/sys/class/gpio/gpio%u/%s", pin, filename);

Did a “sudo make uninstall” from within the quick2wire-gpio-admin folder, then “sudo make install” and added the user “sudo adduser $USER gpio” (where $USER is your user..). Logout and login,

 

Read More

Raspberry Pi – Edimax EW-7811Un Wifi dongle powers down / goes to sleep fix.

Edimax EW-7811Un Power Management

I have several of the tiny Edimax Wifi dongles that I use on my Raspberry Pi’s. If you leave the Pi unattended for awhile, the Edimax will go to sleep and you’ll lose your SSH connection. Here is a fix that worked for me. This is entered on the command line / terminal.

sudo nano /etc/modprobe.d/8192cu.conf

Add the following lines to this file you created. It disables the power down on the Edimax.

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

Then, do your normal Ctrl-X, Yes and save this file. Reboot. 


Read More

Raspberry Pi 2 & WebIOPi – Error AttributeError: ‘module’ object has no attribute ‘GPIO’

If you are getting this error on a RPI2 - The following solution worked for me.
AttributeError: 'module' object has no attribute 'GPIO'

In the webiopi-0.7.X directory is the /python directory:
1.CD into /python/native/
Edit the file:  cpuinfo.c
change "BCM2708" to "BCM2709"

2.While still in python/native/   
Edit the file gpio.c 
change #define BCM2708_PERI_BASE 0x20000000   to 
#define BCM2708_PERI_BASE 0x3f000000

3.Head back out to your root webiopi-0.7.X directory and run setup.sh again.
sudo ./setup.sh

Hope this helps.

Read More

WebIOPi on Raspberry 2

If you have the newer Raspberry Pi 2 and want to run WebIOPi on it you’ll need to make a change.

From the command line interface go to your home directory:

cd /home/pi

cd WebIOPi-0.7.1  or  WebIOPi-0.7.0 depending on which version you are using. d

cd python/native

nano gpio.c

Change “#define BCM2708_PERI_BASE 0x20000000” to “#define BCM2708_PERI_BASE 0x3f000000”

Ctrl – X , save and exit. Reboot.

 

Read More

Quick Reference for WebIOPi

This is taken from Eric Trouch's page at http://webiopi.trouch.com/INSTALL.html

Installation

WebIOPi is developed and tested on Raspbian. You only need Python, either 2.7 or 3.2. Download, then extract and install WebIOPi. The setup script will automatically download and install required dependencies using apt-get. You may have to manually install GCC and Python development headers if you are not using Raspbian.

Upgrade note: Stop your existing WebIOPi service, then process with the setup. Your configuration will be kept but others files will be override.

See downloads page to get latest package, and adapt x.y.z with the version you download.

$ tar xvzf WebIOPi-x.y.z.tar.gz
$ cd WebIOPi-x.y.z
$ sudo ./setup.sh

Setup may take a moment.

Running WebIOPi

Finally, use webiopi command :

$ sudo webiopi [-h] [-c config] [-l log] [-s script] [-d] [port]

    Options:
      -h, --help           Display this help
      -c, --config  file   Load config from file
      -l, --log     file   Log to file
      -s, --script  file   Load script from file
      -d, --debug          Enable DEBUG

    Arguments:
      port                 Port to bind the HTTP Server

For instance, to start with verbose output and the default config file :

$ sudo webiopi -d -c /etc/webiopi/config

You’re done, and ready to enjoy WebIOPi ! But the server and GPIO state will be lost when you’ll stop the script (CTRL-C) or close the terminal.

Running WebIOPi (Daemon)

You can also start/stop the background service, the configuration will be loaded from /etc/webiopi/config.

$ sudo /etc/init.d/webiopi start
$ sudo /etc/init.d/webiopi stop

Auto start at boot

To setup your system to start webiopi at boot :

$ sudo update-rc.d webiopi defaults

To remove webiopi start from boot :

$ sudo update-rc.d webiopi remove

Access WebIOPi over local network

If your Raspberry Pi is connected to your network, you can open a browser to http://raspberrypi:8000/ with any device of your network. Replace raspberrypi by its IP.

Default user is “webiopi” and password is “raspberry”

By choosing the GPIO Header link on the main page, you will be able to control GPIO using a web UI which looks like the board header.

  • Click/Tap the OUT/IN button to change GPIO direction.
  • Click/Tap pins to change the GPIO output state.

http://trouch.com/wp-content/uploads/2012/08/webiopi-chrome.png

Access WebIOPi over Internet

Thanks to Weaved IoT Kit, it’s easy to access your Raspberry from anywhere in a secure fashion.

Register on the Weaved developper portal

Go to https://developer.weaved.com/portal/ and follow instruction to create an account.

Download Weaved for Raspberry Pi

Copy and paste the command line below into a terminal window or SSH client connected to your Raspberry Pi, then hit the Enter key.

wget https://github.com/weaved/installer/raw/master/binaries/weaved-nixinstaller_1.2.5.bin

Install Weaved

Make the installer executable:

chmod +x weaved-nixinstaller_1.2.5.bin

Launch the installer:

./weaved-nixinstaller_1.2.5.bin

Enter the e-mail address and password for your Weaved account.

https://developer.weaved.com/portal/images/Login.png

When asked, choose WebIOPi during the install process. then enter an alias, or nickname for your device.

https://developer.weaved.com/portal/images/Provide-an-alias.png

Note: If you run the installation more than once, you’ll get this question.

https://developer.weaved.com/portal/images/previous_installation.png

Support of multiple services is not fully tested in 1.2.5. We recommend that you answer ‘y’ here to remove the previous installation before proceeding.

Test your setup

To test the connection to your Raspberry Pi from your browser, go to the device list, find the line with your Raspberry Pi’s alias, and click on “Connect”. Your device’s internet address will be shown in the area blurred below.

https://developer.weaved.com/portal/images/Device-list.png

Read More

Simple Wifi Configuration for Raspberry Pi /etc/network/interfaces

Sometimes, when I’m troubleshooting or initially setting up a Raspberry Pi,  I like to create a dead simple configuration to connect to my home wifi network. This skips using the wpa_supplicant and has all the information in the intitial networking file for simplicity.

From the command line on your Pi I do the following:

  1. cd /etc/network
  2. sudo cp interfaces interfaces-wifi

    This makes a copy of our existing interfaces file for a backup.

  3. sudo nano /etc/network/interfaces

    We open the file in a text editor to make our changes.

Update the code in this file so that it contains the code following this paragraph:
Be sure to insert the name of your network in place of ssid inside the quotes as the value for wpa-ssid and password in the appropriate place as the value for wpa-psk, within the code. You may already some of these lines in there for your ethernet (eth0) so you can keep it or replace it.

auto lo
iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid "ssid"
wpa-psk "password"

After your file looks like this, hit Ctrl-X, then y for yes and enter.
I usually reboot at this point with a command of:

sudo reboot

Note: If something happens and you can’t log onto your wifi network, don’t despair. Just hook up your monitor and keyboard and go back to this file, change it back or rename your backup file to interfaces and you are back where you started. To change back to your original interfaces file that we renamed in step #2, just type this on the command line.

sudo cp /etc/network/intefaces-wifi /etc/network/interfaces

When finished doing this, reboot again.

sudo reboot

Read More

Creating an Ad-hoc network for your Raspberry Pi

I have found this setup to be very useful for my Raspberry Pi.
Instead of connecting to an existing wireless network, you have the Pi create it’s own. That way you can login to the Pi even if a wi-fi network is not available. I’m using it for my Pi Powered robots outside.

Hopefully, this little snippet of code will be useful to others:

Here are the steps:
=====================

  1. From the command line (LX terminal or SSH) go to the following directory.
    cd /etc/network
  2. Copy the existing interfaces file as a backup.
    sudo cp interfaces interfaces-wifi
  3. Create a new file for our ad-hoc network.
    sudo nano interfaces-adhoc
  4. Once this file is open, copy the code snippet below so that it reads as below.
    auto lo
    iface lo inet loopback
    iface eth0 inet dhcp
    
    auto wlan0
    iface wlan0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    wireless-channel 1
    wireless-essid RPiwireless
    wireless-mode ad-hoc
    
    Once you've entered this do a Ctrl-X, yes and enter to save the file.
  5. Now we have a interfaces-wifi and interfaces-adhoc files in the /etc/network directory along with your original interfaces file. Now, we can switch between using a wireless connection and our ad-hoc network by simply copying the appropriate file over to the interfaces file.
  6. For example, if you want to use the ad-hoc network enter the following command >
    sudo cp /etc/network/interfaces-adhoc interfaces

    To switch back to a wifi network do the following:

    sudo cp /etc/network/interfaces-wifi interfaces
  7. You’ll need to install a package to allow your Pi to assign a device connecting to it an IP address.
    sudo apt-get install isc-dhcp-server

    It creates a config file that we will need to edit. You can access it using the code below.

    sudo nano /etc/dhcp/dhcpd.conf

    Once you have this open, edit it so that it only contains the code below.

    ddns-update-style interim;
    default-lease-time 600;
    max-lease-time 7200;
    authoritative;
    log-facility local7;
    subnet 192.168.1.0 netmask 255.255.255.0 {
     range 192.168.1.5 192.168.1.150;
    }
  8. Save this config file and reboot.
  9. When you boot up now under ad-hoc mode you will need to use your computer’s wifi to search and find the new network called PiWireless. Connect to it and then use SSH or VNC to connect to the IP address we assigned of 192.168.1.1Hope this helps.

Read More

Setting Up ServoBlaster On Raspberry Pi

Project Notes for using servoblaster and webiopi on my Raspberry Pi Robot :

gpio-descriptions

Start ServoBlaster at boot and have the ability to restart using init.d

Note: I’ve set this up to start and only use pins 11 and 12 by adding  –p1pins=”11,12″ after servod.
If you leave this off it will default to use all of the pins. I did it this way because the other pins were interfering with my Webiopi operation of two motors.
1. Create a file in /etc/init.d/ called servoblaster.
2. paste the code below


#!/bin/bash
# /etc/init.d/servoblaster

### BEGIN INIT INFO
# Provides: servoblaster
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This service is used to manage a servo
### END INIT INFO

case "$1" in
start)
echo "Starting servoblaster"
/home/pi/WebIOPi-0.7.0/examples/magpi-cambot/servod --p1pins="7,11,12"
;;
stop)
echo "Stopping servoblaster"
killall servod
;;
*)
echo "Usage: /etc/init.d/servoblaster start|stop"
exit 1
;;
esac

exit 0


4. Make it executable

sudo chmod +x /etc/init.d/servoblaster

5. I could start it with the following:

sudo /etc/init.d/servoblaster start

…and stop it again with this one:

sudo /etc/init.d/servoblaster stop
6. Have it start every time the PI boots
sudo update-rc.d servoblaster defaults

 

These notes were compiled using the tutorial at the link below. Thanks Raspberrypiwebserver for posting this info:
Please note that the tutorial originally references a /etc/init.d/servoblaster file but then moves to /etc/init.d/servod later on. I have changed that in my notes above to reflect only a /servoblaster file name in /etc/init.d

http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html

 


I am using Webiopi for my web control of the robot, motors and servos. Webiopi is passing commands to ServoBlaster in my cambot.py file. Through testing I’ve found these are my settings for the Pan and Tilt servos which hold my Pi Camera.

Lights: Servo 0 – Pin 7 / GPIO 4
I use this pin to control an LED light on the front of my vehicle

Pan: Servo 1 – Pin 11 / GPIO 17
Negative value is pan right using incremental method – echo 0=-10 > /dev/servoblaster
Positive is pan left using incremental method-  echo 0=+10 > /dev/servoblaster
Neutral is 120-   echo 0=120 > /dev/servoblaster

Tilt: Servo 2 – Pin 12 / GPIO 18
Positive value is tilt up using incremental method – echo 1=+10 > /dev/servoblaster
Negative value is tilt down using incremental method – echo 1=-10 > /dev/servoblaster
Set value 100 is 3/4 up –  – echo 1=100 > /dev/servoblaster
Neutral is 60 –   echo 1=60 > /dev/servoblaster

 


 

Read More

Raspberry Pi Troubleshooting List

This is a place to store notes and tips when I run into troubleshooting issues on the Raspberry Pi.

Wireless Issues:

  1. If using a USB wi-fi dongle that has the Ralink RT5370 ** chip. I have been experiencing lost signals and shutoff after using for short and long periods of time. This dongle has a power management feature that is causing issues. From the command line on Pi type iwconfig . Do you see an entry for Wlan0 that mentions power management: on  ?
    Hop into your interfaces file at the command line using

    sudo nano /etc/network/interfaces

    Add the following line. wireless-power off in the file. Exit and reboot.
    There is a good forum discussion on the topic here. http://www.raspberrypi.org/forums/viewtopic.php?f=28&t=40474#p330868

  2. If you’ve made a change to /etc/network/interfaces you can restart networking with the command:
    sudo /etc/init.d/networking restart

RaspBian Package Updates & Reinstalls:

  1. Clear your package cache :
    sudo apt-get clean
  2. If you know the name of the package and want to remove it:
    sudo apt-get --purge remove packagename
  3. Install and use the Synaptic Package Manager:
    sudo apt-get install synaptic

    Then=>

    sudo synaptic
  4. Distribution upgrade command: sudo apt-get dist-upgrade
  5. Remove unneeded packages, fix broken installs, update package list, upgrade installed packages).
    sudo apt-get autoremove && sudo apt-get -f install && sudo apt-get update && sudo apt-get upgrade -y
  6. List all packages installed

     

    dpkg-query -l

     

    List packages using a search pattern

     

    It is possible to add a search pattern to list packages:

    dpkg-query -l 'foo*'

     

    Show status of all packages on the system

     

    To check the status of all packages on your system:

    dpkg -l | more

     

    This will show all packages (1 line each) that are in various stages of install (this includes packages that were removed but not purged). To show only the installed:

    dpkg -l | grep '^i'

Read More