-1

I don't understand the error and after 5h searching for a solution I finally gave up.

I'm trying to open a serial connection, but apparently my port isn't a sting?

The same port works fine in a different piece of code...

NOT WORKING

import serial
import pynextion


class NextionApp:

    def __init__(self):
        ser = serial.Serial("/dev/ttyAMA0", 9600, timeout=0)
        pages = [
            {"id": "0", "name": "page0()page",
                "components": [
                    {"id": "1", "type": "text", "name": "txt_tmp"},
                    {"id": "3", "type": "text", "name": "txt_hum"},
                    {"id": "0", "type": "text", "name": "txt_co2"},
                    {"id": "4", "type": "button", "name": "btn_test"},
                ]
            }
        ]
        self.nextion = pynextion.Nextion(ser, pages)
        print("Serial connected")

nextionApp = NextionApp()

WORKING

#!/usr/bin/env python


import time
import serial


ser = serial.Serial("/dev/ttyAMA0", 9600, timeout=1)
counter=0


while 1:
   x=ser.readline()
   print (x)
Community
  • 1
  • 1

1 Answers1

0

The Python Nexation library expects to receive the device path as input not an instance of the serial object (it creates that itself ). You should call:

self.nextion = pynextion.Nextion("/dev/ttyAMA0", pages)
tarkmeper
  • 767
  • 3
  • 12
  • Thank you very much! I just tried do get the example script from pynextion working, so they have a mistake in the example, or am I understand something wrong? https://github.com/python-nextion/pynextion/blob/master/tests/nextion-app.py – daruderude Apr 27 '19 at 22:56
  • I'm not sure - I took a quick look at the library itself to figure it out. I can't see though how the example would work... – tarkmeper Apr 28 '19 at 01:03