Announcement

Collapse
No announcement yet.

Unable to change Arduino Serial ports (works great with Serial0)!

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to change Arduino Serial ports (works great with Serial0)!

    I'm testing my new setup (GEN4-ULCD-70DT-SB) connected to an Arduino using jumper wires. I've already created a custom Genie project with lots of Smart Gauges and such, so I just want to get one to work.
    Using the genieArduino_demo sketch available in the GitHub file I can get the setup working no problem with Serial0, but if I switch to any other hardware serial port then I get no communication.

    I've already reviewed application note AN-00017 and it seems like this should be really easy. So not sure what the hangup is. Thanks for the help.

    Below is the code I'm using. When I switch from one Serial to another, I just change genie.Begin(SerialX) to the correct number and change the jumpers to the correct serial ports. The only other things I think I've changed is the coolgauge to the Smart gauge that I've created (genie.WriteObject(35, 0, gaugeVal);
    Tried using two different Arduino Mega boards. Same result.

    Code:
    #include <genieArduino.h>
    
    ///....
    
    Genie genie;
    #define RESETLINE 4  // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below)
    void setup()
    {
    
      //Serial.begin(115200);  // Serial0 @ 200000 (200K) Baud
      Serial.begin(9600);
      Serial3.begin(9600);
      genie.Begin(Serial);   // 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
    //Serial.println("1a");
      // 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(100);
      digitalWrite(RESETLINE, 0);  // unReset the Display via D4
    
      // Let the display start up after the reset (This is important)
      // Increase to 4500 or 5000 if you have sync problems as your project gets larger. Can depent on microSD init speed.
      delay (3500); */
    //Serial.println("1b");
      // Set the brightness/Contrast of the Display - (Not needed but illustrates how)
      // Most Displays use 0-15 for Brightness Control, where 0 = Display OFF, though to 15 = Max Brightness ON.
      // Some displays are more basic, 1 (or higher) = Display ON, 0 = Display OFF.  
      genie.WriteContrast(10); // About 2/3 Max Brightness
    //Serial.println("1c");
      //Write a string to the Display to show the version of the library used
      genie.WriteStr(0, GENIE_VERSION);
    //  Serial.println("1c");
    }
    
    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(35, 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;
    //    Serial.println(gaugeVal);
    
        // 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.
      *************************************************************************************************/
    }

  • #2
    Hi,

    Welcome to the forum.

    Not really sure why you aren't getting any comms when changing the port.

    The code for the Arduino looks fine to me.

    Could you please send me a picture of your wiring when using a different serial port.

    Best regards

    Paul

    Comment


    • #3
      Click image for larger version

Name:	IMG_20200813_152055.jpg
Views:	20
Size:	4.13 MB
ID:	73156Thanks Paul. I'm confused too, but it is very likely that I'm overlooking something simple! The wiring is very straightforward. I've used the same wiring colors for the jumpers as those supplied in the kit. Yellow being TX from the screen but labeled RX on the connector, and the opposite for the orange wire. When I change the serial I just moved the two serial wires over as pictured. Power is supplied by a separate 5v ac adapter.
      Click image for larger version  Name:	IMG_20200813_152040.jpg Views:	0 Size:	4.69 MB ID:	73155

      Comment


      • #4
        Thanks for the images

        Ok It might be best to attach the reset wire to D4 and then chage the code for the reset logic to


        digitalWrite(RESETLINE, 0); // Reset the Display via D4
        delay(100);
        digitalWrite(RESETLINE, 1); // unReset the Display via D4

        Also, add a gnd wire from the Arduino Mega gnd to the Display gnd

        I hope this does the trick

        Best regards

        Paul

        Comment


        • #5
          I should've known better. Of course it was an issue of grounding- must have common grounds! That absolutely fixed it. Thanks for the help Paul!

          Comment

          Working...
          X