Announcement

Collapse
No announcement yet.

Slow display updates between arduino and uLCD-35DT

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

  • Slow display updates between arduino and uLCD-35DT

    Hello I'm using the arduino shield with the uLCD-35DT reading in data with CANBUS using SPI network, then displaying the data over serial to the LCD. The problem I'm having is that data updates take upwards of 5 seconds each time data is changed before it is changed on the display. Is there an approach that I am missing? This program was derived from the example program to display temperatures from arduino host 4D-AN-00015_R_1_0

    Code:
    // demo: CAN-BUS Shield, receive data with check mode
    // send data coming to fast, such as less than 10ms, you can use this way
    // Updated to incorporate CANbus with Graphics
    
    
    #include <SPI.h>
    #include "mcp_can.h"
    #include <genieArduino.h>
    
    // the cs pin of the version after v1.1 is default to D9
    // v0.9b and v1.0 is default D10
    const int SPI_CS_PIN = 9;
    MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
    
    unsigned int MAP, RPM, TPS, MAT, CLT, PW1, PW2, ADV, AFR1, EGOCRT, EGT, SPW, BAT;
    
    
    Genie genie;
    void setup()
    {
    Serial.begin(115200); //set display communication baud rate
    genie.Begin(Serial); //begin display communications
    
    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 (5000); //let the display start up 5 seconds
    
    CAN.begin(CAN_500KBPS); //init can bus : baudrate = 500k
    }
    
    
    void loop()
    {
    unsigned char len = 0;
    unsigned char buf[8];
    
    
    if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
    {
    CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
    
    unsigned int canId = CAN.getCanId(); //determine CANbus ID
    
    switch(canId) {
    case 1512:
    for(int i = 0; i<len; i++) // fill buffer with data
    
    MAP = (float)(word(buf[0], buf[1])); //assign buffer 0,1 to MAP
    RPM = (float)(word(buf[2], buf[3])); //assign buffer 2,3 to RPM
    CLT = (float)(word(buf[4], buf[5])); //assign buffer 4,5 to CLT
    TPS = (float)(word(buf[6], buf[7])); //assign buffer 6,7 to TPS
    
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x00,MAP ); //Write to Leddigits0 the value of MAP
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x01,RPM ); //Write to Leddigits1 the value of RPM
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x02,CLT ); //Write to Leddigits2 the value of CLT
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x03,TPS ); //Write to Leddigits3 the value of TPS
    break;
    
    case 1513:
    for(int i = 0; i<len; i++) // fill buffer with data
    
    PW1 = (float)(word(buf[0], buf[1])); // assign buffer 0,1 to PW1
    PW2 = (float)(word(buf[2], buf[3])); // assign buffer 2,3 to PW2
    MAT = (float)(word(buf[4], buf[5])); // assign buffer 4,5 to MAT
    ADV = (float)(word(buf[6], buf[7])); // assign buffer 6,7 to ADV
    break;
    
    case 1514:
    for(int i = 0; i<len; i++) // fill buffer with data
    
    AFR1 = (float)(word(buf[0], buf[1])); // assign buffer 0,1 to AFR1
    EGOCRT = (float)(word(buf[2], buf[3])); // assign buffer 2,3 to EGOCRT
    EGT = (float)(word(buf[4], buf[5])); // assign buffer 4,5 to EGT
    SPW = (float)(word(buf[6], buf[7])); // assign buffer 6,7 to SPW
    break;
    
    } //end CASE argument
    
    } // end IF Statement
    
    } //end void loops
    
    
    
    
    /**************************************************************************************************** *****
    END FILE
    **************************************************************************************************** *****/

  • #2
    my 4d visi genie project
    Attached Files

    Comment


    • #3
      there is no genie.DoEvents() in your loop and you havn't enabled the handler for receiving the lcd data, open up the genie demo arduino code for an example

      Comment


      • #4
        I went through the tutorial again, and implemented the .DoEvents() and the event handler, however when I run this code nothing is displayed now. I went to the 4D project and set all my LED_DIGITS to report message as shown in the attached picture.

        Code:
        // demo: CAN-BUS Shield, receive data with check mode
        // send data coming to fast, such as less than 10ms, you can use this way
        // Updated to incorporate CANbus with Graphics
        
        
        #include <SPI.h>
        #include "mcp_can.h"
        #include <genieArduino.h>
        
        // the cs pin of the version after v1.1 is default to D9
        // v0.9b and v1.0 is default D10
        const int SPI_CS_PIN = 9;
        MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin
        
        unsigned int MAP, RPM, TPS, MAT, CLT, PW1, PW2, ADV, AFR1, EGOCRT, EGT, SPW, BAT;
        
        Genie genie;
        void setup()
        {
          Serial.begin(115200);   //set display communication baud rate
          genie.Begin(Serial);  //begin display communications
          genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
          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 (5000);         //let the display start up 5 seconds
        
          CAN.begin(CAN_500KBPS);  //init can bus : baudrate = 500k
        }
        
        
        void loop()
        {
            unsigned char len = 0;
            unsigned char buf[8];
        
            genie.DoEvents(); // This calls the library each loop to process the queued responses from the display
        
            if(CAN_MSGAVAIL == CAN.checkReceive())            // check if data coming
            {
                CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
        
                unsigned int canId = CAN.getCanId(); //determine CANbus ID
        
            switch(canId) {
              case 1512:
                    for(int i = 0; i<len; i++)    // fill buffer with data
        
                MAP = (float)(word(buf[0], buf[1]));  //assign buffer 0,1 to MAP
                RPM = (float)(word(buf[2], buf[3]));  //assign buffer 2,3 to RPM
                CLT = (float)(word(buf[4], buf[5]));  //assign buffer 4,5 to CLT
                TPS = (float)(word(buf[6], buf[7]));  //assign buffer 6,7 to TPS
        
        
          //      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x00, MAP);        //Write to Leddigits0 the value of MAP
          //      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x01,RPM);         //Write to Leddigits1 the value of RPM
          //      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x02, CLT);        //Write to Leddigits2 the value of CLT
          //      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0x03,TPS);         //Write to Leddigits3 the value of TPS
        
              break;
        
              case 1513:
                    for(int i = 0; i<len; i++)    // fill buffer with data
        
                PW1 = (float)(word(buf[0], buf[1])); // assign buffer 0,1 to PW1
                PW2 = (float)(word(buf[2], buf[3])); // assign buffer 2,3 to PW2
                MAT = (float)(word(buf[4], buf[5])); // assign buffer 4,5 to MAT
                ADV = (float)(word(buf[6], buf[7])); // assign buffer 6,7 to ADV
              break;
        
              case 1514:
                    for(int i = 0; i<len; i++)    // fill buffer with data
        
                AFR1 = (float)(word(buf[0], buf[1])); // assign buffer 0,1 to AFR1
                EGOCRT = (float)(word(buf[2], buf[3])); // assign buffer 2,3 to EGOCRT
                EGT = (float)(word(buf[4], buf[5]));  // assign buffer 4,5 to EGT
                SPW = (float)(word(buf[6], buf[7]));  // assign buffer 6,7 to SPW
              break;
        
              } //end CASE argument
            } // end IF Statement
        } //end void loops
        
        
        void myGenieEventHandler(void)
        {
          genieFrame Event;
          genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below
        
          int tempRPM = 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_LED_DIGITS)                // If the Reported Message was from an LED_DIGITS
            {
              if (Event.reportObject.index == 1)                              // If LED_DIGITs (Index = 1) RPM data moves almost continously
              {
                tempRPM = genie.GetEventData(&Event);                  // Receive the event data from the LED_DIGITS_1
                genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, MAP);       // Write arduino value to to LED_DIGITS_0
                genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, RPM);       // Write arduino value to LED_DIGITS_1
                genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, CLT);       // Write arduino value to LED_DIGITS_2
                genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, TPS);       // Write arduino value to LED_DIGITS_3
              }
            }
          }
        }
        Attached Files

        Comment


        • #5
          do your writeobjects in the loop, not jnside the event handler
          the event handler is only activated when the screen sends you data, so all the writes you put there will never work..

          just close the brace "}" right after genie.Dequeueevent in myGenieEventHandler, the handler is very important as it discards the events taken from the lcd in order to know what you pressed on it, or if things changed on the screen, thats why you dont see your writes happening. your doing great just keep doevents in the loop, event handler empty for now, and do your writeobjects in your loop like you did before

          Comment


          • #6
            Thank you for the assistance. The display seems to be updating more quickly, I will keep posted with results.

            Comment


            • #7
              Unfortunately I seem to still be running into the same problem as I had to start with. If there is only 1 item on the screen the data updates just fine, however the more things on the screen the slower and slower the display updates.

              Code:
              // 6-21-2017 Status: Works
              // Arduino CAN-BUS Shield, with 4D system uLCD
              // Updated to incorporate CANbus with Graphics
              // Displays data from megasquirt EFI System
              
              
              #include "mcp_can.h"
              #include <SPI.h>
              #include <genieArduino.h>
              
              
              // the cs pin of the version after v1.1 is default to D9
              // v0.9b and v1.0 is default D10
              
              const int SPI_CS_PIN = 9;
              MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin
              
              unsigned int MAP, RPM, TPS, MAT, CLT, PW1, PW2, ADV, AFR1, EGOCRT, EGT, SPW, BAT;
              Genie genie;
              
              void setup()
              {
                Serial.begin(200000);   //set display communication baud rate
                genie.Begin(Serial);  //begin display communications
                genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
                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 (5000);         //let the display start up 5 seconds
              
                CAN.begin(CAN_500KBPS);              // init can bus : baudrate = 500k
              
              }
              
              void loop()
              {
                  unsigned char len = 0;
                  unsigned char buf[8];
              
              
                  genie.DoEvents(); // This calls the library each loop to process the queued responses from the display
              
                  if(CAN_MSGAVAIL == CAN.checkReceive())            // check if data coming
                  {
                      CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
              
                      unsigned int canId = CAN.getCanId(); //determine CANbus ID
              
                  switch(canId) {
                    case 1512:  //1512 is CANBUS ID start for dash testing  switch to 1520 for normal broadcast
                          for(int i = 0; i<len; i++)    // fill buffer with data
              
                      MAP = (float)(word(buf[0], buf[1]));  //assign buffer 0,1 to MAP
                      RPM = (float)(word(buf[2], buf[3]));  //assign buffer 2,3 to RPM
                      CLT = (float)(word(buf[4], buf[5]));  //assign buffer 4,5 to CLT
                      TPS = (float)(word(buf[6], buf[7]));  //assign buffer 6,7 to TPS
              
              // if only 1 of these are allowed to execute the display performance is very good, if
              //more than one statement executes the display slows down, the more statements that
              //execute the slower the display if all 4 execute refresh slows to 5 seconds
              //        DisplayData(MAP,0);  
              //        DisplayData(RPM,1);
              //        DisplayData(CLT,2);
                      DisplayData(TPS,3);
              
                    break;
              
                    case 1513:
                          for(int i = 0; i<len; i++)    // fill buffer with data
              
                      PW1 = (float)(word(buf[0], buf[1])); // assign buffer 0,1 to PW1
                      PW2 = (float)(word(buf[2], buf[3])); // assign buffer 2,3 to PW2
                      MAT = (float)(word(buf[4], buf[5])); // assign buffer 4,5 to MAT
                      ADV = (float)(word(buf[6], buf[7])); // assign buffer 6,7 to ADV
                    break;
              
                    case 1514:
                          for(int i = 0; i<len; i++)    // fill buffer with data
              
                      AFR1 = (float)(word(buf[0], buf[1])); // assign buffer 0,1 to AFR1
                      EGOCRT = (float)(word(buf[2], buf[3])); // assign buffer 2,3 to EGOCRT
                      EGT = (float)(word(buf[4], buf[5]));  // assign buffer 4,5 to EGT
                      SPW = (float)(word(buf[6], buf[7]));  // assign buffer 6,7 to SPW
                    break;
              
                    } //end Switch Case argument
              
                  } // end  CANBUS date gathering IF Statement
              
              } //end void loop
              
              
              //Function DisplayData
              //this function takes data and displays it on LCD
              //parameters are the Data and the index valueof the LCD display OBJECT
              //
              void DisplayData(float DataToDisplay, int index ){
                  int tempValue;
                  int lastValue;
                     tempValue = DataToDisplay;
                     if(tempValue != lastValue){
                     genie.WriteObject(GENIE_OBJ_LED_DIGITS, index, tempValue);
                        }
                        lastValue = tempValue;
              }
              // End function DisplayData
              
              
              //Function myGenieEventHandler
              //This function is necessary for the LCD to process and que data from the microcontroller
              //
              void myGenieEventHandler(void)
              {
                genieFrame Event;
                genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below
              }
              // End function myGenieEventHandler
              
              /*********************************************************************************************************
                END FILE
              *********************************************************************************************************/

              Comment


              • #8
                Hello,

                Your should really have a last value of every reading eg.

                unsigned int MAP, RPM, TPS, MAT, CLT, PW1, PW2, ADV, AFR1, EGOCRT, EGT, SPW, BAT;
                unsigned int lastMAP, lastRPM, lastTPS, lastMAT, lastCLT, lastPW1, lastPW2, lastADV, lastAFR1, lastEGOCRT, lastEGT, lastSPW, lastBAT;

                at the end of the loop you should also have

                lastMAP = MAP;
                lastRPM = RPM; etc.

                and you would have to check for them individually

                if(lastMAP != MAP) {
                DisplayData(MAP,0);
                }

                I hope this helps

                Best regards

                Paul

                Comment

                Working...
                X