Bienvenido a los foros de FT81x Manía. Te invitamos a regístrate totalmente gratis. Disfruta de tu experiencia con un grandes amigos y Staff.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Thread Contributor: desiredshoeGD23Z and FlexCAN library issue

#1
0
Hi everyone,

I'm having an issue with my HotMCU display running Lightcalamar's GD23Z library along with the flexCAN library.  It's being run on a Teensy 3.5.  

With my current code, the display works fine with a potentiometer connected to the input, the readings update pretty fast.  If I add in the flexCAN code, the can bus readings are really slow, like 30 seconds to update.  If I print the data to the serial monitor, it's also slow.  The data is being fed via CAN bus from a Megasquirt 2 ECU.
Now if I cut out the GD23Z code and just run the flexCAN code, the serial monitor prints the data instantly so it's leading me to believe that the GD code is causing the lag.  I'm using the GD.finish(); command at the end of the code and I've tried GD.flush(); with the same results. 

Also, unrelated issue but I've noticed that if I run a 800x480 jpg as a background, it causes the gauges and numbers to not run as smoothly as it does with just a solid color background.  The display still works but I would love to have it be smooth.

Here's the sample of my code,


#include <SPI.h>
#include <GD23Z.h>
#include <FlexCAN.h>

static CAN_message_t rxmsg;

File loadScreen;

SdFatSdioEX SD;

int analogPIN = 33;
int val = 0;
int KPA = 0;

float MAP, RPM, CLT, TPS, SPKADV, AFR, BATTV, IAT;


void setup() {
 Can0.begin(500000);
 Serial.begin(9600);
 Serial4.begin(115200);

 pinMode(SD_PIN, OUTPUT);
 digitalWrite(SD_PIN, HIGH);  
 delay(20);
 digitalWrite(SD_PIN, LOW);
 delay(20);
 digitalWrite(SD_PIN, HIGH);
 delay(20);

 GD.begin(1);
 SD.begin();

}

void loop() {
 
 GD.Clear();
 loadScreen = SD.open("main2.jpg");
 GD.cmd_loadimage(0, 0);
 GD.loadSDIO(loadScreen);
 GD.Begin(BITMAPS);
 GD.Vertex2ii(0, 0);

 GD.ColorRGB(0xFFFFFF);
 GD.cmd_number(240,28,31,OPT_RIGHTX,(MAP/10));
  GD.cmd_number(240,75,31,OPT_RIGHTX,(IAT/10));
  GD.cmd_number(240,125,31,OPT_RIGHTX,KPA);
 
 GD.swap();
 GD.finish();

 canData();

 Serial.println(IAT);

}

void canData() {
     if ( Can0.read(rxmsg) ) {
   switch (rxmsg.id) { // Using IDs from 1512 as Megasquirt CAN broadcast frames for Simplified Dash Broadcasting.
     // EAch frame represents a data group http://www.msextra.com/doc/pdf/Megasquirt_CAN_Broadcast.pdf
     case 1512:
       MAP = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
       //RPM = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
       CLT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
       TPS = (float)(word(rxmsg.buf[6], rxmsg.buf[7]));
       //CLT = FtoC(CLT / 10);
       break;
     case 1513:
       IAT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
       //SPKADV = (float)(word(rxmsg.buf[6], rxmsg.buf[6]));
       break;
     case 1514:
       AFR = (float)(word(0x00, rxmsg.buf[1]));
       break;
     case 1515:
       //BATTV = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
       //generic1 = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
       //generic2 = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
       break;
   }
 }
}
Reply
#2
2
Better response on post RE: GD23Z and FlexCAN library issueThe jpg load must be called once from the setup 

Try this:

#include <SPI.h>
#include <GD23Z.h>
#include <FlexCAN.h>

static CAN_message_t rxmsg;

File loadScreen;

SdFatSdioEX SD;

int analogPIN = 33;
int val = 0;
int KPA = 0;

float MAP, RPM, CLT, TPS, SPKADV, AFR, BATTV, IAT;


void setup() {
 Can0.begin(500000);
 Serial.begin(9600);
 Serial4.begin(115200);

 GD.begin();
 SD.begin();

 loadScreen = SD.open("main2.jpg");
 GD.cmd_loadimage(0, 0);
 GD.loadSDIO(loadScreen);
}

int Valor;

