Announcement

Collapse
No announcement yet.

Update string on screen from serial

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

  • Update string on screen from serial

    I have a uLCD-35DT-D v2.0 connected via a serial connection to an ATMega 2560. The ATMega keeps a runtime clock that I would like to display on the screen.

    I believe that I want to create a dynamic string on the form in ViSi-Genie, and then use the genieArduino library on the ATMega to update that string.

    Code:
    Genie genie;
    ...
    void setup() {
    ...
    Serial1.begin(9600);
    genie.Begin(Serial1);
    genie.AttachEventHandler(myGenieEventHandler);
    ...
    }
    
    void loop() {
    ...
    [code that assembles a time string in hh:mm:ss called timeToPrint]
    genie.WriteStr(8, timeToPrint);
    ...
    }
    I am reasonably confident that the correct serial outputs are being sent from the ATMega board, though I have not verified this with a serial monitor or similar tool.

    When I try setting the string value through the debugger, I get the expected output:

    Code:
    Set String Text Value 11:56:40.760 [02 08 03 66 6F 6F 6F]
    ACK 11:56:40.791 [06]
    Request Strings Value 11:56:55.641 [00 11 08 19]
    Strings Value 11:56:55.720 [05 11 08 FF FF 1C]
    And the text appears on the screen.

    I have attached a simple mockup of the ViSi-Genie project I am using.

    Can someone help me understand why my ATMega is not updating my screen?
    Attached Files

  • #2
    Hi Joshua,

    When using another Serial beside the Arduino’s default Serial (Digital Pins 0 and 1), you should first disconnect the Arduino Shield’s shorting jumpers for the RX and TX lines. This is to allow you to use the others pins as your Serial ports. In your case, for example, you want to use the Serial1 of Arduino Mega. To do this, you need to connect the TX Pin of the Arduino Shield to TX1 (pin18) of Arduino Mega; correspondingly, RX of Arduino Shield to Arduino Mega’s RX1 (pin19).

    You may refer to the figure below for the comparison of your setup.

    ​​​​ Click image for larger version

