Skip to content

Commit

Permalink
Merge 0d9c2bb into 2c6dba7
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics authored May 14, 2023
2 parents 2c6dba7 + 0d9c2bb commit 67ba830
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 33 deletions.
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.15.2] - 2023-05-14
### Fixed
- Logger import fixed, see #31
- Examples README improved with MicroPython port specific UART pin usage example, see #30

## [0.15.1] - 2023-05-14
### Fixed
- Remove yet unavailable files from `package.json`, see #33
Expand Down Expand Up @@ -220,8 +225,9 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
- [Example HMI file](examples/everything.HMI) to be used for all examples

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.15.1...develop
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.15.2...develop

[0.15.2]: https://github.com/brainelectronics/micropython-nextion/tree/0.15.2
[0.15.1]: https://github.com/brainelectronics/micropython-nextion/tree/0.15.1
[0.15.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.15.0
[0.14.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.14.0
Expand Down
74 changes: 65 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
## Examples Overview

| Example | Nextion name | Supported |
| Example | Nextion name | Supported |
| ------------------------- | ------------- | ------------------ |
| [Button](button) | NexButton | :heavy_check_mark: |
| [Checkbox](checkbox) | NexCheckbox | :heavy_check_mark: |
| [Crop](crop) | NexCrop | :x: |
| [Crop](crop) | NexCrop | :x: |
| [DualButton](dual_button) | NexDual | :heavy_check_mark: |
| [Gauge](gauge) | NexGauge | :heavy_check_mark: |
| [Gpio](gpio) | NexGpio | :heavy_check_mark: |
| [Hardware](hardware) | NexHardware | :heavy_check_mark: |
| [Hotspot](hotspot) | NexHotspot | :x: |
| [Hotspot](hotspot) | NexHotspot | :x: |
| [Number](number) | NexNumber | :heavy_check_mark: |
| [Page](page) | NexPage | :heavy_check_mark: |
| [Picture](picture) | NexPicture | :x: |
| [Picture](picture) | NexPicture | :x: |
| [Progress](progress) | NexProgress | :heavy_check_mark: |
| [Radio](radio) | NexRadio | :heavy_check_mark: |
| [Rtc](rtc) | NexRtc | :heavy_check_mark: |
| [Scrolltext](scrolltext) | NexScrolltext | :x: |
| [Scrolltext](scrolltext) | NexScrolltext | :x: |
| [Slider](slider) | NexSlider | :heavy_check_mark: |
| [Text](text) | NexText | :heavy_check_mark: |
| [Timer](timer) | NexTimer | :x: |
| [Touch](touch) | NexTouch | :x: |
| [Timer](timer) | NexTimer | :x: |
| [Touch](touch) | NexTouch | :x: |
| [Upload](upload) | NexUpload | :heavy_check_mark: |
| [Variable](variable) | NexVariable | :heavy_check_mark: |
| [waveform](waveform) | NexWaveform | :heavy_check_mark: |
| [Variable](variable) | NexVariable | :heavy_check_mark: |
| [waveform](waveform) | NexWaveform | :heavy_check_mark: |

<!-- https://www.webfx.com/tools/emoji-cheat-sheet/ -->

Expand All @@ -32,6 +32,62 @@
The [basic example](basic/main.py) shows the usage of all supported Nextion
elements by simple UART command calls.

The provided examples are designed for an **ESP32**.

Check [MicroPython UART documentation](https://docs.micropython.org/en/latest/library/machine.UART.html)
and the device/port specific setup for further details.

On a RP2 the RX and TX pin needs to be defined as e.g. `tx_pin = Pin(4)`,
`rx_pin = Pin(5)` and `uart_id = 1` whereas an ESP32 can use any pin with e.g.
`tx_pin = 21` and `rx_pin = 22` and `uart_id = 1`.

The following example code provides a universal RX/TX pin and UART ID setup.

```python
tx_pin = 21
rx_pin = 22
uart_id = 1

try:
from machine import Pin
import os
from umodbus import version

os_info = os.uname()
print('MicroPython infos: {}'.format(os_info))
print('Used micropthon-modbus version: {}'.format(version.__version__))

if 'pyboard' in os_info:
# NOT YET TESTED !
# https://docs.micropython.org/en/latest/library/pyb.UART.html#pyb-uart
# (TX, RX) = (X9, X10) = (PB6, PB7)
tx_pin = Pin(PB6)
rx_pin = Pin(PB7)
uart_id = 1
elif 'esp8266' in os_info:
# NOT YET TESTED !
# https://docs.micropython.org/en/latest/esp8266/quickref.html#uart-serial-bus
raise Exception(
'UART0 of ESP8266 is used by REPL, UART1 can only be used for TX'
)
elif 'esp32' in os_info:
# https://docs.micropython.org/en/latest/esp32/quickref.html#uart-serial-bus
tx_pin = 21
rx_pin = 22
uart_id = 1
elif 'rp2' in os_info:
# https://docs.micropython.org/en/latest/rp2/quickref.html#uart-serial-bus
uart_id = 1
tx_pin = Pin(4)
rx_pin = Pin(5)
except AttributeError:
pass
except Exception as e:
raise e

nh = NexHardware(rx_pin=rx_pin, tx_pin=tx_pin, uart_id=uart_id)
```

## Hardware example

The [hardware example](hardware/main.py) shows the usage of the hardware
Expand Down
7 changes: 4 additions & 3 deletions nextion/nextion_rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def write_rtc_time(self, *args, **kwargs) -> bool:
format("2016,11,25,12,34,50",
[2016, 11, 25, 12, 34, 50]))

self._logger.debug("Timestamp (ISO8601): {}-{}-{}T{}:{}:{}".
format(year, month, day, hour, minute, second))
self._nh._logger.debug(
"Timestamp (ISO8601): {}-{}-{}T{}:{}:{}".format(
year, month, day, hour, minute, second))

cmd = "rtc0={}".format(year)
self._nh.sendCommand(cmd)
Expand Down Expand Up @@ -121,7 +122,7 @@ def write_rtc_time(self, *args, **kwargs) -> bool:
else:
raise NexRtcError("Either use keyword or positional args")

self._logger.debug("Set '{}' to '{}'".format(time_type, time))
self._nh._logger.debug("Set '{}' to '{}'".format(time_type, time))
rtc_index = self.time_types.index(time_type.lower())

cmd = "rtc{}={}".format(rtc_index, time)
Expand Down
34 changes: 17 additions & 17 deletions nextion/nextion_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def upload(self) -> bool:
if not self._downloadTftFile():
raise NexUploadError("Download file error")

self._logger.debug("Download ok")
self._nh._logger.debug("Download ok")
return True

def _checkFile(self) -> bool:
Expand All @@ -127,13 +127,13 @@ def _checkFile(self) -> bool:
# https://docs.python.org/3/library/os.html#os.stat
info = stat(self.file_name)
self.file_size = info[6]
self._logger.debug("TFT file size is '{}' bytes".
format(self.file_size))
self._logger.debug("File check ok")
self._nh._logger.debug("TFT file size is '{}' bytes".
format(self.file_size))
self._nh._logger.debug("File check ok")
result = True
else:
self._logger.debug("File '{}' does not exist".
format(self.file_name))
self._nh._logger.debug("File '{}' does not exist".
format(self.file_name))
return result

def _getBaudrate(self) -> int:
Expand All @@ -147,13 +147,13 @@ def _getBaudrate(self) -> int:
_baudrate = 0

for baudrate in baudrate_array:
self._logger.debug("Checking connection with '{}' baud".
format(baudrate))
self._nh._logger.debug("Checking connection with '{}' baud".
format(baudrate))

if self._searchBaudrate(baudrate):
_baudrate = baudrate
self._logger.debug("Success, baudrate set to '{}' baud".
format(_baudrate))
self._nh._logger.debug("Success, baudrate set to '{}' baud".
format(_baudrate))
return _baudrate

return _baudrate
Expand All @@ -174,8 +174,8 @@ def _searchBaudrate(self, baudrate: int) -> bool:
self._nh.sendCommand("connect")
sleep(0.1) # necessary, data might not be available otherwise
response = self._recvRetString()
self._logger.debug("_searchBaudrate response for '{}' baud: {}".
format(baudrate, response))
self._nh._logger.debug("_searchBaudrate response for '{}' baud: {}".
format(baudrate, response))

if "comok" in response:
return True
Expand All @@ -193,16 +193,16 @@ def _setDownloadBaudrate(self, baudrate: int) -> bool:
:rtype: bool
"""
cmd = "whmi-wri {},{},0".format(self.file_size, baudrate)
self._logger.debug("Set download baudrate cmd: '{}'".format(cmd))
self._nh._logger.debug("Set download baudrate cmd: '{}'".format(cmd))

self._nh.sendCommand("")
self._nh.sendCommand(cmd)
sleep(0.05)
self._nh._baudrate = baudrate
self._nh._uart_init()
response = self._recvRetString(500)
self._logger.debug("Set download baudrate response: '{}'".
format(response))
self._nh._logger.debug(
"Set download baudrate response: '{}'".format(response))
if (0x05).to_bytes(1, 'little') in response:
return True
return False
Expand All @@ -222,13 +222,13 @@ def _downloadTftFile(self) -> bool:
data_size = update_file.readinto(file_content)

if not data_size:
self._logger.debug("Reached EOF, update finished")
self._nh._logger.debug("Reached EOF, update finished")
break

self._nh._uart.write(file_content)

response = self._recvRetString(500)
# self._logger.debug("File download response: '{}'".
# self._nh._logger.debug("File download response: '{}'".
# format(response))

if (0x05).to_bytes(1, 'little') in response:
Expand Down
6 changes: 3 additions & 3 deletions nextion/nextion_waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def addValue(self, ch: int, number: int) -> bool:
:rtype: bool
"""
if ch > 3:
self._logger.debug("Only channels (0-3) supported by waveform")
self._nh._logger.debug("Only channels (0-3) supported by waveform")
return False

cmd = "add {},{},{}".format(self.cid, ch, number)
Expand All @@ -67,8 +67,8 @@ def clearChannel(self, ch: int) -> bool:
:rtype: bool
"""
if (ch > 3) and (ch != 255):
self._logger.debug("Only the channels (0-3) or all channels at "
"once (255) can be cleared")
self._nh._logger.debug("Only the channels (0-3) or all channels "
"at once (255) can be cleared")
return False

cmd = "cle {},{}".format(self.cid, ch)
Expand Down

0 comments on commit 67ba830

Please sign in to comment.