API

Nextion Constants

Const

This file contains the constant definitions of all Nextion commands

nextion.const.NEX_END_CMD = b'\xff\xff\xff'

End command

nextion.const.NEX_RET_CMD_FINISHED = <Mock name='mock.const()' id='139649435173984'>

Command finished

nextion.const.NEX_RET_CURRENT_PAGE_ID_HEAD = <Mock name='mock.const()' id='139649435173984'>

Current page ID head

nextion.const.NEX_RET_EVENT_LAUNCHED = <Mock name='mock.const()' id='139649435173984'>

Event launched

nextion.const.NEX_RET_EVENT_POSITION_HEAD = <Mock name='mock.const()' id='139649435173984'>

Event position head

nextion.const.NEX_RET_EVENT_SLEEP_POSITION_HEAD = <Mock name='mock.const()' id='139649435173984'>

Event sleep position head

nextion.const.NEX_RET_EVENT_TOUCH_HEAD = <Mock name='mock.const()' id='139649435173984'>

Event touch head

nextion.const.NEX_RET_EVENT_UPGRADED = <Mock name='mock.const()' id='139649435173984'>

Event upgraded

nextion.const.NEX_RET_INVALID_BAUD = <Mock name='mock.const()' id='139649435173984'>

Invalid baudrate

nextion.const.NEX_RET_INVALID_CMD = <Mock name='mock.const()' id='139649435173984'>

Invalid command

nextion.const.NEX_RET_INVALID_COMPONENT_ID = <Mock name='mock.const()' id='139649435173984'>

Invalid component ID

nextion.const.NEX_RET_INVALID_FONT_ID = <Mock name='mock.const()' id='139649435173984'>

Invalid font ID

nextion.const.NEX_RET_INVALID_OPERATION = <Mock name='mock.const()' id='139649435173984'>

Invalid operation

nextion.const.NEX_RET_INVALID_PAGE_ID = <Mock name='mock.const()' id='139649435173984'>

Invalid page ID

nextion.const.NEX_RET_INVALID_PICTURE_ID = <Mock name='mock.const()' id='139649435173984'>

Invalid picture ID

nextion.const.NEX_RET_INVALID_VARIABLE = <Mock name='mock.const()' id='139649435173984'>

Invalid variable

nextion.const.NEX_RET_NUMBER_HEAD = <Mock name='mock.const()' id='139649435173984'>

Number head

nextion.const.NEX_RET_STRING_HEAD = <Mock name='mock.const()' id='139649435173984'>

String head

Common module

Common

Common functions shared accross all Nextion elements

Check the description of Mixin https://realpython.com/lessons/multiple-inheritance-python/

class nextion.common.Common(nh, pid: int, cid: int, name: str)[source]

Bases: object

docstring for Common

property cid: int

Get component ID of element

Returns

Component ID

Return type

int

hide() bool[source]

Hide component on screen

Returns

True on success, false otherwise

Return type

bool

property name: str

Get name of element

Returns

Name of element

Return type

str

property pid: int

Get page ID of element

Returns

Page ID

Return type

int

show() bool[source]

Show component on screen

Returns

True on success, false otherwise

Return type

bool

class nextion.common.CommonBackgroundColorMixin[source]

Bases: object

docstring for CommonBackgroundColorMixin

Get_background_color_bco() int[source]

Get background color attribute of component

Returns

The background color

Return type

int

Set_background_color_bco(number: int) bool[source]

Set background color attribute of component

Parameters

number (int) – The background color number

Returns

True on success, false otherwise

Return type

bool

exception nextion.common.CommonError[source]

Bases: Exception

Base class for exceptions in this module.

class nextion.common.CommonFontMixin[source]

Bases: object

docstring for CommonFontMixin

Get_font_color_pco() int[source]

Get font color attribute of component

Returns

The font color

Return type

int

Set_font_color_pco(number: int) bool[source]

Set font color attribute of component

Parameters

number (int) – The font color number

Returns

True on success, false otherwise

Return type

bool

getFont() int[source]

Get font attribute of component

Returns

The font color

Return type

int

setFont(number: int) bool[source]

Set font attribute of component

Parameters

number (int) – The font number

Returns

True on success, false otherwise

Return type

bool

class nextion.common.CommonPointerMixin[source]

Bases: object

docstring for CommonPointerMixin

Get_pointer_thickness_wid() int[source]

Get pointer wid attribute of component

Returns

The pointer thickness

Return type

int

Set_pointer_thickness_wid(number: int) bool[source]

Set pointer hig attribute of component

Parameters

number (int) – The pointer thickness

Returns

True on success, false otherwise

Return type

bool

class nextion.common.CommonPositionMixin[source]

Bases: object

docstring for CommonPositionMixin

Get_place_xcen() int[source]

Get xcen attribute of component

