ESP8266 ESP32 Compatibility - nodemcu/nodemcu-firmware GitHub Wiki

This document reflects conflicts between

and requirements to achieve larger degree of compatibility.

Base Modules

  • adc: configure ADC (Analog/Digital Converter), read
  • file: file operations, read/write
  • gpio: configure GPIO, read/write
  • i2c: configure I2C, read/write
  • spi: configure SPI, read/write
  • tmr: timer operations millisecond exact
  • net: client and server (tcp/udp) networking
  • node: general device information, cpu freq settings etc, read/write
  • uart: configure UART, read/write
  • wifi: configure WIFI (station/access-point)

adc

Function ESP8266 ESP32 Linux
init ADC adc.force_init_mode(node) adc.setup(adc_number,channel,atten)
read ADC adc.read() adc.read()
read system ADC adc.readvdd33()

ESP8266:

  • adc.force_init_mode(node) Checks and if necessary reconfigures the ADC mode setting in the ESP init data block.
    • mode:
      • adc.INIT_ADC
      • adc.INIT_VDD33
  • adc.read() Samples the ADC.
  • adc.readvdd33() Reads the system voltage.

ESP32:

  • adc.setup(adc_number,channel,atten)
    • adc_number Only adc.ADC1 now
    • channel When using adc.ADC1: 0 to 7. 0: GPIO36, 1: GPIO37, 2: GPIO38, 3: GPIO39, 4: GPIO32, 5: GPIO33, 6: GPIO34, 7: GPIO35
    • atten One of following constants
      • adc.ATTEN_0db The input voltage of ADC will be reduced to about 1/1 (1.1V when VDD_A=3.3V)
      • adc.ATTEN_2_5db The input voltage of ADC will be reduced to about 1/1.34 (1.5V when VDD_A=3.3V)
      • adc.ATTEN_6db The input voltage of ADC will be reduced to about 1/2 (2.2V when VDD_A=3.3V)
      • adc.ATTEN_11db The input voltage of ADC will be reduced to about 1/3.6 (3.9V when VDD_A=3.3V, maximum voltage is limited by VDD_A)
  • adc.read() Samples the ADC.

bit

bthci

can

dht

file

The object mode of file operations isn't implemented yet (file.read() vs src = file.open() src:read()) according dev-esp32 documentation.

Function ESP8266 ESP32 Linux
open file file.open() file.open() file.open()
close file file.close() file.close() file.close()
read file file.read() file.read() file.read()
write file file.write() file.write() file.write()
seek file file.seek() file.seek() file.seek()
flush file file.flush() file.flush() file.flush()
stat file file.stat() file.stat() file.stat()
list files file.list() file.list() file.list()
close file (object-based) file:close() file:close()
read file (object-based) file:read() file:read()
write file (object-based) file:write() file:write()
read line (object-based) file:readline() file:readline()
write line (object-based) file:writeline() file:writeline()
seek file (object-based) file:seek() file:seek()
flush file (object-based) file:flush() file:flush()

ESP8266:

  • file.obj:close() Closes the open file, if any.
  • file.obj:flush() Flushes any pending writes to the file system, ensuring no data is lost on a restart.
  • file.obj:read() Read content from the open file.
  • file.obj:readline() Read the next line from the open file.
  • file.obj:seek() Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence.
  • file.obj:write() Write a string to the open file.
  • file.obj:writeline() Write a string to the open file and append '\n' at the end.

ESP32:

  • all above listed are missing according documentation

gpio

Function ESP8266 ESP32 Linux
set single pin mode gpio.mode(pin,type,pullup) gpio.mode(pin,type,pullup)
set multiple pin mode gpio.config({gpio=..,dir=..,pull=..,opendrain=..})
trigger callback gpio.trig(pin,type,callback(level,when)) gpio.trig(pin,types,callback(pin,level))

ESP8266:

  • gpio.mode(pin,type,pullup)
    • type:
      • gpio.INPUT
      • gpio.OUTPUT
      • gpio.OPENDRAIN
      • gpio.INT
    • pullup:
      • gpio.FLOAT (default)
      • gpio.PULLUP enables the weak pull-up resistor
  • gpio.trig(pin,type,callback(level,when))
    • type: "up", "down", "both", "low", "high"

