Introduction: Autonomous Agri-Robot Control System

Having robots on farms could negate the need for pesticides, chemicals and destruction of soil structure, giving us hope for the future of our planet. The machines need to be fully autonomous and features in the control system should include:

1. High accuracy, error correcting GPS/GNSS

2. Super fast multi-core micro processor for controlling multiple electric motors

3. Cellular 2G/3G/4G data comms where WIFI is not practical

4. Object recognition and positioning for distinguishing plants from soil

5. Digital compass

6. Screens, buzzers and LEDs for status report / debugging

7. LIDAR / ultra sonic sensors for detecting unexpected objects in pathway

8. Text to Voice and speakers for interaction with humans

The system so far has 3 Arduinos and one TC275 all linked on one I2C bus. At present, the system will concentrate on one easy task - weed prevention, which requires the task of distinguishing crop from soil with a Pixy CMU5 camera module.

Step 1: 3 Core Processor

A lot of this project revolves around the use of a very fast 3 core processor, the TC275. This is the gadget that holds the world record (16 Mar 2018) for solving the Rubik's cube in something like 0.3 seconds.
Firstly, each core can communicate seamlessly with the others so, for example, core 0 could be controlling motors whilst core 1 sends and receives data to other modules such as the GPRS and TFT screens. The advantage is that core 0 can run at full speed and toggle digital output pins at very high speed (10 nano seconds), which is fast enough for most motors, particularly if servo 'gearing' is used. If the code on core 0 is not too protracted, the core can run incredibly fast with lots of motors accelerating, constant speed, decelerating. How many motors? I don't know!

Step 2: PCB Design

The design is 2 layer, with top layer tracks in red and bottom layer in blue. Board outline is green and copper pour is red. At the bottom is mounting for 2 MCUs with the same footprint as an Arduino Mega / Due. At present, bottom right is inhabited by a TC275 - a 3 core MCU which runs at 200 MHz - perfect for controlling a relatively large number of motors.Top left is a weird looking shape that houses the GPS module - a Ublox C94 Rover, which bolts onto the under side of the PCB. Bolting onto the top side is the SIM800 cellular module, a digital compass (bottom left) and some TFT screens (middle). There's also mountings for a couple of Arduino Nanos, a text to speech module and a 35W audio amplifier.

Step 3: Components

2 × PCB (see attached files ... use 'Design Spark' software to open .pcb file)

1 × TC275 'Shield Buddy' MCU

1 × Adafruit LSM303 Compass

1 × Phoenix Contact COMBICON MPT Series 2.54mm Pitch Straight, PCB Terminal Block, Through Hole, 8 Way

1 × TDA 8932 35W mono audio amp

1 × SIM800 cellular module

1 × Ublox C94 M8P Rover and Base kit ..... Get the right one for your country.

1 × EMIC 2 text to speech

2 × 1.8" TFT breakout

2 × Murata 100nF Multilayer Ceramic Capacitor MLCC 50V dc ±10% X7R Dielectric 1206 (3216M) SMD, Max. Temp. +125°C

2 × Samsung Electro-Mechanics 330nF Multilayer Ceramic Capacitor MLCC 50V dc ±10% X7R Dielectric 1206 (3216M) SMD

6 × TE Connectivity CRG Series Thick Film Surface Mount Fixed Resistor 1206 Case 0Ω ±1% 0.25W ±100ppm/°C

4 × PCB Slide Switch SPDT On-On 3 A @ 120 V ac Top

7 × Black Button Tact Switch, SPST-NO 50 mA @ 24 V dc 1.4mm

18 × TE Connectivity CRG Series Thick Film Surface Mount Fixed Resistor 0805 Case 1kΩ ±1% 0.125W ±100ppm/°C

5 × Murata 70dB Through Hole Continuous External Piezo Buzzer 5 × TE Connectivity CRG Series Thick Film Surface Mount Fixed Resistor 1206 Case 100Ω ±1% 0.25W ±200ppm/°C

1 × BSS138 Logick Level Shifter

2 × STMicroelectronics L78S05CV Linear Voltage Regulator, 2A, 5 V 3-Pin, TO-220

4 × Phoenix Contact COMBICON MKDS Series 5.08mm Pitch Straight, PCB Terminal Block, Through Hole, 2 Way

6 × Kingbright 640 nm Red LED, 3216 (1206) SMD package 2 × Arduino NANO MCU 6 × Kingbright 570 nm Green LED, 3216 (1206) SMD package

6 × Kingbright 465 nm Blue LED, 3015 (1206) SMD package

1 × Arduino MEGA 2560 MCU 1 × Arduino Stackable Pin Header Sockets 4, 6, 8 & 10 pins