Name:	strings.png
Views:	85
Size:	436.0 KB
ID:	64559

    You may use the following code as well for testing:

    Code:
    #include <genieArduino.h>
    
    Genie genie;
    
    int timeToPrint;
    
    void setup() {
      Serial1.begin(9600);
      genie.Begin(Serial1);
      genie.AttachEventHandler(myGenieEventHandler);
    
      pinMode(4, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
      digitalWrite(4, 1);  // Reset the Display via D4
      delay(100);
      digitalWrite(4, 0);  // unReset the Display via D4
    
      delay (3500); //let the display start up
    
    }
    
    void loop() {
      genie.DoEvents();
    
      timeToPrint++;
      genie.WriteStr(8, timeToPrint);
    
    }
    
    void myGenieEventHandler(void) {
      genieFrame Event;
      genie.DequeueEvent(&Event);
    }

    This is assuming of course that you’re using a 4D Arduino Adaptor Shield, but if you're not, then you can read this appnote to know how to connect without Adaptor Shield: http://www.4dsystems.com.au/download...017_R_1_01.pdf

    Hope this solves your issue, but if it doesn't, then can you explain more about your setup?


    Best Regards,
    Last edited by Eran; 20th July 2018, 10:41 AM.
    Eran

    Comment


    • #3
      Thank you for the assistance. The issue turned out to be threefold:

      - The program I was running on the Arduino was waiting to receive a report message before it started sending writeStr() events, and my visi-genie program wasn't sending report messages.
      - I was expecting the LCD to be communicating on COM0 (RX0 and TX0), but instead it was communicating on COM1. Changing the options in 4D workshop fixed this.
      - I had TX and RX wired backwards. Oops!

      So your advice and test program were very useful, thank you again for the help.

      My only remaining question is this - in my LCD program, the strings are displayed on a form that is not the default. When I navigate to that form, the strings are blank until the Arduino sends a writeStr() event. (This is described in the app notes: 4D-AN-00013, p. 21.) Is there any way to populate the strings before the form is activated, or immediately after the form is activated, so that they don't display as blank until the LCD receives a writeStr() event?

      Comment


      • #4
        Hi Joshua,

        Am I right on assuming that you’re setting Events as “Form X Activate” to switch forms? I have made a sample project for you to try. This doesn’t set “Form X Activate” Event to switch from one form to another, instead, it makes use of the “Report Message” Event.

        ​​​​ Click image for larger version

Name:	reportmessage.png
Views:	90
Size:	6.6 KB
ID:	64581

        In this way, when the Arduino receives the “Report Message” Event, it would be able to activate the next form and update the String object right after activating the form:
        Code:
        if (Event.reportObject.cmd == GENIE_REPORT_EVENT) {
            if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
              if (Event.reportObject.index == 0x00) {
                genie.WriteObject(GENIE_OBJ_FORM, 1, 0);
                genie.WriteStr(1, timeToPrint);
              }
        The project actually has two String Objects:

        Click image for larger version

Name:	form1.png
Views:	108
Size:	100.3 KB
ID:	64579

        As soon as Form 1 activates, the current count will be shown to the Strings1 object, but it won’t update continuously unless the “Real Time Timer” Button is pressed.

        The strings0 object with an initial String of “TIMER” can be set in the Properties > Strings under Object Inspector.

        Click image for larger version

Name:	stringProperies.png
Views:	89
Size:	99.0 KB
ID:	64580 ​​​​​​​

        If you’re still having problems with using Strings, please don’t hesitate to ask.

        Hope this helps and Best Regards,
        Eran

        Comment


        • #5
          Thanks again for the help. The way my project works is that there is a button on the main menu. Pressing this button activates a magic event which does some legwork and then calls ActivateForm(FORM_WITH_STRINGS). I have the OnActivate event for the destination form set to "Report Message".

          Then, on the Arduino, I have a function in the main loop that checks to see if the clock display needs to be updated. This flag is set once per second when the Arduino's clock ticks up, but it is also set in the genie event handler like so:

          Code:
          void myGenieEventHandler(void) {
              genieFrame Event;
              genie.DequeueEvent(&Event);
              if (Event.reportObject.cmd == GENIE_REPORT_EVENT) {
                  if (Event.reportObject.object == GENIE_OBJ_FORM) {
                      if (Event.reportObject.index == FORM_WITH_STRINGS) { // previously assigned in the code
                          updateRuntime = true;
                      }
                  }
              }
          }
          I expect that calling ActivateForm(FORM_WITH_STRINGS) will send a report message to the Arduino, which will then set this flag, causing the clock to be updated in the main loop. However, this does not appear to be the case. Furthermore, sending the report message manually over the serial connection by running:

          Code:
          serout1(0x07);
          serout1(0x0A);
          serout1(0x04);
          serout1(0x00);
          serout1(0x00);
          serout1(0x09);
          after calling ActivateForm(FORM_WITH_STRINGS) from the magic event does cause the flag on the Arduino to be set.

          So my question is this: Why does setting the OnActivate event for this form to "report message" not cause the message to be sent? Does calling ActivateForm() from within a magic event prevent OnActivate events from triggering?

          (By the way, I am satisfied with my workaround of sending the report message manually, so don't worry about it if my question doesn't have a simple answer - it's probably the result of something else weird that I'm doing in the project.)

          Comment


          • #6
            Hi Joshua,

            A form’s On Activate Event only runs when it is activated from another Event (e.g. Winbutton’s On Changed Event), so the Report Message from a form’s On Activate Event won’t run when the form is Activated thru a magicEvent’s code.
            What you did is right, sending a Report Event manually, but using the Genie Magic function SendReport() is simpler to use.

            Code:
            ActivateForm(1);
            SendReport(REPORT_EVENT,tForm,1,0);
            I have attached a modified version of the previous sample project that I sent you which uses the SendReport() function for your reference.

            More Genie Magic Callable Functions can be found under Genie Magic Section of the ViSi-Genie Reference Manual.

            Hope this helps and Best Regards,
            Attached Files
            Eran

            Comment

            Working...
            X