Announcement

Collapse
No announcement yet.

Keyboard Object Question

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

  • #16
    Thanks Eran, I'll take a good look at the code you referenced.

    The reason I need to rely on information from the Arduino is that I am using the display to programme a programmable midi controller. So the display allows the user to define and edit a list of midi messages which are passed back to the Arduino such that when a given button is pressed the appropriate list of midi actions are sent out to the network. So its a) a bit time critical and b) very dynamic.

    Ultimately we plan to make the Arduino code open source so I am trying to make the display as flexible as possible and avoid 'hard coding' lists into the display or any widgets.

    Hmmmm the reason I went for the 'invisible buttons idea' was to try and keep all my touch code in the magic touch module. (with some help I modified the code you kindly helped me with for the led displays to do this.) I hadn't actually planned to put an object underneath as such (just print some data from the list in a 'known position' Do you think I would be better off using a string object that I can simply detect using magic touch?

    Comment


    • #17
      Eran

      With your fantastic help my project has really moved forward the last couple of days. Thank you so much.

      Two questions (again!) sorry.

      1)

      Is it possible to READ the value that has been set in an Leddiggits object?

      My code is working fine but because I'm not sure how to read these values, I am having to support additional variables to 'mirror' the values held in my LED objects. It would remove some code if I could read these objects from other code segments. Is that possible?

      2)

      Is it possible to read the displays current contrast value?

      One of my set up menu items lets the user change the contrast. First time I use it the slider is set to 0. It would be nice if I could initialise the slider with the contrast value when I power up.

      Comment


      • #18

        That’s good to hear Tim!

        Program-wise, using String objects is simpler; but GUI-wise, the list box is better. If you want an opinion on which one to use, the string object is the one that I will recommend. To make it GUI-wise, utilizing the other features of Workshop4 is the KEY.

        Here are my inputs with regards to your other two questions, although I'm not entirely sure if I understood the questions correctly. Feel free to correct me.

        1. Well, using the Arduino host to read the led values is very possible; but I think using an additional one variable per leddigit is simpler. Consider the following options:
        A. When you are reading a leddgit, you will be needing first a Read function and save it to another variable then use it as you prefer. This will make you code two or three routines with more than five lines of codes.
        B. When you write a value to a leddigit, why not just store that value to another variable? This will only take a single routine and a single line of code. Perhaps this is what you’re referring to as “mirror type”?
        Example:
        WriteObject(tLeddigits, 0, value); //Where “value” is your variable. You can simply copy that variable to a new one so no further reading is to be done; thus
        newValue := value;
        *Taking into consideration that you have mentioned the “time-critical” factor in your previous post.


        2. You want to control the contrast value using the slider object and set a default contrast value other than zero, is this right?
        You can simply insert a magic code “Post Genie init” and set your slider value together with your contrast value there. About reading the contrast value, you can use the peekW(CONTRAST) function; but I don’t think you still need to read its contrast again for you’re already using a variable to set the contrast.


        I’m just assuming that all these routines are on the display side and I’m not sure if my assumptions about your algorithm are right Tim, but if not, maybe you can clarify more about your questions so I can help you?

        Best Regards,
        Eran
        Eran

        Comment


        • #19
          Hi Eran

          The list box I hacked together based on the example you gave me is working really nicely. It is not as sophisticated as the one you sent me in that it doesn't scroll smoothly (still getting my head around how to do that but ) but at this stage of the development I'm happy with where I am at.

          In terms of the other two questions: (btw you are correct that at the moment all my functions and work is 'display side.' I want to do as much clever stuff in the display before moving on to the communication with the Arduino. )

          1) Essentially I am doing what you describe in option B. The only reason I asked the question is that I reuse the code to write to four LED objects. So before I call up the routine that edits the value to be displayed I need to retrieve the correct value in my 'mirror variable' which is fine and as you say not a huge overhead.

          I was just wondering if it were possible to READ the stored value in the LED object then all I would need to do would be to pass the function the index to the LED object I wanted to edit.

          2) I have a slider that is set up to adjust the contrast which is working fine. The slightly annoying thing is that on power up, the display 'resumes' using the last set contrast value. At the moment my slider has no way of knowing what this values is. So the first time I use the slider it is set at 0 when the contrast is maybe at 5. Once I use the slider then everything is ok and in sync as you say. What I'd really like to do on power up is READ the display's contrast setting, write this to my slider object such that the first time my 'set up' screen is displayed, the slider is showing the current value.

          Is there a memory location I can peek the contrast value from? EDIT HAVE I GOT THIS WRONG? DOES THE DISPLAY REMEMBER THE CONTRAST VALUE OR DOES IT START UP WITH A SPECIFIC VALUE EACH TIME?

          when I use the code:

          WriteObject(tGSlider,0, peekW(CONTRAST));

          on startup it always seems to return 0?

          Last edited by Bigtim; 28 April 2018, 07:05 PM.

          Comment


          • #20
            Eran sorry to be a pain

            I am having a brain fart when it comes to using strings.

            I have successfully updated the text within a string object from my Arduino in an earlier version of the project.

            What I am trying to do now is dynamically control what the string displays using my magic code.

            for example

            WriteObject(tStrings,0, "Hello World");

            Should that work?

            I can't use a pre-determined message list (as I have seen in some of the examples) because the text I want to display will be dynamic and edited by the user.

            Comment


            • #21
              Hi Tim,

              1) I’ve made a sample code on how to Read LED object’s value. Hope it helps.
              2) Have you tried the “PostGenie Init” MagicCode Tim? If you haven’t yet, you can try either of these codes to a “PostGenie Init” MagicCode:
              A)
              gfx_Contrast(14);
              WriteObject(tGSlider, 0, peekW(CONTRAST));

              B)
              var CON;
              CON := 8;
              gfx_Contrast(CON);
              WriteObject(tGSlider, 0, CON);

              *The two codes are actually the same, but in actual coding, you’ll probably use the second one (only with the declaration on the “Constant/Global/Data” Magiccode) for you’re going to change the value of CON in the main loop.

              PrintStrings() function is used in Magic instead of WriteObject() to print strings. This is documented in the Visi-Genie Reference Manual under Section 6. You can also read the said manual to know how to use this function.

              This thread may also help you to understand more about using strings in Magic:
              https://forum.4dsystems.com.au/forum...-string-widget
              *I have attached sample codes for both setting up a start-up contrast and printing strings.

              Hope this helps and best regards,
              Eran
              Attached Files
              Eran

              Comment


              • #22
                Thanks for these examples Eran, you are very kind putting your time into providing these very comprehensive and practical answers to my questions. Thank you

                The last (hopefully ) piece of the jigsaw for my project is for me to start talking to my Arduino host. I can already use the gene library to select forms and update string objects etc, ie some basic interaction with the screen. My next challenge will be to set up some communication that will allow the Arduino to send the display a 'string' of data (to populate my list box) and for the display to at a later time send back the same or similar strings of data to the Arduino.

                Is there an app note that you could recommend to help with this? Would the best method be to use "ViSi-Genie Magic How to Read a File Arduino" as a guide?

                Thanks again

                Tim

                Comment


                • #23
                  No worries Tim!

                  You can read https://forum.4dsystems.com.au/forum/forum-aa/4d-systems-hardware/4d-intelligent-display-modules-diablo16/40191-serial-comunication-from-arduino-to-display-ulcd-70-dt to learn about the Communications between the Display and the Arduino.

                  There is also a project in this section where Communications between the Display and the Arduino was needed: https://www.4dmakers.net/projects/de...evel-indicator.

                  Attached is a working example.

                  Best Regards,
                  Eran
                  Attached Files
                  Eran

                  Comment


                  • #24
                    Hi Eran, thanks for the help on the comms.

                    I have managed to get a little further today but have 2 issues.

                    I have adapted the code you sent to try and receive some data from the Arduino which is almost working. I am taking the data received and writing it to a string object. I am trying to use a buffered serial input on com0 of the display. When the count gets to double digits however, I am losing the second digit.

                    I have attached the files and wonder if you could see what it is I am doing wrong as I am making no progress sorting it this afternoon.

                    NB in the programme provided there is a toggle switch that needs to be turned on to enable my serial decoder (I added this due to the second question below)


                    The second thing I have come up against today is what appears to be a conflict if I try and use the gernie aruduino functions such as genie.WriteStr( 0, input); alongside my own messages (like the counter in question 1. What I hoped to be able to do was mix my own messages in amongst genie Arduino messages which I already use quite extensively in a hack version of the product .

                    You might notice in the Arduino script I am trying to send alternating messages using the genie Arduino function and a basic home made serial message via the same port (I only have one spare serial port on the Arduino) the two methods work fine when the other is commented out but if I try to use both then the process that is handling the genie Arduino stuff seems to grind to a halt.

                    Since I can't see how the display is handling these messages, I'm guessing there is some code somewhere handling the genie library message that I am messing up by sending to or reading from COM0?

                    Is there a way around this? Can I structure my messages such that I do not interrupt the genie library functions or will I have to choose one or the other method?

                    I was reading a little today about the magic object object, can I use this to help me handle incoming serial message (hopefully without disrupting the genie Arduino messages?) the messages I will need to send and receive will range from simple 'command type messages' to quite long lists that I will need to receive/store and edit (eg to populate my list boxes)

                    Hope that all makes sense and apologies again for the dumb questions.
                    Attached Files

                    Comment


                    • #25
                      I have a feeling the first issue is something to do with the 2 byte word within the diablo, when I send 4 characters, I seem only to be adding 2 of them to the string! lol this is driving me nuts is there a neat way of handling this 2 byte word thing that I am missing?
                      Last edited by Bigtim; 3 May 2018, 05:42 PM.

                      Comment


                      • #26

                        Hi Tim,
                        The sample code that I sent you can only handle one digit at a time. When you want to make it handle more than one digit/character, you need to make a routine that would append the second buffered digit to the first stored digit.

                        I suppose you already know how to do this in Arduino, but just in case you still need some backup information, you can read this: https://www.arduino.cc/en/Tutorial/StringAppendOperator or you can also use an array and convert it to an integer using the atoi() function if your buffered inputs only include numbers, that is.
                        On the buffer of the display side, you can read these forum threads:
                        https://forum.4dsystems.com.au/forum...es-with-serout
                        https://forum.4dsystems.com.au/forum...uding-decimals

                        As you can see in the latest sample code that I sent you, there’s a library Software Serial that lets you utilize other pins as your Serial ports (RX and TX). On the display side, it can also be implemented (Please review the code) using another serial (i.e. COM1) other than COM0 for COM0 is being used by default.

                        Using the example that I sent you which utilizes a COM1 communication, the connection would be Arduino’s digital pin 6 to gen4 PA’s GPIO 6 and Arduino’s digital pin5 to gen4 PA’s GPIO 5.

                        Regarding the Magic object object, yes. You can use it to send strings to your display and even make your own protocol in order to update your dynamic string. If you have already read much about this object, then it would be really beneficial to your project for it won’t need an additional serial port anymore.

                        I’ll try making an example for you.


                        I have attached a modified example that allows you to make use of two Serial ports. Don’t hesitate to ask for clarifications.

                        Best Regards,
                        Eran
                        Attached Files
                        Eran

                        Comment


                        • #27
                          Hi Eran, Two serial ports is a problem (I am using all four on the Arduino Mega) so I am stuck with only being able to use one port on the display Its not a show stopper but it would be quite nice if I could continue to use the genie Arduino functions along side my own messages down the same serial port. Do you think this will be possible?

                          Thanks for the additional information I'll take a good look through all of that today to see if I can get the basic receiving of a message working properly

                          Comment


                          • #28
                            I'm really intrigued about the magic object thing, thank you so much for the offer of help

                            Comment


                            • #29
                              Hi Tim,

                              No Worries!
                              You can use the digital pins to configure an additional software serial port other than the four hardware serial ports using the Software Serial library. Please see the sample code that I've just uploaded.

                              Best Regards,
                              Eran
                              Eran

                              Comment


                              • #30
                                My main problem is that I have built a bespoke PCB (with a deconstructed Arduino on it) and at this point I don't have access (headers) to any other Arduino pins. For production run 2 I might be advised to make another serial port available and use the software serial library.

                                For now though I am stuck with the one. Is there any way I can format my messages from the Arduino such that the display will 'ignore them' and continue to handle standard genie library function messages?

                                Comment

                                Working...
                                X