1 × Phoenix Contact COMBICON MKDS Series 5.08mm Pitch Straight, PCB Terminal Block, Through Hole, 4 Way

Step 4: Surface Mount Soldering

First thing is to solder all the 1206 components - resistors, LEDs and capacitors. No stencil is required - just a small amount of solder paste and a reflow heat gun. Fear not - soldering this size SMT is easy!

Sometimes it's difficult to spot the polarity of the LEDs so it's a good idea to have a flying 5v power supply to check that the LEDs work before applying the final heat. Lay the LED in the solder on the pads and test they work.

The green LEDs require a higher resistor than the others so 2k is used with these and 1k with the others.

The 0 ohm resistors can be left off - they give options to connect the SIM800 to the MEGA 2560 instead of a NANO. The 2560 tends to be more stable in operation.

Step 5: Mount the Buzzers, Switches, Regulators, Screw Terminals

These items are very robust, so need to be soldered next. Screw connectors are very useful where there is any vibration in the machine as they are pretty solid. Otherwise there are female connectors for flying leads on the stackable pins on the MCUs. The buzzers require 100 ohm resistors to protect the MCU from supplying too much current and burning out the pin circuit.

There are some random locations for ground and 5v screw terminals which are very useful. The 12V screw terminals are all 5.08 mm pitch.

NB. The Ublox Rover module can be connected to the PCB 12v supply or to a 10 to 30 VDC battery which is useful for keeping it 'live'.

Step 6: Solder on the Headers

The headers for the Nanos, compass, Ublox, Emic TFT and SIM800 are all standard male - female 0.1" pitch and are relatively easy to solder - so do these first.

The main 2 MCUs push onto the underside of the PCB and the headers for the MEGA 2560 and TC275 are more difficult and harder to find. They are special stackable male - female headers with long male legs that go through the PCB and allow the MCUs to be attached on the lower side. They are very difficult to solder and it's strongly advised to practise on a spare unpopulated PCB until the MEGA 2560 pushes on and off with ease. To make things even more difficult, there's some 6 way male - female headers in the middle of the MCU footprint that also need soldering. These headers MUST be compatible with the MCU pins and are the same type used on the Nanos etc - don't buy the 2 x 3 blocks with round holes!

Solder the stackable headers one MCU at a time as it's easy to bend the pins when trying to fit each MCU. Get an old MEGA 2560 and squirt WD40 into the female sockets and use this to 'ease' the pins by attaching / detaching a few times. Finally, fit the TC275, which needs an incredible amount of care as - trust me - it's very easy to crack the main chip. This chip covers a very large amount of surface area on the board so if you bend the board - ping - you crack the chip! ....... And these boards are very expensive. It took me about 2 hours just to attach these two MCUs on the last build.

The PCBs can be tested at this stage. First check there are no shorts to ground by checking resistance between 5v to ground and then 12V to ground. 12V to ground should give about 4000 ohms.

Step 7: Wire on the SIM800 Battery

The SIM800 wont work without a battery and it is wired onto the underside of the PCB, but not connected to the PCB ie not soldered, just tied on. There are special holes in the PCB for this.

Step 8: Bolt on Modules

The Ublox bolts onto the underside of the PCB and all the others on the top. Push them all into place and check that they work OK. The TC275 TFT screen will not work unless the EMIC2 serial1 in AND out are connected. Serial 1 is normally right next to the SDA pins, but may also be denoted RX2 / TX2 on the PCB itself. A bit of trial and error may be needed to get the EMIC2 to work properly. Sin connects to TX and Sout to Rx.

