Playing around with yet another version of ILI9341_t3 library (ILI9341_t3n)

Mike - too many threads - not finding summary note on your issue T$ with 9341 or 9488 - or just programming?

Tim - the problem I am having with PACMAN is with the 9341 display. Basically it just hangs after load and loses USB. The little orange light just keeps flashing very rapidly and to reload I have to hit the pgm button.

Looking to put my OSH TFT PCB back on T$ breakout - remembering last time it turned it into a heater … assume it was not having valid VCC for display that time? Breakout brings 3v3 but not 5v ??? Without doing it that way I won't have USBHost connect.

Mike - that reminds me - when I hack the PJRC Purple OSH display board - I've been using 5V pin for power and they work - 9341 and 9488? It is supposed to have a supply built on it that probably takes it down to 3v3 - but I glossed over that ...
I am using 3.3v for VCC for the 9341 and think I used it for the 9488 as well when I attached it - will have to double check.

Hoping between Mike/Kurt/Frank a good shared PCB comes about for next T4 to break out all the bottom - would be really cool it if was PJRC certified like the last breakout … only more connectable.
Be interesting to see what comes out of all this. Now I have to figure out what I need to do SMD soldering! to make my boards smaller.

Mike
 
SMD: I have a cheap hot air station, which is very useful. And since a few days I own a reflow oven - have not used it so far, but I hope it will be useful for the smaller packages or some low ball-count BGAs.
 
SMD: I have a cheap hot air station, which is very useful. And since a few days I own a reflow oven - have not used it so far, but I hope it will be useful for the smaller packages or some low ball-count BGAs.
Yeah. I picked up one a long time ago but never could figure out the settings to use - air flow and temperature - even when I do a search it gets me even more confused :)
 
@KurtE - can you point to a sample(s) in ...\libraries\ILI9341_t3n that will work and what wires to run into the T$ breakout from a breadboard?

I'm finding a mix of #define for pins … and pictureEmbed has a bad include

Tim, Not sure if this will help but here is the pin out that I have been using for the breakout board on the audio board connector:
Code:
MISO = 12
MOSI = 11
CS = 10
MEMCS = 9
SCK = 13
SDA = 18
SCL = 19
MCLK = 23
BLCK = 21 ?
 
@KurtE - can you point to a sample(s) in ...\libraries\ILI9341_t3n that will work and what wires to run into the T$ breakout from a breadboard?

I'm finding a mix of #define for pins … and pictureEmbed has a bad include

The only one I have tried in a long time is the graphic test sketch

Maybe I should try some of the others 8)

@mjs513 - So far I have no definitive plan for breakout board. I am hoping that Tall Dog (https://www.tindie.com/stores/loglow/) comes out with one, that works well with breadboards.

I will probably do one or two for my own usage, in particular probably some robot controller or the like, might be setup as a shield for RPI..., Maybe another one like I was doing earlier for Well monitoring (sort of based on Frank's board) His board is nice in that it is the size of the ILI9341 board... But if we actually have a larger display that becomes standard at PJRC, maybe could be setup for that one. But as OshPark charges by square inch, costs go up as well...
 
@KurtE

Breakout boards are fun and with every iteration it seems to get a little better :) Think Tim was looking to see what we come up with. Like you my main focus is on robot controllers but since I like do autonomous rovers I tend to connect a lot of sensors so need lots of pins...

Need some help on your library if I may, am finding a lot of primitives but have some questions:
1. How to I import Adafruit Fonts into the lib?
2. trying to use strPixelLen function but seems to be always returning 0 - probably using it wrong - here is what am doing:
Code:
int16_t drawString1(char string[], int poX, int poY)
{
….  
  uint16_t cwidth = tft.strPixelLen(string); // Find the pixel width of the string in the font

Any help would be appreciated. Thanks
Mike
 
@defragster - I made versions of pictureEmbed that works now using the breakout board that Paul sent. I have it #if defined(IMXRT...) to use the pins like Mike mentioned.
Likewise I update my Touchpaint_xpt2046 sketch to work with these pins as well... (Feel free to improve the touch code ;) It was setup with a rough conversion of touch point to screen).

@mjs513 - Importing the fonts - Pain in Arch... Reason is the font files include pulling in the whole header file for the whole library, which ends up with conflicts... So I make a copy of them and change the #include in them to the _t3n library... I wish that the font definitions was in their own. Also then run into if you name it font_arial.h, I ran into sometimes the Arduino system would use mine and other times it would try to grab it from, so I usually rename them something like ili9341_t3n_arial.h ...

As for strPixelLen it has been awhile.

Returning 0 - will happen if you pass in NULL pointer, or... Looks like a bug... If you are using default system font and no \n is in the string, it never updates maxlen variable.
Looks like simple fix would be ab about line 3141 to end the else clause (move the } up from 3147, such that in either case we do the if ( len > maxlen ) code...
I could do it now if you want or ...

EDIT: pushed up a change that hopefully fixes it.
 
Last edited:
@KurtE

Breakout boards are fun and with every iteration it seems to get a little better :) Think Tim was looking to see what we come up with. Like you my main focus is on robot controllers but since I like do autonomous rovers I tend to connect a lot of sensors so need lots of pins...