Returns

The x position

Return type

int

Get_place_ycen() int[source]

Get ycen attribute of component

Returns

The y position

Return type

int

Set_place_xcen(number: int) bool[source]

Get xcen attribute of component

Parameters

number (int) – The new x position

Returns

True on success, false otherwise

Return type

bool

Set_place_ycen(number: int) bool[source]

Get ycen attribute of component

Parameters

number (int) – The new y position

Returns

True on success, false otherwise

Return type

bool

class nextion.common.CommonTextMixin[source]

Bases: object

docstring for CommonTextMixin

getText() str[source]

Get text attribute of component

Returns

The text.

Return type

str

setText(text: str) bool[source]

Set text attribute of component

Parameters

text (str) – The text

Returns

True on success, false otherwise

Return type

bool

class nextion.common.CommonValueMixin[source]

Bases: object

docstring for CommonValueMixin

getValue() int[source]

Get value attribute of component

Returns

The value.

Return type

int

setValue(value: int) bool[source]

Set value attribute of component

Parameters

text (int) – The value

Returns

True on success, false otherwise

Return type

bool

Button

NexButton

Functions to interact with a Nextion Button element

class nextion.nextion_button.NexButton(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonPositionMixin, CommonTextMixin

docstring for NexButton

Get_press_background_color_bco2() int[source]

Get the pressed background color

Returns

The pressed background color bco2

Return type

int

Get_press_font_color_pco2() int[source]

Get the pressed font color

Returns

The pressed font color pco2

Return type

int

Set_press_background_color_bco2(number: int) bool[source]

Set the pressed background color

Parameters

number (int) – The background color number

Returns

True on success, false otherwise

Return type

bool

Set_press_font_color_pco2(number: int) bool[source]

Set the pressed font color

Parameters

number (int) – The font color number

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_button.NexButtonError[source]

Bases: Exception

Base class for exceptions in this module.

Checkbox

NexCheckbox

Functions to interact with a Nextion Checkbox element

class nextion.nextion_checkbox.NexCheckbox(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonValueMixin

docstring for NexCheckbox

exception nextion.nextion_checkbox.NexCheckboxError[source]

Bases: Exception

Base class for exceptions in this module.

Dual State Button

NexDSButton

Functions to interact with a Nextion dual state Button element

class nextion.nextion_dual_state_button.NexDSButton(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonFontMixin, CommonPositionMixin, CommonTextMixin, CommonValueMixin

docstring for NexDSButton

Get_state0_color_bco0() int[source]

Get bco0 attribute of component

Returns

The background color

Return type

int

Get_state1_color_bco1() int[source]

Get bco1 attribute of component

Returns

The background color

Return type

int

Set_state0_color_bco0(number: int) bool[source]

Set bco0 attribute of component

Parameters

number (int) – The background color number

Returns

True on success, false otherwise

Return type

bool

Set_state1_color_bco1(number: int) bool[source]

Set bco1 attribute of component

Parameters

number (int) – The background color number

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_dual_state_button.NexDSButtonError[source]

Bases: Exception

Base class for exceptions in this module.

Gauge

NexGauge

Functions to interact with a Nextion Gauge element

class nextion.nextion_gauge.NexGauge(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonPointerMixin, CommonValueMixin

docstring for NexGauge

exception nextion.nextion_gauge.NexGaugeError[source]

Bases: Exception

Base class for exceptions in this module.

GPIO

NexGpio

Functions to interact with Nextion GPIOs

class nextion.nextion_gpio.NexGpio(nh)[source]

Bases: Common

docstring for NexGpio

analog_write(port: int, value: int) bool[source]

Set analog value (PWM wave) to a pin

Parameters
  • port (int) – The GPIO port number

  • value (int) – The duty cycle value (0-100)

Returns

True on success, false otherwise

Return type

bool

digital_read(port: int) int[source]

Read a HIGH or a LOW value of a digital pin

Parameters

port (int) – The GPIO port number

Returns

Value of specified digital pin, either 1 or 0

Return type

int

digital_write(port: int, value: int) bool[source]

Write a HIGH or LOW value to a digital pin

Parameters
  • port (int) – The GPIO port number

  • value (int) – The value (0 or 1)

Returns

True on success, false otherwise

Return type

bool

get_pwmfreq() int[source]

Get the PWM output frequency

Returns

The PWM frequency.

Return type

int

pin_mode(port: int, mode: int, control_id: int = 0) bool[source]

Set GPIO mode

Parameters
  • port (int) – The GPIO port number

  • mode (int) – The GPIO port mode 0 - Pull on the input 1 - the control input binding 2 - Push-pull output 3 - pwm output 4 - open mode leakage

  • control_id (int) – The bound CID of other nextion element

Returns

True on success, false otherwise

Return type

bool

set_pwmfreq(value: int) bool[source]

Set the PWM output frequency for all pins

Parameters

value (int) – The PWM frequency (1-65535)

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_gpio.NexGpioError[source]

Bases: Exception

Base class for exceptions in this module.

Hardware

Common

This class performs the basic and common interactions with the Nextion display

Known issues
class nextion.nextion_hardware.NexHardware(rx_pin: int, tx_pin: int, uart_id: int = 1, baudrate: None = 9600, timeout: None = 100, invert: None = 0, logger: None = None)[source]

Bases: object

docstring for NexHardware

_uart_init() None[source]

Init UART instance

brightness(value: int) None[source]

Set brightness of display

Parameters

value (int) – The value in percent [0, 100]

static create_logger(logger_name: None = None) Logger[source]

Create a logger.

Parameters

logger_name (str, optional) – The logger name

Returns

Configured logger

Return type

logging.Logger

nexInit() bool[source]

Init Nextion interface to display

Returns

Result of init, True on success, False otherwise

Return type

bool

recvRetCommandFinished(timeout: int = 100) bool[source]

Command is executed successfully

Parameters

timeout (int) – The communication timeout

Returns

True on success, False otherwise

Return type

bool

recvRetNumber(timeout: int = 100) int[source]

Receive a uint32_t number

Parameters

timeout (int) – The communication timeout

Returns

Received number

Return type

int

recvRetString(timeout: int = 100) str[source]

Receive a string

Parameters

timeout (int) – The communication timeout

Returns

Received string

Return type

int

reset() None[source]

Reset display like on a power cycle

sendCommand(cmd: str) None[source]

Send a command to the Nextion serial display.

Parameters

cmd (str) – The command

sleep(state: bool) None[source]

Control display sleep state

Parameters

state (bool) – Flag, True is sleep mode, False is wakeup

exception nextion.nextion_hardware.NexHardwareError[source]

Bases: Exception

Base class for exceptions in this module.

Number

NexNumber

Functions to interact with a Nextion Number element

class nextion.nextion_number.NexNumber(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonPositionMixin, CommonValueMixin

docstring for NexNumber

Get_number_length() int[source]

Get length attribute of component

Returns

The number length

Return type

int

Set_number_length(number: int) bool[source]

Set length attribute of component

Parameters

number (int) – The number length

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_number.NexNumberError[source]

Bases: Exception

Base class for exceptions in this module.

Page

NexPage

Functions to interact with a Nextion Page element

class nextion.nextion_page.NexPage(nh, pid: int, cid: int, name: str)[source]

Bases: Common

docstring for NexPage

show() bool[source]

Show itself

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_page.NexPageError[source]

Bases: Exception

Base class for exceptions in this module.

Progressbar

NexProgressBar

Functions to interact with a Nextion Progressbar element

class nextion.nextion_progressbar.NexProgressBar(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonValueMixin

docstring for NexProgressBar

exception nextion.nextion_progressbar.NexProgressBarError[source]

Bases: Exception

Base class for exceptions in this module.

Radio Button

NexRadio

Functions to interact with a Nextion Radio element

class nextion.nextion_radio.NexRadio(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonValueMixin

docstring for NexRadio

exception nextion.nextion_radio.NexRadioError[source]

Bases: Exception

Base class for exceptions in this module.

RTC

NexRtc

Functions to interact with Nextion RTC

class nextion.nextion_rtc.NexRtc(nh)[source]

Bases: Common

docstring for NexRtc

read_rtc_time(return_type: str, length: None = 22) None[source]

Read RTC time

Parameters
  • return_type (str) – The return type, choose “int”, “str” or from [“year”, “mon”, “day”, “hour”, “min”, “sec”, “week”]

  • length (Optional[int]) – The length

Returns

RTC time

Return type

Union[str, List[int]]

property time_types: None

Get available time types

Returns

Requestable time types from RTC

Return type

List[str]

write_rtc_time(*args, **kwargs) bool[source]

Write time to RTC

Parameters
  • time (Union[str, List[int]]) – The time to set the RTC

  • time_type (str) – The type of time to change

Returns

True on success, False otherwise

Return type

bool

exception nextion.nextion_rtc.NexRtcError[source]

Bases: Exception

Base class for exceptions in this module.

Scrolltext

Slider

NexSlider

Functions to interact with a Nextion Slider element

class nextion.nextion_slider.NexSlider(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonPointerMixin, CommonValueMixin

docstring for NexSlider

Get_cursor_height_hig() int[source]

Get cursor hig attribute of component

Returns

The cursor height.

Return type

number

Set_cursor_height_hig(number: int) bool[source]

Set cursor hig attribute of component

Parameters

number (int) – The number

Returns

True on success, false otherwise

Return type

bool

getMaxval() int[source]

Get the maxval attribute of the component

Returns

The maxval

Return type

int

getMinval() int[source]

Get the minval attribute of the component

Returns

The minval

Return type

int

setMaxval(number: int) bool[source]

Set the maxval attribute of the component

Parameters

number (int) – The new maxval

Returns

True on success, false otherwise

Return type

bool

setMinval(number: int) bool[source]

Set the minval attribute of the component

Parameters

number (int) – The new minval

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_slider.NexSliderError[source]

Bases: Exception

Base class for exceptions in this module.

Text

NexText

Functions to interact with a Nextion Text element

class nextion.nextion_text.NexText(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin, CommonPositionMixin, CommonTextMixin

docstring for NexText

exception nextion.nextion_text.NexTextError[source]

Bases: Exception

Base class for exceptions in this module.

Upload

NexUpload

Functions to download TFT file to Nextion display

class nextion.nextion_upload.NexUpload(nh, file_name: str, download_baudrate: int)[source]

Bases: Common

docstring for NexUpload

_checkFile() bool[source]

Check existance of specified TFT file

Returns

True on success, False otherwise

Return type

bool

_downloadTftFile() bool[source]

Download TFT file to Nextion display

Returns

True on success, False otherwise

Return type

bool

_exists(path: str) bool[source]

Check existance of file at given path.

Parameters

path (str) – The path to the file

Returns

Existance of file

Return type

bool

_getBaudrate() int[source]

Get communication baudrate with Nextion display

Returns

The baudrate

Return type

int

_recvRetString(timeout: int = 100) bytearray[source]

Receive a string

Parameters

timeout (int) – The communication timeout

Returns

Received response

Return type

bytearray

_searchBaudrate(baudrate: int) bool[source]

Find suitable download baudrate

Parameters

baudrate (int) – The baudrate

Returns

True on success, False otherwise

Return type

bool

_setDownloadBaudrate(baudrate: int) bool[source]

Set the download baudrate

Parameters

baudrate (int) – The baudrate

Returns

True on success, False otherwise

Return type

bool

property download_baudrate: int

Get the download baudrate

Returns

Download baudrate for communication with Nextion display

Return type

int

property file_name: str

Get the update filename

Returns

Filename of update file

Return type

str

property file_size: int

Get the update filesize

Returns

Filesize of update file in bytes

Return type

int

upload() bool[source]

Perform update of Nextion display content

Returns

True on success, raise NexUploadError otherwise

Return type

bool

exception nextion.nextion_upload.NexUploadError[source]

Bases: Exception

Base class for exceptions in this module.

Variable

NexVariable

Functions to interact with a Nextion Variable element

class nextion.nextion_variable.NexVariable(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonTextMixin, CommonValueMixin

docstring for NexVariable

exception nextion.nextion_variable.NexVariableError[source]

Bases: Exception

Base class for exceptions in this module.

Waveform

NexWaveform

Functions to interact with a Nextion Waveform element

class nextion.nextion_waveform.NexWaveform(nh, pid: int, cid: int, name: str)[source]

Bases: Common, CommonBackgroundColorMixin, CommonFontMixin

docstring for NexWaveform

Get_channel_0_color_pco0() int[source]

Get channel0 pco0 attribute of component

Returns

The channel0 pco0

Return type

int

Get_grid_color_gdc() int[source]

Get grid color attribute of component

Returns

The grid color

Return type

int

Get_grid_height_gdh() int[source]

Get grid height attribute of component

Returns

The grid height

Return type

int

Get_grid_width_gdw() int[source]

Get grid width attribute of component

Returns

The grid width

Return type

int

Set_channel_0_color_pco0(number: int) int[source]

Set channel0 pco0 attribute of component

Parameters

number (int) – The channel0 pco0

Returns

True on success, false otherwise

Return type

bool

Set_grid_color_gdc(number: int) bool[source]

Set grid color attribute of component

Parameters

number (int) – The grid color number

Returns

True on success, false otherwise

Return type

bool

Set_grid_height_gdh(number: int) bool[source]

Set grid height attribute of component

Parameters

number (int) – The grid height

Returns

True on success, false otherwise

Return type

bool

Set_grid_width_gdw(number: int) bool[source]

Set grid width attribute of component

Parameters

number (int) – The grid width

Returns

True on success, false otherwise

Return type

bool

addValue(ch: int, number: int) bool[source]

Add value to waveform

Parameters
  • ch (int) – Channel of waveform (0-3)

  • number (int) – The value to add

Returns

True on success, false otherwise

Return type

bool

clearChannel(ch: int) bool[source]

Clear a channel of the waveform

Parameters

ch (int) – The channel to clear or 255 for all channels

Returns

True on success, false otherwise

Return type

bool

exception nextion.nextion_waveform.NexWaveformError[source]

Bases: Exception

Base class for exceptions in this module.