Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

teensy 3.2 and uncanny eyes
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

teensy 3.2 and uncanny eyes

by dlongley on Sun Jul 19, 2020 6:41 pm

Hi there!

I am having issues getting my Teensy 3.2 and TFT displays to work properly.
I can see part of the Adafruit logo, and part of an eye, and it is moving, but it is all wonky.
Pictures attached. I did NOT modify the config.h.
Any help would be GREATLY appreciated!

IMG_20200719_151452.jpg
IMG_20200719_151452.jpg (81.12 KiB) Viewed 59 times

IMG_20200719_151447.jpg
IMG_20200719_151447.jpg (65.68 KiB) Viewed 59 times

IMG_20200719_151439.jpg
IMG_20200719_151439.jpg (64.56 KiB) Viewed 59 times

dlongley
 
Posts: 18
Joined: Sat Jul 04, 2015 4:58 pm

Re: teensy 3.2 and uncanny eyes

by XRAD on Wed Jul 29, 2020 8:29 pm

Hi, First of all lets make sure you have the newest Arduino IDE 1.8.13, then reload the teensyduino installer to add all teensy boards to the updated IDE. I edited Adafruit's basic GFX test screens for the same pinouts on teensy board that you will need for the uncanny eye. ALSO, you may have to update your arduino libraries with newest adafruit GFX github files AND also the adafruit ST7735.h library from github. I then modified the ST7735.h file constructors to 128 x 128 on page one (which may not be necessary). Then when all that is good to go try this first sketch provided below to get the basic GFX working. Once that is working, then try the uncanny eye sketch. I made NO modifications to the config files of uncanny eye as you see it below, downloaded from: https://github.com/adafruit/Uncanny_Eyes

don't give up, you will get it to work out! medial canthus is trimmed a bit, but otherwise looks good!

basic eye
IMG_0416.JPG
IMG_0416.JPG (227.69 KiB) Viewed 50 times


dragon eye
IMG_0419.JPG
IMG_0419.JPG (119.71 KiB) Viewed 48 times



Code: Select all | TOGGLE FULL SIZE
/**************************************************************************
  This is a library for several Adafruit displays based on ST77* drivers.

  Works with the Adafruit 1.8" TFT Breakout w/SD card
    ----> http://www.adafruit.com/products/358
  The 1.8" TFT shield
    ----> https://www.adafruit.com/product/802
  The 1.44" TFT breakout
    ----> https://www.adafruit.com/product/2088
  The 1.14" TFT breakout
  ----> https://www.adafruit.com/product/4383
  The 1.3" TFT breakout
  ----> https://www.adafruit.com/product/4313
  The 1.54" TFT breakout
    ----> https://www.adafruit.com/product/3787
  The 2.0" TFT breakout
    ----> https://www.adafruit.com/product/4311
  as well as Adafruit raw 1.8" TFT display
    ----> http://www.adafruit.com/products/618

  Check out the links above for our tutorials and wiring diagrams.
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional).

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 **************************************************************************/

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
//#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

 
//these are the same TEENSY 3.2 pinouts for uncanny eye AND this GFX test
  #define TFT_DC         7
  #define TFT_RST        8
  #define TFT_CS         9 //left eye
  //#define TFT_CS       10//right eye
  #define TFT_MOSI       11                                         
  #define TFT_MISO       12
  #define TFT_SCK        13
 
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.

// For 1.44" and 1.8" TFT with ST7735 use:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// For 1.14", 1.3", 1.54", and 2.0" TFT with ST7789:
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);


// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
//#define TFT_MOSI 11  // Data out
//#define TFT_SCLK 13  // Clock out

// For ST7735-based displays, we will use this call
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

// OR for the ST7789-based displays, we will use this call
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;

void setup(void) {
  Serial.begin(9600);
  Serial.print(F("Hello! ST77xx TFT Test"));

  // Use this initializer if using a 1.8" TFT screen:
  //tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab

  // OR use this initializer if using a 1.8" TFT screen with offset such as WaveShare:
  // tft.initR(INITR_GREENTAB);      // Init ST7735S chip, green tab

  // OR use this initializer (uncomment) if using a 1.44" TFT:  THIS IS THE IMPORTANT LINE TO UNCOMMENT
  tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab

  // OR use this initializer (uncomment) if using a 0.96" 160x80 TFT:
  //tft.initR(INITR_MINI160x80);  // Init ST7735S mini display

  // OR use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
  //tft.init(240, 240);           // Init ST7789 240x240

  // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
  //tft.init(240, 320);           // Init ST7789 320x240

  // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
  //tft.init(135, 240);           // Init ST7789 240x135
 
  // SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
  // Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
  // may end up with a black screen some times, or all the time.
  //tft.setSPISpeed(40000000);

  Serial.println(F("Initialized"));

  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
  delay(1000);

  // tft print function!
  tftPrintTest();
  delay(4000);

  // a single pixel
  tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
  delay(500);

  // line draw test
  testlines(ST77XX_YELLOW);
  delay(500);

  // optimized lines
  testfastlines(ST77XX_RED, ST77XX_BLUE);
  delay(500);

  testdrawrects(ST77XX_GREEN);
  delay(500);

  testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
  delay(500);

  tft.fillScreen(ST77XX_BLACK);
  testfillcircles(10, ST77XX_BLUE);
  testdrawcircles(10, ST77XX_WHITE);
  delay(500);

  testroundrects();
  delay(500);

  testtriangles();
  delay(500);

  mediabuttons();
  delay(500);

  Serial.println("done");
  delay(1000);
}

