Announcement

Collapse
No announcement yet.

Gen4-ulcd Diablo16 display -Raspi3 python

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gen4-ulcd Diablo16 display -Raspi3 python

    Please help,

    Has anyone successfully interfaced a Diablo16 Display to a Raspberry Pi 3 using Python only.
    It seems that all available libraries are in "C" I do not know this language at all.

    I have a beginners level of Python which I want to use. I have looked at all of the documents and searched this board.

    Would anyone please share their python code and how you set up the system (what libraries and support files) to work over the 2 wire serial interface.

    Thanks,

    Mitch

  • #2
    Hello Mitch,

    Referring to this thread post: https://forum.4dsystems.com.au/forum...events-control
    Have you tried the python file that I have send? Did you encounter any errors?
    You can use the ViSi-Genie program attached by Kayven (post#6).

    The python file uses the module: pyserial which enables you to easily
    access the serial port using pre-defined functions. You can find more
    documentation through this link: https://pyserial.readthedocs.io/en/latest/pyserial.html

    The appnote: ViSi-Genie Connecting a 4D Display to the Raspberry Pi. https://www.4dsystems.com.au/appnote/4D-AN-00023/
    contains hardware configuration for the Raspberry Pi and the 4D Display.
    Also, the steps to enable the serial hardware and disable the default serial login shell.
    After enabling the serial hardware you can use the port: "/dev/ttyS0".

    I hope this helps.
    Best Regards,
    Kevin

    Comment


    • #3
      John,

      Does the Visi-Genie-RaspPi-Library still need to be loaded even though I will be writing code in Python?

      Is there a prebuilt Library I should be using instead of this for Python.

      Again,

      I have no programming at all in C or C++, I have homework assignment level in Python.

      Thanks for all of your help!

      Mitch

      Comment


      • #4
        John,

        I set up the display with the project from ViSi-Genie Connecting a 4D Display to the Raspberry Pi.

        I also setup the raspberry pi as in the app note. I am trying to run the python program you sent and am getting the following error....


        Traceback (most recent call last):
        File "4Dtest.py", line 29, in <module>
        numchar = ser1.inWaiting()
        File "/usr/local/lib/python3.5/dist-packages/serial/serialutil.py", line 590, in inWaiting
        return self.in_waiting
        File "/usr/local/lib/python3.5/dist-packages/serial/serialposix.py", line 467, in in_waiting
        s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
        OSError: [Errno 25] Inappropriate ioctl for device


        Please help

        Mitch

        Comment


        • #5
          I just retried this with the project sent for the Beagle bone in your previous post same error....


          Traceback (most recent call last):
          File "4Dtest.py", line 29, in <module>
          numchar = ser1.inWaiting()
          File "/usr/local/lib/python3.5/dist-packages/serial/serialutil.py", line 590, in inWaiting
          return self.in_waiting
          File "/usr/local/lib/python3.5/dist-packages/serial/serialposix.py", line 467, in in_waiting
          s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
          OSError: [Errno 25] Inappropriate ioctl for device

          Comment


          • #6
            Installed the Visi-Genie-RaspPi-Library anyway as directed in the Connecting a 4D Display to the Raspberry Pi and same error.....

            File "4Dtest.py", line 29, in <module>
            numchar = ser1.inWaiting()
            File "/usr/local/lib/python3.5/dist-packages/serial/serialutil.py", line 590, in inWaiting
            return self.in_waiting
            File "/usr/local/lib/python3.5/dist-packages/serial/serialposix.py", line 467, in in_waiting
            s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
            OSError: [Errno 25] Inappropriate ioctl for device
            [email protected]:~ $


            contents of Python Program


            #!/usr/bin/python
            #----------------------------------------------------------
            #python
            #this project requires pyserial module
            #To install the module: sudo apt-get install python-serial
            #To run the program: python Program.py
            #----------------------------------------------------------
            #import libraries
            import serial
            from time import sleep

            ser1 = serial.Serial(port = "/dev/ttyAMA0", baudrate = 9600,timeout = 0, writeTimeout=0)
            def reset():
            global numchar
            if numchar >= 1:
            data1 = data[0]
            if numchar >= 2:
            data2 = data[1]
            if numchar >= 3:
            data3 = data[2]
            if numchar >= 4:
            data4 = data[3]
            if numchar >= 5:
            data5 = data[4]
            if numchar >= 6:
            data6 = data[5]
            buttontoggle = 0
            while True:
            numchar = ser1.inWaiting()
            if numchar > 0:
            data = ser1.readline()
            if numchar >= 1:
            data1 = data[0]
            if numchar >= 2:
            data2 = data[1]
            if numchar >= 3:
            data3 = data[2]
            if numchar >= 4:
            data4 = data[3]
            if numchar >= 5:
            data5 = data[4]
            if numchar >= 6:
            data6 = data[5]
            #winbutton0
            if data1 == '\x07' and data2 == '\x06' and data3 == '\x00' and data4 == '\x00' and data5 == '\x00' and data6 == '\x01':
            print("Button is pressed")
            buttontoggle = buttontoggle + 1
            buttontoggle = buttontoggle%2
            if buttontoggle == 0:
            #set LED on state
            print("LED is HIGH\n")
            ser1.write(b'\x01\x13\x00\x00\x01\x13')
            #send string "LED is ON"
            ser1.write(b'\x02\x00\x09\x4C\x45\x44\x20\x69\x73\x20\x4F\x4E\x5D')
            if buttontoggle == 1:
            #set LED off state
            print("LED is LOW\n")
            ser1.write(b'\x01\x13\x00\x00\x00\x12')
            #send string "LED is OFF"
            ser1.write(b'\x02\x00\x0A\x4C\x45\x44\x20\x69\x73\x20\x4F\x46\x46\x10')
            reset()
            sleep(0.05)


            Also tried under just python instead of python3

            Comment


            • #7
              Hello Mitch,

              Sorry for the delayed response. Unfortunately, we do not have a library available for
              the Python language. The ViSi-Genie-RaspPi-Library is written in C, if you will not use this
              module you do not need to include this one. What you will need is the pyserial module
              which is used on the given python file.

              The error is due to the port you are using, port = "/dev/ttyAMA0".
              Kindly enable the serial hardware and disable the default serial login shell.
              1.) Type the command: sudo raspi-config
              2.) Select P6 Serial
              3.) Would you like a login shell to be accessible over serial? No
              4.) Would you like the serial port hardware to be enabled? Yes

              Then replace the port by: "/dev/ttyS0".

              If you want to use the port ttyAMA0, you can disable the bluetooth function
              available for the Raspberry Pi 3.

              For more information you can check this link: https://www.raspberrypi.org/document...ration/uart.md

              If you'd like you can use this library available for Beagle Bone Black: https://github.com/simiolabs/ViSi-Genie-BBB-Library
              You just need to modify some things on the library for you to be able to use it on your Raspberry Pi.
              We have tested the two functions available on the Library: "vgWriteObject and vgWriteString" and this
              works as intended. Although this does not cover all the commands available for the display, this may be
              a good start-up for you to study and explore.

              I have attached the modified version of the library and the sample application.

              Note: This uses the same ViSi Genie file.

              I hope this helps.
              Best Regards,
              Kevin
              Attached Files

              Comment


              • #8
                Kevin,

                Thanks for all of your help!! I first needed to concur some setup issues to properly enable serial com etc. as you noted. - SOLVED

                The next hurdle was to figure out why the provided library (ulcd.py) was causing so many errors... Then I discovered it was not compatible with python3.

                What needed to be done was thus:

                calls to reduce is no longer allowed, we need to import functools and all reduce() become functools.reduce().

                Next, there was:
                raise TypeError('Unicode strings are not supported. Please encode to bytes: {!r}'.format(seq))
                TypeError('Unicode strings are not supported, please encode to bytes:'\x01\n\x00\x00\x00\x0b')

                This was solved with: all instances of ser.write(cmd) changed to ser.write(cmd.encode()).

                Now your provided example works as intended....

                Thanks,

                Mitch

                Comment


                • #9
                  Hello Mitch,

                  I am glad that you have solved your problem.
                  If you still have any concerns, please don't hesitate to contact us.

                  Best Regards,
                  Kevin

                  Comment


                  • #10
                    Thanks to MitchS for the Python 3 corrections I sort of got this working.

                    I'm running the sample code on a Windows10 laptop to prototype before moving over to a Raspberry Pi (mainly for using PyCharm on Windows). I made the necessary COM port changes for windows and setup a basic screen with a LED and a script box on form 0 of my display. I still could not get the code to run. I was getting errors from the screen initializing function of uLCD.py. Basically it was throwing an error when evaluating the response from the screen. There was nothing in the receive buffer to evaluate. I tried putting in some pauses to give some time after the initial message to the screen to request form 0. Still errors.

                    My next step was to take the timeout off the port configuration. This resulted in the program hanging at the point where the serial input buffer is read for the first time. I then added a loop with the serial.in_waiting command to continually send the form 0 request command until something appeared in the buffer. I also added a counter to see how many times I had to send something to the screen before a response came back. It usually takes the command 18 to 20 times before I get an 06 ACK back. The screen then seems to glitch and eventually go white as I send the commands to turn the LED on and then OFF and send the corresponding text string to the string container.

                    I have tried adding pauses in multiple places with no luck. I have also used the Genie Test eXecutor to activate the LED and send the string and this works properly. I have compared the hex I'm sending in Python to the hex sent by the Genie Test eXecutor and they match up.

                    The screen is very responsive and works easily when using the Genie Text eXecutor.

                    Any thoughts on what might be going on ?

                    Thanks,
                    Mark

                    Comment


                    • #11
                      Hi,

                      So far, I'm the one who will handle this thread.

                      For the meantime, I will try to find out what we can do regarding your concern and I will contact you as soon as possible.

                      Best regards,
                      Kayven

                      Comment


                      • #12
                        Hi Mark,


                        Sorry for the delayed response.


                        I had made a python script that utilized the Raspberry Pi's "ttyS0" and you can modify the script if needed because it's used for testing only.
                        ​​​​​​​
                        And also it is a good start for you.


                        If you have time, you could try the script and let see the result on your side.


                        This will help us to come up with an idea.


                        I have attached the ViSi-Genie program and simple genie python script I have used.




                        Please, let me know if it works.

                        Best regards,
                        Kayven
                        Attached Files

                        Comment


                        • #13
                          Kayven,

                          Thank you for the sample files. I was able to get these working on my Windows 10 system with minor changes.

                          First, the serial port needed changing from Linux style /dev/tty0/ to the Windows COMx specification. In my case, COM3.

                          The second needed change was a Python 3 issue. The ser1.write(cmd) commands throw an error due to encoding mismatch. For this program to work under Python 3, all of the ser1.write(cmd) statements needed to be changed to ser1.write(cmd.encode()).

                          These two minor changes got the sample program working perfectly.

                          I can work to build off this example for my project.

                          Thanks for your help.

                          Best regards,
                          Mark Chollett

                          Comment


                          • #14
                            I was happy to help you, Mark


                            Thank you for sharing your solution, this will help others with this kind of situation.
                            If I have free time, I will continue to make changes with pyGenie and post an update here.


                            If you have concerns, please don't hesitate to ask here.

                            Best regards,
                            Kayven
                            Last edited by [email protected]; 29th November 2018, 03:34 PM.

                            Comment


                            • #15
                              Kayven,

                              Your sample python file for writing strings and objects was very helpful. I thought that was all I would need for the project. I have now linked a slider to an Leddigit object and I need to query the Leddigits0 object for a value.

                              I have enough logic to figure out if it changed, I just don't know how to query the object for a value in Python.

                              Thanks in advance for any help you can provide.

                              Mark

                              Comment

                              Working...
                              X