Ar2Pi2 – Dual Mode Robot – Arduino vs Raspberry Pi

Ar2Pi2 – The Robot That Can be Arduino or Raspberry Pi

(Previously known as BotZero)

Click on any photo to enlarge.

botzero03a

Ar2Pi2 as an Arduino Uno compatible robot

 

botzero07

Ar2Pi2 as a Raspberry Pi robot

 

Overview

Ar2Pi2 is a tiny robot that fits well inside the boundaries of an A6 sheet of paper (148 x 105mm). This makes it ideal for Micro Pi Noon and other small robot competitions.

Including the wheels it is 110 x 90mm and is 60mm high

The robot contains an ATMega328 which can be programmed over the USB interface just like an Arduino Uno. The robot is then fully programmable using any of the standard Arduino methods. A simple demo program is BotZMotor.ino

Alternatively, you can program the ATMega328 with the BotZero01.ino code and plug in your Raspberry Pi Zero and use the Pi to control the robot. This is very similar to the way our Picon Zero intelligent robotic controller works (in fact they share a lot of the same code). In this Raspberry Pi mode, there is a full Python library to enable you to control everything on the robot from python running on the Pi

The whole robot is powered by 3 AA cells. There is an onboard “boost” regulator to generate the 5V needed for the Pi.

 

Features

  • Hardware controlled by ATMega328
  • Powered by 3xAA batteries
  • 6 x RGB pixels (mini “neopixels”)
  • 2 x Analog light sensors
  • 2 x Analog line following sensors
  • 2 x DC motors fitted in servo cases
  • Large 60mm diameter wheels
  • Front smooth running caster
  • USB interface to the ATMega328
  • 4 x general purpose I/O lines with GVS (Ground, Volts, Signal) 3-pin connections. These can be Digital or Analog etc (just like Picon Zero)
  • On/Off switch
  • Special fitting for Micro Pi Noon balloon holder and popper (If this is fitted, the 4 I/O lines GVS pins cannot be used)
  • Designed for Raspberry Pi Zero, but other Raspberry Pis could be fitted by using a suitable extension header

 

Pictorial Overview

botzero05a

 

Assembling the Kit

Step 1 – Attach the Bottom plate and mounting pillars

step01a

Check you have the bottom mounting plate, 2 pan-head screws and 2 10mm pillars

step01b

Orient the bottom plate so the holes clear the soldered components as shown

step01c

Push the screws through the bottom plate and the main board, then screw into the 10mm pillars

step01d

 

Step 2 – Attach the Motors

step02a

All you need is the motors. Ensure the wires exit from the back of the motors and the red wires are both on the inside as shown

step02b

Carefully twist the wires so they fit between the motors, ensuring they don’t go over the motors

 

Step 3 – Fit the Battery Holder

step03a

You’ll need the battery holder and 2 countersink head screws

step03b

First connect the battery holder to the screw terminals. Red towards the rear, marked Vin

step03c

Twist the wires in between the 2 motors – again being careful that the wires do not get trapped between the motors and the battery holder. Warning: this is tricky! You can leave the wires out which is much easier, but it doesn’t look as tidy, so it is worth persevering.

 

Step 4 – Fit the Front Caster

step04a

Use the short 6mm screws (in the separate bag of screws and pillars) and note that the spacers provided with the caster are not required

step04b

With the ball out of the holder, push the screws through the black holder and through the PCB

step04c

Screw the nuts on tight

step04d

Finally, push the steel ball into the holder. It should snap tightly in and move very smoothly

 

Step 5 – Attach the Wheels

step05a

First stretch the tyres over the plastic wheels. Then push the wheels onto the shafts of the motors

step05b

Use the screws provided to tightly fix the wheels

 

Your Ar2Pi2 is ready to rock and roll!

Add batteries and switch it on to demo the LEDs and the motor operations. Next step, write some programs…

 

Download the python library and examples from here

 

 

Win a Picon Zero and Raspberry Pi Zero!

Win a Picon Zero and Raspberry Pi Zero!

Competition Now Closed

  • You wanted analog inputs for your Raspberry Pi? – You got it!
  • You wanted to drive servos with no difficult software? – You got it!
  • What about driving WS2812 “neopixels” without kernel software that breaks every other release? – You got it!
  • Or maybe you want to get temperature from DS18B20-based sensors without lockouts and waits? – You got it!
  • Oh, and you want to drive a pair of 1.5A per channel DC motors using simple PWM settings? – You got it!
  • And of course, you want it for free? – You (maybe) got it!
  • Hang on, you want a Raspberry Pi Zero for free as well?? – You (maybe) got it!

We’re running a competition: simply retweet the competition tweet to be entered into the draw. On Sunday 3rd April, we will draw the winners:

  • 1st randomly selected, will receive a Picon Zero
  • 2nd randomly selected, will receive a Picon Zero and a Raspberry Pi Zero
  • 3rd randomly selected, will receive a Picon Zero and a Raspberry Pi Zero and a mini robot kit

Postage is FREE anywhere in the world

Competition closes 8pm BST on Sunday 3rd April. Winners will be announced shortly after.

Find out more about the Picon Zero here

Purchase Picon Zero here

 

 3rd Prize

prize01

 

2nd Prize

prize01    plus   prize02

 

1st Prize

prize01  plus  prize02  plus  prize03

Picon Zero – Intelligent Robotics for Raspberry Pi

Picon Zero – Intelligent Robotic Controller for Raspberry Pi

Purchase Picon Zero here

Worksheets now available – see the bottom of this page

 

Description

The Picon Zero is an add-on PCB for the Raspberry Pi. It is physically the same size as a Raspberry Pi Zero and so is ideal as a pseudo-Hat (pHat) for the Pi Zero. However, it can of course be used on any Raspberry Pi with a 40-pin GPIO connector. Currently that includes the A+, B+, 2B and 3B.

As well as 2 full H-Bridge motor drivers, the Picon Zero has a number of Input and Output pins that can be configured in a variety of ways, allowing you to easily add analog inputs or neopixel outputs to your Raspberry Pi without any complicated software and kernel specific drivers. It also provides an interface for an HC-SR04 ultrasonic distance sensor and opens up 5 GPIO pins from the Raspberry Pi for you to use as you see fit.

The Picon Zero is shipped with all components, including the headers and screw terminals, fully soldered. This saves you doing any soldering and allows you to use it directly from the box

 

Specification

  • Pseudo-Hat format PCB, 65 x 30 mm with gold plated pads and a ready-fitted 40-pin female header (if using a Pi-Zero, ensure you have soldered a male header in place)
  • 2 full H-Bridge motor drivers. Can drive up to 1.5A continuously (2A peak) per channel, at from 3 – 11V
  • Each motor output has both a 2-pin screw terminal and a 2-pin male header. You choose which to use, depending what connectors you have on the motors
  • The power for the motors can be taken from an external power source (3V to 11V) or from the Picon Zero’s own 5V
  • The Picon Zero’s 5V can be selected to be from the Raspberry Pi’s 5V line, or from a USB connector on the Picon Zero. This allows you to use 2 USB battery banks: one to power the Pi and the other to power the servos and motors on the Picon Zero
  • 4 Inputs that can accept up to 5V. These inputs can be configured as:
    • Digital inputs
    • Analog inputs (10 bits, 0..1023)
    • DS18B20
    • DHT11 (TBD)
  • 6 Outputs that can drive 5V and be configured as:
    • Digital Output (High or Low)
    • PWM Output (Pulse Width Modulation from 0% to 100%)
    • Servo (drives a standard servo through 180 degrees)
    • Neopixel WS2812 (Can drive up to 64 neopixels in a chain. Only available on output 5)
  • All Inputs and Outputs use GVS (Ground, Volts, Signal) 3-pin male headers. This is a common standard for 3-pin sensors and servos and allows direct connection without additional wires
  • 4-pin female header that can connect directly to an HC-SR04 ultrasonic distance sensor. You can plug the sensor directly into this header for an ultra-compact, object avoiding robot
  • 8-pin female header for Ground, 3.3V, 5V and 5 GPIO signals allowing users to add their own additional features

 

Hardware Configuration

Picon Zero has 2 jumpers for setting the hardware configuration. Make sure you have them set in the correct positions for your requirements

  1. JP1 – Board 5V Selector. This jumper selects where to get the 5V power from for the Picon Zero Outputs. The options are:
    1. Jumper at the top between RPI and 5V. The 5V power for the board is taken from the Raspberry Pi 5V pins on the GPIO connector. With low power output devices and low power 5V motors, this allows you to power all devices with a single 5V power input to the Raspberry Pi
    2. Jumper at the bottom between USB and 5V. The 5V power is taken from the micro-USB connector on the Picon Zero. For higher power out devices, you can provide extra power through the micro-USB connector on the board
  2. JP2 – Motor Power Selector. This jumper selects where to get the power for the motors from. The two options are:
    1. Jumper at the top between Vin and MotorPower. The motors are driven from the 2-pin screw terminal. This voltage can be anything from 3V to 11V. Useful for motors that require a voltage different from 5V, or that require more current than is available on either of the USB input connectors
    2. Jumper at the bottom between 5V and MotorPower. The motors are driven from the board’s 5V power signal. Remember that this in turn can be selected to be either the Raspberry Pi or the micro-USB connector on the Picon Zero.

 

Programming

Raspberry Pi Setup

The Picon Zero is an I2C device, so you must ensure that your Raspberry Pi is setup to use I2C and smbus correctly:

  • sudo apt-get install python-smbus python3-smbus python-dev python3-dev
  • sudo nano /boot/config.txt
    • and add the following 2 lines to the end of the file:
    • dtparam=i2c1=on
    • dtparam=i2c_arm=on
    • Press <ctrl-x> and accept the default prompts to save the file
  • sudo reboot