I hear you! As I mentioned, I may play around with a few different designs, maybe some based off of some earlier T3.2 boards. The interesting thing will be seeing how much I wish to try to fit...

I might start off with one similar to the RPI Hat I did earlier...
T3.2---RPI-Shield-V2a---Top.jpg

Or again back to the Well Monitor board:
Well-display_board_v03.jpg

Or maybe back to an Arduino Shield like board? Teensyduino-.00001w.jpg
Although that board is when I used to use RC servos and needed a lot of three pin headers... Not sure if I would go that far again...

But which ever way I go, I would like to have the ability for USB host adapter, maybe SD card, although I have not used those much, or maybe use those as other IO pins...

Lots of possibilities to play with.
 
…...
@mjs513 - Importing the fonts - Pain in Arch... Reason is the font files include pulling in the whole header file for the whole library, which ends up with conflicts... So I make a copy of them and change the #include in them to the _t3n library... I wish that the font definitions was in their own. Also then run into if you name it font_arial.h, I ran into sometimes the Arduino system would use mine and other times it would try to grab it from, so I usually rename them something like ili9341_t3n_arial.h ...

As for strPixelLen it has been awhile.

Returning 0 - will happen if you pass in NULL pointer, or... Looks like a bug... If you are using default system font and no \n is in the string, it never updates maxlen variable.
Looks like simple fix would be ab about line 3141 to end the else clause (move the } up from 3147, such that in either case we do the if ( len > maxlen ) code...
I could do it now if you want or ...

EDIT: pushed up a change that hopefully fixes it.
Ok thanks was going to go ahead and do the edit. I kind of figured you were going to tell that we had to make local copies after I actually looked closer at the directory:) those errors were what I was getting so back to playing now.
 
I hear you! As I mentioned, I may play around with a few different designs, maybe some based off of some earlier T3.2 boards. The interesting thing will be seeing how much I wish to try to fit...

I might start off with one similar to the RPI Hat I did earlier...
….

Or again back to the Well Monitor board:
...

Or maybe back to an Arduino Shield like board? ...
Although that board is when I used to use RC servos and needed a lot of three pin headers... Not sure if I would go that far again...

But which ever way I go, I would like to have the ability for USB host adapter, maybe SD card, although I have not used those much, or maybe use those as other IO pins...

Lots of possibilities to play with.
Since I have lots of sensor I may go with the one with lots of pins and the Arduino type shield. One of the nice things is that there are expansion shields available that will give some of that to you so less 3 pin soldering - but we'll see. But will definitely have to add the ubs2 connector and CAN transceivers.
 
Sorry (I know I am off my own thread subject here ;) )
I hear you about sensors. Although I have not done much with them for awhile. At one point was playing around with contact sensors in legs to try to detect when the foot hits the ground. Or sometimes FSR sensors in foot to see how biped foot is hitting the ground.

In earlier robot days with RC servos, Would have to run all of those servo wires so adding additional ones did not show up much.

But now with using servos like ones from Robotis that daisy chain connections, I have played around with maybe making the sensor connections more distributed.

That is for example with using a set of FSR sensors in the HROS1 biped, instead of wing up the sensors to go to main processor from the feet, we build simple board which connected up in the servo chain and allowed the main processor to get/set the information using Dynamixel communication (Set and Get registers)...
Teensy-and-Trinket-Neopixel.jpg
Likewise we had ones to try to put into hands to have a Neopixel to light up the hand different colors... The above I had two versions, one using a Adafruit pro trinket and the other using a Teensy 3.2... Nice thing about Trinket for this was at least by spec it could handle the 3S lipo servo without needing another VR and it was 5v so driving Neopixel...

