Announcement

Collapse
No announcement yet.

WriteObject(GENIE_OBJ_FORM, x, x) not working?

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

  • WriteObject(GENIE_OBJ_FORM, x, x) not working?

    Hi guys, I'm running a 3.2" Picaso Micro LCD hooked up to an Arduino Uno.

    I can switch forms via the touchscreen fine.
    I can call genie.WriteObject(GENIE_OBJ_FORM, form number, 0); in the main loop and it works fine also.

    The problem seems to be when I make the above call in another function, it just doesn't change at all.

    For example,
    for function:

    void showform()
    {
    Serial.print("SHOWING FORM 2");
    Serial.println();
    genie.WriteObject(GENIE_OBJ_FORM, 2, 0); // Change to form 2
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, 53); //test
    }

    It will show as the default form on the LCD, and in the Serial Monitor it will show as:

    "SHOWING FORM 2
    
     "

    Any idea what's going on? Baud rate is 9600 btw.

  • #2
    Okay, so it will only change the form some of the time (like 5-10% of the time), so it's not a problem in the code.

    Comment


    • #3
      Hello
      Welcome to the forum.​ ​

      Have you seen this Sticky post in the Arduino section?
      http://forum.4dsystems.com.au/forum/...and-4d-display

      Given you are using an Arduino Uno, I am guessing you have the display connected to Serial0, right?
      You are then doing Serial.print statements in your showform() function.
      You cannot use the same serial port to talk to the display, and talk to the terminal.
      Please refer to the Sticky post for more information.

      If this is not the case, please let me know

      Regards
      James

      Comment


      • #4
        Thanks that seemed to fix it!

        Comment


        • #5
          Hello All,
          Hoping to solve this issue, basically i have an arduino Uno and GEN4-ULCD-70DCT-CLB-SB, have gone through the genie demos with arduino which work fine, the serial link is woring great,
          What i have created as a new project, is a simple 2 form project, with an image on either. I was hoping to use this function genie.WriteObject(GENIE_OBJ_FORM, 0x01, 0); to switch between form 0 and form 1. I have put the genie.WriteObject(GENIE_OBJ_FORM, 0x01, 0); at the end of the VoidSetup to Form 1 is effectively as splash screen.
          The forms do not seem to change, i can use the GTX dashboard and the forms change, but not using the command via arduino, Any help here would be great,
          Thanks
          Rich

          Comment


          • #6
            Hi,

            Welcome to the forum,

            Could you post your complete Arduino code here so we can see if there is a difference between that and the demos you used.

            Best regards

            Paul

            Comment


            • #7
              Hi Paul,
              Its basically the genieArduino_Demo with a line added to change the form to form 1 at the end of Void Setup.
              I have changed the Visi project to be just 2 forms each with an image on. .
              Form 0 shows immediately but doesn't change to form 1

              Really appreciate the reply
              Rich



              #include <genieArduino.h>

              // This Demo communicates with a 4D Systems Display, configured with ViSi-Genie, utilising the Genie Arduino Library - https://github.com/4dsystems/ViSi-Genie-Arduino-Library.
              // The display has a slider, a cool gauge, an LED Digits, a string box and a User LED.
              // The program receives messages from the Slider0 object using the Reported Events. This is triggered each time the Slider changes on the display, and an event
              // is genereated and sent automatically. Reported Events originate from the On-Changed event from the slider itself, set in the Workshop4 software.
              // Coolgauge is written to using Write Object, and the String is updated using the Write String command, showing the version of the library.
              // The User LED is updated by the Arduino, by first doing a manual read of the User LED and then toggling it based on the state received back.

              // As the slider changes, it sends its value to the Arduino (Arduino also polls its value using genie.ReadObject, as above), and the Arduino then
              // tells the LED Digit to update its value using genie.WriteObject. So the Slider message goes via the Arduino to the LED Digit.
              // Coolgauge is updated via simple timer in the Arduino code, and updates the display with its value.
              // The User LED is read using genie.ReadObject, and then updated using genie.WriteObject. It is manually read, it does not use an Event.

              // This demo illustrates how to use genie.ReadObject, genie.WriteObject, Reported Messages (Events), genie.WriteStr, genie.WriteContrast, plus supporting functions.

              // Application Notes on the 4D Systems Website that are useful to understand this library are found: http://www.4dsystems.com.au/appnotes
              // Good App Notes to read are:
              // ViSi-Genie Connecting a 4D Display to an Arduino Host - http://www.4dsystems.com.au/appnote/4D-AN-00017/
              // ViSi-Genie Writing to Genie Objects Using an Arduino Host - http://www.4dsystems.com.au/appnote/4D-AN-00018/
              // ViSi-Genie A Simple Digital Voltmeter Application using an Arduino Host - http://www.4dsystems.com.au/appnote/4D-AN-00019/
              // ViSi-Genie Connection to an Arduino Host with RGB LED Control - http://www.4dsystems.com.au/appnote/4D-AN-00010/
              // ViSi-Genie Displaying Temperature values from an Arduino Host - http://www.4dsystems.com.au/appnote/4D-AN-00015/
              // ViSi-Genie Arduino Danger Shield - http://www.4dsystems.com.au/appnote/4D-AN-00025/

              Genie genie;
              #define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below)
              void setup()
              {
              // NOTE, the genieBegin function (e.g. genieBegin(GENIE_SERIAL_0, 115200)) no longer exists. Use a Serial Begin and serial port of your choice in
              // your code and use the genie.Begin function to send it to the Genie library (see this example below)
              // 200K Baud is good for most Arduinos. Galileo should use 115200.
              Serial1.begin(200000); // Serial0 @ 200000 (200K) Baud
              genie.Begin(Serial1); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

              genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events

              // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)
              // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC
              // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and
              // the 4D Arduino Adaptors invert this signal so must be Active High.
              pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
              digitalWrite(RESETLINE, 1); // Reset the Display via D4
              delay(500);
              digitalWrite(RESETLINE, 0); // unReset the Display via D4

              delay (3500); //let the display start up after the reset (This is important)

              // Set the brightness/Contrast of the Display - (Not needed but illustrates how)
              // Most Displays, 1 = Display ON, 0 = Display OFF. See below for exceptions and for DIABLO16 displays.
              // For uLCD-43, uLCD-220RD, uLCD-70DT, and uLCD-35DT, use 0-15 for Brightness Control, where 0 = Display OFF, though to 15 = Max Brightness ON.
              genie.WriteContrast(14);

              //Write a string to the Display to show the version of the library used
              genie.WriteStr(0, "hello");
              delay(3500);
              genie.WriteObject(GENIE_OBJ_FORM, 0x01, 0);

              }

              void loop()
              {

              static long waitPeriod = millis();
              static int gaugeAddVal = 1; // Simulation code variable. Value to change the gauge by each loop
              static int gaugeVal = 50; // Simulation code variable. Value to start the gauge at when powered on

              genie.DoEvents(); // This calls the library each loop to process the queued responses from the display

              if (millis() >= waitPeriod)
              {
              // Write to CoolGauge0 with the value in the gaugeVal variable

              genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, gaugeVal);

              // Simulation code, just to increment and decrement gauge value each loop, for animation
              gaugeVal += gaugeAddVal;
              if (gaugeVal == 99) gaugeAddVal = -1;
              if (gaugeVal == 0) gaugeAddVal = 1;

              // The results of this call will be available to myGenieEventHandler() after the display has responded
              genie.ReadObject(GENIE_OBJ_USER_LED, 0); // Do a manual read from the UserLEd0 object

              waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time.
              }
              }

              /////////////////////////////////////////////////////////////////////
              //
              // This is the user's event handler. It is called by genieDoEvents()
              // when the following conditions are true
              //
              // The link is in an IDLE state, and
              // There is an event to handle
              //
              // The event can be either a REPORT_EVENT frame sent asynchronously
              // from the display or a REPORT_OBJ frame sent by the display in
              // response to a READ_OBJ (genie.ReadObject) request.
              //

              /* COMPACT VERSION HERE, LONGHAND VERSION BELOW WHICH MAY MAKE MORE SENSE
              void myGenieEventHandler(void)
              {
              genieFrame Event;
              genie.DequeueEvent(&Event);

              int slider_val = 0;

              //Filter Events from Slider0 (Index = 0) for a Reported Message from Display
              if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_SLIDER, 0))
              {
              slider_val = genie.GetEventData(&Event); // Receive the event data from the Slider0
              genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to LED Digits 0
              }

              //Filter Events from UserLed0 (Index = 0) for a Reported Object from Display (triggered from genie.ReadObject in User Code)
              if (genie.EventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_USER_LED, 0))
              {
              bool UserLed0_val = genie.GetEventData(&Event); // Receive the event data from the UserLed0
              UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable
              genie.WriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to UserLed0
              }
              } */

              // LONG HAND VERSION, MAYBE MORE VISIBLE AND MORE LIKE VERSION 1 OF THE LIBRARY
              void myGenieEventHandler(void)
              {
              genieFrame Event;
              genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below

              int slider_val = 0;

              //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
              if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
              {
              if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider
              {
              if (Event.reportObject.index == 0) // If Slider0 (Index = 0)
              {
              slider_val = genie.GetEventData(&Event); // Receive the event data from the Slider0
              genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to LED Digits 0
              }
              }
              }

              //If the cmd received is from a Reported Object, which occurs if a Read Object (genie.ReadOject) is requested in the main code, reply processed here.
              if (Event.reportObject.cmd == GENIE_REPORT_OBJ)
              {
              if (Event.reportObject.object == GENIE_OBJ_USER_LED) // If the Reported Message was from a User LED
              {
              if (Event.reportObject.index == 0) // If UserLed0 (Index = 0)
              {
              bool UserLed0_val = genie.GetEventData(&Event); // Receive the event data from the UserLed0
              UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable
              genie.WriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to UserLed0
              }
              }
              }

              /********** This can be expanded as more objects are added that need to be captured *************
              *************************************************************************************************
              Event.reportObject.cmd is used to determine the command of that event, such as an reported event
              Event.reportObject.object is used to determine the object type, such as a Slider
              Event.reportObject.index is used to determine the index of the object, such as Slider0
              genie.GetEventData(&Event) us used to save the data from the Event, into a variable.
              *************************************************************************************************/
              }

              Comment


              • #8
                Hi,

                Try commenting out

                genie.WriteStr(0, "hello");
                delay(3500);

                if the object is not in your genie project it will most likely fail at this point.

                Comment


                • #9
                  Top answer Pauleilio.. thanks for that,
                  Rich

                  Comment

                  Working...
                  X