ESP32:

  • gpio.config({gpio=..,dir=..,pull=..,opendrain=..})

    • dir:
      • gpio.IN
      • gpio.OUT
      • gpio.IN_OUT
    • pull:
      • gpio.FLOATING disables both pull-up and -down
      • gpio.PULL_UP enables pull-up and disables pull-down
      • gpio.PULL_DOWN enables pull-down and disables pull-up
      • gpio.PULL_UP_DOWN enables both pull-up and -down
  • gpio.trig(pin,types,callback(pin,level))

    • type:
      • gpio.INTR_UP for trigger on rising edge
      • gpio.INTR_DOWN for trigger on falling edge
      • gpio.INTR_UP_DOWN for trigger on both edges
      • gpio.INTR_LOW for trigger on low level
      • gpio.INTR_HIGH for trigger on high level

i2c

ledc

net

node

Function ESP8266 ESP32 Linux
general info node.info() node.info()
chip id node.chipid() node.chipid() node.chipid()

ESP8266:

  • node.info() returns 8 elements:

    • majorVer (number)
    • minorVer (number)
    • devVer (number)
    • chipid (number)
    • flashid (number)
    • flashsize (number)
    • flashmode (number)
    • flashspeed (number)
  • node.chipid() returns an integer (last 3 bytes of the station MAC address)

ESP32:

  • node.info() missing
  • node.chipid() returns hex string with '0x' as prefix and 7 bytes whereas the last byte of the MAC address is dropped (risk of 256 identical chipids)

Linux:

  • node.info() reports 8 elements plus new 9th element the architecture 'linux' ('esp8266' or 'esp32' as other options)
  • node.chipid() reports last 3 octets of first network MAC address

ow (1-Wire)

sdmmc

sigma delta

spi

struct

tmr

Function ESP8266 ESP32 Linux
microsecond counter [integer] tmr.now() tmr.now()
second counter [integer] tmr.time() tmr.time()
seconds with us precision [float] tmr.uptime()

ESP8266:

  • tmr.now() returns microseconds [integer]
  • tmr.time() time in seconds since boot (uptime) [integer]
  • tmr.uptime() might not be available when integer only firmware

ESP32:

  • tmr.now() missing
  • tmr.time() missing
  • tmr.uptime() missing

Linux:

  • tmr.uptime() added, uptime with microsecond precision [float]

u8g2

u8g2 Display

uart

Function ESP8266 ESP32 Linux
change pins uart.alt()
set callbacks uart.on()1) uart.on()2)
setup uart.setup() uart.setup()
get config uart.getconfig()
write uart uart.write() uart.write()
start uart uart.start()
stop uart uart.stop()
  1. and 2) API has changed, not compatible.

ESP8266:

  • uart.alt(on) Change UART pin assignment (on: 0 = default, 1 = use alternate pins GPIO13 and GPIO15)
  • uart.on(method, [number/end_char], [function], [run_input]) Sets the callback function to handle UART events.
  • uart.setup() (Re-)configures the communication parameters of the UART.
  • uart.getconfig() Returns the current configuration parameters of the UART.
  • uart.write() Write string or byte to the UART.

ESP32:

  • uart.on([id], method, [number/end_char], [function], [run_input]) Sets the callback function to handle UART events.
  • uart.setup() (Re-)configures the communication parameters of the UART.
  • uart.start() Start the UART.
  • uart.stop() Stop the UART.
  • uart.write() Write string or byte to the UART.

wifi

ESP8266 and ESP32 differ a lot:

ESP8266

  • events are captured via wifi.eventmon.*:
    • wifi.eventmon.register(event[, function(T)])
      • wifi.eventmon.STA_CONNECTED
      • wifi.eventmon.STA_DISCONNECTED
      • wifi.eventmon.STA_AUTHMODE_CHANGE
      • wifi.eventmon.STA_GOT_IP
      • wifi.eventmon.STA_DHCP_TIMEOUT
      • wifi.eventmon.AP_STACONNECTED
      • wifi.eventmon.AP_STADISCONNECTED
      • wifi.eventmon.AP_PROBEREQRECVED

ESP32:

  • events are captured via wifi.on()
    • wifi.ap.on(event, callback)
      • event:
        • start: no additional info
        • stop: no additional info
        • sta_connected: information about the client that connected:
        • mac: the MAC address
        • id: assigned station id (AID)
        • disconnected: information about disconnecting client
        • mac: the MAC address
        • probe_req: information about the probing client
        • from: MAC address of the probing client
        • rssi: Received Signal Strength Indicator value

ws2812

⚠️ **GitHub.com Fallback** ⚠️