ESP32: Customizing - Paciente8159/uCNC GitHub Wiki

µCNC for ESP32 can be configured/customized to fit different ESP32 powered boards other than Arduino WeMos D1 R32

Jump to section

Customizing boardmap

µCNC for ESP32 can be customized either using the Web Config Tool or by manually modifing the source code files. For the latest method most configurations and pin assigning should be done in the corresponding boardmap file inside the uCNC/src/hal/boards/esp32/ directory and then the respective board file.

Configure IO pin

An HAL pin need to be mapped to a physical IO pin. The way this is done is by defining the IO BIT. There is no need do define IO PORT on this MCU. This must be performed for every used pin. ESP32 PORT is ignored This is similar to the general customization instructions

//set pin D2 as STEP0 (output pin) 
#define STEP0_BIT 16 // assigns STEP0 pin
//set pin B3 as PWM0 (pwm output pin) 
#define PWM0_BIT 2  // assigns PWM0 pin

Input pin options

Weak input pull-ups

All input pins can have a weak pull-up activated to drive them high if unconnected. This is similar to the general customization instructions

External interrupt feature

All pins all repeatedly read by a soft polling routine. But for special function pins an interrupt driven event to force a reading and respective action can be also activated. This causes the response to be immediate and not depend on the pin reading routine cycle. For WeMos D1 R32 the pin mapping can be checked here. Arduino WeMos D1 R32 pin mapping

This is similar to the general customization instructions

Configure communications

By default ESP32 uses the UART0 port. It also makes available a telnet server to be able to connect via WiFi or BlueTooth. If not configured an ESP32 WiFi AP will be available. To access the WiFi setup connect to this network then open a browser and navigate to 192.168.4.1. Configure your home network parameters there. The device will then connect to your home WiFi and you will be able to communicate with it via telnet.

Configure pwm clock

On the ESP32 the PWM is software generated. Besides defining the IO pins nothing else is needed. The RTC timer is used for this function.

Configure analog channel

Although not used anywhere inside µCNC reading analog pins is possible. Beside configuring the pin like an input pin, two more definitions are needed to configure the ESP32 analog reading. These are setting the ADC and the channel for the conversion. For example on ESP32 ADC2-0 (Analog channel 0 of ADC 2) is on GPIO4. To configure it as µCNC's ANALOG0 input add the following code to the boardmap file:

#define ANALOG0_BIT 4
#define ANALOG0_ADC 2 // select ADC
#define ANALOG0_CHANNEL 0 //ADC channel 0

To make a read just do

uint8_t value = mcu_get_analog(ANALOG0);

Configure step generator timer

All step and dir pins are modified inside a timer ISR (µCNC's heartbeat). In the ESP32 Timer1 (of 4 available Timers) is used by default. RTC is guaranteed by a FreeRTOS task and there is no need to configure it.

Configure servo pins

This is similar to the general customization instructions

Configure WiFi and Bluetooth

Both WiFi and Bluetooth share the same transition hardware. Enabling them both might lead to unexpected behavior and poor performance. Both WiFi and Bluetooth also save their last state. On power on their previous state (enabled or disabled) will automatically be reinstated.

WiFi interface exposes the following system commands that can be used to configure and control WiFi:

$wifion - this enables WiFi. When this command is issued all changes made to the WiFi settings are stored.
$wifioff - this disables WiFi. When this command is issued all changes made to the WiFi settings are stored.
$wifireset - this resets all WiFi settings.
$wifisave - this saves all WiFi settings. Settings will only be in effect after disabling and enabling the WiFi.
$wifiscan - scans all available WiFi AP's.
$wifissid - gets the current defined AP SSID.
$wifissid=<ssid> - (text) sets the current defined AP SSID.
$wifipass=<pass> - (text) sets the current WiFi password.
$wifimode=<mode_number> - (number) sets the WiFi mode.  1-STA+AP, 2-STA, 3-AP
$wifiip - gets the board IP address

Bluetooth interface exposes the following system commands that can be used to control BLE module:

$bthon - this enables WiFi. When this command is issued all changes made to the WiFi settings are stored.
$bthoff - this disables WiFi. When this command is issued all changes made to the WiFi settings are stored.
⚠️ **GitHub.com Fallback** ⚠️