Train Controller With Seeed Studio XIAO ESP32C3
by TiagoSantos in Circuits > Electronics
1257 Views, 3 Favorites, 0 Comments
Train Controller With Seeed Studio XIAO ESP32C3
For this project i'll control a lego train.I'll use a XIAO ESP32C3 to connect to the train. I'll also will use a Wemos D1 Mini for the controller.
Supplies
- Lego Train
- Seeed Studio ESP32C
- Perfboard
- Protoboard
- Logic Level Converter (5V<->3.3V)
- L293D
- Potenciometer
- AMS1117-5V
- AMS1117-3.3V
- Switch
- 0.96 inch ssd1306 LCD
- Wemos D1 Mini
- Dupont Cables
Intro
This is the Seeed Studio XIAO ESP32C3. This is a microcontroller thas Seeed Studio send me to test it.
Seeed Studio XIAO ESP32C
The XIAO ESP32C3 is a microcontroller based on ESP32-C3 CPU. Is a 32 bits RISC-V CPU with support for bluetooth 5.0, bluetooth mesh and Wi-Fi at 2.4ghz that supports Station mode, SoftAP mode, SoftAP & Station mode, and promiscuous mode 5.0. It has an ultra small size with 21 mm by 17.5 mm, ideal for projects with little space like Internet of things and wearables.
Is has multiple interfaces like UART, I2C, I2S, SPI, ADC and multiple GPIO. Nad like the XIAO nRF52840 it's also is breadboard friendly with no componet in the back.
On the power field it only consumes 44UA in deep sleep mode and, ike the XIAO nRF52840, has a built in lithium battery charger.
Train Side
On the train side the power is supplied by the 9V train power box. From this box it connects to two AMS1117. One converts to 5v and the other to 3.3V. With this i have three power rails: A 9V, a 5v and a 3.3V. Although the XIAO has a battery connector, i want to use only one power source, so i power it by the USB-C connector. The XIAO send the signal to a L293D motor driver that controls the train motor through a logic level converter tha converts the 3.3v signal toa 5v signal.
Controller Side
On the controller side i have a wemos d1 mini that receives the speed bay a potenciometer andthe direction by a switch. It also show the actual speed on a 0.96 inch ssd1306 LCD. This componets are all power by the Wemos, that is power by his Micro-USB connector.
Lego Trains
Usualy the Lego trains control have multiple parts:
- A remote controller;
- A battery box;
- An IR receiver;
- The motor.
With one remote is possible to control 8 trains changing the transmit channel.
Prototipe
For this project the first step is solder the XAO headers. This will permit to place it on a perfboard easily and reuse in the future. When solder pins on a chip they must solder them interleaved to avoid overheating in the components.
Controller Side
Next step is make the prototipe. This is made following the inicial sketch. In this case this is the prototipe for the controller.
Next is time for the perfboard. When prototipyng a project first i create a manual perfboard circuit for quick testing and after all is checked, make the final PCB. One inportant step on making the perfboard is checking for short circuits between pins.
One cool feature os the perfboard are the fact that can be snapped easily.
Enclosure
For the encousure i use Autodesk Fusion 360 an printed all in PLA on a 3D printer. Next it's time to start the assembly. Again, being a prototype it can be all fixed with hot glue.
I also print a label in resin to easy understand of the buttons. The final step is testing all.
For doing the label i use Autodesk Fusion 360 and Chitubox for slicing.
Train Side
On the train connect part, i placed it on a small protoboard tha will be placed on the top of the train. In future, when making the final PCB, one important feature will be to fit inside of the train.
To power the XIAO i use a micro-USB cable cuted in half. To check the pinout and see what is VCC and ground, in this case, the iasy way is test on the USB side and not on micro-USB side because the size of the plug. In USB pinout the VCC is the pin at the right and the ground the pin at the left. In this case is the red and black cables.
After the cable is identified it's time to place dupont headers for easy connect to the protoboard. Finally i place a micro-USB to USB-C converter to connect to the XIAO and test it.
How It Works
The controller connects to WIFI and sends the speed and the direction using a MQTT server. The connector also connects to wifi, to the same MQTT topic, reads the info and apllies. Because the potenciometer is analog and linear, and because the standard Lego train speeds are 7, i create seven intervals on the potenciomenter range. Only chages the speed when changes the interval. All the code will be avaiable on my GitHub account for download.
Because i'm using MQTT theres a delay between the controller and the train
Final Result
Finaly is time to attach the connector to the train an test it.
I have another projects that you may like. Don't forget to check out.
Thanks to Seeed Studio for sending the micro controller to test it.
I hope you like this project.
You can follow my projects on my social networks: