PDA

View Full Version : teensy 2.0 and teensy 3.0 question



dani190
12-02-2012, 08:50 AM
Hello, was wondering is there any way to make the Teensy load the code it has on it upon boot?

I find that when i turn the power on my script does not run. I know this because my LCD's are not showing anything when they should be. If i plug the usb in and hit reboot on the teensyloader program, it then works.

I know Teensy 3.0 has a pin i can just trigger to do this but the Teensy 2.0 does not from what i read.

cmason
12-02-2012, 02:09 PM
This is not the behavior I see. I see that when I plugin the teensy my code runs. I suspect something else is going on. Maybe some timing thing? Can you blink the LED or something to verify that your code is running?

PaulStoffregen
12-02-2012, 09:42 PM
Teensy always runs your program when it powers up.

Perhaps your code has something that depends on the PC responding? Could your post your code, or a small/simple program which demonstrates the problem? Also, it matter which option you've selected from Tools > USB Type, which isn't in your message, so please let us know that too?

dani190
12-03-2012, 11:16 PM
The code on my teensy 2.0 is as follows


HardwareSerial Uart = HardwareSerial();

void setup()
{
Uart.begin(9600);
}

void loop()
{
shiftLeft();
}

void shiftLeft()
{
Uart.print("Welcome to Centennial College - ICET");
while(1)
{
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
}
}


As for tools > USB Type is set as serial

PaulStoffregen
12-03-2012, 11:45 PM
I'm running it right now on a Teensy 2.0, powered from a 5V power supply (no USB connection). It's sending those 2 bytes on pin 8 every 350 ms.

I've switched the power off and back on several times. Every time it starts up and sends those bytes.

dani190
12-03-2012, 11:53 PM
I'm running it right now on a Teensy 2.0, powered from a 5V power supply (no USB connection). It's sending those 2 bytes on pin 8 every 350 ms.

I've switched the power off and back on several times. Every time it starts up and sends those bytes.

My exact setup has an LCD connected to the TX pin and it turns on at the same time with the Teensy 2.0 using the same power supply.

Any ideas what could be wrong?

PaulStoffregen
12-04-2012, 12:54 AM
I have no idea.

As a first step, you might change your code to something like this:



pinMode(11, OUTPUT);
while(1) {
digitalWrite(11, HIGH); // LED on
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
digitalWrite(11, LOW); // LED off
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
}


Then you'll at least be able to see if the LED changes, to know if your program is running.

Maybe the LCD isn't starting up properly?

dani190
12-04-2012, 07:49 AM
I have no idea.

As a first step, you might change your code to something like this:



pinMode(11, OUTPUT);
while(1) {
digitalWrite(11, HIGH); // LED on
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
digitalWrite(11, LOW); // LED off
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
}


Then you'll at least be able to see if the LED changes, to know if your program is running.

Maybe the LCD isn't starting up properly?

Thanks Paul, that worked and i just modified my code a bit further. By adding a delay to the actual start of the code that allowed the LCD to start fully and then start the code.

My code now looks like


HardwareSerial Uart = HardwareSerial();
void setup()
{
Uart.begin(9600);
pinMode(11, OUTPUT);
delay(100);
}

void loop()
{
shiftLeft();
}

void shiftLeft()
{
Uart.print("Welcome to Centennial College - ICET");
while(1) {
digitalWrite(11, HIGH); // LED on
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
digitalWrite(11, LOW); // LED off
Uart.write(0xFE);
Uart.write(0x55);
delay(350);
}
}


Just incase anyone was wondering.

Thanks again for the help!