Skip to main content

Nextion display serial client

Project description

Nextion serial client Build Status

Lightweight Python 3.5+ async library to control Nextion displays.

Installation

Pypi

pip install nextion

Simple usage:

import asyncio
import logging
import random

from nextion import Nextion, EventType

def event_handler(type_, data):
    if type_ == EventType.STARTUP:
        print('We have booted up!')

    logging.info('Event %s data: %s', type, str(data))

async def run():
    client = Nextion('/dev/ttyS1', 9600, event_handler)
    await client.connect()

    # await client.sleep()
    # await client.wakeup()

    # await client.command('sendxy=0')

    print(await client.get('sleep'))
    print(await client.get('field1.txt'))

    await client.set('field1.txt', "%.1f" % (random.randint(0, 1000) / 10))
    await client.set('field2.txt', "%.1f" % (random.randint(0, 1000) / 10))

    await client.set('field3.txt', random.randint(0, 100))

    print('finished')

if __name__ == '__main__':
    logging.basicConfig(
        format='%(asctime)s - %(levelname)s - %(message)s',
        level=logging.DEBUG,
        handlers=[
            logging.StreamHandler()
        ])
    loop = asyncio.get_event_loop()
    asyncio.ensure_future(run())
    loop.run_forever()

Event handling

event_handler method in the example above will be called on every event comming from the display.

EventType Data Data attributes
TOUCH TouchDataPayload page_id, component_id, touch_event
TOUCH_COORDINATE TouchCoordinateDataPayload x, y, touch_event
TOUCH_IN_SLEEP TouchCoordinateDataPayload x, y, touch_event
AUTO_SLEEP None -
AUTO_WAKE None -
STARTUP None -
SD_CARD_UPGRADE None -

For some components in the Nextion Editor you need to check Send Component ID for required event.

Additional resources:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nextion-1.4.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

nextion-1.4.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file nextion-1.4.0.tar.gz.

File metadata

  • Download URL: nextion-1.4.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.1

File hashes

Hashes for nextion-1.4.0.tar.gz
Algorithm Hash digest
SHA256 8b49598b43378f48d06e8fb82a1a8b34c4f321826cc79aafddcbe403b9fb988c
MD5 be4c56a50836bf3506b0c977fe6a9a2e
BLAKE2b-256 87567e4326efeadcaca5f9bc7c94cf5cc4b59e03bc3da029d85ae5b03f8de905

See more details on using hashes here.

File details

Details for the file nextion-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: nextion-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.1

File hashes

Hashes for nextion-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 671ac282f274b5570d9f1bd181a275c88ba796231fa1632a1f4a867946cf6c5e
MD5 4acf07fd3c2fce50811099f898392a37
BLAKE2b-256 c61a3011bf1fa58b11f3adaf68f3d84ca33e269a89688ced18995d7ab51714f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page