I recently gave a talk at my local .Net user group, Dot Net Notts, on Dot Net IoT Core. I ended my talk by demonstrating the 4tronix Pi2Go Robot, which I had modified for Dot Net IoT Core. I’ll go over the basics of Dot Net IoT Core, and explain what I needed to do in order to get the Pi2Go robot working with a Raspberry Pi Running Windows 10 IoT Core.
A Brief Introduction:
The Internet of things is a buzzword which has been difficult to escape in the last couple of years, and one of the names most likely to be associated with this is the £30 Raspberry Pi.
This little bundle of joy has flown off the shelves since it’s first version was released, to much acclaim, in early 2012. Now on it’s sixth version; A, A+, B, B+, Compute, the Raspberry Pi 2 packs a Quad Core Broadcom Processor and 1Gb of Ram squeezed onto a PCB not much bigger than a credit card.
Windows 10 Core:
With this step in processing power and memory came the ability for the Pi to become a far more capable device, and as a result Microsoft sat up and took notice. With its push to a unified Windows 10 platform, Microsoft created a specially slimmed build of Windows 10 named Windows 10 IoT Core. This version doesn’t have the usual Windows 10 Shell for example, where the deployed application’s UI becomes the Shell.
Dot Net Core and IoT Core:
Windows 10 IoT Core allows Microsoft Stack developers to use there existing skills to develop and deploy applications using Visual Studio 2015. IoT Core uses as its base underpinning, Microsoft’s Dot Net Framework for the Universal Windows Platform – Dot Net Core.
Dot Net Core is an open source project, available on GitHub, which was driven in part by the Cross Platform ASP.Net 5 Project. The aim being, to allow ASP.Net to run on as many environments as possible, including, Windows, Linux, Mac etc.
Apps which run on the Raspberry Pi are essentially UWP applications, however in order to use the extra capabilities of the device, a set of IoT extension APIs are added on top, creating Dot Net IoT Core.
Once these extensions have been added, the various peripheral devices on board the Raspberry Pi can then be accessed, such as GPIO, SPI, I2C, etc.
The 4tronix Pi2Go Robot:
The 4tronix Pi2Go Robot is a nifty piece of kit with a bunch of features, including;
- Two Wheel Drive system.
- Sonic Range Sensor,
- Front Left and Right IR Sensors,
- Line Sensors,
- Wheel Tacho Sensors,
- Battery Power Pack
It is designed for the Raspberry Pi, and can accommodate everything from a Raspberry Pi A+ up to the Pi 2 B+.
Windows IoT Core and the Raspberry Pi 2 GPIO:
The Raspberry Pi 2 B+ has a 40 Pin GPIO header on-board for connecting various peripherals to. Each Pin and it’s primary function is shown above, where the standard GPIO pin’s are shown in Orange. Most of the GPIO Pins on the Raspberry Pi, are dual function, however the current version of Windows 10 IoT core is rather strict with the pin functions of the Raspberry Pi, not allowing pin functions to be re-designated from say, SPIO to GPIO.
The Hardware and Rewiring the Pi2Go Robot:
As a result of the strict Pin Assignments, it was necessary to rewire the interface between the Pi2Go robot and the Raspberry Pi. For this I used a 40 pin to 40 pin Male to Female Ribbon cable. The wiring schema I used is shown below. I’ve highlighted in green, the pins which have been rerouted.
New Connection Schema
Raspberry Pi 2 Pin No |
IoT Core Function |
Connected to Pi2Go Pin No |
Original Pi 2 Function(s) |
Pi2Go Function |
1 |
3v3 Power |
1 |
3v3 Power |
3v3 Power |
2 |
5v Power |
2 |
5v Power |
5v Power |
3 |
I2C1 SDA |
3 |
GPIO 2 / |
None |
4 |
5v Power |
4 |
5v Power |
5v Power |
5 |
I2C1 SCL |
5 |
GPIO 3 / |
None |
6 |
Ground |
6 |
Ground |
Ground |
7 |
GPIO 4 |
7 |
GPIO 4 |
IR Front Left |
8 |
Reserved |
x |
GPIO 14 / |
(Sonar Trigger) |
9 |
Ground |
9 |
Ground |
Ground |
10 |
Reserved |
x |
GPIO 15 / |
None |
11 |
SPI1 CS0 |
x |
GPIO 17 / |
(IR Front Right) |
12 |
GPIO 18 |
12 |
GPIO 18 |
Line Left |
13 |
GPIO 27 |
13 |
GPIO 27 |
Line Right |
14 |
Ground |
14 |
Ground |
Ground |
15 |
GPIO 22 |
15 |
GPIO 22 |
Front LED |
16 |
GPIO 23 |
16 |
GPIO 23 |
Rear LED |
17 |
3v3 Power |
17 |
3v3 Power |
3v3 Power |
18 |
GPIO 24 |
8 |
Reserved |
Sonar Trigger |
19 |
SPI0 MOSI |
x |
x |
(Motor R1) |
20 |
Ground |
20 |
Ground |
Ground |
21 |
SPI0 MISO |
x |
x |
(Motor R2) |
22 |
GPIO 25 |
11 |
SPI1 CS0 |
IR Front Right |
23 |
SPI0 SCLK |
x |
x |
(Left Switch) |
24 |
SPI0 CS0 |
x |
x |
(Motor L2) |
25 |
Ground |
25 |
Ground |
Ground |
26 |
SPI CS1 |
x |
x |
(Motor L1) |
27 |
Reserved |
27 |
Reserved |
None |
28 |
Reserved |
28 |
Reserved |
None |
29 |
GPIO 5 |
21 |
SPI0 MISO |
Motor R2 |
30 |
Ground |
30 |
Ground |
Ground |
31 |
GPIO 6 |
19 |
SPI0 MOSI |
Motor R1 |
32 |
GPIO 12 |
24 |
SPI0 CS0 |
Motor L2 |
33 |
GPIO 13 |
* |
* |
*Sonar Echo |
34 |
Ground |
34 |
Ground |
Ground |
35 |
SPI1 MISO |
35 |
35 |
None |
36 |
GPIO 16 |
26 |
SPI0 CS1 |
Motor L1 |
37 |
GPIO 26 |
23 |
SPI0 SCLK |
Left Switch |
38 |
SPI1 MOSI |
38 |
SPI1 MOSI |
None |
39 |
Ground |
39 |
Ground |
Ground |
40 |
SPI1 SCLK |
40 |
SPI1 SCLK |
None |
For reference, the Pi2Go Robot Schematic can be found here.
Using the 40 pin ribbon cable however meant that the Pi no longer fitting to the Pi2Go main board using the standard fixings, as there wasn’t enough space between the two boards, so I added 8 Metric Hex Spacers so that I could space the two boards far enough apart.
Basic Motor Control Theory:
The Pi2Go uses the ST Electronics L293DD as the basis of the motor control. This chip, on a basic level, takes 4 digital inputs and drives the high load Motors.
With the Motors connected between the two sets of outputs, the Raspberry Pi GPIO pins are connected to the 4 inputs. The directionality is controlled by setting one or other of the two corresponding Inputs High, with the Other input Low. Swapping the High and Low will reverse the direction of the Motor. Obviously setting both high or both low will result in no movement at all.
The HC-SR04 Range Sensor:
The HC-SR04 Range Sensor is device which generates a sequence of ultrasonic pulses and “listens” for an echo off a solid object, generating an output pulse relative to the reflected objects distance from the sensor. The ranging is triggered by a short 10us minimum TTL pulse on the “Trig” pin. The HC-SR04 will then send the Ultrasonic Pulses, and if an object is within range, a short TTL pulse will be generated on the Echo Pin;
I needed to take a separate feed for the Sonar Echo Pin, as indicated by the stars in the Connection Schema Table above, this was mainly to make the coding slightly easier from a timing perspective.
As I interfaced directly to the Echo Pin, I needed to add a potential divider to reduce the 5v to a Raspberry Pi tolerant 3v3, as shown in the image above. I’ve used 470 and 330 Ohms, which should give a high voltage of around of around 3v, which the Pi will easily recognise as high.
In the next part, I’ll run through how the code works!
Leave A Comment
You must be logged in to post a comment.