Program not runnin at power up Teensy 3.1

Status
Not open for further replies.

danpea

New member
Hi there,

I having problems with my Teensy 3.1 in that is doesn’t seem to run the installed program at power up.

I am just messing around with a four pin I2C 0.96 64x128 OLED module from Heltech.

I have the OLED module SDA pin wired to A4 and the SCL pin wired to A5.

IMAG0315.jpg



The only way i seem o be able to get the program running and the OLED to display its output upon power up is to press the rest button a few times in quick succession.

The application i have in mind needs to run from power up without any human.

The code (excuse poor coding - I’m no programmer ):-


Code:
/* ssd1306_128x64_i2c_spinning box
date complied 29th Aug 2014 by Dan Peabody
*/


#include <Adafruit_SSD1306.h>

// A4 = SDA
// A5 = SCL

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>


#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {                
//Serial.begin(9600);
//while(!Serial);
//delay(5000);
//Serial.println("ssd1306_128x64_i2c_spinning box");
//Serial.println(SSD1306_LCDHEIGHT);
//Serial.print(debug);
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
  // init done
  //display.clearDisplay();   // clears the screen and buffer
  // text display 
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  delay(100);
  display.clearDisplay();   // clears the screen and buffer
  //drawBox();
}

// -- MAIN LOOP -------------------------------------------------------------
void loop() {
 /*
  for (int i=0; i <= 5; i++)
{ 
drawBox_wobble();
}
*/
 for (int i=0; i <= 3000; i++)
{ 
  delay(500);
drawBox_grow();
}
//delay(50);
}

// --------------------------------------------------------------------------
void drawBox_wobble() {
  
  display.clearDisplay();   // clears the screen and buffer
  int C1x = 10; 
  int C1y = 10; 
  int C2x = 100; 
  int C2y = 10;
  int C3x = 100; 
  int C3y = 50;
  int C4x = 10; 
  int C4y = 50;

  C1x = random(10, 20); // corner 1 position
  C1y = random(10, 20); 
  
  C2x = random(110, 120); // corner 2 position
  C2y = random(10, 20); 
  
  C3x = random(110, 120); // corner 3 position
  C3y = random(50, 60); 
  
  C4x = random(10, 20); // corner 4 position
  C4y = random(50, 60); 
  
  display.drawLine(C1x, C1y, C2x, C2y, WHITE); // Line 1
  display.drawLine(C2x, C2y, C3x, C3y, WHITE); // Line 2
  display.drawLine(C3x, C3y, C4x, C4y, WHITE); // Line 3
  display.drawLine(C4x, C4y, C1x, C1y, WHITE); // Line 4
  display.display();

 
  
  C1x = C1x +random(0, 2)-1; // corner 1 position
  C1y = C1y +random(0, 2)-1;
  
  C2x = C2x +random(0, 2)-1; // corner 2 position
  C2y = C2y +random(0, 2)-1; 
  
  C3x = C3x +random(0, 2)-1; // corner 3 position
  C3y = C3y +random(0, 2)-1; 
  
  C4x = C4x +random(0, 2)-1; // corner 4 position
  C4y = C4y +random(0, 2)-1; 
  
  
  
  display.drawLine(C1x, C1y, C2x, C2y, WHITE); // Line 1
  display.drawLine(C2x, C2y, C3x, C3y, WHITE); // Line 2
  display.drawLine(C3x, C3y, C4x, C4y, WHITE); // Line 3
  display.drawLine(C4x, C4y, C1x, C1y, WHITE); // Line 4
  display.display();


}

