Why not? Raspberry Pi 4b is more than capable of programming an ESP32 module via its native 3.3 V RS232 port which is available through its 40-pin connector. ESP32 module RxD0 pin must be connected to Raspberry Pi 4b TxD0 pin (GPIO14) and ESP32 module TxD0 pin must be connected to Raspberry Pi RxD0 pin (GPIO16). ESP32 module EN and GPIO0 (boot/programming mode selection) pins must also be controlled by the Raspberry Pi 4b. I connected Raspberry Pi GPIO17 pin to ESP32 module EN pin and Raspberry Pi 4b GPIO18 pin to ESP32 module GPIO0 pin. I also used ESP32 module GPIO23 pin to control Raspberry Pi global enable pin via BC109C transistor.
Raspberry Pi 4b also needs a software library package to directly control GPIO17 and GPIO18 states. Though there are a number of software packages available from the Internet, it is hard to find (and build from source code if executables are not provided) a working package for a 64-bit operating system. Therefore, it may not be a bad idea to stick to a 32-bit Raspberry Pi OS or other 32-bit Linux version for now. I installed wiringPi package, which internally interprets GPIO17 as GPIO0 and GPIO18 as GPIO1. The package also installs gpio command, which can be used from a console to control GPIOs without any programming. To set ESP32 module in programming mode type:
gpio 0 out
gpio 1 out
gpio 0 write 0
gpio 1 write 0
gpio 0 write 1
To normally boot ESP32 module type:
gpio 0 out
gpio 1 out
gpio 0 write 0
gpio 1 write 1
gpio 0 write 1
The remote power on/off controller circuit is designed to normally start Raspberry Pi even with a new ESP32 module with no firmware. It also automatically boots when its power supply is restored, which is determined by resistor pull-ups on EN and GPIO0 lines (see the circuit).
Next, Arduino IDE and Espressif Systems ESP32 board plugin must be installed (see instructions from various Arduino related internet sites). Select ESP32 Dev module and select /dev/ttyS0 port and 115200 kbps speed to verify connection through Arduino IDE serial interface window. You may also test GPIOs operation.
Start ESP32 in programming mode (see the procedure above), compile and upload the firmware with Arduino IDE. My firmware source code is provided from PC USP Projects Download site (ESP32-RasberryPi-controller.zip). It also worth to note that Raspberry Pi uses a native RS-232 interface and it is therefore faster and more reliable.
Telnet terminal emulator application and testingMy ESP32 module firmware is designed to accept telnet commands “-“ (Raspberry Pi 4b OFF), “+” (Raspberry Pi 4b ON) and “?” (displays Raspberry Pi 4b current power state and ESP32 module eeprom status). Any terminal emulation software that supports a telenet connection (ex. PuTTY) should do just fine. Android devices may use Terminus or a similar application.
Can the circuit be simplified?Yes. If you decide to preprogram ESP32 module on a PC, you can make a simple interface to USB to RS-232 bridge (FTDI interface) just for programming and you can remove it before in-building the ESP32 module to Raspberry Pi casing. Please, note that pull-up resistor on EN (enable input) must remain to properly boot the ESP32 module. The only lines that remain connected to Raspberry Pi 4b 40-pin expansion connector are GND and 5 V power supply and GPIO23 is connected to BC109C that controls global enable.
What about other Raspberry Pis?Raspberry Pi 3b has implementation of the global enable signal slightly differs from Rasbperry Pi 4b’s due to an inbuilt voltage divider. 1.8 k Ohm : 3.3 k Ohm voltage divider gives 3, 23 V on global enable pin when not connected to the ground, but BC109C transistor should still work the same. You may also connect global enable directly to ESP32 module.
What about Raspberry Pi 2b? It only has a 3.3 V run pin that must be connected to the ground to reset the microprocessor, but it has no global enable pin. The run pin may be used instead of the global enable pin, but power consumption in a disabled state would be higher that Raspberry Pi 3b’s or Raspberry Pi 4b’s.
However, the original Raspberry Pi have neither run nor global enable pins, so the circuit below may not be implemented.
Comments