Some kids love motorized toys, cars, trucks and basically anything that makes a noise or have a motor can be a child's toy.
I've been searching for a quick, simple, cheap, generic option to replace the remote controls with something I can easily source without building a specialized PCB or costing too much and I think I've found that option.
This is the
battlebot I've been using it for, the original controller stopped working after 3 minutes.
Wemos D1 R32
The Wemos D1 R32 is ESP32 in Arduino Uno form factor. The pinout is standard while still allowing access to all Arduino Uno standard pins and GPIO2 for onboard led. The schematics are available.
L293D Motor Control Shield
The motor shield was originally created by Adafruit but has since become ubiquitous through other online shops.
But it was designed to work with Arduino Uno so I had to go through the schematic to understand how the ESP32 should access it.
DIR_SER - GPIO12
PWM1A - GPIO13 - servo2
PWM1B - GPIO5 - servo1
PWM2A - GPIO23 - dc1
DIR_LATCH - GPIO19
DIR_EN - GPIO14
PWM0A - GPIO27 - dc4
PWM0B - GPIO16 - dc3
DIR_CLK - GPIO17
PWM2B - GPIO25 - dc2
Bluepad32
Bluepad32 was created by Ricardo Quesada, it was designed to to allow using newer gamepad controllers with retro gaming consoles.
While it has a long list of supported controllers, I've found that the DualShock 4 works best for me.To pair the DualShock 4 to ESP32 you'll need to turn it on while pressing the "SHARE" button and PS Button.
Firmware
After mapping the pins between the ESP32 and the Motor Shield, I needed to write a new Bluepad32 platform, I've called mine uni_platform_motor. The new platform uses Adafruit's AFMotor to control the motors, but you can use anything else you'd like to control.
The uni platform has the following important events:
- on_init_complete - which fires when the platform is initialized
- on_device_connected - where you can do motor arming
- on_device_disconnected - where you can do motor disarming, stopping the engines etc'
- on_gamepad_data - where you can process incoming joysticks and buttons processing and convert it into motors commands.
Porting AFMotor
The AFMotor was not designed for ESP32 and I did a very crude job of porting it since it was just to see if they can work together and it was good enough.
Please note that the Motor Driver uses a few pins that might not be mapped to GPIO, (for example: pin 14), to use these pins its not enough to use the gpio_set_direction, but rather you should use the more generic gpio_config.
Motor Direction Algorithm
Summary
The proposed solution enables relatively cheap components to be bound to a single remote and so I don't have to disassemble the controller or build my own.
Also, thinking about the future, it can be used for scratch or Arduino development with the same hardware so another one for the pros list.
Lastly, The DualShock4 can be used with other game consoles, PCs, TV Stocks etc' therefore future proofing the whole expense.
I would like to express my gratitude again to Ricardo Quesada for making the Bluepad32.
0 comments:
Post a Comment