Plug the Picon Zero onto the Pi and run

  • i2cdetect -y 1

If all is well, you will see the Picon Zero showing up as address 22 as below:

i2cdetect

 

Python Example Installation

The Picon Zero is provided with a python library which allows very simple access to all the features in an intuitive and consistent manner. A separate small library handles the ultrasonic which is on a GPIO pin and not part of the onboard micro-controller.

Download the Picon Zero library itself  from here

You can also download directly both libraries and example files by typing the following into the terminal window. Open LXTerminal and type:

  • wget http://4tronix.co.uk/piconz.sh -O piconz.sh
  • bash piconz.sh

That will create a piconzero folder in your home folder, with the libraries and example files:

  • piconzero.py  library module for Picon Zero
  • hcsr04.py  library module for ultrasonic sensor
  • version.py prints the board type and firmware version
  • motorTest.py  tests the motor functions using the arrow keys on the keyboard
  • ioTest.py  demonstrates the use of an analog input (potentiometer on Input 0) used to control various forms of output
  • sonarTest.py  demonstrates taking distance readings if you have an HC-SR04 ultrasonic sensor attached
  • tempTest.py demonstrates reading the temperature from an attached DS18B20 sensor
  • 10linesTest.py  shows a simple 10 (or 11) line program that reads an analog input and outputs to various devices (same as ioTest.py but without some bells and whistles). Simply to show how easy it can be to use the Picon Zero
  • pixelTest.py  flashes all the attached neopixels from White to Off and back again
  • servoTest.py uses the arrow keys to move 2 servos (pan and tilt) and the G, H keys to move a third servo (grabber claw)

 

Basics of Programming Picon Zero

A python program should start by importing the library, eg.

import piconzero as pz

Notice that we have imported the whole library and then called it ‘pz’ for short. Now whenever we use any of the library functions we need to put the ‘pz.’ in front so python knows where to get the functions from.

Then you should call the initialising function to clear any previous settings that may have been left from a previous program closing untidily

pz.init( )

Now the library is set up and ready to go. Ensure you set the configuration required for each pin before using it (unless you are using the default configurations, when it is not necessary)

At the end of your program you should clean up the system and leave it in a nice state for the next program to use

pz.cleanup( )

The classified complete list of library functions follows

 

General Functions

  • init ( ): This clears all the Inputs and Outputs back to their default configurations, stops the motors, disables any servos and switches off neopixels. It also sets a few internal variables that allows the Picon Zero to keep track of what it is doing
  • cleanup ( ): This is pretty much the same as init() but is used at the end of the program to clean up all the outputs for the next program
  • getRevision ( ): This returns a list with board revision and firmware revision. It allows you to check whether the firmware is capable of any new functions (assuming new functions will be added later)

 

Motor Functions

  • forward (speed): Moves both motors forward at selected speed. Speed can vary from 0 to 100. (it can also be negative, which would cause the robot to reverse)
  • reverse (speed): Moves both motors in reverse ar selected speed. Speed can vary from 0 to 100 (can also be negative)
  • spinLeft (speed): Spins left on the spot at selected speed. Speed can vary from 0 to 100 (can also be negative)
  • spinRight (speed): Spins right on the spot at selected speed. Speed can vary from 0 to 100 (can also be negative)
  • stop ( ): Stops both motors
  • setMotor (motor, speed): This is the primitive motor function, called by all the others. Motor can be either 0 (Motor A) or 1 (Motor B). Speed can vary from -100 (full reverse) to +100 (full forwards). The speed number is a percentage.

 

