Line Follower With ESP32-CAM L0Cost Robot Controller for FPV
by tekyinblack in Circuits > Robots
3433 Views, 11 Favorites, 0 Comments
Line Follower With ESP32-CAM L0Cost Robot Controller for FPV
The line follower robot is a basic step in robot construction and the cheapest construction kits offer an introduction which can operate as intended, or as documented here, be upgraded to something more sophisticated.
This is an instructable to demonstrate the use of the L0Cost robot controller in building a mobile robot which can be steered with a Bluetooth controller or via a web page with video feed. It uses the L0Cost Robot Controller software held on Github here.
Even if you don't add the controller, it's a walk through of building the basic line follower. Building the line follower is steps 1-12, if you want to skip forward to the L0Cost controller then its from Step 13 onwards
Supplies
Line follower robot kit - this is the $5 kit, not the $10,$15 or even $30 kit!!!!!
4 x 75R resistors to replace the 4 x 51R resistors in the kit
2 x 4k7 resistors to replace the 3k3 resistors in the kit
4 x 330R resistors for the interface adapter
1.5mm or 2mm heat shrink sleeving, various colours if possible but not essential.
ESP32-CAM with psram
ESP32-CAM-MB to help program the ESP32
3xAA battery holder if you don't want to make the battery box and display.
dupont pcb headers and sockets, need 2x3 pin sockets, and 14 pins.
dupont patch leads
3D printed plastic frames - though possible to make out of other materials
Tools
Soldering iron with solder
Small wire cutters
Small needle nosed pliers
Wire striper
Masking tape - to help position, attach and hold components to the PCB
Solder sucker - especially if you're learning to solder! but not essential
Third-hand grips/stand
A light - anglepoise or small table led - something which will help light your work
Magnifying glass(es) - especially if you have difficulty with your vision like me. There are also USB microscopes which can be helpful.
The Basic Kit of Parts
There are various line follower kits which are good starter soldering practice and produce something which works and can be played with afterwards. It all comes in a small plastic bag with some Chinese instructions and a circuit diagram which isn't accurate. Your luck with this may vary, but it shouldn't be too daunting if everything is kept organised.
Start of Modifications
The standard kit expects all connections to be soldered but a few are definitely best done with connectors. To fit these, six holes highlighted in the picture, have been drilled with a 1.2mm bit. These will be fitted with pcb pins later.
First Soldering
To make assembly easer, the fixed resistors, IC socket and variable resistors are soldered first. Only the 1k resistors from the original kit are used if the upgrade version will be constructed. It's helpful to get the orientation of the IC correct as a reminder when inserting the IC later. Check with the outline image on the PCB. To secure the components in place when soldering, bending the leads can help or secure them in place temporarily with masking tape.
Add the On/Off Switch
There's not a lot of guidance for this, but generally it's switch down for on, switch up for off. It's not a disaster if the switch is connected the other way round, but the picture shows the switch in the demonstration kit orientated so as to give that operation. If the switch in the kit used doesn't have any orientation marks, testing with a multi meter to see which way is preferred will be needed.
Adapter Sockets
These are two three pin PCB sockets with the centre pin cut out to fit the holes in the PCB where R9 and R10 would normally go. See the next step as to their orientation.
Add the Rest of the Top Surface Components
The PCB pins and sockets are added, as well as the capacitors and direction LEDs. The motor pins have to be added singly but the battery can be added as a pair. The two sockets are added in the orientation shown, they don't fit the holes otherwise. The capacitors are added with the white negative stripe to the front of the robot pcb. The LEDs have to be fitted with a particular orientation, looking at each LED, the short lead has to be fitted in the hole nearest the edge of the PCB.
Underside Components
This is more tricky as the components have to be attached to the same side as the PCB solder pads and have to have long leads the same length. As per the pictures, I've added insulating sleeves to the leads to prevent short circuits in the future.
The skid steering bolt should be added first at this stage as it gives a small amount of protection to the attached components. Align the resistors and LEDs with each other and the bolt and when in position, brace them with masking tape, attached to both the components and bolt, before soldering them in place.
Add Male Dupont Leads to Motors and Battery Box
Having added PCB pins to the circuit board, female DuPont leads can be soldered to the motors. 10cm leads have been used here with the plastic end cut-off but leaving some of the cable crimp to give a better connection. The battery box leads were cutdown in length and the female headers soldered onto the ends, using heat shrink to insulate the join.
Attach the Motors
Two double sided sticky foam pads are used to attach the motors. The pads need to be stuck down so that they fit within the outline printed on the PCB. Test the alignment of the motors to make sure they will fit. Once fastened on, peal off the backing strip and attach the motors, aligning them with the outline printed on the PCB as accurately as possible, and taking care not to let the wheel touch the PCB.
Plug in the Batteries and Motors
Route the motor wires between the PCB and motor and twist them round to plug onto the PCB pins on the top of the PCB. When testing later, these may need to be swapped around. Connect the battery box used to the battery terminals, checking the polarity with that printed on the PCB..
Make the Upgrade Adapter
The point of this is to interrupt the circuit between the IC and the motor switch transistors so that an alternative control signal can be inserted. The small circuit contains 4 resistors together with PCB pins to secure it in the sockets that were fitted earlier and to provide a connection for the L0cost Robot Controller later. This mod works fine to run the kit as a line follower but problems with the ESP32 boot means that it needs a hardware fix to do seamless cutover from remote to automatic which I haven't developed yet. A later step describes a remote control insert.
Complete the Basic Line Follower and Test
Remove the upgrade adapter and motor connections before starting testing. Check the wiring, especially the battery polarity, and insert some batteries into the holder.
Holding the robot up firmly, switch on. If all is connected correctly, the LEDs next to the bolt should both light up evenly. If they don't, check your soldering of the LED's all the way back to the switch and the battery connections. Switch off.
Plug in the upgrade adapter and IC and switch on. The LED's next to the bolt should both still switch on. One of the two LED's on the top of the PCB should light up. Holding the robot, move the bolt and LEDs above a black line, the LED's should blink on/off alternately. If neither LED lights, switch off and trace the soldering all the way back to the battery and switch, via the transistors and IC.
If the LEDs don't switch over evenly, use a screwdriver to adjust the position of the preset resistors next to the IC. Do this while the robot is powered on and after each adjustment, move the bolt back and forth over the black line to check its working. Both presets may need to be adjusted and there are many positions which are correct. In some cases, no adjustment is needed at all.
Once the LEDs blink on/off evenly as the bolt is moved over the black line, switch off and attach the motors. Holding teh robot up, switch on and one of the motors will start to turn. It should turn to move the robot forwards. If reversing, switch off and revers that motor's connections and switch on again. Place the robot over the black line and check that alternate motors switch on/off with the LEDs. If the other motor also runs backwards, switch off and reverse it's connections.
The test circuit was made by taping a length of old wall paper to the floor and then marking out a course using black electrical tape. The tape does like to go in a straight line but by being determined can be made to turn corners successfully. It doesn't have to be in one continuous length and it can be fun to also include 'junctions' where the tape goes in two different directions to see where the line follower goes.
Place the robot over the black line of a test circuit, switch on and verify that it runs ok. Be prepared to adjust the presets again if it veers off too often.
This is a video of the basic line follower working. This is a basic but very effective robot.
Upgrade
The next few steps upgrade the line follower with the L0cost robot controller to give a remote controlled robot with video feed which can be run in a variety of ways. The robot can continue to run as a line follower with a first person video feed from the front of the robot. Using the web interface, the robot can be remotely steered instead of the line following function. I'm trying to get an interface to work with this cheap robot to allow seamless changeover between remote control and line follower but so far haven't found a simple and cost effective method. The robot can also be steered using a PS3 joystick controller but there won't be a video feed. Finally, an SDcard based script file can be executed to cause the robot to follow a predefined set of movements.
Several 3D printed parts are use to adopt the upgrades. A mount is fitted to the front of the PCB using the skid bolt, and an adapted L0Cost Robot Battery Box is used to provide power. The battery box is described in this instructable and the adapter matrix board for the controller is described in this instructable here.
Attached are the .stl file for the 3D printed parts but they are also shared on TinkerCAD at the following links.
As well as the extra plastic parts, a matrix board for the camera is needed and a small adapter board for the remote control function. This small adapter has two lines of three connector pins with a fourth pin in line to which the controller connects. A 330ohm resistor connects this to the motor pin on each side. See picture.
Install the L0Cost Robot Controller Software
Download the latest L0Cost Robot Controller software from Github and load it onto your ESP32-CAM board.
The code should only require one piece of customisation and that is to select the type of ESP32-CAM being used. In the picture shown, the AI-Thinker model is chosen.
It's possible to use an FTDI card to program the ESP32-CAM and there are many instructables describing how to do this. The easiest way is to have an ESP32-CAM-MB USB card just for programming these boards as it makes the task much easier.
Insert the ESP32-CAM board into the ESP32-CAM-MB board as shown in the picture, and while pressing the IO0 button, connect the board to a USB cable already connected to your powered on computer.
To load the software, the Arduino IDE needs to be installed along with the ESP32 customisation. If this is not already available on your PC, again there are many instructables available giving instructions on how to install this. Other means of loading the software are available but not covered here.
Using the Arduino IDE, open the L0Cost Robot Controller software and select the ESP32 board version being used from the board manager. Select the port to be used, and then compile and load the software. If it doesn't load because the board isn't ready, press and hold the IO0 button again briefly press the reset button on the ESP32-CAM board before trying again.
The board will operate with default settings but these are unlikely to be compatible with your environment, the next step provides the necessary customisation via the SDcard.
Customise the SDcard Contents - Config.txt
The L0Cost Robot Controller is customised from the configuration held on the inserted SDcard.
Download the example SDcard contents from Github and copy them to a MicroSD card formatted with the FAT32 filesystem.
Edit the following files in each step on the SDcard for use in your environment
Config.txt
This file contains the definitions for the initial setup of the environment and an outline configuration is shown in the pictures.
The line BASICSTA indicates that the implementation is to use the servo interfaces with a Wi-Fi client, the parameters for which are in the Wi-Fi file listed.
The next line is the name for this system on the network, in this case 'LineFollower01'. Give it the name you want.
The next line lists the name of the file on the SDcard containing the Wi-Fi credentials. This is described later. This entry must exist but it can be a dummy entry, in which case the defaults will be used.
Line 4 is the entry for the script to be run during start-up of the controller and in this case contains defaults for the camera. If it is not required but the main script file is, then a dummy file name must be present here.
Line 5 is the entry for the main script to be run after the controller has started, it doesn't have to be present.
Downloads
Customise the SDcard Contents - Wifi
The name of this file is the same as specified in the Config.txt file
The contents of this file list the properties of the wifi connectivity for the controller.
Line 1 contains the SSID of the wifi network to be used
Line 2 contains the password of the wifi network to be used
Line 3 contains the name of the file containing the html code of the web page to be used as the home or index page of the controller on the wifi network. If it isn't present or fails to load then a default page is loaded.
The following two lines only need to be present or changed if access to the controller over the internet through a firewall is required.
Line 4 contains the port number of the home or index page
Line 5 contains the port number of the video stream
Downloads
Customise the SDcard Contents - Startup.txt
This file has to be the same name as listed in the config.txt file and if it fails to load will be ignored. It is intended to load default commands for the controller. A selection of commands are listed and can be uncommented for use.
Downloads
Customise the SDcard Contents - Main.txt
This file has to be the same name as listed in the config.txt file and if it fails to load will be ignored. It is intended to load commands for the controller. It currently doesn't hold anything other than comments describing the commands available. These are primarily movement commands for the motors or pause.
Downloads
Customise the SDcard Contents - Html
For web based control and viewing, the controller publishes a home page defined in config.txt. A copy of this can be downloaded from the Github repository, along with all the other SDcard files.
Wiring in the L0Cost Robot Components
- Detach the battery box and carefully unscrew the skid bolt, being careful to not bend the LED or light sensor leads.
- Mount the matrix board with the controller sockets onto the camera mount using M3 nuts and bolts
- Fit the camera mount to the PCB by passing the skid bolt through the mounting hole on the camera mount and then through the PCB. Fit the nut and tighten it up making sure it faces forward. Add the skid nut when finished.
- Fit the battery box to the PCB with the voltage display pointing backwards using two M3 Bolts and nuts. Do this without the batteries connected as it's a lot easier.
- The battery box only supplies power to the L0Cost Robot Controller, connect two female to female dupont patch cables between the battery box and the matrix board, negative is the top connection.
- Connect an additional female to female dupont lead between the negative of the battery box and the negative battery terminal on the pcb.
- Connect an additional female to female dupont patch lead from the positive battery connector on the PCB to the 3.3V connector on the bottom row of the matrix board. This is the single pin by itself.
- Making sure that both the battery box and robot are switched off, fit the batteries and check wiring.
- Fit the L0Cost robot controller with SD card.
- Switch on the battery box power and check that the controller can be contacted. If using the web interface, connect to the web page, the red indicator light should be flashing on the controller.
- When satisfied all is working ok, switch on the robot PCB. It should still operate as a line follower and the video feed will show something like the video linked below
Adding Remote Control
The robot has been configured to run as a line follower with a video feed.
- Switch off the robot, if it's still switched on, and remove the small adapter matrix board fitted earlier.
- Fit the remote control matrix board to the PCB, making sure all six of the lower connector pins it into the socket.
- Using two female to female dupont patch leads, connect the two pins on the top of the remote control board to the control pins on the controller board. They are the bottommost pins in the set of six next to the power pins.
- Switch on the robot and if it appears to burst into life, should become dormant very quickly. Wait until the controller web site is available and connect to it.
- The basic web page supplied can be used to steer the robot remotely. If the directions are reversed, swap the dupont lead connections on the remote control adapter. If a script is written, it can be executed by the controller to direct the robot automatically.
Summary
This is a basic introductory project for the L0Cost Robot controller and if you try it out, I hope it all works well for you. I will update this instructable if the seamless function switchover is possible but right now its manual. Please check back for updates and see the other L0Cost robot ideas.