Once everything is working, use 3mm and 2mm bolts and appropriate plastic spacer cylinders to secure the modules in place. The EMIC2 has no bolt holes :(

Attach to Motor Drives

The motors themselves each have their own power supplies and sophisticated 'Drives' which are normally interfaced to the MCUs by 5V PWM logic. A basic test can be done with just one connection to 'STEP' or 'PULSE' on the drive to the relevant pin on the MCU ... and ground to ground. Make sure that the motor is securely clamped / bolted down and test! Some of the more complicated servo motors need to be tuned, but that is another story!

Step 9: Bolt on Lower PCB

An identical PCB is bolted to the underside of the main PCB, which in turn is bolted to a piece of plywood for testing. This is the most robust way of securing the controller against vibration etc.

Step 10: Set Up Ublox Base and Rover Devices

The base station remains static in one location and transmits a signal via a radio link to enable error correction for the Rover, as long as the radios are in range of each other. Ublox supply an excellent bit of software for showing satellite information and configuring the two devices (C94 M8P). For convenience, I've created 3 configuration files that can be uploaded with UCenter software straight to the devices.

For an initial test, use the quick 2 minute 'survey in' file:

For accurate, repeatable, results use the 24 hour version - be warned - it takes 24 hours before you can use the devices! :

The Rover uses the same config file whatever:

Just upload the files into non-volatile flash using tools > GNSS config > GNSS > FILE. If you want to see the actual survey in status go to View > Messages > UBX > NAV > SVIN and right click 'enable'.

It's worth mentioning that these Ublox devices are 3.3V logic and using them on a 5V MCU without logic level shifters may destroy them.

Step 11: MCU Code

Arduino MEGA 2560 code
The code for this MCU is here:

This MCU currently hosts a magnetic compass and receives NMEA data from the Ublox network. It's connected to the TC275 MCU as a slave on I2C bus. There are numerous libraries required to run this code, including NeoGPS by SlashDevin : The code also accepts long and lat data from the GPRS module and calculates a heading and distance for transmitting onto the TC275 master. It's very much in development so please expect major changes in the near future! Upload the code and libraries to the MCU in the normal way. The orange LED and buzzer indicate that valid, uncorrupted, NMEA data has been received and the blue LED flashes to indicate that the MCU is still working.

Arduino Nano Code
This MCU controls the SIM800 GPRS module, sending / recieving 'AT' commands and downloading data from an online database. Code is here:

It also receives data from the TC275 regarding which waypoint is currently active so that it can get the correct line of information from the table in the database. It then sends details of latitude and longitude to TC275.

TC275 Code

The TC275 is a 3 core processor running at 200 MHz and works as the Master on the I2C bus. The file is here:

The MCU requires software to be installed on the PC and then becomes integrated with the Arduino compiler so that it can be updated just like an Arduino although the compiler should be run with Admin privileges. More info about the board can be found here:

.. and there is a very useful discussion forum here:

The main part of the code, on core 0, is for controlling the steering and drive motors and runs in one short loop with no interrupts. It relies on one simple 'Micros' timer, breaking down the loop into 'intervals' so that each interval is effectively it's own timer. In this way all the motors are precisely synchronised with each other. The code allows full differential steering and allows for the peculiar offset steering design where the wheel pivet is offset from the Z axis. When turning, the inside wheel slows down according to the angle of the turn, effectively adding torque to the steering mechanism. The code also accounts for which 'lock' the wheels are on and what direction they are swivelling and if the machine is going forwards or backwards.

Step 12: Create an Online Database

On a remote web server enabled with MySQL and PHP, use phpMyAdmin to create a new database and a new table on that database which should look something like the screenshot above. The ID column needs to 'auto increment'.

Step 13: PHP Files

<p>Header("Cache-Control: must-revalidate");<br>$offset = 10;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() - $offset) . " GMT";
//include ("getid.php");
$host="localhost"; // Host name 
$username="####################"; // Mysql username 
$password="####################"; // Mysql password 
$db_name="####################"; // Database name 
$tbl_name="####################"; // Table name</p><p>// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");</p><p>// Retrieve data from database 
$sql="SELECT * FROM ############## WHERE ID = '5'";   
?> </p><p>// Start looping rows in mysql database.
  ?>LAT echo $rows['WAYLAT001'];?>LONG echo $rows['WAYLONG001'];
 ?></p><p> Create a set of PHP files like the one above and label them according to the table ID you want to access so, for example, I might call this one 'waypoint005.php' since it's selecting a line of data corresponding to an Id value of '5'. </p><p>When the WEEDINATOR wants to actually travel to way point 5 it will change the url sent to the GPRS SIM 800 module to something like:</p><p>Header("Cache-Control: must-revalidate");
$offset = 10;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() - $offset) . " GMT";
Create a set of PHP files like the one above and label them according to the table ID you want to access so, for example, I might call this one 'waypoint005.php' since it's selecting a line of data corresponding to an Id value of '5'. When the WEEDINATOR wants to actually travel to way point 5 it will change the url sent to the GPRS SIM 800 module to something like:
Header("Cache-Control: must-revalidate");
$offset = 10;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() - $offset) . " GMT";

Notice in the above 4 lines there is code for refreshing the PHP data. Currently it is set to refresh after 10 seconds. If this code is not used then you could update the values on the database but the PHP code would only ever download the data once and that value will get stored in memory somewhere for a very long time! (Trust me on this one).

Step 14: Finished Controller

Now the controller can be linked to the Pixy CMU 5 camera, the motor drivers, LIDAR / ultra sonic sensors etc. There's enough resources on this PCB to link to dozens of sensors. There's even a spare NANO slot for a watch dog or whatever.

So that's the controller ..... and if you want to build an actual agri-robot using this controller click here:

Microcontroller Contest

Participated in the
Microcontroller Contest