nextion
Communicate with ITEAD's Nextion HMI Devices
Status
- [x] Support all non-success/error return values
- [ ] Support all success/error messages
- [ ] Send operation commands
- [ ] Reasonable, high-level API; don't require user to send raw commands
- [ ] System-level abstraction
- [ ] Component-level abstraction
- [x] Tessel 2 support
- [ ] Remove
serialport
dependency
Basic Usage
COM Port, USB-to-UART adapter, etc.
const Nextion = require('nextion');
// CH340G usually shows up at this path on macOS
Nextion.fromPort('/dev/tty.SLAB_USBtoUART')
.then(nextion => {
console.log('Listening...');
nextion.on('touchEvent', data => {
console.log(data);
});
});
For port auto-detection, try:
const Nextion = require('nextion');
Nextion.create()
.then(nextion => {
// do exciting stuff here
});
Tessel 2
const tessel = require('tessel');
const Nextion = require('nextion/minimal');
const uart = new tessel.port.A.UART({
baudrate: 9600
});
Nextion.fromSerial(uart)
.then(nextion => {
// Yipper McCheese!
});
The nextion/minimal
module is for resource-constrained systems; it's compressed and does not include source maps.
Compatibility
As long as the argument passed into Nextion.fromSerial
is a Duplex stream or a duck-typed one (a la serialport), you should be able to use it. Hack away!
API Docs
TODO
Development
- Use environment variable
DEBUG=nextion*
for debug output. - To run end-to-end tests against a connected device, read
test/e2e/README.md
, then executeyarn test:e2e
. - For serial port debugging, use
DEBUG=nextion*,serialport
.
Events
The Nextion
instance (nextion
) in above examples is an EventEmitter
. If the device sends any of these over the UART channel, the Nextion
instance will emit a corresponding event (w/ data, if any).
- Return Values (Table 2)
touchEvent
: Touch event return datapageId
: Current page IDtouchCoordinate
: Touch coordinate datawake
: Touch event in sleep modestringData
: String variable datanumericData
: Numeric variable dataautoSleep
: Device automatically enters sleep modeautoWake
: Device automatically wakes from sleep modestartup
: Successful system startupcardUpgrade
: Start SD card upgradetransmitFinished
: Data transmit finishedtransmitReady
: Ready to receive data transmission
TODO: Describe shape of data for data-emitting events.
Motivation
- Send & receive events over UART to a Nextion device (hardware reference)
- Support Tessel 2
- Support USB-to-UART serial adapters for debugging
- Endgame: combine a Tessel 2 w/ a Nextion to design/implement a (mainly) JS-based home environmental control panel/dashboard.
Future:
- Ensure support on popular ARMv6/7/8
- Ensure support on popular (non-Tessel) MIPS devices
- Interface into GUI designer commands
- Johnny-Five support?
Notes
Johnny-Five
Johnny-Five support is problematic, because:
- Only "enhanced" Nextion models have any GPIO pins (8 PWM-capable pins)
- All communication w/ the device is over UART, so an IO plugin would be extremely wonky
- No ADC, as far as I know
- Any I2C or SPI communications would probably need to be handled by a daughter board
ARM
If the serialport module supports the architecture, this module should work out-of-the-box, meaning RPi's and BBB's are theoretically covered.
MIPS
This shouldn't be too bad, because the Tessel 2 is MIPS-based, but we require Node.js v4. Other MIPS-based boards I've used have had trouble getting it compiled, packaged, or running at a respectable speed.
License
:copyright: 2017 Christopher Hiller. Licensed MIT.