mladenman93
Member
Hello everyone!
I'm having a problem with my Teensy 3.2. I had been happily coding with it throughout the last days. Yesterday I implemented a code that uses the serial monitor as input. The code would get bytes from the serial monitor and then print the respective text on a LED-Matrix that I've built on my own. All worked perfectly until I unplugged the teensy at some point while serial monitor was still running. Since then I can't connect my Teensy anymore as the arduino IDE throws the "No Teensy boards were found on any USB ports of your computer." error message and there is no COM Port device detected by the Computer. I tried to upload new code by pressing the pushbutton - didn't work. However the old code appears to still run on the Teensy it just doesn't print anything anymore because there's no input from the serial monitor. I also noticed that in the bottom right corner of my arduino IDE it doesn't say "Teensy 3.2 [...] on COM1" anymore like it did before but rather "Teensy 3.2 [...] on usb:0/140000/0/3" (I don't know if that's related but I had to switch from COM1 to COM5 in the tools>ports menu to be able to connect the teensy and the serial monitor). Finally I tried to reinstall the arduino and Teensy uploader but it didn't work either. I attached the code below and highlighted the parts where I used the serial.
Help would be greatly appreciated!
Thanks in advance and cheers,
Mladenman
I'm having a problem with my Teensy 3.2. I had been happily coding with it throughout the last days. Yesterday I implemented a code that uses the serial monitor as input. The code would get bytes from the serial monitor and then print the respective text on a LED-Matrix that I've built on my own. All worked perfectly until I unplugged the teensy at some point while serial monitor was still running. Since then I can't connect my Teensy anymore as the arduino IDE throws the "No Teensy boards were found on any USB ports of your computer." error message and there is no COM Port device detected by the Computer. I tried to upload new code by pressing the pushbutton - didn't work. However the old code appears to still run on the Teensy it just doesn't print anything anymore because there's no input from the serial monitor. I also noticed that in the bottom right corner of my arduino IDE it doesn't say "Teensy 3.2 [...] on COM1" anymore like it did before but rather "Teensy 3.2 [...] on usb:0/140000/0/3" (I don't know if that's related but I had to switch from COM1 to COM5 in the tools>ports menu to be able to connect the teensy and the serial monitor). Finally I tried to reinstall the arduino and Teensy uploader but it didn't work either. I attached the code below and highlighted the parts where I used the serial.
Code:
#include <TimerOne.h>
#define ROW_DATA 0 //Pin Number for Row Serial Data output
#define ROW_SCLK 1 //Pin Number for ROW SERIAL CLK output
#define ROW_NSCLR 2 //Pin Number for ROW INV SERIAL CLK output
#define BLUE_DATA 3 //Pin Number for B-Value Serial Data output
#define BLUE_NSCLR 4 //Pin Number for BLUE INV REGISTER CLEAR
#define BLUE_SCLK 5 //Pin Number for BLUE SERIAL CLK output
#define BLUE_RCLK 6 //Pin Number for BLUE REGISTER CLK output
#define BLUE_NOE 7 //Pin Number for BLUE INV OUTPUT ENABLE output
#define GREEN_DATA 8 //Pin Number for G-Value Serial Data output
#define GREEN_NSCLR 18 //Pin Number for GREEN INV REGISTER CLEAR
#define GREEN_SCLK 17 //Pin Number for GREEN SERIAL CLK output
#define GREEN_RCLK 16 //Pin Number for GREEN REGISTER CLK output
#define GREEN_NOE 20 //Pin Number for GREEN INV OUTPUT ENABLE output
#define RED_DATA 19 //Pin Number for R-Value Serial Data output
#define RED_NSCLR 23 //Pin Number for RED INV REGISTER CLEAR
#define RED_SCLK 22 //Pin Number for RED SERIAL CLK output
#define RED_RCLK 21 //Pin Number for RED REGISTER CLK output
#define RED_NOE 15 //Pin Number for RED INV OUTPUT ENABLE output
#define RED 1 //Color Code for Red
#define GREEN 2 //Color Code for Green
#define YELLOW 3 //Color Code for Yellow
#define BLUE 4 //Color Code for Blue
#define PURPLE 5 //Color Code for Purple
#define TURQ 6 //Color Code for Turquoise
#define WEISS 7 //Color Code for White
#define LED 13
//Initialize Counter and State Variable for Interrupt handler
volatile int scnt = 0;
volatile int rcnt = 9;
volatile int SCLK_State = 0;
volatile int RCLK_State = 0;
volatile int RSCLK_State = 0;
volatile int RSER_State = 0;
int color[8]={0,RED,GREEN,BLUE,YELLOW,TURQ,PURPLE,WEISS};
//Buchstaben
int Alphabet[26][10]={{14,17,17,17,31,17,17,17,17, 0},{30,17,17,17,30,17,17,17,30, 0},{15,16,16,16,16,16,16,16,15, 0},
{28,18,17,17,17,17,17,18,28, 0},{31,16,16,16,28,16,16,16,31, 0},{31,16,16,16,28,16,16,16,16, 0},
{14,17,16,16,16,23,17,17,15, 0},{17,17,17,17,31,17,17,17,17, 0},{31, 4, 4, 4, 4, 4, 4, 4,31, 0},
{31, 1, 1, 1, 1, 1, 1, 1,30, 0},{17,17,18,20,24,20,18,17,17, 0},{16,16,16,16,16,16,16,16,31, 0},
{17,27,21,17,17,17,17,17,17, 0},{17,25,21,19,17,17,17,17,17, 0},{14,17,17,17,17,17,17,17,14, 0},
{30,17,17,17,30,16,16,16,16, 0},{14,17,17,17,17,17,21,19,15, 0},{30,17,17,17,30,20,18,17,17, 0},
{15,16,16,16,14, 1, 1, 1,30, 0},{31, 4, 4, 4, 4, 4, 4, 4, 4, 0},{17,17,17,17,17,17,17,17,31, 0},
{17,17,17,17,17,17,17,10, 4, 0},{17,17,17,17,17,17,21,27,17, 0},{17,17,17,10, 4,10,17,17,17, 0},
{17,27,21, 4, 4, 4, 4, 4, 4, 0},{31, 1, 2, 4, 8,16,16,16,31, 0}};
//Zeichen
int Space[10]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int Qmark[10]={14,17, 1, 1, 2, 4, 4, 0, 4, 0};
int Xmark[10]={ 4, 4, 4, 4, 4, 4, 4, 0, 4, 0};
//Initialize Image Matrix
volatile byte image[10][24];
volatile byte pixel=0;
String inString; //Ausgelesener String
volatile int SerFlag=0; //Interrupt Flag
void setup() {
// put your setup code here, to run once:
//Set output Pins
pinMode(RED_DATA,OUTPUT);
pinMode(GREEN_DATA,OUTPUT);
pinMode(BLUE_DATA,OUTPUT);
pinMode(ROW_DATA,OUTPUT);
pinMode(RED_RCLK,OUTPUT);
pinMode(GREEN_RCLK,OUTPUT);
pinMode(BLUE_RCLK,OUTPUT);
pinMode(RED_SCLK,OUTPUT);
pinMode(GREEN_SCLK,OUTPUT);
pinMode(BLUE_SCLK,OUTPUT);
pinMode(RED_NSCLR,OUTPUT);
pinMode(GREEN_NSCLR,OUTPUT);
pinMode(BLUE_NSCLR,OUTPUT);
pinMode(RED_NOE,OUTPUT);
pinMode(GREEN_NOE,OUTPUT);
pinMode(BLUE_NOE,OUTPUT);
pinMode(ROW_SCLK,OUTPUT);
pinMode(ROW_NSCLR,OUTPUT);
pinMode(LED,OUTPUT);
// Initialize output pins
digitalWrite(RED_DATA,HIGH);
digitalWrite(GREEN_DATA,HIGH);
digitalWrite(BLUE_DATA,HIGH);
digitalWrite(ROW_DATA,LOW);
digitalWrite(RED_RCLK,LOW);
digitalWrite(GREEN_RCLK,LOW);
digitalWrite(BLUE_RCLK,LOW);
digitalWrite(RED_SCLK,LOW);
digitalWrite(GREEN_SCLK,LOW);
digitalWrite(BLUE_SCLK,LOW);
digitalWrite(RED_NSCLR,LOW);
digitalWrite(GREEN_NSCLR,LOW);
digitalWrite(BLUE_NSCLR,LOW);
digitalWrite(RED_NOE,HIGH);
digitalWrite(GREEN_NOE,HIGH);
digitalWrite(BLUE_NOE,HIGH);
digitalWrite(ROW_SCLK,LOW);
digitalWrite(ROW_NSCLR,LOW);
digitalWrite(LED,LOW);
delay(100);
digitalWrite(RED_NSCLR,HIGH);
digitalWrite(GREEN_NSCLR,HIGH);
digitalWrite(BLUE_NSCLR,HIGH);
digitalWrite(RED_NOE,LOW);
digitalWrite(GREEN_NOE,LOW);
digitalWrite(BLUE_NOE,LOW);
digitalWrite(ROW_NSCLR,HIGH);
digitalWrite(ROW_DATA,HIGH);
//Initialize Timer to trigger interrupt with 14.4kHz
Timer1.initialize(20);
Timer1.attachInterrupt(MatrixOut);
[COLOR="#FF8C00"]//Initialize Serial Port
Serial.begin(9600);[/COLOR]
//Initialize Matrix
for (int i=0; i<10; i++){
for (int j=0; j<24; j++){
image[i][j]= BLUE;
}
}
}
//Timer1 Interrupt handler
void MatrixOut(void)
{
SCLK_State = scnt & 1; //Toggles with every interrupt
RCLK_State = scnt == 0; //Toggles twice when new row starts
RSER_State = rcnt == 1; //Stays up during first row of every image, the 1 is then shiftet through with RSCLK to enable the other rows subsequently
RSCLK_State = scnt<24; //Toggles twice during every row
pixel = image[rcnt][scnt>>1]; //Copy current image pixel
//Write pinstates
digitalWrite(RED_SCLK,SCLK_State);
digitalWrite(RED_RCLK,RCLK_State);
digitalWrite(RED_DATA,!(pixel & 1));
digitalWrite(GREEN_SCLK,SCLK_State);
digitalWrite(GREEN_RCLK,RCLK_State);
digitalWrite(GREEN_DATA,!((pixel>>1) & 1));
digitalWrite(BLUE_SCLK,SCLK_State);
digitalWrite(BLUE_RCLK,RCLK_State);
digitalWrite(BLUE_DATA,!((pixel>>2) & 1));
digitalWrite(ROW_DATA,RSER_State);
digitalWrite(ROW_SCLK,RSCLK_State);
//increment counters
scnt++;
if(scnt > 47){
scnt=0;
rcnt++;
if(rcnt > 9){
rcnt=0;
}
}
}
[COLOR="#FF8C00"]//SerialEvent Handler
void serialEvent(){
SerFlag=1;
}
void loop() {
// put your main code here, to run repeatedly:
for (int j=0;j<10;j++){
for (int k=0;k<24;k++){
image[j][k]=0;
}
}
if(Serial.available()){
SerFlag=0;
int n=Serial.available();
char chars[n];
for(int i=0;i<n;i++){
chars[i]=Serial.read();
}
inString=chars;
Serial.print(inString);
Serial.println("");
runText(inString,BLUE);
}
}[/COLOR]
void runText(String Input, int color){
int len=Input.length();
int Text[10][len*6+48];
for (int h=0; h<len*6+48;h++){
for (int g=0; g<10; g++){
Text[g][h]=0;
}
}
for (int i=0; i<len; i++){
int cnt=0;
int let=Input.charAt(i);
if ((let<65)||(let>122)){
if(let==33){
for (int j=24+i*6;j<i*6+30;j++){
for (int k=0; k<9; k++){
int on=((Xmark[k]>>(5-(j-(24+i*6))))&1);
if (on){
Text[k][j]=color;
}
}
}
}else if(let==63){
for (int j=24+i*6;j<i*6+30;j++){
for (int k=0; k<9; k++){
int on=((Qmark[k]>>(5-(j-(24+i*6))))&1);
if (on){
Text[k][j]=color;
}
}
}
}else{
}
}else if(let<97){
int idx=let-65;
for (int j=24+i*6;j<i*6+30;j++){
for (int k=0; k<9; k++){
int on=((Alphabet[idx][k]>>(5-(j-(24+i*6))))&1);
if (on){
Text[k][j]=color;
}
}
}
}else{
int idx=let-97;
for (int j=24+i*6;j<i*6+30;j++){
for (int k=0; k<9; k++){
int on= ((Alphabet[idx][k]>>(5-(j-(24+i*6))))&1);
if (on){
Text[k][j]=color;
}
}
}
}
}
int shift=0;
while(1){
while(shift<len*6+24){
for (int i=0; i<24;i++){
for (int j=0; j<10;j++){
image[j][i]=Text[j][shift+i];
if(SerFlag){
return;
}
}
}
shift++;
delay(100);
}
shift=0;
}
}
Help would be greatly appreciated!
Thanks in advance and cheers,
Mladenman