It’s time to code up the ESP32 Utility Driver. I am not that found of Arduino IDE, but it works and I like the wire library concept and how it simplify things. A Servo port is a signal that send a 50Hz pulse. The technique I suggest is a bit-banger where we loop as fast as we can checking pulse length. We set up the 12 signals in a table, start them at the same time and then iterate as fast as we can closing them at the proper time to get a correct pulse length.
The alternative is to use an interrupt. This could work, but we would get a resolution of 1ms (1000/sec) or 0.1ms(10000/sec) max. Any interrupt faster than that would use to much CPU time. Another technique would be to bit-bang signal 1, then signal 2 etc. this is what the classic Arduino library does. The technique I suggest gives a much higher resolution as we iterate and check much faster that we can use interrupts.
This would have worked well with a single core, but as we have a dual core we can allocate this task to one core and I expect something like 10uS accuracy or 100Khz sampling if we use this as data sampler.
We have 21 IO ports to maintain in an iteration:
- 12 Servo or IO ports
- 2 (4) H-Bridge signals
- 7 PWM signals
ESP32 is perfect for this job as we can use 1 core for this purpose while the second core handle the Wifi and easyIPC that I will return to later.
This ESP32 based Utility driver is just awesome in what it can do. I have to make a Rev 1.1, but for most parts it worked “as is”
- 7 x PWM Signals 0,5A each.
- CH340G UART to USB.
- ESP32 WROOM.
- 12 x Servo or IO ports.
- 12V PSU Input.
- 2 x H-Bride for DC Motors.
I had 2 errors on the board. (1) I did not cross Rx/Tx correctly and (2) I overlooked some logic needed for the serial bootloader. The later forces me to use the boot jumper all the time, but I will fix that on Rev 1.1. The schematics below illustrate the bootloader fix:
This is copied from the reference diagram at expressif and indicate how DTR and RTS on the serial interface is used to automatically toogle ChipPU and Boot as we download new firmware. This should avoid the need to set the boot jumper and restart to trigger the serial bootloader protocol. I will see if I can test this on a vero board before ordering 1.1 rev of the PCB’s.
The LMR14206 ripple was a bit much for my taste. It worked, I had 12V out, 3V3 out and the MCU ticked. But, it’s not a design I can live with. For now I continue on a different board and avoid mounting the DC/DC because I also realized that I could not really bypass it they way I had set up the jumpers. I decided for a 78M05 in TO252 format that gives 0,5A. But, for now I will use 12V directly.
This will work for now. I will return to DC/DC later, but looking at other peoples postings and the lack of LMR14206 popularity I get the picture.
The supercap in the schematics works well, but I probably need to add a bit of circuitry like I did on on PLC Com module. I use a 0.33F due to the size.
I bought this robot arm a few years back for educational purposes. It’s great fun, but a bit limited in what it can do. The robot consist of 5 DC motors, but no sensors indicating position, so it is basically remote operated with no option for automation. I did create a RPI Hat dedicated for this one, but even that require a RPI that add to it’s size. ESP32 is so much neater as it replaces both RPI and the IO MCU.
This block diagram is based on the Train Utility Driver as I just remove the PWM signals and increase the number of H-Bridges to 5+ 1/2.
If you compare with the Train Utility Controller you will see that this have 6 H-Bridges on right side. It actually is 5 H-Bridges and 1 PWM signal. The illustration show right angle connectors, but this will mostly use straight connectors.
That said I want to wait a bit with this one until I get the others back and get a bit more experience with ESP32.
Early mornig fun. Just changed the driver to use USB (CH340G) and added a separate 12V supply and some jumpers to select power Source. It can now be driven from 12V or 5V and you can use 12V for PWM’s while using USB 5V for ESP32 etc to have some isolation. Also added pull-up for Boot/Reset and jumper to use them.
A bit more labels and TVS diodes on the left 12 x IO and we’re done. I must admit that this little fellow will see some usage.
My 12 legged robot comes to mine as this is a very small, compact alternative for this one. But, I need some experience with using ESP32 before I continue.
We have a lot of space on the Utility Driver, so I can afford to add some TVS diodes on the ports that go directly out. These are 3.3V and can only handle 6-12mA out – basically they can just about drive a Led with some care.
I also need to change UART0 pins + I would like to replace the RS485 port with an USB powered by CH340G – in which case the LM1117 can have a jumper selecting if it is powering 3.3V from USB or 12V. The advantage of this is that I get the Boot pin free.
I also need to add a pull-up on Reset and a way to Reset the ESP32.
And obviously – a power Led.
I found this schematics on esp32.com forum. I will add pull-up resistors on GPIO0 and EN as well as route them to the extension bus on the TCS. I also need to change pins so I use pin 34/35 as UART0.
UARTS can be assigned to any GPIO pins, but in this case I need to know where it is after Reset and how we boot firmware on a clean system.
As for the FTDI chip above – I apologize for this – You will NEVER see a FTDI chip on any of my designs!
This is a draft of the Utility Driver. Basically this is a ESP32 based driver board with 7 PWM lines, 2 H-Bridges, 12 IO lines and a RS-X connection. The board can be used as a wired/wireless utility board.
- ESP32 Wroom
- 7×2 PWM connectors
- 2 x H-Bridge Motor ports
- RS-X port w 12V Power inn.
- Jumper to select 3.3V or 12V on signal channels.
- 12 x Signal channels. Can be analogie in, Digital In/Out, Servo, I2S, I2C, UART, SPI, PWM or others.
With a small controller in each train I need a standard wireless router, a train central and Train Utility Drivers to have a complete system. I also need a HMI, but I will use the HMI Browser for this.
The Utility Driver based on ESP32 (actually ESP WROOM 32) already contains Wifi/Bluetooth. But it is sometimes nice to have wired alternatives to reduce radio density (collisions) so we add RS-X. On the driver side we add an ULN2003 providing 7 PWM channels for lights etc. We ad a few H-Bridges and min 8 input channels for analogue/digital.
This shows the new Train Model Control System based on ESP-WROOM-32. The full size is 19.5 x 26.6 mm. The old one was 20 x 30 and I needed to cut it down from 30 to fit in my smallest cockpit.
Pin 1,2 & 9 are GPIO. Pin 7 & 8 can also be used as GPIO.
Pin 3 & 4 are 12V AC or DC Power. I am using a small rectifier bridge even if I only plan 12V DC. The 3.3V Regulator is a classic LM1117.
Pin 5 & 6 is the H-Bridge using a L9110.
Pin 7 & 8 is the UART for programming the ESP32. This is basically only needed for first time factory config, so 5&6 can be used as GPIO pins.
Pin 10 is Ground.
Notice that it is 3mm pads on the connector so wires can be connected on the surface, but it is also possible to attach a pin header with some work. It can’t go though so soldering the pins will require some care.
The design require an isolater tape between ESP32 and the PCB.
I have never programmed one of these, but I believe we just set the Wifi correct and work through this. The UART ahould only be needed as backup – but, we will learn as we go.
I will wrap up full schematics and gerbers later, but I prefer to do that after initial testing.