void loop() {

 canData();
 Serial.println(IAT);
 
 GD.Clear();
 
 GD.Begin(BITMAPS);
 GD.Vertex2ii(0, 0);

 Valor=Valor+1; GD.cmd_number(150,50,30,OPT_RIGHTX,Valor);  //flag only for speed test, can be erased

 GD.ColorRGB(0xFFFFFF);
 //GD.cmd_number(240,28,31,OPT_RIGHTX,(MAP/10));
  GD.printNfloat(240, 28, (MAP/10), 2, 31);
  
  //GD.cmd_number(240,75,31,OPT_RIGHTX,(IAT/10));
  GD.printNfloat(240, 75, (IAT/10), 2, 31);
  
  //GD.cmd_number(240,125,31,OPT_RIGHTX,KPA);
  GD.printNfloat(240, 125, KPA, 2, 31);

 GD.swap();
 GD.finish();

}

void canData() {
     if ( Can0.read(rxmsg) ) {
   switch (rxmsg.id) { // Using IDs from 1512 as Megasquirt CAN broadcast frames for Simplified Dash Broadcasting.
     // EAch frame represents a data group http://www.msextra.com/doc/pdf/Megasquirt_CAN_Broadcast.pdf
     case 1512:
       MAP = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
       //RPM = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
       CLT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
       TPS = (float)(word(rxmsg.buf[6], rxmsg.buf[7]));
       //CLT = FtoC(CLT / 10);
       break;
     case 1513:
       IAT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
       //SPKADV = (float)(word(rxmsg.buf[6], rxmsg.buf[6]));
       break;
     case 1514:
       AFR = (float)(word(0x00, rxmsg.buf[1]));
       break;
     case 1515:
       //BATTV = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
       //generic1 = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
       //generic2 = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
       break;
   }
 }
}
Reply
#3
0
The reason I am running the jpg load in the loop is because eventually I plan to have different pages with different jpgs. Thank you for the code though, I will try it out and see if it fixes the issue.
Reply
#4
0
In fact, You can load different background images at any moment if you manage an array of pictures, without losing speed:

#include <SPI.h>
#include <GD23Z.h>
#include <FlexCAN.h>

static CAN_message_t rxmsg;

                       //    0           1           2         3           4            5           6            7              8
char Array1JPG[10][15]={"main0.jpg","main1.jpg","main2.jpg","main3.jpg","main4.jpg","main5.jpg", "main6.jpg","main7.jpeg","main8.jpg" };
int BaseJPG = 8;
int Image=2;

File loadScreen;

SdFatSdioEX SD;

int analogPIN = 33;
int val = 0;
int KPA = 0;

float MAP, RPM, CLT, TPS, SPKADV, AFR, BATTV, IAT;

int Valor;

void setup() {
  Can0.begin(500000);
  Serial.begin(9600); 
  Serial4.begin(115200);

  GD.begin();
  SD.begin();

  BackImage(Image);
  MP();
}
void loop() {}


void MP(){
  while(1)
  {
  canData();
  Serial.println(IAT);
  
  GD.Clear();
  GD.get_inputs();
  GD.Begin(BITMAPS);
  
  GD.Tag(1);  GD.Vertex2ii(0, 0);  GD.Tag(255);

  GD.cmd_number(150,50,30,OPT_RIGHTX,Valor);
  
  GD.ColorRGB(0xFFFFFF);
  GD.printNfloat(240, 28, (MAP/10), 2, 31);
  GD.printNfloat(240, 75, (IAT/10), 2, 31);
  GD.printNfloat(240, 125, KPA, 2, 31);

   if (GD.inputs.tag == 1)
      {
       delay(45);
       Image = Image+1;
       if(Image>=BaseJPG+1){Image=0;}
       BackImage(Image);
      }

  GD.swap();
  GD.finish();
  }

 }

 void canData() {
  Valor=Valor+1;
      if ( Can0.read(rxmsg) ) {
    switch (rxmsg.id) { // Using IDs from 1512 as Megasquirt CAN broadcast frames for Simplified Dash Broadcasting.
      // EAch frame represents a data group http://www.msextra.com/doc/pdf/Megasquirt_CAN_Broadcast.pdf
      case 1512:
        MAP = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
        //RPM = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
        CLT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
        TPS = (float)(word(rxmsg.buf[6], rxmsg.buf[7]));
        //CLT = FtoC(CLT / 10);
        break;
      case 1513:
        IAT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
        //SPKADV = (float)(word(rxmsg.buf[6], rxmsg.buf[6]));
        break;
      case 1514:
        AFR = (float)(word(0x00, rxmsg.buf[1]));
        break;
      case 1515:
        //BATTV = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
        //generic1 = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
        //generic2 = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
        break;
    }
  }
}

void BackImage(int count)
{
  loadScreen = SD.open(Array1JPG[count]);  
  GD.cmd_loadimage(0, 0);
  GD.loadSDIO(loadScreen);
  loadScreen.close();
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)