This project is about creating an autonomous robot using cheap parts from AliExpress or your favorite supplier using a mainboard from JLCPCB or your favorite PCB prototyping supplier.
You can buy a complete chassis kit, or you can buy the parts separately. It should not set you back more than 10-15$.
If you decide to buy the items separately, the motor/wheel assemblies are about 30 cents a piece.
In this project, I will use 4 of them, but you can make do with two.
The motor driver is the L298, available from AliExpress at about 40 cents.
The robot will have a QMC5883 compass, 3 VL53L0X laser ranging modules and an optional GPS module.
None of these items should cost more than a couple of bucks.
In addition, I use an Adafruit Servo controller and 3 small servos, letting me point the VL53L0X modules in any direction.
This is where it gets interesting. The system will be controlled by an ESP32 microcontroller running a customized version of ESP32Forth. Forth is the ideal robot/prototyping language in that you flash the MCU once, burning the Forth kernel. From then on, you have built-in OTA. If you want to change something while the system is running, you upload the change. Everything else stays in place.
You will need a 5V power supply. I use two 18650 batteries with a buck regulator.
You’ll need 3 small LEDs and 3 200 Ohm resistors.
You’ll need a good soldering iron, flat cables, a Dupont crimping tool, pliers, and a small drill.
The Main Board
The main board will be designed using KiCad.
The entire project and gerber files are available on Github. The Gerber files can be uploaded to JLCPCB and you will receive 5 mainboards looking like the one in the picture.
When the PCB arrives from JLCPB, solder the headers, resistors and LEDs as shown. Be careful to mount the LEDs the correct way, that is, the short lead goes in the hole with a square pad.
Using your tools and your tinkering skills, you're assumed to be able to assemble everything into a cool looking rover.
In the above, I have tried to make the project as cheap as possible. However, if you have a well-paying job, you should consider getting all you can afford from Adafruit and Pololu. If you do that, you will help them continue to develop free hardware and free software. Follow your conscience and remember, St. IGNUcius is watching you.
This is the fun part. Install the Arduino IDE and the ESP32 boards. Then, go to Github and get this file. It differs from the standard ESP32Forth in that it supports the sensors you purchased.
Compile it and flash it onto the ESP32.
From Github, get the ESP32 File System Uploader and install it.
Next, Get these three files containing startup code for WiFi, driver code for the LM298, and last, but not least, the code that lets the Forthmobile find its way across your living room floor.
Alternatively, you could clone the entire project, hack it, and contribute. That would make me happy.
Open the file called autoexec.fs and change the passphrase “Thoushal” into whatever you want. Save the file when you’re sure you didn’t touch anything else.
The last thing you do is to upload the three files autoexec.fs, motor.fs, and autodrive.fs to the ESP32 using the ESP32 File System Uploader.
In the directory FORTHMOBILE-JUNE-35V, create a subdirectory called data.
Copy the three files autoexec.fs, motor.fs, and autodrive.fs to data.
Using the Arduino IDE, select Tools->ESP32 Sketch Data Upload from the menu. It should only take a few seconds.
When the ESP32’s blue LED is lit, you’re ready to see if it works.
Disclaimer: I have used Linux since Yggdrasil Linux was released in 1992 and I’ve never looked back. Since then, myriads of Windows versions have come and gone. I know nothing about them. I will assume that you know how to make Windows do what I do in Linux.
In the following you need access to WiFi.
Open a terminal and type iwlist scan | grep -e ESSID
If you see an entry with ESSID Forthmobile, the WiFi code works. Using the passphrase you chose above, connect to Forthmobile and make sure you got an IP address.
Using your favorite telnet client (I use nc) connect to port 23 and see if you get a prompt like the one below.
If you do, see if it can add two and two.
If you don’t, go back and make sure that autoexec.fs looks exactly like shown here. Download it again if you’re unsure.
Next, we’re going to watch the blinkenlights using code that we wrote.
1 constant on
0 constant off
13 output pinMode
14 output pinMode
18 output pinMode
: XSHUTL ( on | off )
13 swap digitalwrite
: XSHUTC ( on | off )
18 swap digitalwrite
: XSHUTR ( on | off )
14 swap digitalwrite
on XSHUTL 20 ms
off XSHUTL 20 ms
on XSHUTC 20 ms
off XSHUTC 20 ms
on XSHUTR 20 ms
off XSHUTR 20 ms
: tst 1000 0 do testLED loop ;
If all three LEDs are flashing, that’s a good indicator.
Mount the board on the car’s acrylic plate. If the holes don’t line up, this is where you need the drill.
Before connecting the cables, make sure that the pin labels correspond to the pin labels on the modules. I’ve taken every precaution to make sure that a 6 lead flat cable with a female Dupont connection on each end will be all you need, but as comrade Lenin said: “Trust is good. Control is better.”
If you have a GPS module, connect it to the RX2/TX2 breakout next to the POWER plug, and any I2C devices to I2C_1, I2C_2, I2C_3, respectively. I mounted all the sensors onto small servos at the front of the car. The reason for this is that it takes too long to ‘swipe’ left and right while driving, so I chose to read the three sensors, and only move the servos if I detected an obstacle.
If you find a better way, please let me know.
To prepare for the test drive, insert the following code into the top of autoexec.fs and save it to flash.
s” /spiffs/motor.fs” included
S” /spiffs/autodrive.fs” included
The next time you start, you won’t have to load these files manually.readsensor
To test the compass and laser modules, type
If the sensor values seem sensible (sorry, couldn’t help myself) then place the Forthmobile on the floor, go back to your terminal and type
If you check the code, you will see that the Forthmobile continues to roam until it gets boxed in.