Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: coupling of two cards tennsy 4.0

  1. #1
    Junior Member
    Join Date
    May 2021

    coupling of two cards tennsy 4.0

    I mainly work with teensy 4.0 for creation projects on led screens 2.4inch LCD Module 240*320 pixels ili9341,
    but for my new project, I do a lot of sine and cosine calculations following an input from a GY521 sensor that I return to a screen but the display is not great and is lagging behind.

    my question is therefore, and is it possible to couple two cards, one for the calculations and the other for the display?
    sorry for my bad English

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Yes, there many ways to communicate between 2 boards. But using 2 may not be the best solution.

    I can only guess how your code works... so here is a blind guess. Most of the display libraries wait for SPI communication to finish. The same is true for most sensor libraries, they wait for the sensor to complete a measurement. This is simpler, but it means you can't do other work while waiting.

    Kurt's ILI9341_t3n library might be your best place to look first (assuming you are not already using it... this is guesswork). That library allow you to compose the image in memory and then it does the work of sending the pixels to the display using DMA while the rest of your program runs. That feature could allow you to communicate with the sensor and do the math you need while the previous drawing to the screen is updating.

  3. #3
    Junior Member
    Join Date
    May 2021
    Good-morning Paul,
    thank you for your answer, I understand the waiting time for SPI communications,
    I use the following libraries.
    #include <SPI.h>
    #include "I2Cdev.h"
    #include "MPU6050_6Axis_MotionApps20.h"
    #include <Adafruit_GFX.h>
    #include <Adafruit_ILI9341.h>
    I looked at the ILI9341_t3n, it goes really faster but it is not compatible with GFX.

    Do you think that putting the sensor in I2C would be a solution?

    currently the screen and connect as below
    #define TFT_DC 8
    #define TFT_CS 10
    #define TFT_MOSI 11
    #define TFT_CLK 13
    #define TFT_RST 9
    #define TFT_MISO 12

    and the sensor as below

    INT 2
    SCL 19
    SDA 18
    GND -
    VCC +
    changing the spindle would also be a solution?

    Do you have an example or a link to correctly integrate ILI9341_t3n, it seems to me bad that it is not GFX compatible. for part of my code i use in about 200 sin cos calculates the rest of my code also uses calculations to simulate real device in smaller size.
    I spent a lot of time on it .... and I would really like to stay on teensy 4.0 which is perfect for me

  4. #4
    Junior Member
    Join Date
    May 2021
    what I wanted to say, I do not understand how to integrate the DMA of this library in my code
    // # include <Adafruit_ILI9341.h>
    #include <ILI9341_t3n.h>
    // Adafruit_ILI9341 display = Adafruit_ILI9341 (TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
    ILI9341_t3n display = ILI9341_t3n (TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_CLK, TFT_MISO);
    DMAMEM uint16_t tft_frame_buffer [ILI9341_TFTWIDTH * ILI9341_TFTHEIGHT];
      display.begin ();
      display.setFrameBuffer (tft_frame_buffer);
    but then I don't know how to do it.
    void loop () {
        // if programming failed, don't try to do anything
        if (! dmpReady) return;
        // wait for MPU interrupt or extra packet (s) available
        while (! mpuInterrupt && fifoCount <packetSize) {
          // other program behavior stuff here
        // reset interrupt flag and get INT_STATUS byte
        mpuInterrupt = false;
        mpuIntStatus = mpu.getIntStatus ();
        // get current FIFO count
        fifoCount = mpu.getFIFOCount ();
        // check for overflow (this should never happen unless our code is too inefficient)
        if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
          // reset so we can continue cleanly
          mpu.resetFIFO ();
          //Serial.println(F("FIFO overflow! "));
          // otherwise, check for DMP data ready interrupt (this should happen frequently)
        } else if (mpuIntStatus & 0x02) {
          // wait for correct available data length, should be a VERY short wait
          while (fifoCount <packetSize) fifoCount = mpu.getFIFOCount ();
          // read a packet from FIFO
          mpu.getFIFOBytes (fifoBuffer, packetSize);
          mpu.resetFIFO (); // *** more line to avoid bug !! ***
          // track FIFO count here in case there is> 1 packet available
          // (this lets us immediately read more without waiting for an interrupt)
          fifoCount - = packetSize;
          // display Euler angles in degrees
          mpu.dmpGetQuaternion (& q, fifoBuffer);
          mpu.dmpGetGravity (& gravity, & q);
          mpu.dmpGetYawPitchRoll (ypr, & q, & gravity);
    /*sample code
    void rotation(){
      display.drawLine(oldrcd , oldrsd, oldrc  , oldrs , BLACK);
      display.drawLine(rcd , rsd, rc , rs , WHITE);
      display.setCursor(oldNx, oldNy);
      display.setCursor(Nx, Ny);
    Last edited by defragster; 05-14-2021 at 06:46 PM. Reason: Added # CODE around program for readability

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Added CODE marking to prior post - using "#" on toolbar

    To enable the auto DMA update look at the samples there should be one showing use of the ASYNC behavior

    This one seems to do it :: T:\tCode\libraries\ILI9341_t3n\examples\ili9341_t3n_UpdateAsyncCont_T est\ili9341_t3n_UpdateAsyncCont_Test.ino

  6. #6
    Junior Member
    Join Date
    May 2021
    Hello Defragster,
    sorry for the #code ....
    thanks for the example, i looked, i don't understand how i can do it, i watch this afternoon in more detail.

    with this way of proceeding, is it possible to refresh just part of the screen?

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    No problem on the # Code - everyone has to see it once sometime

    There are other examples - that code is in use on the Teensy MicroMod thread with the B&W camera updating 10 or 15 fps or at video rates.

    If you have a buffer allocated the whole screen is updated with DMA in the background.

    @KurtE or @mjs513 might have better ideas or details - it does have some ability to define an update rectangle - whether that helps or not is TBD.

  8. #8
    Junior Member
    Join Date
    May 2021
    I spent a good part of Saturday figuring out how to put DAM in my code but I didn't get any conclusive results (I'm not at your level).
    I even watched the entire video post.

    I wonder if this solution and the best.

    in addition to my 2 main functions, which processes the data from the GY521 sensor and the posters in the form of two drawings calculated on the screen (about 1/3 of the surface).
    it is these two main functions that take too many resources to display properly.
    it works if I activate one or the other
    I have a lot of smaller function that calculates and displays on part of the screen but randomly over time.

    I understand that without seeing my code, it is difficult to help me but the purpose of my code is just on the rendering of the screen.
    so if i give it ....... i will have to work for nothing, hope you understand me.

    I therefore continue to search

  9. #9
    Junior Member
    Join Date
    May 2021
    Hello, after a lot of testing, I understood the error, the mpu was sending wrong information.
    So I did a comparison with the accelerometer and delete the values that displayed anything.
    all are working fine now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts