Module: gpio

Module to access pins for general purpose input/output. Also supports reading pins voltage via ADC and setting pins via PWM.
Source:

Classes

GPIOPin

Members

(static) ANALOG

Flag for GPIOPin.getValue. Retrieves voltage of pin via ADC (0 = 0 V, 1 = board voltage, usually 3.3 V).
Source:

(static) ANALOG_ATTEN_DB_0

Analog measurements up to 1.1 V, mediocre quality. For use with setAnalogAttenuation. Only available if not on neonious one, as neonious one always allows up to 3.3 V at industry-standard precision (uses LPC822 for ADC, not the ESP32).
Source:

(static) ANALOG_ATTEN_DB_2_5

Analog measurements up to 1.5 V. For use with setAnalogAttenuation. Only available if not on neonious one, as neonious one always allows up to 3.3 V at industry-standard precision (uses LPC822 for ADC, not the ESP32).
Source:

(static) ANALOG_ATTEN_DB_6

Analog measurements up to 2.2 V. For use with setAnalogAttenuation. Only available if not on neonious one, as neonious one always allows up to 3.3 V at industry-standard precision (uses LPC822 for ADC, not the ESP32).
Source:

(static) ANALOG_ATTEN_DB_11

Analog measurements up to 3.3 V, worst quality. Default setting on program startup. For use with setAnalogAttenuation. Only available if not on neonious one, as neonious one always allows up to 3.3 V at industry-standard precision (uses LPC822 for ADC, not the ESP32).
Source:

(static) BUTTON :Number

The pin number for the user defined button = 27. Only defined on the neonious one.
Type:
  • Number
Source:

(static) DIGITAL

Flag for GPIOPin.getValue. Retrieves level of pin (exact 0 or 1).
Source:

(static) HIGH :Number

High level = 1
Type:
  • Number
Source:

(static) INPUT

Pins set to this type are input pins.
Source:

(static) INPUT_PULLDOWN

Pins set to this type are input pins with the internal pulldown resistor active.
Source:

(static) INPUT_PULLUP

Pins set to this type are input pins with the internal pullup resistor active.
Source:

(static) LED_GREEN :Number

The pin number for the green LED = 2. Only defined on the neonious one.
Type:
  • Number
Source:

(static) LED_RED :Number

The pin number for the red LED = 1. Only defined on the neonious one.
Type:
  • Number
Source:

(static) LOW :Number

Low level = 0
Type:
  • Number
Source:

(static) OUTPUT

Pins set to this type are output pins.
Source:

(static) OUTPUT_OPENDRAIN

Pins set to this type are output pins where level 1 is defined as not connected. Great for implementing busses. To use these, you need to use an external pull-up.
Source:

(static) pins :Array.<GPIOPin>

Access all pins via this array. The index is the pin number.
Type:
  • Array.<GPIOPin>
Source:

Methods

(static) getFrequency() → {Number}

Returns the frequency of the PWM pins.
Source:
Returns:
in Hz, default: 100 Hz
Type
Number

(static) getValues(callback)

Retrieves the levels of all pins which are set to input at once, via bit array.
Parameters:
Name Type Description
callback GPIOGetValuesCallback the callback called with the input levels
Source:

(static) setFrequency(frequency)

Set the frequency of the PWM pins.
Parameters:
Name Type Description
frequency Number in Hz, default: 100 Hz
Source:

(static) setValues(bits, bitsHiopt)

Allows to set all pins which are set to output at once, via bit array. PWM pins are not modified.
Parameters:
Name Type Attributes Description
bits Number the values for the first 32 pins as bit array
bitsHi Number <optional>
the values for the pins 33-39. Only required on plain ESP32-WROVER, as the bit numbering on the device is clumbersome: Even though there are less usable pins as with the neonious one, there are more pin numbers.
Source:

(inner) setAnalogAttenuation(attenuation)

Only available if not on neonious one. Allows to set the attenuation of the ESP32 ADC. The ESP32 ADC is a quite bad design: Depending on the range you want to measure (between 1.1 V and 3.3 V) you get mediocre or very bad accuracy. For industry-standard accuracy, use the ADC on the neonious one which is provided by the LPC822 chip instead.
Parameters:
Name Type Description
attenuation gpio.ANALOG_ATTEN_DB_0 | gpio.ANALOG_ATTEN_DB_2_5 | gpio.ANALOG_ATTEN_DB_6 | gpio.ANALOG_ATTEN_DB_11 to use. Default: gpio.ANALOG_ATTEN_DB_11
Source:

Type Definitions

GPIOGetValueCallback(errnullable, valueopt)

Callback for retrieval of the level or voltage (ADC) of an input pin
Parameters:
Name Type Attributes Description
err Error <nullable>
optional error. If not null, the next parameters are not set
value Number <optional>
if gpio.DIGITAL was used exactly 0 or 1, if ANALOG was used a value from 0 (= 0V) to 1 (= board voltage).
Source:

GPIOGetValuesCallback(errnullable, bitsopt, bitsHiopt)

Callback for retrieval of the levels of all input pins at once.
Parameters:
Name Type Attributes Description
err Error <nullable>
optional error. If not null, the next parameters are not set
bits Number <optional>
the values for the first 32 pins as bit array
bitsHi Number <optional>
the values for the pins 33-39. Only set on plain ESP32-WROVER, as the bit numbering on the device is clumbersome: Even though there are less usable pins as with the neonious one, there are more pin numbers.
Source:

Events

fall

Fires on GPIOPin if the pin is set to gpio.INPUT, gpio.INPUT_PULLUP or gpio.INPUT_PULLDOWN and the level of the pin falls to 0
Parameters:
Name Type Description
timestamp Number Offset in milliseconds from boot. Resolution on ESP32: 1 microsecond, on LPC822: 33.333... nanoseconds. May reset to 0 every few days. Base/boot timestamp/0 is different between ESP32 and LPC822 pins and should not be compared between these pins.
Source:

rise

Fires on GPIOPin if the pin is set to gpio.INPUT, gpio.INPUT_PULLUP or gpio.INPUT_PULLDOWN and the level of the pin rises to 1
Parameters:
Name Type Description
timestamp Number Offset in milliseconds from boot. Resolution on ESP32: 1 microsecond, on LPC822: 33.333... nanoseconds. May reset to 0 every few days. Base/boot timestamp/0 is different between ESP32 and LPC822 pins and should not be compared between these pins.
Source: