Raspberry Pi RoboPi User manual

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Using RoboPi
Copyright 2014 William Henning
RoboPi User Manual v0.85
Photo 1: Fully assembled RoboPi v1.00
The most up to date documentation will always be available at:
http://www.mikronauts.com/raspberry-pi/robopi/
http://Mikronauts.com 1 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Table of Contents
Introduction................................................................................................................................................4
RoboPi Printed Circuit Board....................................................................................................................5
RoboPi I/O Pin Definitions........................................................................................................................6
P0-P7: SERVO 1 – SERVO 8................................................................................................................6
P8-P15: SERVO 9 – SERVO 16............................................................................................................6
P16-P23: SENSOR 1 – SENSOR 8......................................................................................................6
P24-P27: SPI port for MCP3008/MCP3208.........................................................................................6
ADC1-ADC8: 0-5V Analog inputs.......................................................................................................6
RoboPi Expansion Connectors...................................................................................................................7
Raspberry Pi I/O header pins.................................................................................................................7
EXP1/EXP2/EXP3 3v3 Expansion Connectors....................................................................................7
PI-I2C eader........................................................................................................................................7
PROP-I2C eader.................................................................................................................................7
PROPPLUG eader..............................................................................................................................7
Using RoboPi with the Raspberry Pi.........................................................................................................8
Downloading & Installing Raspbian (Debian for the Pi)......................................................................8
Step 1: Get a compatible Class 10 speed SD card, 8GB – 32GB in size..........................................8
Step 2: Download the latest Raspbian image...................................................................................8
Step 3: Install Raspbian....................................................................................................................8
Step 4: Using the Raspberry Pi serial port with RoboPi...................................................................9
Step 5: Installing RoboPiLib..........................................................................................................10
Step 6: Installing the RoboPi Firmware..........................................................................................10
Step 7: Installing SimpleIDE for the Raspberry Pi (OPTIONAL).................................................10
Introducing RoboPiLib.............................................................................................................................11
Python RoboLib Constants..................................................................................................................13
Python RoboPiLib Functions..............................................................................................................13
C RoboPiLib Constants......................................................................................................................14
C RoboPiLib Functions......................................................................................................................14
Using RoboPi without a Raspberry Pi (stand alone operation)................................................................15
Installing SimpleIDE on PC/Mac/Linux for stand-alone RoboPi use.................................................15
Introducing RoboPiObj.......................................................................................................................15
RoboPiObj Constants..........................................................................................................................16
RoboPiObj Methods............................................................................................................................16
RoboPiObj Resource Utilization.........................................................................................................16
ow to use Digital Inputs........................................................................................................................17
Reading Bumper Switches..................................................................................................................17
ow to use Digital Outputs......................................................................................................................18
Using LED's to show which bumper is pressed..................................................................................18
ow to use Analog Inputs........................................................................................................................19
Reading a Potentiometer.....................................................................................................................19
Reading a CdS Photocell (light sensor)...............................................................................................19
Reading SirMorph (short range distance / line sensor).......................................................................19
ow to use Servos....................................................................................................................................20
http://Mikronauts.com 2 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Controlling a Continuous Rotation Servo...........................................................................................20
Controlling a Standard Servo..............................................................................................................20
ow to use PWM to control Gear Motors...............................................................................................21
EN/A/B Three Wire Driver.................................................................................................................21
A/B Two Wire interface.......................................................................................................................22
EN/DIR/PWM Three Wire Driver.......................................................................................................22
DIR/PWM Two Wire Driver...............................................................................................................22
Why the ENABLE signal of three wire drivers is useful....................................................................23
Two pin motor driver sample code......................................................................................................24
ow to Read Analog Distance Sensors....................................................................................................26
ow to Read Digital Ultrasonic Range Sensors......................................................................................27
Supported Ultrasonic Sensors:............................................................................................................27
ow to connect your ultrasonic range sensor:....................................................................................27
Stand-Alone Operation Requirements.....................................................................................................28
Appendix A: Software..............................................................................................................................29
Appendix B: Data Sheets.........................................................................................................................29
Appendix C: Support...............................................................................................................................29
Appendix D: RoboProp Software Compatibility:....................................................................................30
Appendix E: Frequently Asked Questions...............................................................................................31
http://Mikronauts.com 3 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Introdu tion
RoboPi is the most advanced robot controller add-on board for the Raspberry Pi available at this time.
RoboPi adds an eight-core 32-bit microcontroller running at 100Mhz to the Raspberry Pi in order to
off-load hard real time I/O and allow more precise timing than Linux running on the Pi allows.
RoboPi stacked on top of a odel A
Raspberry Pi
RoboPi can also be stacked on top of
odel B Raspberry Pi's
RoboPi Features
•Parallax Propeller P8X32 eight core 32 bit Risc microcontroller running at 100Mhz
•Each of the eight cores provides up to 25MIPS as most instructions take only 4 clock cycles
•three ten-pin Mikronauts I/O module expansion connectors (P0-P7, P8-P15, P16-P23)
•24 servo compatible headers on P0..P23
◦P0-P7 jumper selectable power from Pi's 5VDC supply or external servo power supply
◦P8-P15 jumper selectable power from Pi's 5VDC supply or external servo power supply
◦P16-P23 is powered by 5V from the Pi expansion header for sensors
•Screw terminal for providing external power for Servo connectors P0-P15
•8 servo compatible headers for an eight channel 0-5V analog to digital converter with choice of
◦MCP3008 for 10 bit A/D conversion
◦MCP3208 for 12 bit A/D conversion
•Choice of 256Kbit or 512Kbit boot EEPROM for the Propeller
•On-board voltage regulation providing 3.3V with power on LED from the 5V on the Pi header
•4 pin I2C expansion header for the Raspberry Pi
•4 pin I2C expansion header for the Propeller
•5 pin COM connector for use with PropPlug in stand alone operation (optional)
•Mikronauts EZasPi prototyping board can stack below RoboPi
•Mikronauts Pi Jumper can stack on top of RoboPi
•Mikronauts SchoolBoard ][ and other Propeller products are compatible with RoboPi
http://Mikronauts.com 4 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
RoboPi Printed Cir uit Board
ere is a top view of where parts are located on the RoboPi printed circuit board:
You can refer to this image while wiring your robot after assembling your RoboPi.
PLEASE NOTE
The “PROPPLUG” connection is for stand-alone RoboPi operation (where RoboPi is NOT stacked on
top of a Raspberry Pi. Pins 1-4 are the same as PropPlug (Pin 1 is GND), Pin 5 adds 3.3V for SerPlug.
Plugging in a PropPlug while RoboPi is sta ked on the Raspberry Pi may damage your
Raspberry Pi, PropPlug and/or RoboPi.
http://Mikronauts.com 5 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
RoboPi I/O Pin Definitions
Before you can write programs for your RoboPi based robot, you have to learn what resources are
available for you to connect to sensors, motors and other devices or boards.
P0-P7: SERVO 1 – SERVO 8
•10 pin EXP1 connector connected directly to processor pins, 3v3 I/O only
•connects to signal pin on SERVO1-8 through a 2k4 current limiting resistor, 5V I/O safe
•For the servo header, SV2 selects between the Pi's 5V and VBat from the screw terminal
P8-P15: SERVO 9 – SERVO 16
•10 pin EXP2 connector connected directly to processor pins, 3v3 I/O only
•connects to signal pin on SERVO9-16 through a 2k4 current limiting resistor, 5V I/O safe
•For the servo header, SV3 selects between the Pi's 5V and VBat from the screw terminal
P16-P 3: SENSOR 1 – SENSOR 8
•10 pin EXP3 connector connected directly to processor pins, 3v3 I/O only
•connects to signal pin on SENSOR1-8 through a 2k4 current limiting resistor, 5V I/O safe
•the Pi's 5V is used for SENSOR1-8 to provide cleaner power to Ping's etc
P 4-P 7: SPI port for MCP3008/MCP3 08
•P24 is MISO, connected to DO on ADC through a 2k4 current limiting resistor
•P25 is MOSI
•P26 is CLK
•P27 is /CS
ADC1-ADC8: 0-5V Analog inputs
•connects to the signal pin on ADC1-8 servo style header
•the Pi's 5V is used for ADC1-8 to provide cleaner power to Ping's etc
http://Mikronauts.com 6 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
RoboPi Expansion Conne tors
Raspberry Pi I/O header pins
•RoboPi requires exclusive use of RX/TX
•RoboPi makes the Raspberry Pi I2C available on a Mikronauts four-pin 3v3 I2C header
•All other Raspberry Pi I/O pins are available for your use
•Mikronauts EZasPi was designed to stack between RoboPi and Raspberry Pi for expansion
•Mikronauts EZasPi (B) was designed to stack below the Raspberry Pi for more expansion
EXP1/EXP /EXP3 3v3 Expansion Connectors
•EXP1 is for Propeller pins P0-P7, and servo connectors 1-8
•EXP2 is for Propeller pins P8-P15, and servo connectors 9-16
•EXP3 is for Propeller pins P16-P23, and sensor connectors 1-8
•Mikronauts 3v3 10 pin modules can be used in EXP1/EXP2/EXP3
•You must not use the 3 pin servo connectors for pins used by a 10 pin module
PI-I C Header
•For using 3v3 I2C expansion modules with RoboPi
PROP-I C Header
•For using 3v3 I2C expansion modules with the Raspberry Pi
PROPPLUG Header
•For programming RoboPi when it is not mounted on a Raspberry Pi
•Intended for stand-alone RoboPi applications
•DO NOT USE WHEN MOUNTED ON A RASPBERRY PI
http://Mikronauts.com 7 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Using RoboPi with the Raspberry Pi
Downloading & Installing Raspbian (Debian for the Pi)
If you already have Raspbian running on your Raspberry Pi, you an skip to Step 4
Installing Raspbian on your Raspberry Pi is required before you can use and control RoboPi with your
Raspberry Pi. The Raspberry Pi Foundation has made this easy, by providing downloadable images of
the Raspbian operating system, with instructions for using PC's, Mac's and Linux computers to make a
bootable Raspbian SD card.
Step 1: Get a ompatible Class 10 speed SD ard, 8GB – 32GB in size.
You can find a database of SD cards that are known to work with the Raspberry Pi at:
http://elinux.org/RPi_SD_cards
Other SD cards are likely to work as well, I suggest Class 10 for speed.
Step 2: Download the latest Raspbian image
You can find the latest version of Raspbian at:
http://www.raspberrypi.org/downloads/
Step 3: Install Raspbian
The Raspberry Pi foundation provides excellent instructions on how to make a bootable Raspbian SD
card for your Raspberry Pi with your PC/Mac/Linux computer at:
http://www.raspberrypi.org/documentation/installation/installing-images/READ E.md
http://Mikronauts.com 8 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Step 4: Using the Raspberry Pi serial port with RoboPi
The Raspberry Pi has 3.3V serial RX and TX signals available on its 26 pin header.
Normally this port is configured to display boot messages, after which it becomes a serial console.
My favorite small text editor is 'joe', which you can install with
sudo apt-get install joe
then
sudo joe /boot/cmdline.txt
remove “console=ttyAMA0, 115200 kgdboc=ttyAMA0, 115200”
sudo joe /etc/inittab
Find the line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
and insert a '#' in front of T0:23
For the changes to take effect, type
sudo shutdown now -r
http://Mikronauts.com 9 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Step 5: Installing RoboPiLib
Download the latest version of RoboPiLib.zip from the RoboPi product page at:
http://www.mikronauts.com/raspberry-pi/robopi/
Step 6: Installing the RoboPi Firmware
Download the latest version of RoboPiObj.zip from the RoboPi product page at:
http://www.mikronauts.com/raspberry-pi/robopi/
You will also need to download the latest version of propeller_load.zip from the product page.
Step 7: Installing SimpleIDE for the Raspberry Pi (OPTIONAL)
You only need to install SimpleIde if you want to write your own custom Propeller software for RoboPi
on your Raspberry Pi, and do not wish to use the RoboPi firmware and RoboPiLib.
Only advanced users should attempt to program RoboPi from the “bare metal”
ere is how you can install the Propeller SimpleIDE development environment:
http://Mikronauts.com 10 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Introdu ing RoboPiLib
RoboPiLib is a library designed to interface the Raspberry Pi with the RoboPi firmware.
RoboPiLib was designed to make it easy to write programs on the Raspberry Pi that use all of the
firmware features of RoboPi, and was designed to be familiar to those coming to RoboPi from
WiringPi, Arduino or Wiring environments.
RoboPiLib is available for both Python and C, and the native Spin object uses the same API as
RoboPiLib.
The Python interface that is almost identical to the C interface – all you have to do is prefix the library
function names as follows:
Python Examples:
import RoboPiLib as RoboPi
# connect to RoboPi
RoboPi.RoboPiInit(“/dev/ttyAMA0”,115200)
# set pin 16 to an output and write 1 to it
RoboPi.pinMode(16,RoboPi.OUTPUT)
RoboPi.digitalWrite(16,1)
# set pin 17 to a PWM output and generate a 50% PWM on pin 17
RoboPi.pinMode(17,RoboPi.PWM)
RoboPi.analogWrite(17,127)
# read analog input 0
print RoboPi.analogRead(0)
http://Mikronauts.com 11 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
http://Mikronauts.com 12 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Python RoboLib Constants
Digital pins can be configured for one of the following four modes:
INPUT pin mode for a digital input
OUTPUT pin mode for a digital output
PWM pin mode for a PWM output (0..255)
SERVO pin mode for a servo output (0..2500)
Python RoboPiLib Functions
RoboPiInit(device, bps) use RoboPiInit(“/dev/ttyAMA0”,115200)
RoboPiExit() close the serial connection with RoboPi
readMode(pin) returns int returns INPUT/OUTPUT/SERVO/PWM
pinMode(pin, mode) set pin to one of INPUT/OUTPUT/SERVO/PWM
digitalRead(pin) returns int returns 0 or 1 state of pin
digitalWrite(pin, val) sets pin to 0 or 1
analogRead(chan) returns int returns 0..1023 from specified channel
analogReadRaw( pin) returns int returns 0..4095 from specified channel
analogWrite(pin, val) write 0..255 to PWM pin (off to full on)
servoRead(pin) returns int return last servo value written to pin
servoWrite(pin, val) set servo on pin to val (0..2500 us)
readDistance(int pin) returns int return distance to nearest object in milimeters
In your program, in lude the following at the top:
import RoboPiLib as RoboPi
See the example on the previous page to see how to use the Python interface.
http://Mikronauts.com 13 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
C RoboPiLib Constants
Digital pins can be configured for one of the following four modes:
INPUT pin mode for a digital input
OUTPUT pin mode for a digital output
PWM pin mode for a PWM output (0..255)
SERVO pin mode for a servo output (0..2500)
C RoboPiLib Functions
void RoboPiInit(char *device, int bps) use RoboPiInit(“/dev/ttyAMA0”,115200)
void RoboPiExit() close the serial connection with RoboPi
int readMode(int pin) returns INPUT/OUTPUT/SERVO/PWM
void pinMode(int pin, int mode) set pin to one of INPUT/OUTPUT/SERVO/PWM
int digitalRead(int pin) returns 0 or 1 state of pin
void digitalWrite(int pin, int val) sets pin to 0 or 1
int analogRead(int chan) returns 0..1023 from specified channel
int analogReadRaw(int pin) returns 0..4095 from specified channel
void analogWrite(int pin, int val) write 0..255 to PWM pin (off to full on)
int servoRead(int pin) return last servo value written to pin
void servoWrite(int pin, int val) set servo on pin to val (0..2500 us)
int readDistance(int pin) return distance to nearest object in milimeters
getPa ket/putPa ket for advan ed users only - requires modifying RoboPi firmare
int putPacket(char c, char *bf, int ln) send a custom packet to RoboPi
int getPacket(char *c, char *bf, int *ln) receive response to custom packet sent to RoboPi
In your program, include “RoboPiLib.h”, and add RoboPiLib.o to your command line as follows:
gcc -o myprog myprog.c RoboPiLib.o
http://Mikronauts.com 14 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
Using RoboPi without a Raspberry Pi (stand alone operation)
Installing SimpleIDE on PC/Mac/Linux for stand-alone RoboPi use
Parallax has written an excellent guide for installing SimpleIDE at:
http://learn.parallax.com/propeller-c-set-simpleide
Introducing RoboPiObj
If you want to run RoboPi stand-alone (without a Raspberry Pi) you can still take advantage of the
RoboPI API natively.
RoboPiObj.spin is the top-level Spin object for implementing the functionality that is exposed by the
firmware; and as such, it can be used directly from Spin programs running on RoboPi's Propeller
micrcocontroller.
Please note – this is only recommended for those that want to get to the “bare metal”, as it means that
your robot will be controlled by RoboPi's propeller – and not by a Raspberry Pi or external computer.
You can ofcourse implement your own protocol, and even ignore RoboPiObj, by writing from the
ground up – but I think you will find that RoboPiObj takes care of the low level details for you, and lets
you concentrate on your application.
http://Mikronauts.com 15 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
RoboPiObj Constants
INPUT pin mode for a digital input
OUTPUT pin mode for a digital output
PWM pin mode for a PWM output (0..255)
SERVO pin mode for a servo output (0..2500)
RoboPiObj Methods
start Initialize RoboPiObj, start service cogs
pinMode(pin, mode) set digital pin to specified mode
readMode(pin) read current mode of digital pin
digitalRead(pin) read current value (0 or 1) at pin, regardless of mode
digitalWrite(pin) write 0 or 1 to digital pin
analogRead(chan) read analog input channel, scale to 0..1023 return value
analogReadRaw(chan) read analog input channel, return raw 0..4095 value
analogWrite (pin, value) write PWM value to pin, 0 is off, 255 is fully on
servoWrite(pin, value) write servo position to pin , 0 to 2500 microseconds
servoRead(pin, value) return last servo position written to pin
readDistance(int pin) return distance to nearest object in milimeters
delay(ms) delay for ms milliseconds
delayMicroseconds(us) delay for us microseconds
RoboPiObj Resource Utilization
RoboPiObj currently uses 4944 bytes of EEPROM/RAM and two cogs for drivers,
ADC_INPUT_DRIVER MCP3208 driver object
PWM_32_v4 PWM/Servo driver object
http://Mikronauts.com 16 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
How to use Digital Inputs
Reading Bumper Switches
Probably the simplest digital input possible is a switch.
<insert schematic of two bumper switches, 100k pullup to 5v, shorts to ground when closed>
#include <stdio.h>
#include “RoboPiLib.h”
#define LEFT_BUMPER 22
#define RIG T_BUMPER 23
#define PRESSED 0
int main(int argc, char *argv[]) {
RoboPiInit(“/dev/ttyAMA0”,115200);
pinMode(LEFT_BUMPER, INPUT);
pinMode(RIG T_BUMPER, INPUT);
while (1) {
if (digitalRead(LEFT_BUMPER)==PRESSED)
puts(“Left Bumper Pressed”);
if (digitalRead(RIG T_BUMPER)==PRESSED)
puts(“Right Bumper Pressed”);
sleep(1); // only check once per second
}
}
http://Mikronauts.com 17 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
How to use Digital Outputs
The simplest way of demonstrating a digital output is to use it to light an LED.
Using LED's to show which bumper is pressed
<insert schematic of two LED's connected to EXP pins through 470R resistors>
#include <stdio.h>
#include “RoboPiLib.h”
#define LEFT_BUMPER 22
#define RIG T_BUMPER 23
#define LEFT_LED 8
#define RIG T_LED 9
#define PRESSED 0
int main(int argc, char *argv[]) {
RoboPiInit(“/dev/ttyAMA0”,115200);
pinMode(LEFT_BUMPER, INPUT);
pinMode(RIG T_BUMPER, INPUT);
pinMode(LEFT_LED, OUTPUT);
pinMode(RIG T_LED, OUTPUT);
while (1) {
digitalWrite(LEFT_LED, ~digitalRead(LEFT_BUMPER));
digitalWrite(RIG T_LED, ~digitalRead(RIG T_BUMPER));
}
}
http://Mikronauts.com 18 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
How to use Analog Inputs
Reading a Potentiometer
Probably the simplest analog input possible is a potentiometer.
<insert schematic of potentiometer as voltage divider going to analog input>
#include <stdio.h>
#include “RoboPiLib.h”
#define POT 0
int main(int argc, char *argv[]) {
RoboPiInit(“/dev/ttyAMA0”,115200);
while (1) {
printf(“Potentiometer value is %d\n”, analogRead(POT));
sleep(1); // only check once per second
}
}
Reading a CdS Photocell (light sensor)
<insert schematic of CdS circuit>
Connect a 10K pullup to the signal pin of an analog input to +5V, also connect one side of the CdS to
the signal pin. Connect the other leg of the CdS to GND.
Use analogRead(ch) to read SirMorph sensors, and you will get a value between 0..1023 representing
the amount of light detected by the CdS sensor.
Reading SirMorph (short range distance / line sensor)
SirMorph provides a standard 3-pin Sig/+/GND interface that can be plugged directly into any of the
eight analog inputs on RoboPi.
Use analogRead(ch) to read SirMorph sensors, and you will get a value between 0..1023 representing
the amount of light reflected into the photo transistor.
http://Mikronauts.com 19 2014-01-27

RoboPi v1.00 User Manual v0.85 Copyright 2014 William enning
How to use Servos
#include <stdio.h>
#include "RoboPiLib.h"
#define LEFT_SERVO 0
#define RIG T_SERVO 1
#define SERVO_MIN 500
#define SERVO_MAX 2500
#define SERVO_REV (SERVO_MIN+SERVO_MAX)
int main(int argc, char *argv[]) {
int i;
RoboPiInit("/dev/ttyAMA0",115200);
pinMode(LEFT_SERVO, SERVO);
pinMode(RIG T_SERVO, SERVO);
while (1) {
for(i=SERVO_MIN;i<=SERVO_MAX;i+=100) {
servoWrite(LEFT_SERVO, i);
servoWrite(RIG T_SERVO, SERVO_REV-i);
printf("LEFT SERVO = %d\n", servoRead(LEFT_SERVO));
printf("RIG T SERVO = %d\n", servoRead(RIG T_SERVO));
sleep(1);
}
}
}
Controlling a Continuous Rotation Servo
If you are using continous rotation servos, the above code will cause the two servos run in one
direction, then the opposite direction, at varying speed.
Controlling a Standard Servo
If you are using standard servos, the above code will turn the servos as far as possible in one direction,
then the other direction.
http://Mikronauts.com 20 2014-01-27
Other manuals for RoboPi
1
Table of contents
Other Raspberry Pi Motherboard manuals