Announcement

Collapse
No announcement yet.

This program cannot get a UserButton to change state of LED or Write to String

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

  • This program cannot get a UserButton to change state of LED or Write to String

    Hello there all,

    Completely stumped on getting my touchscreen userbutton to communicate with my Arduino program to write to a string box on the display, or to turn on an LED. Completely new to 4D system implementation to an Arduino program. Especially something this complex.

    Please find whole project attached, be great if someone could look through this and make some sense on what I am trying to achieve. One of many problems I am facing.

    Sometimes the button gets a black box with a red cross if this is an indication

    Thanks in Advance,

    Sean
    Attached Files

  • #2
    Hi Sean

    Can you explain the project a little, for our benefit of what you are trying to achieve.

    What is the Nokia display code in your Arduino project for? Do you have a different screen as well as the gen4-uLCD-70DCT-CLB?

    When you get a black box with a red X, it means you are writing to an object with a value that is outside of its range. Ie if you have a gauge with 0-99 positions, and you write 200 to it for example, it will go black with a red X.

    You cannot write to things which dont exist in your project.

    A quick scan of your project and you have this on line 118:
    Code:
    genie.WriteObject (GENIE_OBJ_FORM, 2, 0); // Select form 2 (return to home screen)
    You have no Form 2 in your Workshop4 project...
    Doing this could result in a number of weird effects.

    What Arduino are you using?
    Any particular reason you are using 14400 Baud rate?

    Regards
    James

    Comment


    • James_4DSystems
      James_4DSystems commented
      Editing a comment
      You shouldn't need to write to GENIE_OBJ_USERBUTTON to set it to 0. Is there a reason you are doing this? Some effect you are trying to overcome? You have the Userbutton set to Momentary and you have it Reporting its event, so when you touch it, it send an event - the value of the event is largely irrelevant, you should just need to capture the event in the myGenieEventHandler() like you are already,from UserButton0, and do something. You shouldn't need to write the Userbutton to a value. Writing it to anything other than 0 will result in a black box with a red X it seems...
      If you didnt intend for it to be momentary and you want it to latch, then look at the other options in the parameters, and change it to No. The data will then change from 0 to 1 when you press the User button, and then from 1 to 0 when you press it again, so you can filter that in your handler to act accordingly.

      You should avoid using 0x00 hex too, just use decimal, its much cleaner to read. I assume you found some old demo which had hex in it?

      Its hard to simulate your code without commenting a bunch of it out, like the Nokia stuff, and the stepper stuff, as I don't have that hardware.
      If you can explain a bit of what you are trying to do, that will go a long way.

  • #3
    Originally posted by James_4DSystems View Post
    Hi Sean

    Can you explain the project a little, for our benefit of what you are trying to achieve.

    What is the Nokia display code in your Arduino project for? Do you have a different screen as well as the gen4-uLCD-70DCT-CLB?

    When you get a black box with a red X, it means you are writing to an object with a value that is outside of its range. Ie if you have a gauge with 0-99 positions, and you write 200 to it for example, it will go black with a red X.

    You cannot write to things which dont exist in your project.

    A quick scan of your project and you have this on line 118:
    Code:
    genie.WriteObject (GENIE_OBJ_FORM, 2, 0); // Select form 2 (return to home screen)
    You have no Form 2 in your Workshop4 project...
    Doing this could result in a number of weird effects.

    What Arduino are you using?
    Any particular reason you are using 14400 Baud rate?

    Regards
    Thanks for your response James,

    What I want to achieve from the project is that the keypad on the 4D Display enables me to enter a 3 digit number of a value (maximum) 500. After pressing go on the keypad, it combines these digits entered to be used in a calculation ("z*6400/40") to move a stepper motor so many steps. Obviously each entry on the keypad would be shown in the string box and have capabilities to delete numbers if entered wrong etc.

    I cannot get the keypad to work, so currently working on the buttons that would be set as 'preset digits' to be used in that calculation as described above. Will come back to the keypad hopefully once this is resolved.

    The reason for the nokia codes withing the Arduino program, as before moving to the 4D systems display, I had programmed all I needed to be displayed on a nokia display. As well as just writing to string boxes on the 4D display when I recieved it as a better display. Obviously the trouble is now occurring taking this program one step further to be fully touchscreen. Instead of having a display and a physical keypad.

    Thank you for your explanation on the black box with red cross, and I understand what you mean. How could a button become 'outside of its range' when I would have thought it would only have 2 positions, on and off?

    Now noticed that form 2, thank you for pointing that out. I am trying to build upon the non-touchscreen version of the program that I had already completed.

    I am using the Arduino Mega 2560

    The reason I am using the 14400 Baud rate was just initally an experiment to desperately try and get things to work , after reading it in the 'ViSi-Genie Connecting a 4D Display to an Arduino Host' document by 4D systems on page 21 in the blue table.

    Many thanks,

    Sean

    Comment


    • #4
      Originally posted by Sean147 View Post
      Thank you for your explanation on the black box with red cross, and I understand what you mean. How could a button become 'outside of its range' when I would have thought it would only have 2 positions, on and off?
      Yeah I am investigating this and will report back tomorrow (its past midnight here now). But see my comment above, you shouldn't need to write to the button, so that in itself might solve this problem for you.

      If you continue to play with this over the course of your day, send your latest code before you sign out for the day and ill check it out in the morning and see if we can get you a bit closer to what you want to achieve.

      I don't see any reason we cant achieve what you want to do, its all very do-able. Its just a matter of coding it in your Arduino.

      Regards
      James

      Comment


      • #5
        Originally posted by James_4DSystems View Post

        Yeah I am investigating this and will report back tomorrow (its past midnight here now). But see my comment above, you shouldn't need to write to the button, so that in itself might solve this problem for you.

        If you continue to play with this over the course of your day, send your latest code before you sign out for the day and ill check it out in the morning and see if we can get you a bit closer to what you want to achieve.

        I don't see any reason we cant achieve what you want to do, its all very do-able. Its just a matter of coding it in your Arduino.

        Regards
        Lovely, thank you for your help in advance. I get what you mean.

        I will be continuing to play around with the program and the setup for the rest of my working day. If I make any more changes that prove beneficial. I will post.

        In theory it seems 'easy' to do. But is just proving difficult for someone with not a lot of experience. Hope we can work this out.

        Many thanks,

        Sean

        Comment


        • #6
          Hi Sean

          Got something for you.

          I deleted a bunch out of your Arduino code, just so it clears things up, so it leaves just the Genie stuff there so you can see how this works.
          The keyboard is functional, it limits input to 3 digits and to a max value of 500, so if you type 789 for example, it will jump to 500. This is displayed on String0 as you type. When you click GO, it sends it to the LED Digit, and the String0 is cleared. While typing your number, the backspace works, you can type and DEL and type more and then click GO and it all works as it should.
          User button I just have setting String1 currently to a number.
          Winbutton0 jumps to Form1 like you had it. I added another Winbutton on Form1 to jump back again, so you dont get stuck while testing.
          Tweaked your graphics a little so things didnt overlap and so the lines were fully drawn, and also so your strings didnt only half delete with the DEL key etc.

          I hope this clears some things up. You can now add your stepper code back in here.

          Have a read of my comments in the code, hopefully this helps it make more sense.

          You will notice I used your char array from the keyboard still, and saved the operation to a int called 'value'. This is the number that gets sent to the LED Digits, and what you would use in your formula you mentioned. ("z*6400/40")

          I hope this helps. There may be a better way to do it, but this is what I have

          Regards
          Attached Files
          James

          Comment


          • #7
            Originally posted by James_4DSystems View Post
            Hi Sean

            Got something for you.

            I deleted a bunch out of your Arduino code, just so it clears things up, so it leaves just the Genie stuff there so you can see how this works.
            The keyboard is functional, it limits input to 3 digits and to a max value of 500, so if you type 789 for example, it will jump to 500. This is displayed on String0 as you type. When you click GO, it sends it to the LED Digit, and the String0 is cleared. While typing your number, the backspace works, you can type and DEL and type more and then click GO and it all works as it should.
            User button I just have setting String1 currently to a number.
            Winbutton0 jumps to Form1 like you had it. I added another Winbutton on Form1 to jump back again, so you dont get stuck while testing.
            Tweaked your graphics a little so things didnt overlap and so the lines were fully drawn, and also so your strings didnt only half delete with the DEL key etc.

            I hope this clears some things up. You can now add your stepper code back in here.

            Have a read of my comments in the code, hopefully this helps it make more sense.

            You will notice I used your char array from the keyboard still, and saved the operation to a int called 'value'. This is the number that gets sent to the LED Digits, and what you would use in your formula you mentioned. ("z*6400/40")

            I hope this helps. There may be a better way to do it, but this is what I have

            Regards
            Hi James,

            Thank you for this. After seeing what you have put and then putting my stepper code back in, it works how I want it to. A big thanks for this!

            One question to hopefuly finish this project off:

            How do I add a countdown timer on a button for instance, so that I have to hold the button for a second for it then to do something.

            Many thanks,

            Sean

            Comment


            • #8
              Hi Sean

              I am very happy to hear it is working as you hoped, that's great.

              Regarding the button timer. I would get say a Winbutton or button of your choice, and set it to report 'Both' (instead of Momentary), so you will get an event for push and another event for release.
              In your myGenieEventHandler() take note of the millis() when the press happens and maybe set a flag. Then in the release one, reset the flag. In your main loop, if millis() is greater than the time noted in the 'press' event + the desired hold time, and the flag is still set, then you know you are still holding the button as the release hasn't happened yet.

              Maybe something like that is a place to start.

              Give it a go, but if you get stuck just report back.

              Regards
              James

              Comment


              • #9
                Originally posted by Sean147 View Post

                Hi James,

                Thank you for this. After seeing what you have put and then putting my stepper code back in, it works how I want it to. A big thanks for this!

                One question to hopefuly finish this project off:

                How do I add a countdown timer on a button for instance, so that I have to hold the button for a second for it then to do something.

                Many thanks,

                Sean
                Could you give us an example of how this would be used?

                Many thanks,

                Sean

                Comment


                • #10
                  Hi Sean

                  Ok done, see attached.

                  I have repurposed UserButton0 for this example.

                  Now you need to hold the button down for at least 2 seconds, and then String1 will populate with a message saying "GO!". When you release your finger, String1 will be cleared. If you just press and release before 2 seconds, it wont do anything.

                  I haven't bothered to attach the WS4 application again, the only thing you need to change is to set the UserButton0 to have the Momentary parameter set to 'BOTH', which means it will send a 1 when you press, and send a 0 when you release.

                  You will see a few global variables at the top, a little bit of code in the loop() which is what is detecting if the time has elapsed, and then a bit in the myGenieEventHandler() for the UserButton to trigger on the 0 and 1 events.

                  Hope this helps

                  Regards
                  Attached Files
                  James

                  Comment


                  • #11
                    HI James

                    Thank you for that example, it worked great apart from i can still tap the userbutton and the stepper motor will move and if i hold the button down the word "GO" will appear and stepper motor will move i just don't want to be able to do the tap just the hold down to move stepper motor, i have set the buttons to "both" so probably i got something in the wrong place in the code, i have attached the code if you good have a look for me please once again thank you.

                    Sean
                    Attached Files

                    Comment


                    • #12
                      Hi Sean

                      Well yes its a bit messy now, but I think you need to explain in full what you actually want it to do, what button you want to do what, etc.

                      I had the only Userbutton in the program do this, so you hold down for 2 seconds to make the String change to "GO!", but you have no stepper code at that point. So if you want the stepper to work after holding that down, then you need to put your stepper code where the "GO!" string printing was. Instead you have your stepper code when you click the GO button on the keyboard. So you need to explain how you want this to work in full detail, and I can help rearrange it if you like.

                      Regards
                      James

                      Comment

                      Working...
                      X