Input Functions

  • setInputConfig (channel, config): This sets the configuration of the selected Input channel. There are 4 Input channels (0 to 3). The config parameter determines if the channel is:
    • 0: Digital (0 or 1) – this is the Default input configuration [there is a 3rd parameter for version 08 firmware and later: Pullup, set to False by default, but can be set to True which will provide a 10K internal pullup resistor on the selected channel
    • 1: Analog (0 to 1023) – read analog values from selected channel. 0V -> 0;  5V -> 1023
    • 2: DS18B20 [Available from firmware revision 06].  Reads a 18B20 temperature sensor
  • readInput (channel): Gets the value of the selected input channel. This will return:
    • o (False) or 1 (True) if the channel is Digital
    • A value from 0 to 1023 if the channel is analog
    • A temperature in centigrade if the channel is a DS18B20

 

Output Functions

  • setOutputConfig (channel, config): This sets the configuration of the selected Output channel. There are 6 Output channels (0 to 5) and these can be set as follows:
    • 0: Digital (Low or High) – this is the Default output configuration
    • 1: PWM (0 to 100% duty cycle)
    • 2: Servo ( 0 to 180 degrees)
    • 3: Neopixel WS2812B (individually address any pixel and set values of 0..255 for each colour). Only Output channel 5 can be set to this configuration value
  • setOutput (channel, data): Sets the output channel with the data entered – Digital, PWM and Servo data only.
  • setPixel (pixel, red, green, blue): Sets the selected pixel (0 to 63) with the selected red, green and blue values (0 to 255).
  • setPixel(pixel, red, green, blue, update): The optional parameter update (defaults to True), determines if the updated pixel data is updated immediately or not. Updating the pixel strip strip takes time, so if you are changing a number of pixels at once, it is best to switch off updates until they have all been changed, then use the updatePixels ( ) function
  • setAllPixels (red, green, blue): Sets all pixels with the selected red, green and blue values (0 to 255) [Available from firmware revision 07]
  • setAllPixels (red, green, blue, update): The optional parameter update (defaults to True), determines if the updated pixel data is updated immediately or not. Updating the pixel strip strip takes time [Available from firmware revision 07]
  • updatePixels ( ): Causes an immediate update of all the pixels from the latest data
  • setBrightness (brightness): Sets the overall brightness (0 to 255) of the neopixel chain. All RGB values are scaled to fit into this max value. Default is 40

 

 Worksheets

These downloadable worksheets take you through using various features of the Picon Zero in simple, self-contained, stages.

  1. Worksheet 01 – Setting up your Raspberry Pi for Picon Zero
  2. Worksheet 02 – Configuring and controlling motors
  3. Worksheet 03 – Getting Input from Buttons and Switches
  4. Worksheet 04 – First steps with analog inputs
  5. Worksheet 05 – Controlling servos
  6. Worksheet 06 – Controlling the brightness of LEDs (PWM)
  7. Worksheet 07 – Reading temperatures from a DS18B20
  8. Worksheet 08 – Driving WS2812B RGB LEDs (aka NeoPixels)

 

Assembling Initio using RoboHAT

Using RoboHAT with Initio

rh13

Click on any image to enlarge

 

You should already have followed the instructions for assembling the chassis here.

In this section we will add the RoboHAT controller, the obstacle sensors, line sensors and the pan/tilt assembly with ultrasonic sensor.

1. Fitting the RoboHAT to the Raspberry Pi

step01

Screw one of the support pillars to the underneath of the RoboHAT at the front (under the RoboHat logo). Then plug the RoboHAT onto the Raspberry Pi.

Push the RoboHAT carefully onto the GPIO pins of the Raspberry Pi, ensuring the pins are placed correctly as shown in the photo above

step02

Connect the motor wires as shown. Red – Black – Black – Red

It won’t damage it if you connect them differently, but the example programs won’t go the direction that you would expect

ultpi_23

Plug the Black/White cable with the DC Jack into the left-most pins on the switch PCB on Initio and the DC Jack end into the RoboHAT as shown above.

There will be a spare cable with Red and Black wires. This is not required for the Raspberry Pi build and should be removed so the ends don’t short.

Check all the wiring again very carefully, then now is a good time to see if the Pi powers up and you can control the motors.

Use 6xAA batteries. These should be good quality rechargeable batteries. We recommend Energizer Extremes or Eneloops

Connect a monitor, keyboard and mouse to the Raspberry Pi, plug in your SD card and switch on. The green light near the On/Off switch should turn on, the LEDs on the Pi should start flashing and the booting sequence should appear on the monitor. If not, switch off and double check the wiring.

Instead of using the batteries, you can plug a micro-USB cable directly into the connector on the Pi. This is an excellent way to get started and allows you to test everything (except the motors, which may turn but only slowly) without using batteries.

 

2. Mounting Obstacle Sensors

ultpi_02

Check that each sensor has 2 mounting collars. Screw one onto the body of the sensor, leaving room at the front for the second one

ultpi_03

Push the sensor through from the rear of the mounting bracket and screw on the second collar. Feed the wires up through the holes in the top plate

ultpi_04

Repeat for the second side

step03

Connect to the RoboHAT INPUTs

  • Left sensor to Pin 7 (marked x07 or #04)
  • Right sensor to Pin 11 (marked x11 or #17)

The wire colours from the obstacle sensor are:

  • Black: Gnd
  • Red:  5V
  • White or Yellow: Signal

Make sure you connect them to the correct pins on the RoboHAT

 

3. Mounting the Line Sensors

ultpi_07

First, take the 30cm female-female jumper strip of 10 wires and split it into three strips:

  • Brown, Red, Orange, Yellow (this is for the Ultrasonic Sensor)
  • Green, Blue, Purple (this is for the Left Line Sensor)
  • Grey, White, Black (this is for the Right Line Sensor)

ultpi_08

Next, prepare the two Line Sensors and 2 of the 3x8PB screws as shown

ultpi_09

Screw the line sensors in position as shown, using the screwhole in the middle of the circuit board

ultpi_10

Connect the Green, Blue, Purple wire to the Left Sensor and the Grey, White, Black cable to the Right Sensor

** Note some sensors have the pins in order 5V, Signal, Gnd; other have them in order Signal, 5V, Gnd – make sure you know which wire colour is connected to which.

step04

Connect the sensors to the RoboHAT

  • Left sensor to Pin 29 (marked x29 or #05)
  • Right sensor to Pin 13 (marked x13 or #27)

 

4. Connecting the Pan/Tilt Assembly

ultpi_12

This is now supplied fully assembled with the Initio Ultimate kit. If you have an unassembled one, then please visit the assembly instructions here (opens in new window)

Take 4 of the 2.0x6PB screws (these are the smallest ones in the packet and there are 6 of them)

ultpi_13

Screw the base of the pan/tilt assembly to the upper plate in the position shown

Rotate the pan/tilt carefully left and right to access the screw holes

step05

Connect the Pan servo (bottom servo) to Pin 22 (marked x22 or #25)

Connect the Tilt servo (upper servo) to Pin 18 (marked x18 or #24)

Note the colours of the servo wires and ensure they are connected correctly:

  • Black: Gnd
  • Red: 5V
  • Orange or White: Signal

 

5. Connecting the Ultrasonic Sensor

NOTE: More recent kits use a specially purchased ultrasonic sensor which has the connection pins at the front, instead of at the rear as shown below. If you have one of these, then simply use 2 small screws (included) to fit the sensor securely to the mounting plate. If your connection pins are at the back, please follow the instructions below. The wiring is the same in either case.

ultpi_15

For this you will need the mounting plate, saddle clamp and the final 2 of the 2.0x6PB screws used in step 4

ultpi_16

Push the 4-way 30cm female-female cable that you made in Step 3 onto the top of the ultrasonic sensor:

  • Brown: Gnd
  • Red: Echo
  • Orange: Trig or Ping
  • Yellow: 5V or VCC

ultpi_17

Screw the saddle clamp over the cable terminals as shown above

ultpi_18

Clip the whole assembly to the front of the Pan/Tilt assembly as shown above

Note that you can purchase additional clip-on mounts so you could mount a camera on one and simply clip it off to change from Ultrasonic to Camera

step06

Connect the other end of the cable into the ultrasonic pins located between the 2 motor terminals

Ensure that Brown is Gnd, and they are in the order as shown

 

The main build of your Ultimate Initio Kit for the Raspberry Pi is now complete.

 

6. Connecting the Wheel Sensors (Optional)

Note that the wheel sensors require additional code to operate properly that is not included in the python library.

It is recommended that you do not fit these until you are familiar with the operation of the rest of the robot.

If you want to fit them, use Pins 15 and 16 (marked x15, x16 or #22, #23)

For each Wheel Sensor, connect:

  • Black to Gnd
  • Red to 5V
  • Orange or Brown to the selected pin (in fact, each wheel has 2 sensors that are slightly out of phase so you can get direction of travel from them, but you will then need 2 pins for each sensor)

It is recommended to leave the wheel sensor cables unconnected to start with

RoboHAT – Robotics Controller for Raspberry Pi

Links for Various Resources for the 4tronix RoboHAT

rh09

 

See the bottom of this page for software library and downloads.

 Useful Links

Know your RoboHAT

rh12a

Clockwise from top left:

  • 2-way screw terminal for DC Motor 1 (left motor if using the Python library)
  • EEPROM containing the HAT information for the device tree
  • DRV8833 motor driver chip
  • 2-way screw terminal for DC Motor 2 (right motor)
  • 4-pin male connector for the Ultrasonic distance sensor (HC-SR04)
  • 6-pin female connector for the I2C breakout. This is the standard header used on all 4tronix controller boards
  • 4 x 3-way (GVS) inputs. These accept 3-5V input signals and are converted to the 3.3V logic required for the Raspberry Pi GPIO pins. They are labelled with both pin numbers and Broadcom GPIO numbers
  • Blue Power indicator LED
  • Jumper to select power input method for the motor driver. In most cases this should be to the left so that a single set of batteries can be used to power the Raspberry Pi and the motors. If you want a separate power supply for the motors, then move this jumper to the right and connect the separate motor power to the 2-pin screw terminal
  • 2-pin screw terminal for optional separate motor power
  • DC Jack for the main power input. This is the input from your (typically) 7.2V battery pack and is used to create the 5V for the Raspberry Pi and to drive the motors directly (if motor power jumper is to the left)
  • 6 x 3-way (GVS) outputs. These provide a 5V driven output from the Raspberry Pi GPIO pins. They are labelled with both pin numbers and Broadcom GPIO numbers

 

Pin Assignments

RoboHAT signals are mapped directly to individual GPIO pins as follows:

Description

In/Out

J5 Pin Number

Broadcom Number

1 Motor1 A

Out

36

16

2 Motor1 B

Out

35

19

3 Motor2 A

Out

33

13

4 Motor2 B

Out

32

12

5 Ultrasonic

In/Out

38

20

6 Input 0

In

7

4

7 Input 1

In

11

17

8 Input 2

In

29

5

9 Input 3

In

13

27

10 Input 4

In

15

22

11 Input 5

In

16

23

12 Output 0

Out

18

24

13 Output 1

Out

22

25

14 Output 2

Out

12

18

15 Output 3

Out

31

6

 

Python Software

To download the library and example programs from the internet, you can use the following commands from your Raspberry Pi in the home folder. (open LXTerminal from desktop):

  • wget http://4tronix.co.uk/robohat.sh -O robohat.sh
  • bash robohat.sh

 

Files included

  • robohat.py This is the python library module, see the first few lines of the library for listing of all the exposed functions for controlling motors, LEDs and reading sensors
  • motorTest.py – cycles through various motor directions
  • motorTest2.py – use the arrow keys on your keyboard to control the direction and speed of the motors
  • motorTestRaw.py – cycles through various motors, but doesn’t use the library
  • irTest.py – check the state of the IR line and obstacle sensors sensors (assumes you have the sensors connected as shown in the Initio build instructions)
  • sonarTest.py – prints the distance using the UltraSonic sensor
  • servo.py – a very simple servo test using the RPI.GPIO PWM commands
  • servoTest.py – a more sophisticated test that uses ServoBlaster (servod) to create the timing pulses

PZM – Pi Zero Motor Shim

Add Motors to (Almost) Any Pi Zero Project

2016-01-22_0008a

Purchase here

This tiny little board (38 x 16mm) can be added to a Raspberry Pi Zero (or any other Pi for that matter) to provide dual H-Bridge control of 2 DC motors.

It is so thin (0.8mm) that it can be soldered onto the bottom of the connector (assuming you have added one to your Pi Zero), or you can solder on the female or male headers included in the kit so you can connect and remove it, however you have configured your Pi Zero.

2016-01-22_0007a

Above shows the PZM with a female header added so it can be plugged onto a “normal” male header as shown below, Note how the PZM sticks out from the Pi, so other boards can still be mounted as usual

2016-01-22_0002

 

Alternatively, you can mount it by soldering it directly to the bottom of the header, thus leaving the header free to attach other boards as shown below:

2016-01-22_0013a

2016-01-22_0012a

 

Contents

So what do you get in the package?

  • Ready assembled PZM shim
  • 3 x screw terminals
  • 3×2 Male header
  • 3×2 Female header

pzm_kit01

 

Programming?

This is a 4 pin driven, dual H Bridge. 2 pins control Motor A and 2 pins control Motor B

  • Motor A is physical pins 35 and 36 (Broadcom GPIO 16 and 19)
  • Motor B is physical pins 37 and 38 (Broadcom GPIO 26 and 20)
  • For each motor:
    • One pin High and the other Low for Forward
    • One pin Low and the other High for Reverse
    • Both pins Low will stop driving the motor and allow it to slowly coast to a halt
    • Both pins High will brake the motor and bring it to a halt very quickly
  • The pzm.py library module provides basic functions for forward, reverse, spin left, spin right, turn left/right forward, turn left/right reverse

 

Downloads:

From a terminal window on your Pi type the following lines exactly:
$ wget http://4tronix.co.uk/pzm.sh -O pzm.sh
$ bash pzm.sh

This will have created a pzm folder in your home directory, with the following files:

  • pzm.py python library
  • pzmTest01.py shows use of the motors without using the library
  • pzmTest02.py shows the motors moving in the same way as pzmTest01 but using the library (much simpler program)
  • pzmTest03.py allows the use of arrow keys (and , and . to change speed) to control the motor directions

 

Wiring?

  • Put power 3V to 11V on the terminal marked VIN and GND. If you are using low power motors you can use the 5V from the Pi (note this isn’t connected to the PZM board)
  • Reverse polarity protection is provided so you won’t break it by putting them on the wrong way round, but it won’t work until you get it right!
  • Connect one motor to Motor A and the other to Motor B
  • Done!

 

 

Assembling Pi2Go

Assembling Pi2Go

pi2go_01a

Pi2Go is the pre-soldered big brother of the popular Pi2Go-Lite kit. Assembly is simply a matter of screwing together and plugging connectors.

Overview of Steps

  1. Fit the front caster and line following assembly
  2. Fit the mounting pillars for your chosen Raspberry Pi
  3. Attach the motors
  4. Fit the Raspberry Pi
  5. Fit the battery box

 

Step 1 – Fit the Front Caster and Line Follower Assembly

Step01

You will need the M3 screws, 27mm pillars, ball caster and 9-way extended header and the line follower PCBA

Step02

Fit the 2 pillars to the front of the Pi2Go using 2 of the M3 screws

Step03

Carefully push in the 9-way header, then attach the line follower PCBA

<photo missing>

Use the remaining 2 screws to attach the ball caster. If there is a bit of slack in its position, ensure that it doesn’t touch the pins of the connector

 

Step 2 – Fit the Mounting Pillars for Raspberry Pi

For the older Raspberry Pi models with a 26-pin GPIO connector, you will need to fit 2 pillars. For the A+, B+ and RPi 2B you should fit 4 pillars

Step04

Fitting the pillars is a 2 step process: 1) fit the small 5mm pillars, 2) screw in the 16mm pillars.

Step05

The photo above shows the 5mm pillars in the mounting positions for A+, B+ and RPi 2B models

Use the very small 4mm screws to attach all the pillars. Note that the holes under the motors have been countersunk to allow the motors to sit flat onto the PCBA

Step06

The photo above shows the 16mm pillars added for the correct height (A+, B+, RPi 2B)

Step06a

The photo above shows the 2 pillars in place ready for the Model A or Model B

 

Step 3 – Attach the Motors

Step07

For this you will need 25mm screws, nuts and the motor mounts

Step08

Push the screws through the outer motor mount, then the motor, then the inner motor mount and attach to the nuts

Step09

 

Step 4 – Fit the Raspberry Pi

Step10

Using the extended header (in the bag with the battery box), connect the Pi onto the Pi2Go PCBA.

NB. Ensure that the mounting holes line up with the pillars! If they don’t then the Pi is not fitted correctly and may be damaged.

The above photo shows the RPi 2B in place. The A+ and B+ fit the same way.

Step10a

This photo (above) shows a Model B

 

Step 5 – Fit the Battery Holder

Step11

Use the 5mm pillars to attach the Raspberry Pi firmly to the mounting pillars. Use 2 or 4 pillars depending on your model of Pi (RPi 2B shown above)

For the Model A and Model B, you can now screw the battery holder directly to the 2 supporting 5mm pillars

Step12

For the A+, B+ and RPi 2B you will need to fix the support plates in place first

Step13

Ensure the one at the front has the threaded insert on the left of the Pi2Go and the one at the rear on the right. Also ensure that the wide parts of the mounting holes are at the top so that they can accept the heads of the screws.

Step15

Finally, screw in the battery holder using 2 of the very small 4mm screws

pi2go_01a

Now you can add batteries, software and enjoy!

iBoost64 – What is It?

iBoost64 Overview

iBoost64 is a little board to boost input signals and electrically clean them up. It is designed solely for use with the Pirocon2

Pirocon2 has 8 bi-directional pins that determine the direction (input or output) using the strength of the drive signal applied to them. We have found that some sensors have insufficient drive strength to reliably convince the level shifters that they should behave as inputs. This has the effect of appearing to randomly react to or ignore inputs – especially with marginal sensors.

This little board can be plugged onto the pins of the Pirocon that you want to use as inputs only. With the board in place, the selected signals are always inputs and cannot be outputs.

Because the power and ground pins go all the way across the 8×3 connector on the Pirocon, you can plug the iBoost64 into any position even with only 1 set of three pins (although it wouldn’t be very stable like that)

The iBoost64 has 6 inputs which can either be high or low (hence the 64 because 2^6 is 64)

  • 6 non-inverting schmitt trigger inputs
  • high hysteresis so slow moving signals produce a nice clean edge for the Pi
  • Enables weak sensor outputs to drive the Pirocon directly
  • Wheel sensors on Initio can be driven with 5V as intended and plugged directly into the iBoost64

Assembling Ultimate Initio Kit for Raspberry Pi with Pirocon

Ultimate Initio kit for Raspberry Pi

ultpi_01b

You should already have followed the instructions for assembling the chassis here.

In this section we will add the Pirocon2 controller, the obstacle sensors, line sensors and the pan/tilt assembly with ultrasonic sensor.

The (optional) iBoost64 is also used to boost incoming signal strength and resolve issues with marginal IR sensors, including the wheel sensors on the Initio

 

Quickstart Pinout Description

If you use the recommended iBoost64 input signal booster, then we can connect the 8 I/O signals as follows:

  • Pin 7 – Left Obstacle sensor
  • Pin 11 – Right Obstacle sensor
  • Pin12 – Left Line sensor
  • Pin 13 – Right Line sensor
  • Pin 15 – Left Wheel sensor 1 (Optional)
  • Pin 16 – Right Wheel sensor 1 (Optional)
  • Pin 18 – Tilt Servo (Output – not connected to iBoost64)
  • Pin 22 – Pan Servo (Output – not connected to iBoost64)

 

1. Fitting the Pirocon to the Raspberry Pi

ultpi_20

Screw the support pillar to the underneath of the Pirocon. The position shown above is suitable for a Raspberry Pi Model B+, Model A+ or Raspberry Pi 2 Model B

Use the hole in the centre if using a Model A or Model B

ultpi_21

Push the Pirocon carefully onto the GPIO pins of the Raspberry Pi, ensuring the pins are placed correctly as shown in the photo above

ultpi_22

Connect the motor wires as shown. Red – Black – Black – Red

It won’t damage it if you connect them differently, but the example programs won’t go the direction that you would expect

ultpi_23

Plug the Black/White cable with the DC Jack into the left-most pins on the switch PCB on Initio and the DC Jack end into the Pirocon as shown above.

Check all the wiring again very carefully, then now is a good time to see if the Pi powers up and you can control the motors.

Use 6xAA batteries. These should be good quality rechargeable batteries. We recommend Energizer Extremes or Eneloops

Connect a monitor, keyboard and mouse to the Raspberry Pi, plug in your SD card and switch on. The green light near the On/Off switch should turn on, the LEDs on the Pi should start flashing and the booting sequence should appear on the monitor. If not, switch off and double check the wiring.

Instead of using the batteries, you can plug a micro-USB cable directly into the connector on the Pi. This is an excellent way to get started and allows you to test everything (except the motors, which may turn but only slowly) without using batteries.

 

2. Mounting Obstacle Sensors

ultpi_02

Check that each sensor has 2 mounting collars. Screw one onto the body of the sensor, leaving room at the front for the second one

ultpi_03

Push the sensor through from the rear of the mounting bracket and screw on the second collar. Feed the wires up through the holes in the top plate

ultpi_04

Repeat for the second side

ultpi_05

Connect to the Pirocon2 (or the iBoost64 as below)

  • Left sensor to Pin 7 (marked x07 or #04)
  • Right sensor to Pin 11 (marked x11 or #17)

The wire colours from the obstacle sensor are:

  • Red:  5V
  • Black:  Gnd
  • White or Yellow: Signal

Make sure you connect them to the correct pins on the Pirocon or iBoost64

ultpi_06

 

3. Mounting the Line Sensors

ultpi_07

First, take the 30cm female-female jumper strip of 10 wires and split it into three strips:

  • Brown, Red, Orange, Yellow (this is for the Ultrasonic Sensor)
  • Green, Blue, Purple (this is for the Left Line Sensor)
  • Grey, White, Black (this is for the Right Line Sensor)

ultpi_08

Next, prepare the two Line Sensors and 2 of the 3x8PB screws as shown

ultpi_09

Screw the line sensors in position as shown, using the screwhole in the middle of the circuit board

ultpi_10

Connect the Green, Blue, Purple wire to the Left Sensor and the Grey, White, Black cable to the Right Sensor

** Note some sensors have the pins in order 5V, Signal, Gnd; other have them in order Signal, 5V, Gnd – make sure you know which wire colour is connected to which.

ultpi_11

Connect the sensors to the Pirocon or iBoost64 (shown below)

  • Left sensor to Pin 12 (marked x12 or #18)
  • Right sensor to Pin 13 (marked x13 or #27)

ultpi_06

 

4. Connecting the Pan/Tilt Assembly

ultpi_12

This is now supplied fully assembled with the Initio Ultimate kit. If you have an unassembled one, then please visit the assembly instructions here (opens in new window)

Take 4 of the 2.0x6PB screws (these are the smallest ones in the packet and there are 6 of them)

ultpi_13

Screw the base of the pan/tilt assembly to the upper plate in the position shown

Rotate the pan/tilt carefully left and right to access the screw holes

ultpi_14

Connect the Pan servo (bottom servo) to Pin 22 (marked x22 or #25)

Connect the Tilt servo (upper servo) to Pin 18 (marked x18 or #24)

Note the colours of the servo wires and ensure they are connected correctly:

  • Black: Gnd
  • Red: 5V
  • Orange or White: Signal

 

5. Connecting the Ultrasonic Sensor

ultpi_15

For this you will need the mounting plate, saddle clamp and the final 2 of the 2.0x6PB screws used in step 4

ultpi_16

Push the 4-way 30cm female-female cable that you made in Step 3 onto the top of the ultrasonic sensor:

  • Brown: Gnd
  • Red: Echo
  • Orange: Trig or Ping
  • Yellow: 5V or VCC

ultpi_17

Screw the saddle clamp over the cable terminals as shown above

ultpi_18

Clip the whole assembly to the front of the Pan/Tilt assembly as shown above

Note that you can purchase additional clip-on mounts so you could mount a camera on one and simply clip it off to change from Ultrasonic to Camera

ultpi_19

Connect the other end of the cable into the ultrasonic pins located between the 2 motor terminals

Ensure that Brown is Gnd, and they are in the order as shown

 

The main build of your Ultimate Initio Kit for the Raspberry Pi is now complete.

 

6. Connecting the Wheel Sensors (Optional)

Note that the wheel sensors require additional code to operate properly that is not included in the python library.

It is recommended that you do not fit these until you are familiar with the operation of the rest of the robot.

If you want to fit them, use Pins 15 and 16 (marked x15, x16 or #22, #23 and note that the silk screen on the board has these swapped over)

For each Wheel Sensor, connect:

  • Black to Gnd
  • Red to 5V
  • Orange or Brown to the selected pin (in fact, each wheel has 2 sensors that are slightly out of phase so you can get direction of travel from them, but you will then need 2 pins for each sensor)

It is recommended to leave the wheel sensor cables unconnected to start with