After working on version 2 LINK, it became apparent that implementing some of the real-time elements on the microBit in micro-python was a little tricky. This was further complicated owing to restrictions of what I/O lines could be used e.g. some pins are already used to drive LEDs etc. Therefore, decided to move this functionality into separate hardware, freeing the microBit to implement the top level control software / functionality.
Version 3.0 : BBC Micro:Bit + dedicated hardware
Version 3.1 : BBC Micro:Bit + Arduino prototype
Version 3.2 : Base PCB
Version 3.2 : Chassis
The first problem encountered in Roach v1 and v2 was the lack of fine grain speed control, could of used the analogue output lines on the microbit i.e. PWM, but this then removes two analog I/O lines from the limited pool, some of which are hard-coded into he python libraries e.g. audio output. Therefore, to decouple the microBit from these tasks moved this functionality into dedicated hardware, communication between the microBit and this hardware was implemented using the I2C two wire serial bus. After a little thought came up with a general purpose expansion card containing:
All of these devices are controlled using the I2C bus. The PWM controller is implemented using a PCA9685, a 16-channel, 12-bit PWM controller PCA9685.pdf. Originally designed to control the brightness of LED panels, so there are some restrictions on how these outputs are controlled and frequencies used, but can be used to generate D.C. motor speed and servo motor control signals. Motor drivers are based on a standard H-bridge driver, BD6230 BD622XXX.pdf, controlled using an I2C GPIO expander PCF8574 PCF8574.pdf and the PWM generator. Analogue inputs are connect to two PCF8591 PCF8591.pdf ADCs. Power supplies are implemented using switch mode modules Recom-78XX-regs Recom-78XX-regs.pdf. These are pin compatible replacement for the more traditional 7805 linear regulators, having the advantage of being 90% efficient converting the 7.2V battery pack voltage down to 3.3V and 5V.
The schematic for this circuit is shown in figure 1 (pdf version:interface_board.pdf) and its PCB layout in figure 2.
Figure 1 : Interface board schematic v1
Figure 2 : Interface board PCB layout v1
Went for a mix of surface-mount and pin-through board, prototype PCB made in house as shown in figure 3, unfortunately an untested assumption about the driver ICs came back to bite me, as illustrated by the green wires and the addition 7408 AND gate. Thought the motor driver had an enable input for the PWM speed control, but turned out it didn't work the way i thought, solution was to gate the direction control signal with the PWM signal. Also got the regulator footprint back to front. Apart from those two 'small' mistakes all worked. However, when i was correcting these errors, decided that this functionality (and more) could actually be implemented in an Arduino. This would be a lot cheaper, result in a simpler PCB and allow a greater degree of freedom / flexibility in later designs i.e. an additional software layer.
Figure 3 : Improved PCB (can you spot the mistakes)
Had played around with an Arduino Uno in the past, but had not really done anything too complex. Looking around there is a range of compatible devices, in the end decide upon the Arduino Nano, shown in figure 4, smaller footprint, good number of I/O lines and functional units, and could be programmed using USB or ICSP.
Figure 4 : Arduino Nano
To see if the Arduino could implement the real-time functions needed constructed a prototype using a Raspberry Pi (Rpi) and Arduino Uno, as i already had these parts to hand (development speed) i.e. could write the I2C python code on the Pi and program the Arduino using the avrdude commandline tools. Will move to microbit and arduino nano for final design. The chassis for this prototype was just what i had spare (an old ScratchPi robot), shown in figure 5. The really nice thing about the Rpi is that it can program the Uno using GPIO lines over the ICSP i.e. you only need to SSH into the Rpi to do all your programming and downloads.
Figure 5 : Prototype system
The aim is to use the Arduino as a low level controller (interfacing/control all sensors and actuators), Rpi (or microbit) communicates to the Uno using the I2C bus i.e. writes commands (move etc), reads status (distance sensor). I like this separation as the top level device (Rpi/Mbit) does not need to worry about resources or timing etc. Down side is speed, not as fast as the dedicated hardware implementation, but for the target user i don't see this as a problem. At the moment the prototype system has:
The Arduino acts as an I2C slave, Mbit/Rpi sends command across this 2 wire bus:
An advantage of this system is that if you need more motor controllers / sensors etc, you can double up on this PCB i.e. give each Arduino board a different I2C slave address.
Prototype worked, but as figure 5 shows, a bit of a balancing act. The new base board: interface_board_v2, uses the same voltage regulators, but moves the PWM, GPIO and ADC functionality into the Arduino. Additional functionality has also been added to support a wider range of topics and exercises. The first of these are wheel encoders, primarily aimed at measuring distance travelled, but could also be used as feedback for speed control, very low resolution, only 15 pulses per revolution. 3D printed in white plastic (encoder.stl). These sensors use an infra-red LED and photo-transistor module (OPB608: IR_TX_RX_Module.pdf), detecting changes in reflected light from the drive wheel encoder disk, as shown in figure 6. These fluctuations can be quite small, shown in figure 7, also looks like either the wheel is not square or picking up some mains hmm. Therefore, to convert this analogue signal in a digit representation a comparator circuit is used, its output is passed through two Schmitt-triggers and a low pass filter to remove any noise, as these signals will be used to drive the external IRQ pin on the Arduino.
Figure 6 : wheel encoder disk
Figure 7 : Sensor signal
Figure 8 : comparator + filter circuit
Battery low level detection is implemented using another comparator circuit, its input signal sourced from a potential divider connected across the battery pack. This output is used to drive a LED and can be read by the microBit via an I2C GPIO expander. There is also a spare comparator on connector X8, this input can be accessed using the GPIO expander (intention was to use this for a rear analogue distance sensor). The remaining six I/O lines are used to read the bumper switches, connector X3. Line following sensors (same sensor as wheel encoders), light sensors (LDR) and the infra-red distance sensor (GP2Y0A21YK: GP2Y0A21YK.pdf) all connect directly to the Arduino's ADC inputs, connectors X9, X12, X13, X17 and X18.
Figure 9 : battery level detector
Figure 10 : I2C GPIO expander + interface connectors
Connector X15 can be used as either a RS232 serial port, or for an ultrasonic distance sensor. Lastly connector X16 is the servo motor connector, the servo supply voltage can be selected using jumper J1 i.e. either +5V from the regulator or the input battery voltage. The full schematic and PCB layouts are show in figures 11 & 12
Figure 11 : interface_board_v2 schematic
Figure 12 : Interface board PCB layout v2
The chassis for the new PCB shown in figure 12 is based on a simple skeleton of 3D printed elements, shown in figure 13 (grey rectangle is the interface PCB). For this particular implementation decided to use a 7.2V battery pack i.e. 6 x AA, this does increase the robot's weight, but removes the need for a boost converter. However, as the boost converter board used in version 2 of this is robot quite small, could replace this with a 4 x AA box and still have room under the robot for the converter PCB. The robot uses a 'tricycle' style wheel configuration, using a ping-pong ball as the front caster wheel i.e. rear differential drive. This keeps the weight/centre of gravity over the drive wheels and allows space for line following sensor array at the front of the robot.
Figure 13 : 3D model (green=motor, red=battery box, blue= servo, grey=interface pcb, yellow=microbit)
Figure 14 : chassis
Been a little while, but finished the initial prototype as shown in figure 15, went for a Pi zero W for initial testing, also allows me to easily add a camera and control the robot using an old PS3 controller over Bluetooth (and stream the video back a PC). The only negative is that the weight of the batteries does cause the ping-pong ball to move a little in its enclosure, this needs to be re-enforced.
Figure 15 : chassis
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
Contact details: email - firstname.lastname@example.org, telephone - 01904 32(5473)Back