Note: this is now similar to some of the directions that Robotis is going with some of their Robotics stuff. They have recently setup the XEL Network of controllers (http://xelnetwork.robotis.com/en/latest/) Where they have the main communications and processing board which includes Ethernet and the like (Setup to work with ROS2) and then they have Sensor XEL modules which allow you to connect them up in the Servo chain and communicate.

Now back to playing!
 
@KurtE

That networking idea is interesting - you can actually do it over the can bus as well, with FD it makes it even more interesting.

Got that stuff I was working kind of working enough to give you the idea - but some it was designed to be part of the ILI9341 lib that isn't visible from a sketch so it kludged really badly :(

If you want to give it a try load it and go - nothing xtra needed.

View attachment TFT_String_Align.zip
 
Hi @mjs513,

Which processor are you running on? I tried with T4 and I think it is crashing... Might have to get out one of my T3.5/6 boards with display and see what ti does there.
 
Hi @KurtE

Been running on the T4 all day without out a problem - there is a lot of spew you might want to get rid of because I was debugging it. Just comment out the Serial.prints.

Just for reference I have been using your latest ILI9341_t3n lib.

EDIT: May have to break out my DUE just to see what it is suppose to actually do versus what I am getting.
 
@mjs513 - Runs on my T3.6 Well monitor board which uses some non standard pins:
Code:
#if 1
#define TFT_BACKLIGHT 6     // TFT Backlight control
#define TFT_MOSI      7     // SPI MOSI
#define TFT_TCS       8     // SPI Touch CS
#define TFT_MISO      12    // SPI MISO
#define TFT_SCK       14    // SPI SCK
#define TFT_CS        15    // TFT CS
#define TFT_DC        22    // TFT DC
#define TFT_RST       -1
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
Feel free to add the functionality to the main library and do PR...
 
@KurtE

Did the pull request and it does work better embedded in the lib. Added an example as well.

Also having a problem with loading one of the fonts you already have in the library. I did the following:
Code:
#include <ili9341_t3n_font_Arial.h>
and
tft.setFont(&ili9341_t3n_font_Arial) as tft.setFont(&ILI9341_t3_font_t Arial_8)

The setFont command gave me an error - something like not declared.... any ideas.

EDIT: Still using the T4 for testing purposes.
 
@KurtE

Did the pull request and it does work better embedded in the lib. Added an example as well.

Also having a problem with loading one of the fonts you already have in the library. I did the following:
Code:
#include <ili9341_t3n_font_Arial.h>
and
tft.setFont(&ili9341_t3n_font_Arial) as tft.setFont(&ILI9341_t3_font_t Arial_8)

The setFont command gave me an error - something like not declared.... any ideas.

EDIT: Still using the T4 for testing purposes.

I Always have to look at the header file to remember how font's are defined.

Like in one test app I see I use: tft.setFont(Arial_24_Bold);

So my guess is that you simply need to do: tft.setFont(Arial_8);

PR pulled in. Running on T4 (with DC=10)...

On test app, wondering if the comment makes sense?
Code:
 #########################################################################
 ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
 ######       TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE       ######
 #########################################################################
 
@KurtE
Actually it makes no sense at all - I didn't even notice it since I was so wrapped up with getting it work right. I make the mode and do another push. Oh, forgot to mention you still have the warning showing up about have to use DC on a valid cs pin.

As for setFont thought I tried that as well but will give it another try.

EDIT: ok that worked with set font. But now I have to go look and see what the equivalent text size would be. Right now the lib just uses textsize.

UPDATE: DONE - PR put in :) Getting scared I am beginning to see how this works argh!
 
Last edited:
@mjs513 - I will comment out the warning message as it is working... Maybe not as fast, but...

Edit: Done
 
@KurtE
Pretty quick if you don't use a font just text size. If you can figure out how to make it faster let me know. Remember there are 1 second delays in the example so if you change that it should be better :)

To be honest it was a really good learning experience.
 
@KurtE
If you want to try out a fractal called a Buddhabrot here is a fun little sketch that you and run. I would make it bigger but I run out of DTCM memory on the T4.
Code:
// Buddhabrot
// j.tarbell   January, 2004
// Albuquerque, New Mexico
// complexification.net
//  http://www.complexification.net/gallery/machines/buddhabrot/appletl/index.html
// based on code by Paul Bourke
// astronomy.swin.edu.au/~pbourke/

// Processing 0085 Beta syntax update
// j.tarbell   April, 2005

