Teensy3.1 Occasionally unresponsive

Status
Not open for further replies.

TonyParakka

New member
My Teensy 3.1 (T3.1) loses serial connection and also non-functional (but recoverable); Could use help tot figure out why.
In this un-responsive mode, it no longer appears connected (under Port) and devices attached to it (2.2" TFT ILI9341) goes blank.

Recovery : (Thanks Paul, picked this up from a previous "Teensy dead thread") Disconnect USB cable, hold Reset button, reconnect USB cable, wait 15sec release USB button; then load "Blinky"; then upload program again (code below)
After recovery, the code works; but would feel much better knowing why the T3.1 went un.responsive.

This behaviour is a recent thing, since I moved the T3.1 from the breadboard to a prototype board.
On the breadboard, the program was stable, and operated indefinitely.
On the breadboard mu connections were: CS=D10, DC=D9; MOSI=D11, MISO=D12, SCK=D13, RESET=Vdd(3.3v), RLED=100ohm from 3.3v
In going to the porto board, I did make a few small change,
CS=D15, DC=D10, others remained the same MOSI=D11, MISO=D12, SCK=D13 RESET=Vdd, RLED=82ohm from 3.3v
HW wise, I have double-checked connections; all seem fine (evidenced by the board working after recovery)
I do not see any component on the T3.1 board, or the 82ohm resistor, or anything on the TFT board getting hot.

Grateful for any thoughts and suggestions..

thanks..

-Tony

PS. I am relatively new to the Teensy devices, and still learning..

Full Code:#include "ILI9341_t3.h" //TFT library with Teensy3+
#include <SPI.h>
#include <Wire.h>
#include "font_Arial.h"

#define TFT_CS 15 //<<<<<<====NOTE: FOR INTEGRATED BOARD WITH T3 AND 2.2TFT
#define TFT_DC 10 //<<<<<<====NOTE: FOR INTEGRATED BOARD WITH T3 AND 2.2TFT
#define TFT_MOSI 11 //defaulat MOSI
#define TFT_MISO 12 //default MISO
#define TFT_SCK 13 //default SCK
#define TFT_RST 255 //tied to 3.3v

#define TFT_GREY 0x5AEB

ILI9341_t3 tft=ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);

#define CMPS11_ADDRESS 0x60 // Address of CMPS11 shifted right one bit for arduino wire library
#define ANGLE_8 1 // Register to read 8bit angle from

#define aXneutral 160 //aircraft Xneutral = center of box
#define aYneutral 150 //aircrat Yneutral = cener of box
#define aYoffset 0 //aircraft Yoffset to compensate for installation
#define aXrange 90 //box is 180 wide
#define aYrange 90 //box is 180 tall
#define aRadius 8 //aircraft fuselage size
#define tLen 30 //aircraft tail size
#define wLen 50 //aircraft wing size
#define maxPitch 45 //LIMIT MAX PITCH FOR PITCH DISPLAY SENSITIVITY
#define maxUPpitch 45
#define maxDNpitch -45
#define screenColor ILI9341_BLACK
#define headingTxtColor ILI9341_YELLOW
#define headingBakColor ILI9341_BLACK
#define headingBoxColor ILI9341_YELLOW
#define headingFont 6
#define headingTxtSize 1
#define boxFillColor ILI9341_NAVY
#define boxBoxColor ILI9341_WHITE
#define boxXhairColor ILI9341_DARKGREEN
#define boxBankMarkerColor ILI9341_WHITE
#define boxPitchMarkerColor ILI9341_WHITE
#define boxPitchLineColor ILI9341_DARKGREEN
#define boxAircraftColor ILI9341_WHITE


int pitch, roll;//pitch and roll: valid range are +/-85degrees
int newHeading, oldHeading;//heading
int fontValue=6;//heading text font
// screen positions and increments for heading value display
int hYpos=10, hXpos=115, hXinc=30;//heading text position and increment
// aircraft display box start and end values
int aXstart=aXneutral-aXrange, aXend=aXneutral+aXrange;
int aYstart=aYneutral-aYrange, aYend=aYneutral+aYrange;
int oldAYpos= 150; //=(71+239)/2 aircraft dot position
int WX1=0, WX2=0, WY1=0, WY2=0;//wing line position
int TX1=0, TX2=0, TY1=0, TY2=0;//tail line position
//roll angle marker coord -inside, outside for R1=62, R2=70/80: angles 0->180deg, 15deg increments
int mX1[]={62,60,54,44,31,16,0,-16,-31,-44,-54,-60,-62}, mX2[]={80,68,69,49,40,18,0,-18,-40,-49,-69,-68,-80};//marker xcoord for 15, 30, 45, 60deg, R=45, 60
int mY1[]={0,16,31,44,54,60,62,60,54,44,31,16,0}, mY2[]={0,18,40,49,69, 68,80,68,69,49,40,19,0};//marker ycoord for 15, 30, 45, 60deg, R=45, 60
//pitch angle marker coordinates outside the Attitude box
int pMx[]={10,5,10,5,10}, pMy[]={0,18,36,54, 72, 90};
// marker coordinates from MarkerCoordinates Spreadhseet

void setup()
{
//tft.init();
tft.begin();
tft.setRotation(1);
tft.fillScreen(screenColor);
//tft.fillRect(aXstart,aYstart, aXrange*2,aYrange*2, boxFillColor); //attitude box
//Attutude Box
tft.fillRect(aXstart, aYstart, aXrange*2, aYrange, ILI9341_BLUE); //sky half
tft.fillRect(aXstart, aYneutral, aXrange*2, aYrange, ILI9341_MAROON); //ground half
tft.drawRect(aXstart, aYstart, aXrange*2, aYrange*2, boxBoxColor); //draw Outline
for(int i=0; i<6; i++){ //draw pitch angle markers
tft.drawLine(aXstart-pMx,aYneutral+pMy,aXstart, aYneutral+pMy, boxPitchMarkerColor);
tft.drawLine(aXstart-pMx,aYneutral-pMy,aXstart, aYneutral-pMy, boxPitchMarkerColor);
tft.drawLine(aXend+pMx,aYneutral+pMy,aXend, aYneutral+pMy, boxPitchMarkerColor);
tft.drawLine(aXend+pMx,aYneutral-pMy,aXend, aYneutral-pMy, boxPitchMarkerColor);
}
tft.setFont(Arial_24);
tft.setTextColor(headingTxtColor, headingBakColor); //heading text color
tft.drawRect(100, 5, 120, 53, headingBoxColor); //box over heading
for(int i=0; i<13; i++){
mX1=aXneutral-mX1;
mX2=aXneutral-mX2;
mY1=aYneutral-mY1;
mY2=aYneutral-mY2;
}
Wire.begin();
//Serial.begin(9600); //Debug only
}

void loop()
{
Wire.beginTransmission(CMPS11_ADDRESS); //starts communication with CMPS11
Wire.write(ANGLE_8); //Sends the register we wish to start reading from
Wire.endTransmission();
// Request 5 bytes from the CMPS11: byteHeading, wordHeading, bytePitch, byteRoll
Wire.requestFrom(CMPS11_ADDRESS, 5);
while(Wire.available() < 5);// Wait for all bytes to come back
newHeading = Wire.read();//read byteHeading heading value and discard
newHeading = Wire.read();//read high byte of wordHeading value
newHeading = (newHeading<<=8)+Wire.read();//shift high byte by 8bits, then read and add lower byte
pitch = Wire.read();//read bytePitch
roll = Wire.read();//read byteRoll
//-----------------------------------
newHeading/=10; //Remove decimal value
//reverse heading direction for board header at aircraft tail end---------
newHeading-=180;
if(newHeading<0) newHeading+=360;
if(pitch>127) pitch-=256;
if(roll>127) roll-=256;
//limit pitch value to maxPitch for better pitch display sensitivity
if(pitch>maxUPpitch) pitch=maxUPpitch;
else if(pitch<maxDNpitch) pitch=maxDNpitch;
//-----------------------------------
//Serial.print("Pitch="); Serial.print(pitch); //Debug only
//Serial.print(" : Roll="); Serial.print(roll); //Debug only
//Serial.print(" : Heading="); Serial.println(newHeading); //Debug only
//----------------------------------
printHeading();//update heading display value
drawAircraft(roll, pitch);//update pitch/roll display

delay(100); // update approx 10 times per second
}

void drawAircraft(int rValue, int pValue){ //For T3, changed to int from char; fixed ISSUE in _000
//
int newYneutral=aYoffset+map(pValue, maxDNpitch, maxUPpitch, aYend, aYstart);
int aYdip= (int)((float)aXrange*sin((float)rValue*0.0174));
int aY1=newYneutral-aYdip, aY2=newYneutral+aYdip;
if(aY1>aY2){ //aY1 is left side, aY2 is right side
tft.fillRect(aXstart, aYstart, aXrange*2, (aY2-aYstart), ILI9341_BLUE);//fill sky to higherY on screen
tft.fillRect(aXstart, aY1, aXrange*2, (aYend-aY1), ILI9341_MAROON);//fill ground from lower Y to bottom
tft.fillTriangle(aXstart, aY1, aXend, aY1, aXend, aY2, ILI9341_MAROON);//fill lower triangle with ground
tft.fillTriangle(aXstart, aY2, aXstart, aY1, aXend,aY2, ILI9341_BLUE);//fill upper triangle with sky
}
else{ //roll Left -works well
tft.fillRect(aXstart, aYstart, aXrange*2, (aY1-aYstart), ILI9341_BLUE);//fill sky to higher Y on screen
tft.fillRect(aXstart, aY2, aXrange*2, (aYend-aY2), ILI9341_MAROON);//fill ground from lower Y to bottom
tft.fillTriangle(aXstart, aY1, aXend, aY1, aXend, aY2, ILI9341_BLUE);//fill upper triangle with Sky
tft.fillTriangle(aXstart, aY1, aXstart, aY2, aXend, aY2, ILI9341_MAROON);//fill lower triangle with Ground
}
//Draw Aircraft
tft.fillRoundRect(aXneutral-wLen, aYneutral, wLen*2, 4, 2, ILI9341_WHITE); //draw Wings
tft.fillRoundRect(aXneutral-2, (aYneutral-tLen), 4, tLen, 2, ILI9341_WHITE); //draw Tail
tft.fillCircle(aXneutral, aYneutral, aRadius, ILI9341_WHITE); //draw Fuselage
//Draw Bank Markers
for(int i=0; i<13; i++){
tft.drawLine(mX1, mY1, mX2, mY2, ILI9341_WHITE);//Flickers jsut redrawing! Why?
}
}

void printHeading(){
int i, decade, nHvalue=newHeading, oHvalue=oldHeading, x=hXpos, y=hYpos;

tft.setFont(Arial_40);
// Check individual digits; only if changed then erase old/print new; eliminates flicker
for(i=0, decade=100; i<3; i++){
if((nHvalue/decade) != (oHvalue/decade)){
tft.setCursor(x, y);
tft.setTextColor(headingBakColor);
tft.print(oHvalue/decade);
tft.setCursor(x, y);
tft.setTextColor(headingTxtColor);
tft.print(nHvalue/decade);
}
nHvalue%=decade; oHvalue%=decade;
decade/=10; x+=hXinc;
}
tft.drawRect(100, 5, 120, 53, headingBoxColor); //box over heading

oldHeading=newHeading;
}
 
Adding some more details, occasionally the program on the T3.1 now hangs.
When the program is hung, the T3.1 no longer appears in Tools>Port

Could the choice of CS(D15) and DC(D10) have something to do with the in-stability?
(that and the RLED are the only change that I can think of)

One additional note: When I re-upload the code (modified or not), the upload now seems to take much longer than previously on the breadboard.

Any help much appreciated!
 
Paul could say - but I only know the T_3.5 and T_3.6 to have been programmed with the 15 second recovery process. Never saw upload speed change or seem long.

Code would be much easier to read if post was edited to select the code block and then hit the "#" hash on the post edit toolbar to enclose in the [C0DE] /... [/C0DE] block.

Most often hangs stopping USB are from trashing memory. Odd thing I see is the 'while(Wire.available() < 5);' that will show teensy to be unresponsive if the i2c gets hosed - though that shouldn't stop the USB from facilitating new upload - unless that code has gone badly. A timeout on that followed by an error note might indicate a problem - or just turn on LED_BUILTIN before and off after to know it isn't stuck on that.
 
Update: I moved CS->D10 and DC->D9 on the protoboard (like I had on breadboard) and operation appears to be stable.
Will run it overnight to see if still happy in the morning..

@defragster: Thanks! I tried other means of recovery (e.g. re-boot computer, hold button and connect cable) -did not make T3 appear on Tools>Port. But with the 15sec procedure , the T3.1 programmed ok.
and thanks for the pointer on including code; my first post.. learning..

So, am I understanding D10 <-> CS are exclusive?

-tony
 
Status
Not open for further replies.
Back
Top