Using Dyalog APL and a Raspberry Pi to drive a robot – Part 1 (hardware)

Over the past few weeks at work, We have been working with Quick2Wire to build a robot that can be driven from Dyalog APL on a Raspberry Pi. The robot will contain a Raspberry Pi; either a model A or model B will work. We are using a model B as we have them around the office.

You can see the robot in action on the Dyalog CTO blog here: http://cto.dyalog.com/2013/04/apl-coming-to-a-robot-near-you/

The Raspberry Pi will be running Raspbian with Dyalog APL 13.2 which will be talking to an Arduino using I2C which will then talk to a motor controller. In this case we are using a L298n motor controller and an Arduino 328 Pro Mini (5v/16Mhz).

Pictures of the Arduino and motor controller are below.

Motor Controller Board

L298n motor controller

Arduino Pro Mini

Arduino Pro Mini

After soldering programming pins to the Arduino, we used an Arduino Uno without a CPU to program the Arduino Pro Mini. To do this you simple wire TX to TX, RX to RX, 5V to 5V, GND to GND and RST to RST (reset), This allows programming of the Arduino Pro Mini without the need for an FTDI cable as we already had an Arduino Uno for prototyping. For simplicity, the Arduino Pro Mini was plugged into a breadboard as there were 4 of them to be programmed.

Programming Arduino

Programming Arduino

Once the Arduino Pro Mini is programmed, the next task is to solder on the wires for power, communicating to the Raspberry Pi and communication to the motor controller. You could choose to use pin headers on the Arduino to plug devices into, I have chosen in this case to solder the wires directly to the Arduino.

Arduino Pro Mini ready to go

Arduino Pro Mini ready to go

From here you should be able to plug the boards together and you’re almost ready to go. Here is our first built up robot.

DyaBot

DyaBot

As you’re able to see here, the Pi has Wifi and we have modified a USB-mini cable to plug into the 5v regulated feed on the motor controller. This had some issues as it turns out the 5v regulator on the motor controller has a 2v drop at around 250mA and the Pi then reboots as the Pi requires around 500mA minimal with 700mA recommended (for non-overclocked Pis). I will address this later in this document.

Here is the wiring diagram for the Arduino.

Arduino Wiring

Arduino Wiring

The 6-pin header will connect to your motor controller, the 2 pin (blue/green) will connect to your Pi, there are 2 wires to connect to the +5v voltage regulator and to the common ground.

Below you can see the same layout with a cut of the Raspberry Pi pins to connect between the Arduino and Raspberry Pi.

Arduino & Raspberry Pi

Arduino & Raspberry Pi

The pins on the Raspberry Pi here are labelled to make life slightly easier.

Due to the voltage regulator on the motor controller board not being powerful enough to power the Raspberry Pi, I am currently using a 5v/3A BEC (Battery Eliminator Circuit). This is simply a 5v power regulator which has been plugged into pins 2 (+5v) and 6 (GND) of the Raspberry Pi. There is also a common ground wired from pin 14 on the Pi. Even with the BEC I am still running the Arduino from the 5v regulator on the motor controller.

Here you can see a top view of the working robot.

DyaBot ready to run

DyaBot ready to run

On the left is the Raspberry Pi, the small board next to the Pi is the Arduino, the red board next to this is our motor controller and above this is the BEC. The thick wires from the motor controller connect to our battery.

Here are the Pin connections to get the robot ready to go.

Raspberry Pi:

Pin 2 – +5v Regulated
Pin 3 – Pin A4 on Arduino
Pin 5 – Pin A5 on Arduino
Pin 6 – GND (common)
Pin 14 – GND (common)

Arduino:

Pin A4 – Pin 3 on Raspberry Pi
Pin A5 – Pin 5 on Raspberry Pi
Pin 3 – IN4 (motor controller)
Pin 4 – IN3 (motor controller)
Pin 5 – ENB (motor controller)
Pin 7 – IN2 (motor controller)
Pin 8 – IN1 (motor controller)
Pin 9 – ENA (motor controller)
VCC – +5v Regulated
GND – GND (common)
Motor Controller:
VMS – Battery input (also connected to VCC on BEC)
GND – GND (common – also connected to battery GND)
5v – N/A

There are also 2 motor connections on the motor controller, you may have to play with the direction of the wires to your motors to have the robot respond correctly and head in the correct direction.

I am currently using an 11.1v 3-cell Li-Po pack, although this is far more power than it requires it does allow me to have the robot running for most of a day without issues. If you chose to run a Li-Po pack, Please be aware of how these packs operate, if mistreated they can expand, catch fire or explode. The safest way to use these packs is a good balance charger and a low voltage warning on the battery balance leads. This will ensure the battery does not get too low.

Quick2Wire are currently working on a new motor controller that will have a higher powered 5v regulator integrated. This will mean we no longer have to use a separate 5v regulator to power the Raspberry Pi.

If you use a different motor controller than the one we are using you will have to check that the connections are correct from the Arduino.

In Part 2 we will go over some of the APL Code, and changes we had to make in order to talk to the I2C bus on the Pi.

Parts used:

Robot Chassis
Motor Controller
Arduino Pro Mini
BEC
Raspberry Pi

Resources:

http://www.raspberrypi.org
http://quick2wire.com/
http://www.arduino.cc/en/Main/ArduinoBoardProMini
http://www.andremiller.net/content/raspberry-pi-pinout-diagram

2 thoughts on “Using Dyalog APL and a Raspberry Pi to drive a robot – Part 1 (hardware)

Comments are closed.