#include <ILI9341_t3n.h> // Hardware-specific library
#include <SPI.h>
#include <ili9341_t3n_font_Arial.h>

#define ILI9341_RST 23
#define ILI9341_DC 9
#define ILI9341_CS 10
ILI9341_t3n tft = ILI9341_t3n(ILI9341_CS, ILI9341_DC, ILI9341_RST);


int dim = 240;             // screen dimensions (square window)
int bailout = 200;         // number of iterations before bail
int plots = 10000;        // number of plots to execute per frame (x30 = plots per second)

// 2D array to hold exposure values
byte exposure[240*240];
int maxexposure;           // maximum exposure value
int time = 0;
int exposures = 0;

boolean drawing;

void setup() {
  Serial.begin(115200);
  tft.begin();
  tft.setRotation(3);
  tft.setFont(Arial_9);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
  tft.setTextDatum(BL_DATUM);
}

void loop() {
  plotPlots();
  time++;
  if (time % 30 == 0) {
    // show progress every 2 seconds or so...
    findMaxExposure();
    renderBrot();
    // show exposure value
    tft.drawString("bailout:  ",0,0);
    tft.drawNumber(bailout, 0, 25);
    tft.drawString("exposures: ",0,40);
    tft.drawNumber(exposures, 0, 60);
  }
}

void plotPlots() {
  float x, y;
  // iterate through some plots
  for (int n=0;n<plots;n++) {
    // Choose a random point in same range
    x = randomFloat(-2.0,1.0);
    y = randomFloat(-1.5,1.5);
    if (iterate(x,y,false)) {
      iterate(x,y,true);
      exposures++;
    }
  }
}


//   Iterate the Mandelbrot and return TRUE if the point exits
//   Also handle the drawing of the exit points
boolean iterate(float x0, float y0, boolean drawIt) {
  float x = 0;
  float y = 0;
  float xnew, ynew;
  int ix,iy;

  for (int i=0;i<bailout;i++) {
    xnew = x * x - y * y + x0;
    ynew = 2 * x * y + y0;
    if (drawIt && (i > 3)) {
      ix = int(dim * (xnew + 2.0) / 3.0);
      iy = int(dim * (ynew + 1.5) / 3.0);
      if (ix >= 0 && iy >= 0 && ix < dim && iy < dim) {
        // rotate and expose point
        exposure[ix*dim+iy]++;
      }
    }
    if ((xnew*xnew + ynew*ynew) > 4) {
      // escapes
      return true;
    }
    x = xnew;
    y = ynew;
  }
  // does not escape
  return false;
}

void findMaxExposure() {
  // assume no exposure
  maxexposure=0;
  // find the largest density value
  for (int i=0;i<dim;i++) {
    for (int j=0;j<dim;j++) {
      maxexposure = max(maxexposure,exposure[i*dim+j]);
    }
  }
}


void renderBrot() {
  // draw to screen
  for (int i=0;i<dim;i++) {
    for (int j=0;j<dim;j++) {
      float ramp = exposure[i*dim+j] / (maxexposure / 2.5);
      
      // blow out ultra bright regions
      if (ramp > 3)  {
        ramp = 1;
      }
      uint16_t color = tft.color565(int(ramp*128), int(ramp*128), int(ramp*255));
      tft.drawPixel(j+80, i, color);

      //color c = color(int(ramp*255), int(ramp*255), int(ramp*255));
      //set(j,i,c);
    }
  }
}

double randomFloat(float minf, float maxf)
{
  return minf + random(1UL << 31) * (maxf - minf) / (1UL << 31);  // use 1ULL<<63 for max double values)
}
 
Last edited:
Didn't get my display on T$ anything but white yet, need to grab another one …

If "int exposure[160*160];" was refactored to "byte exposure[220*220];" it would take less space
 
Didn't get my display on T$ anything but white yet, need to grab another one …

If "int exposure[160*160];" was refactored to "byte exposure[220*220];" it would take less space

Done - got up to 240x240. Also, edited the color values - looks a lot better.

EDIT: The longer it runs it will zoom in automatically.
 
Last edited:
Also interesting, is if you put in DMAMEM you can for example do 240x240, but the you end up with garbage on display... Probably something about write through...
Will experiment again... Actually did try adding: arm_dcache_flush(exposure, sizeof(exposure))
to the start of renderBrot() did not appear to help...

Ran it on T3.6 as well, it also did not like DMAMEM specified? Thought that just set address to other area... But 240x240 works on T3.6
 
Back
Top