void loop() {
  tft.invertDisplay(true);
  delay(500);
  tft.invertDisplay(false);
  delay(500);
}

void testlines(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, 0, x, tft.height()-1, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, 0, tft.width()-1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, 0, 0, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, tft.height()-1, x, 0, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
    delay(0);
  }
}

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

void testfillrects(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=tft.width()-1; x > 6; x-=6) {
    tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
  }
}

void testfillcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=radius; x < tft.width(); x+=radius*2) {
    for (int16_t y=radius; y < tft.height(); y+=radius*2) {
      tft.fillCircle(x, y, radius, color);
    }
  }
}

void testdrawcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
    for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
      tft.drawCircle(x, y, radius, color);
    }
  }
}

void testtriangles() {
  tft.fillScreen(ST77XX_BLACK);
  uint16_t color = 0xF800;
  int t;
  int w = tft.width()/2;
  int x = tft.height()-1;
  int y = 0;
  int z = tft.width();
  for(t = 0 ; t <= 15; t++) {
    tft.drawTriangle(w, y, y, x, z, x, color);
    x-=4;
    y+=4;
    z-=4;
    color+=100;
  }
}

void testroundrects() {
  tft.fillScreen(ST77XX_BLACK);
  uint16_t color = 100;
  int i;
  int t;
  for(t = 0 ; t <= 4; t+=1) {
    int x = 0;
    int y = 0;
    int w = tft.width()-2;
    int h = tft.height()-2;
    for(i = 0 ; i <= 16; i+=1) {
      tft.drawRoundRect(x, y, w, h, 5, color);
      x+=2;
      y+=3;
      w-=4;
      h-=6;
      color+=1100;
    }
    color+=100;
  }
}

void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.print(" seconds.");
}

