Building Cheapest ROS2 Robot using ESP32 — Part 1 — Hardware Build
I have always wanted to build a robot that was inexpensive and accessible to many people as an entry level robot to build that was running using ROS2. However, several challenges remained in order to accomplish that goal. If you have read any of my previous robot build articles, you would know that the biggest cost for building a ROS2 based robot comes from an SBC like Raspberry Pi or Jetson Nano and a 360 Lidar like RPiLidar, both approximately $100 each. All the other parts can be fairly manageable cost if you are able to 3D print some parts or buy off the shelf cheap wheeled robot kit from Amazon or Aliexpress including base frame, battery, motors with encoders and IMU. However, the RPi and Lidar were always a bottleneck until recently I was able to run the Linorobot2 hardware on esp32 microcontroller using micro-ROS framework. This basically opened up the possibility that I had pretty much closed the door on due to cost of Rpi/Lidar.
This article series is continuation of my efforts to build a small and affordable ROS2 robot that anyone can build with widely available parts anywhere in the world and learn and tinker with ROS2 concepts. Learning robotics finally doesn’t have to be very expensive.
At the end of the build you will be able to drive the robot around using a joystick. In future, we may even be able to add Lidar to do SLAM based mapping to build the map using a package like slam_toolbox. At the least, you will walk away with a solid knowledge of ROS2 and how to build and troubleshoot a robot from scratch that will help you in your future endeavors.
In this article we will focus on hardware build of the esp32 ROS2 robot that is based on linorobot2 framework. The goal is to build a basic differential drive robot that is able to
- Read encoders and IMU sensors and broadcast those messages
- Control motors using a joystick controllers driven by cmd_vel topic
In the next few articles we will test and calibrate motors and IMU and visualize the robot in RViz2 and Gazebo. In subsequent articles if everything goes according to plan and that’s a big if, we will be able use SLAM to localize the robot and Nav2 to drive robot autonomously to a selected location on the map.
Bill of Materials needed for hardware build of the robot [these are not affiliate links]:
- ESP32-WROOM-32D or later version of ESP32 microcontroller [these support micro-ROS] 3 for $17 approx. $6@each
3PCS ESP32-DevKitC Core Board ESP32 Development Board ESP32-WROOM-32D Wireless WiFi Development…
Shop Amazon for 3PCS ESP32-DevKitC Core Board ESP32 Development Board ESP32-WROOM-32D Wireless WiFi Development Board…
2.Encoder motors- 6V [quantity — 2 for differential drive robot] approx. $7@each total of $15 for 2 motors. These DFRobot FIT0450 motors come in two variation I-shape and L-shape. I went with I-shape because I already had them from previous project. You can also substitute these with other encoder motors if you have them but if you get higher voltage like 12V, make sure you adjust the power bank or battery to supply necessary voltage and power.
FIT0450 | Digi-Key Electronics
Order today, ships today. FIT0450 - DC Motor Gearmotor 160 RPM Incremental 6VDC from DFRobot. Pricing and Availability…
3.Power bank battery [quantity — 1] approx. $15–20
INIU Portable Charger, Slimmest 10000mAh 5V/3A Power Bank, USB C in&out High-Speed Charging Battery…
Shop Amazon for INIU Portable Charger, Slimmest 10000mAh 5V/3A Power Bank, USB C in&out High-Speed Charging Battery…
My power bank is old PowerAdd that is no longer sold on Amazon so this is just a suggested replacement, you can find any power bank that works for you that has similar specs and output ports. I have not tried this myself.
4.L298N motor controller [quantity — 1] 4 for $12 [approx. $3@each]
HiLetgo 4pcs L298N Motor Driver Controller Board Module Stepper Motor DC Dual H-Bridge for Arduino…
Shop Amazon for HiLetgo 4pcs L298N Motor Driver Controller Board Module Stepper Motor DC Dual H-Bridge for Arduino…
5.MPU6050 or GY521 IMU [quantity -1 ] 3 for $10 [approx $3@each]
HiLetgo GY-521 MPU-6050 MPU6050 3 Axis Accelerometer Gyroscope Module 6 DOF 6-axis Accelerometer…
Shop Amazon for HiLetgo GY-521 MPU-6050 MPU6050 3 Axis Accelerometer Gyroscope Module 6 DOF 6-axis Accelerometer…
6.Wheeled Robot kit — something like this from amazon $13 or this from digikey $8. The digikey one is 4WD so you may have to provide your own castor wheel. I have bunch of these old kits so I was Ok to modify the kit a bit. Alternatively, you can 3D print the entire base using something like this Open Robotics Platform system, they have library of many freely downloadable parts you can simply download the 3D printing files and print them yourself. Of course, your robot will look different than this but the basic principles will still be same.
110090263 | Digi-Key Electronics
Order today, ships today. 110090263 - Raspberry Pi pHAT, Grove Arduino IDE Wheeled Robotics Kit from Seeed Technology…
7. Couple of breadboards and wires [$10]
HUAREW Breadboard and Jumper Wires Kit Include 830 Tie Points Breadboard 400 Tie Points Breadboard…
Buy HUAREW Breadboard and Jumper Wires Kit Include 830 Tie Points Breadboard 400 Tie Points Breadboard Jumper Wire…
8.Voltage regulator — optional [$9]. I was originally planning to use this but I have found easier way to power the robot with two separate batteries to avoid brown out for ESP32 so I’m not going to use it.
DFR0205 | Digi-Key Electronics
Order today, ships today. DFR0205 - GS2678 - DC/DC, Step Down 1, Non-Isolated Outputs Evaluation Board from DFRobot…
9.mini USB hub — optional [$5]. I’m planning to use two separate batteries — one for motors [6V] and second for powering ESP32 [power bank with micro-USB connector for ESP32]. However, you can potentially power everything with single battery, you’ll have to get a hub like this and plug it into your power bank and then extend USB cables to power motors and ESP32 from the hub.
2998 | Digi-Key Electronics
Order Adafruit Industries LLC 2998 (1528-1612-ND) at DigiKey. Check stock and pricing, view product specifications, and…
10. Joystick Controller [optional] — I use one of these cheap joystick controllers to control the robot to send cmd_vel messages. You can avoid using this and use terminal based tools like teleop_twist or teleop_keyboard or even use a mobile app like Dabble for joystick. There are so many options. Check out this article for more options.
FANDRAGON USB Wireless Gaming Controller Gamepad for PC/Laptop Computer(Windows XP/7/8/10) & PS3 &…
1) streamlined appearance, elegant and fashionable, humanized design 2) strong compatibility: support Android games…
In addition, to this you may need a few more things like:
- Additional dupont wires with different combinations male-to-male, female-to-male or female-to-female depending on how you wire it.
- You may need some double sided tape or 3M pads for installing photo frames to install breadboard on top of the top base plate. This way you can pull out the easy removable tab to uninstall the breadboard later if necessary.
- Few types of USB cables — USB-A to microUSB, USBA to USBA, USB-A to bare wires [positive and negative].
- You may need additional standoffs to increase the height between two base plates to make sure you have room to install batteries between the two base plates.
- You may need some velcro ties like these or silicone ties like these to make sure batteries are held tightly with the base plate.
- We are doing the wiring purely using breadboard and dupont wires to keep things simple but you can use more perma boards and solder the wires if you are good with soldering. I’m not great at soldering so I would rather build a PCB and get it printed than solder so many connection points.
Overall as you can see all these parts add up to approx. $60–70. You can also cut the cost further if you just drop the power bank and supply two separate 4xAA battery holders that will supply 6V. That will make it a sub $50 build!!!
Depending on which base frame wheeled robot kit you decided to go with, this will vary but lets build the first layer of the base plate along with two front wheels and castor wheel in the back. It should look something like this. Mine was a 4WD robot kit so I’m using a castor wheel from another robot I built in past but you can buy that separately or get a kit with everything together. You only need baseframe, two wheels and caster wheels. We will be replacing the cheap TT motors that come with this kit with our own TT motor with encoders so we can get wheel odometry.
One of the things I had a little trouble with was while replacing original TT motor that came with kit with the DFRobot FIT0450 Encoder motor. The problem was the FIT0450 has an rounded Encoder board protruding out which was not flushing properly with base plate. So I needed holes in the T-Slots that were supplied with the robot kit to be moved out by 5–7 mm to accomodate for the rouding protrusion in FIT0450. I tried to drill the existing hole to make it longer but broke a few T-slots in the process. So I decided to build a CAD drawing and 3-D printed a part that looks like this [4 copies of it]. This solved the problem for me to adjust for the offset in hole location on motor and on the T-slots.
See the picture below that shows the original T-Slot that came with the kit and one I had to 3D print to replace it. I’ll upload an STL file for this in github once I have everything working.
It is important to note how the pin numbers are counted [ESP32 reference doc]. This version of ESP32 board I’m using is ESP32-WROOM-32D devkit and it has 19 pins on each side so total 38 pins. As shown in diagram above, while you are holding the usb port of ESP32 at bottom, the right side jumper [row of pins] is labeled J3 and left side jumper is labled J2. For each jumper we count the pin numbers starting at 1 from top to bottom. So for J2 and J3 the top pins are #1 and bottom pins are #19.
Now that you have proper orientation of pinout, you can start wiring the pins one by one as described in table below.
In addition to this you need provide power to L298N motor driver, two motors, two encoders [one for each motor] and MPU6050.
Here is the general power plan
Power for L298N
- Connect positive and negative of main battery to L298 power in screw terminals. This is the 3-point screw terminal shown in blue at left bottom in diagram above.
- Make sure the 5V output jumper is installed [as shown in diagram]. When this jumper is installed, the 5V output terminal will act as a voltage regulator supplying 5V output which we can use for powering Encoders.
- The first pin out of the 3-pins closest to the corner of the L298N board is input power to L298N, this can be up to 12V. However, in out case we will be supplying 6V since our DFRobot TT motors are 6–7.5V max rating and we don’t want to exceed that.
- The pin in the middle is common GND for input and output voltages. We will be using this for GND to connect with our breadboard -ve line.
- And the third pin furthest from corner is 5V output. This 5V out we will use for powering the motor encoders. So we will connect the 5V output screw terminal to breadboard +ve line.
Power for Motor and Encoders
The DFRobot FIT0450 motors have total 6 wires coming out. The two pair is for power and 4-pair wire is for encoder. See FIT0450 product wiki for more details.
The main power for motor will be supplied by connecting the two pair wire [red/black] to one of the two output screw terminals as shown in diagram above. These are 2-point screw terminals on the sides [marked M1 and M2 in diagram above]. You can initially connect the red and black wire in interchangeable fashion to the L298N screw terminal, it will not hurt the motor [as long as voltage is 6–7.5V]. The only thing that can happen is motor will rotate in opposite direction to what you desire. This we can correct during testing phase.
The encoders have total 4 wires, two signal wires — one for Channel A and one for Channel B. And two more wires positive and GND to supply power to Encoder. The channel A and B wires will be connected to ESP32 pins as described in the diagram and wiring table above. However, for positive and GND wires for Encoder, simply connect them to breadboard positive and negative/GND lines as shown in second power arrangement diagram above with breadboard.
Power for MPU6050 IMU Sensor
The MPU6050 needs 3.3V power which we can supply using ESP32 J2 pin 1 and another GND pin from ESP32. The SCL and SDA signal pins from MPU6050 will be connected to ESP32 as described in the diagram and wiring table above.
When mouting the MPU6050 board on the breadboard, make sure that you are aligning the X arrow to point to front of robot, Y should be pointing to right of the robot. See the diagrams in original linorobot2_hardware readme file.
Alternate Power arrangement with Single Battery
The default power arrangement assumes that we are going to use two separate batteries to power motor and ESP32. However, if you want to supply power with a single battery, you will need an arrangement that looks something like this. I have not used this because I didn’t want to risk brown out of the ESP32 if motors consume too much power.
The USB to bare wire cable essentially splits the USB cable into two positive and negative wires and looks something like this:
ELNONE 2PacK 1M/3.3Ft 20AWG USB 2.0 Male Plug 2pin Wire DIY Pigtail Cable 5V 5A Black USB Power…
Buy ELNONE 2PacK 1M/3.3Ft 20AWG USB 2.0 Male Plug 2pin Wire DIY Pigtail Cable 5V 5A Black USB Power with 2-Position…
The final assembled robot looks something like this:
That’s pretty much it for the mechanical and hardware build of the robot.
In the next article we will work on uploading the software into ESP32 and running all sorts of tests on the robot to make sure motors, encoders and IMU sensors are working well and publishing the data on ROS2 topics. In addition we will be setting up Linorobot2 on host computer [your laptop or desktop].
Running linorobot2_hardware on esp32-WROOM-32D using Wifi
Recently, I wrote an article that described how to get some of the micro-ROS examples running on esp32-WROOM-32D board…
Making a Mobile Robot #5 - Power Concepts
In this tutorial we're going to look at all things power, and hopefully cover everything you'd want to know about…
GitHub - robofoundry/linorobot2_hardware_hippo_esp32_fix: A fork of linorobot2_hardware with…
A fork of linorobot2_hardware with support of esp32 on ROS2 Humble and other devices - GitHub …
wiki:TT Motor with Encoder is a motor with a 120:1 gearbox and an integrated quadrature encoder that provides a…
ESP32-DevKitC V4 Getting Started Guide - ESP32 - - ESP-IDF Programming Guide latest documentation
ESP32-DevKitC V4 is a small-sized ESP32-based development board produced by Espressif. Most of the I/O pins are broken…