// --------------------------------------------------------------------------
void drawBox_grow() {
  
 // display.clearDisplay();   // clears the screen and buffer
  int C1x = 54; 
  int C1y = 22; 
  int C2x = 74; 
  int C2y = 22;
  int C3x = 74; 
  int C3y = 42;
  int C4x = 54; 
  int C4y = 42;

  
 // display.drawLine(C1x, C1y, C2x, C2y, WHITE); // Line 1
 // display.drawLine(C2x, C2y, C3x, C3y, WHITE); // Line 2
//  display.drawLine(C3x, C3y, C4x, C4y, WHITE); // Line 3
//  display.drawLine(C4x, C4y, C1x, C1y, WHITE); // Line 4
//  display.display();

 //grow 
   for (int i=0; i <= 5; i++)
{ 
 
  C1x = C1x - i; // corner 1 position
  C1y = C1y - i;
  
  C2x = C2x + i; // corner 2 position
  C2y = C2y - i; 
  
  C3x = C3x + i; // corner 3 position
  C3y = C3y + i; 
  
  C4x = C4x - i; // corner 4 position
  C4y = C4y + i; 
    
  display.drawLine(C1x, C1y, C2x, C2y, WHITE); // Line 1
  display.drawLine(C2x, C2y, C3x, C3y, WHITE); // Line 2
  display.drawLine(C3x, C3y, C4x, C4y, WHITE); // Line 3
  display.drawLine(C4x, C4y, C1x, C1y, WHITE); // Line 4
  
   display.setCursor(2,25);
 display.setTextSize(1);
 display.print(C1x);
 display.print(",");
 display.println(C1y); 
 display.setCursor(2,35);
 display.print(C2x);
 display.print(",");
 display.println(C2y);
 display.setCursor(2,45);
 display.print(C3x);
 display.print(",");
 display.println(C3y);
 display.setCursor(2,55);
 display.print(C4x);
 display.print(",");
 display.println(C4y);

 
 display.setCursor(58,58);
 display.setTextSize(1);
 display.print("GROW");
 display.display();
 delay(10);
 display.clearDisplay();
  
  }
  
delay(500);

//shrink
   for (int i=0; i <= 7; i++)
{ 
 
  C1x = C1x + i; // corner 1 position
  C1y = C1y + i;
  
  C2x = C2x - i; // corner 2 position
  C2y = C2y + i; 
  
  C3x = C3x - i; // corner 3 position
  C3y = C3y - i; 
  
  C4x = C4x + i; // corner 4 position
  C4y = C4y - i; 
    
  display.drawLine(C1x, C1y, C2x, C2y, WHITE); // Line 1
  display.drawLine(C2x, C2y, C3x, C3y, WHITE); // Line 2
  display.drawLine(C3x, C3y, C4x, C4y, WHITE); // Line 3
  display.drawLine(C4x, C4y, C1x, C1y, WHITE); // Line 4
  display.display();
  
  
 display.setCursor(2,25);
 display.setTextSize(1);
 display.print(C1x);
 display.print(",");
 display.println(C1y); 
 display.setCursor(2,35);
 display.print(C2x);
 display.print(",");
 display.println(C2y);
 display.setCursor(2,45);
 display.print(C3x);
 display.print(",");
 display.println(C3y);
 display.setCursor(2,55);
 display.print(C4x);
 display.print(",");
 display.println(C4y);
 
 display.setCursor(58,58);
 display.setTextSize(1);
 display.print("SHRINK");
 display.display();
 delay(10);
 display.clearDisplay();
}

}


Any suggestion greatly appreciated.

Kind regards


Dan
 
Can you take a step back and make sure there's no issues with your power supply etc.? Try uploading "Blink", does that one work without the computer?
 
Hi There,

Yes the Blink program works.

I have tried tried a few different PSUs but no luck with the OLED code.

Cheers
 
OK the next step is to see if it's a hardware or software problem.

Leave the Teensy programmed with "Blink" but reconnect all your OLED hardware and try that.

If that works then it's a software problem. Comment out everything except the bare setup() and loop() in your code, and add the basic functionality of "Blink". Once you've verified that's working, start uncommenting your code line by line, until you find out where it's failing.
 
Hi Potatotron,

Yes the Blink program works with all the OLED connected - i left everything as is and just loaded up the blink sketch.

I will investigate commenting out sections of the code but it looks like it must be something to do with the Adafruit <Adafruit_SSD1306.h> & <Adafruit_GFX.h> libraries.


Do i need to add the Arduino.h library as i have read somewhere (on this forum i think) that i need this to allow the Teensy i run the delay() command?

Cheers


Dan
 
You don't need to include Arduino.h in your main .ino (or .pde) file because the Arduino IDE includes it automatically. You only need to include it when writing libraries, maybe you saw it used there.
 
Hi Dan,
Did you sort this? I had almost exactly the same problem using the Adafruit demo code. Inserting a 5 second delay at the start of setup() fixed it - I don't understand why...
Try uncommenting your delay(5000)
Cheers
Ian
 
Status
Not open for further replies.
Back
Top