This tutorial was extracted from Erich Styger blog http://mcuoneclipse.wordpress.com with his agreement.
With the Zumo I have a base platform for cool robotics applications. So why not build a line following robot with this? Especially as Pololu offers a reflectance sensor array for it. The result is: I have a line following robot
It turned out that things were not working out of the box with the FRDM-KL25ZFRDM-KL25Z board. So if you want to do the same thing, here are some tips how to make it working with the Freedom board.
5V Power for the Shield
The Freedom board does not generate 5V from the V_IN (Battery) supply voltage. The Zumo Arduino shield expects the 5V generated from the Arduino microcontroller board. To overcome this limitation, I’m using a tiny S7V7F5 DC-DC step up/down voltage converter which generates 5V from 2.7..11.8V. I have it soldered on a 3 pin header and placed it on the Zumo shield:
On the backside, I have the DC-DC converter connected to GND and V_IN on the shield headers, and wired the 5V output to the 5V pin:
Reflectance Sensor Array Supply
The Reflectance Sensor Array is using 5V logic levels by default, as designed to work with 5V Arduino (or compatible) boards. While that works with 5V tolerant input pins, it is not ideal from a timing perspective to use it with 3.3V logic levels (charging and discharging the sensor capacitors). So I changed the supply voltage to 3.3V which is the logic level for the Freedom board. Unfortunately the sensor array connector does not offer a 3.3V option, so I have cut the 5V pin and wired it to the 3.3V on the shield:
Pololu offers another sensor array which is designed for both 3.3V and 5V which could be used with the Zumo.
The other issue with the original Pololu sensor module is that the leftmost sensor is connected to the Arduino shield data 4 (D4) pin. Unfortunately this pin is connected to the NMI (Non-Maskable Interrrupt) of the Kinetis Cortex-M4 on the Freedom Board. That way it happens that it creates an NMI interrupt.
It is possible to disable the NMI functionality of that pin for the KL25Z. However, depending on the sensor state during startup/power-on of the microcontroller, this still very likely will raise an NMI, especially right after flashing/debugging the device. The problem can be avoided if debugging is done without powering the sensor array. That means that the battery supply voltage needs to be switched off during flashing and startup of the microcontroller. This worked for me, but was painful after a while.
The solution is to re-route the D4 sensor to another pin. For this a trace on the sensor board needs to be cut, and rerouted to another pin. I used A0 as this pin is available on the connector and I have not used it otherwise:
Software
The software is written with the help of Processor Expert components. It runs FreeRTOS as operating system:
It features a command line (shell) interface using the OpenSDA USB CDC connection:
The shell commands are manually control the motors, perform calibration of the sensors or inspect the state of the system:
ZumoBot in Action
The following video shows the ZumoBot following a line. After power-up, the sensors get calibrated with moving the sensors over the line, while the sounder is on. Another press of the button runs the line following (PD control loop) algorithm. If the robot does not detect a line any more, it stops:
The current software was attached to this document but I would recommend to download the updated version on GitHub with all the Processor Expert components.