No announcement yet.

How to use Visi Genie generated Header Files?

  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Hi. I've been away for a few days and just came back to this. Thanks for the help again.

    Unfortunately my code doesn't work with the 4D screen. It doesn't seem to update the gauges. I've spent all day (7 hours!!) trying to isolate the problem. I even completely commented out the whole of void loop and made a new void loop simply saying genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, 1); with the intention of just sending the number 1 to the first gauge.

    To go with this, I also created a new Visi Genie project with a single gauge copied and pasted in to it. Again the gauge wouldn't update.

    As a sanity check, I temporarily uploaded an old project (Visi Genie project and Arduino code) that I made as a precursor to this one. That old project works fine, so I know the Arduino and screen still work.

    Here's the code for the latest version of my project. As you can see it's almost identical to the one you modified above:

    #include <genieArduino.h>
    #include <EEPROM.h>
    #include "OmniGaugeV8Const.h" //Header file holding names of all the Visi Genie objects
    const int MAPSensorPin = A0;       //MAP input pin
    const int WBAFRSensorPin = A1;     //Wideband AFR input pin
    const int OilPressSensorPin = A2;  //Oil Pressure input pin
    const int OilTempSensorPin = A3;   //Oil Temperature input pin
    const int NightPin = 3;            //Connects to dash lights live (i/p voltage must be limited to 5v). Lights on = HIGH
    int BoostVal;     //Holds digital value to be sent to Boost gauge
    int AFRVal;       //Holds digital value to be sent to AFR gauge
    int OilPressVal;  //Holds digital value to be sent to oil pressure gauge
    int OilTempVal;   //Holds digital value to be sent to oil temperature gauge
    byte FormNumber = 0x00;                //Holds number of last active form
    int BoostDayColour = BoostGaugeWht;    //Holds day colour of last active boost gauge
    int BoostNightColour = BoostGaugeWht;  //Holds night colour of last active boost gauge
    int AFRDayColour = AFRGaugeWht;        //Holds day colour of last active AFR gauge
    int AFRNightColour = AFRGaugeWht;      //Holds night colour of last active AFR gauge, and so forth
    int OilPressDayColour = OilPressGaugeWht;
    int OilPressNightColour = OilPressGaugeWht;  
    int OilTempDayColour = OilTempGaugeWht;
    int OilTempNightColour = OilTempGaugeWht;  
    const int FormPromAddress = 0;      //eeprom address to store form number (first 16 bits of eeprom)
    const int BoostDayPromAddress = 2;  //eeprom address to store Boost gauge colour (2nd 16 bits of eeprom, and so on)
    const int BoostNightPromAddress = 4;
    const int AFRDayPromAddress = 6;
    const int AFRNightPromAddress = 8;
    const int OilPressDayPromAddress = 10;
    const int OilPressNightPromAddress = 12;
    const int OilTempDayPromAddress = 14;
    const int OilTempNightPromAddress = 16;
    Genie genie;
    genieFrame Event;
    #define RESETLINE 4
    //Functions to replace Visi Genie object numbers with names given in the def file, OmniGaugeV8Const.h
    void WriteObject(int alias, int value)
      genie.WriteObject(alias >> 8, alias & 0xFF, value);
    void ReadObject(int alias)
      genie.ReadObject(alias >> 8, alias & 0xFF);
    bool ReportEvent(int alias)
      return genie.EventIs(&Event, GENIE_REPORT_OBJ, alias >> 8, alias & 0xFF);
    void setup()
      Serial.begin (200000);  //Serial0 @ 200k Baud
      genie.Begin(Serial);    // Use Serial0 for talking to the Genie Library, and to the 4D Systems display
      // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)
      // 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
      digitalWrite(RESETLINE, 0);  // unReset the Display via D4
      delay (3500);        //let the display start up
      //Change active form to number stored in eeprom
      FormNumber =;
      genie.WriteObject(GENIE_OBJ_FORM, FormNumber, 0);
    void loop()
      static long waitPeriod = 100; //Set up non-blocking delay to update gauges by this number of milliseconds
      static long prevTime;         // Part of non-blocking delay
      genie.DoEvents();   //Genie events are received and queued here.
      if(millis() - prevTime >= waitPeriod)  //non-blocking delay
      {                                                                       //Maths for gauges: ((([Max sensor reading - Min sensor reading] * ADC value) / ADC resolution) + lowest gauge value) * multiplier to make a whole number for 4d gauges
        BoostVal = ( (((3 * analogRead(MAPSensorPin)) / 1023) - 1) * 1000 );  //((([3bar - -1bar] * value) / resolution) -1bar) * multiplier  
        AFRVal = ( ((10 * analogRead(WBAFRSensorPin)) / 1023 + 10) * 1000 );  //((([20AFR - 10AFR] * value) / resolution) +10AFR) * multiplier
        OilPressVal = ( ((10 * analogRead(OilPressSensorPin)) / 1023 + 0) * 1000 );
        OilTempVal = ( ((100 * analogRead(OilTempSensorPin)) / 1023 + 50) * 1000 );
        if(digitalRead(NightPin) == LOW)
          WriteObject(BoostDayColour, BoostVal);
          WriteObject(AFRDayColour, AFRVal);
          WriteObject(OilPressDayColour, OilPressVal);
          WriteObject(OilTempDayColour, OilTempVal);  
        else if(digitalRead(NightPin) == HIGH)
          WriteObject(BoostNightColour, BoostVal);
          WriteObject(AFRNightColour, AFRVal);
          WriteObject(OilPressNightColour, OilPressVal);
          WriteObject(OilTempNightColour, OilTempVal);
        prevTime = millis();
    //Genie Event Handler
    void myGenieEventHandler(void)
      genie.DequeueEvent(&Event);  //Remove the next queued event from the buffer and process it below


    • #17
      Hi VooMan,

      It’s quite odd that you are experiencing such event. I can’t really pinpoint what exactly is causing the error since your setup is working on your previous code. Can you provide me your ViSi Genie project in zip format for me to troubleshoot the project? Generating zip file of the project can be done by clicking File tab in Workshop4 and then clicking Zip Project.
      If you don’t want to share your project file on this thread, you can send it on this email vincent at 4dsystems dot com dot au.

      But you may also try the simplified Arduino code (based on your code) attached to see if it is working. Attached are the needed files for the implementation.

      Hope this will help.

      Best regards,
      Attached Files


      • #18
        Your modified files didn't work either. I can see that it's supposed to make the gauge rise continuously, but it does nothing. It seems that it can't talk to CoolGauge objects. Very strange.

        I've just emailed you, with a wetransfer download link to my project folder (too big to attach to the email).

        Thanks again.


        • #19
          Hi, Vince_4D. I emailed you this but I thought I'd put it here in case it's usueful to anyone else:

          I worked out the problem! It was a mismatch between the set baud rate of the screen and the board rate in the arduino code; the code said 200k baud, but the Genie environment said 156k.

          In the Workshop 4 Options window, I set the Default Baud Rate to 200k and I also set the Serial Environment Initial Baud Rate to 200k. The Arduino now communicates with the screen, however it is ridiculously slow and unresponsive. Do you know how I should set the baud rate options to make the screen react at normal speed?


          I Just read this. I'm going to try increasing the reset delay and also change the code so it's only updating the gauges that are on-screen.
          Last edited by VooMan; 31st May 2018, 07:28 PM.


          • #20
            ... Problem solved! I increased the startup delay from 3500ms to 5000ms. So now the display responds as it should.


            • #21
              Greetings VooMan,

              I’m glad you figured it out by yourself.
              If you encounter any problems in the future, do not hesitate to inform us.
              We will try to help you the best way we could.

              Based on your project, you changed the color of the gauges by superimposing gauges with different colors. It’s not quite ideal to do so since ViSi Genie will forcefully display all the gauges hence you could see them initializing when the form is being activated.

              You might want to know about Genie Magic. It could simplify your project and address the unnecessary gauge initializations. One of its many features is customizing gauges in many ways possible. This can be achieved in the PRO version of Workshop4. For more information, please see the product page for the Worskhop4 IDE:
              You can watch the videos provided below on the said link, to know its general features.

              Hope this will help.

              Best regards,