void mediabuttons() {
  // play
  tft.fillScreen(ST77XX_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
  delay(500);
  // pause
  tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
  delay(500);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
  delay(50);
  // pause color
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
}
Last edited by XRAD on Wed Jul 29, 2020 8:44 pm, edited 2 times in total.

XRAD
 
Posts: 585
Joined: Sat Nov 19, 2016 3:28 pm

Re: teensy 3.2 and uncanny eyes

by dlongley on Wed Jul 29, 2020 8:35 pm

Thank you! I will try all the above and report back my results! Take care!

dlongley
 
Posts: 18
Joined: Sat Jul 04, 2015 4:58 pm

Re: teensy 3.2 and uncanny eyes

by XRAD on Wed Jul 29, 2020 8:47 pm

you are welcome. Enjoy the build!

XRAD
 
Posts: 585
Joined: Sat Nov 19, 2016 3:28 pm

Re: teensy 3.2 and uncanny eyes

by michaelmeissner on Sun Aug 02, 2020 12:58 pm

One minor note, in your connection, you have the battery power (red) wire connected to the VIN pin, and the ground (black) wire connected to the pin next to VIN. On the Teensy 3.2 there are two different ground pins. The normal digital ground pin is on the other side of the Teensy from the VIN pin (next to pin 0). The pin you have connected to is the analog ground pin, that has some extra filtering for doing analog reads. Try moving your ground wire to the digital ground pin.

In running uncanny eyes on various Teensy boards (3.2, 3.5, 3.6, 4.0), I have run into issues where you have to adjust the SPI clock speed to match the displays. If you go into the 'config.h' file, there is a SPI_FREQ define. Try to set it lower. The value I currently use is 18000000U, but you may need to adjust it down to match your particular displays.

In addition, I have found that if I add pull-up resistors between each of the display CS pins and 3.3v, that it allows me to run the displays much faster. I tend to use 2.2K resistors (that I also add for pins 18/19 for I2C). Generally, I noticed this when I was running 2 displays.

Another thing that helped me in the past, is there was at least one time I was using cheap jumper wires and breadboards that had been used quite a bit. When I replaced the wire, and breadboard things improved. You do want to keep the wires as short as possible.

Here is an older article I wrote in 2017 in the Teensy forum (note, some things have changed since then):

And here is a paper about using pull-ups on the CS pins:

michaelmeissner
 
Posts: 1422
Joined: Wed Aug 29, 2012 12:40 am

Re: teensy 3.2 and uncanny eyes

by XRAD on Sun Aug 02, 2020 1:49 pm

Hi MM! Thx for reply. Good point on grounds. OK so we should use AGND for anything that could have a current in it? apparently, AGND and GND(DGND) are somehow 'isolated' from each other on the teensy board.

Works fine with GND or AGND, but I want to wire 'correctly'...I left the joystick pot (not in pic) on the AGND pin...

XRAD
 
Posts: 585
Joined: Sat Nov 19, 2016 3:28 pm

Re: teensy 3.2 and uncanny eyes

by michaelmeissner on Sun Aug 02, 2020 2:07 pm

In general, you want to use analog ground when you do an analogRead (some audio things also use the analog ground). Use the digital ground for everything else. Having the analog ground being filtered means the analog devices are a little cleaner in terms of their output.

There is a second digital ground at the back of the Teensy, but that is not as convenient to use for breadboard work. On the Teensy 3.2, there is a third digital ground as a solder pad under the Teensy board.

In particular, since you were providing ground from a power source, I didn't know if the filtering done internally between the digital and analog grounds would affect it being powered.

Note, I am a computer programmer by training, though I've been using Teensys since they came out. I.e. I can't tell you the electrical differences between the two.

michaelmeissner
 
Posts: 1422
Joined: Wed Aug 29, 2012 12:40 am

Re: teensy 3.2 and uncanny eyes

by dlongley on Sun Aug 02, 2020 5:07 pm

Hi XRAD and michaelmeissner!,

Thank you both for the very helpful tips. I am happy to report I have the Teensy 3.2 uncanny eyes up and running! :)
The root of my problem is that I started with the Animated Snake Eyes Bonnet for Raspberry Pi project using the Adafruit 1.54" 240x240 (ST7789), and then jumped directly into the Electronic Animated Eyes for ARM Microcontrollers project ASSUMING I could still use the ST7789. After reading posts from both of you on the forum, the lightbulb lit up and I realized the issues when trying to use the ST7789 with the Teensy 3.2. I made no modifications to the code and wired up a pair of ST7735R, and POOF! Everything worked. I really learned a lot about the code and hardware with this project and truly appreciate your help. Take care and see you in the tubes!

dlongley
 
Posts: 18
Joined: Sat Jul 04, 2015 4:58 pm

Re: teensy 3.2 and uncanny eyes

by XRAD on Sun Aug 02, 2020 8:29 pm

cool! glad you got it working

XRAD
 
Posts: 585
Joined: Sat Nov 19, 2016 3:28 pm

Re: teensy 3.2 and uncanny eyes

by michaelmeissner on Sun Aug 02, 2020 8:57 pm

IIRC, the Teensy 3.2 does not have enough memory to do 240x240 displays. Also when Phil Burgess wrote the Teensy uncanny eyes sketch, only the 128x128 displays were available.

As I understand it, Phil Burgess first wrote the uncanny eyes sketch for the Teensy. After that he moved to the snake eyes on the Raspbery Pi. Finally with the introduction of the Adafruit M0/M4 processors, he concentrated on those new processors (M0 Express, Hallowing, Hallowing M4, M4 express, Monster M4SK, etc.). With the embedded flash and tinyUSB support, it is a lot easier to modfiy the eyes used on the Adafruit M0/M4 processors.

The Teensy code at Adafruit will run on the Teensy 3.2, 3.5, and 3.6 (though with the 3.5 and 3.6, you will need to adjust the SPI bus speed). In the Teensy 4.0/4.1, things changed quite a bit under the covers, and the code at Adafruit will not compile.

However, there is a port for the Teensy 4.0/4.1. If you use the latest teensydunio (1.53). There are two examples:
  • Version for 128x128 displays: ST773_t3 -> uncannyEyes7735
  • Version for 240x240 displays: ST773_t3 -> uncannyEyes_async_st7789_240x240 (note this is Teensy 4.0/4.1)

Teensy 4.x does not have the special hardware option for the CS/DC pins that the Teensy 3.x processors have. This means the first example, may run slower on a Teensy 4.0 than a 3.2.

The second example uses the fact that the Teensy 4.x has two hardware SPI buses, and it puts each display on a separate bus. Unfortunately to get access to the 2nd SPI pins, you have to solder a few wires to connect to pads underneath the Teensy (or use one of the breakout PCBs). The Teensy 4.1 does bring out these pins on the breadboard pins.

I don't recall if I've used the 240x240 sketch on the Teensy 4.1.

michaelmeissner
 
Posts: 1422
Joined: Wed Aug 29, 2012 12:40 am

Please be positive and constructive with your questions and comments.