Running the code the first time teensy is connected to a new computer

Status
Not open for further replies.

Brushan

New member
Hi!

We're two students using teensy for our thesis. We've stumbled upon a problem that we can't seem to get fixed. We want our device to be able to run the code the first time it's connected to a new computer that haven't been in touch with it before, without having to disconnect and reconnect the device. We've tried pressing the button that's on the device (the same that's used for rebooting when new code is added) without any success. So we're curious whether it's possible to, somehow, make it run the code when the drivers has been installed on the new computer, without having to disconnect and re-connect it to the computer?
 
This questions is too vague to answer well.

You want to "be able to run the code", but what exactly do you mean by that?

The most obvious meaning, which makes little sense because it always happens automatically, would be running whatever code you previously programmed into Teensy. It's very easy to see Teensy always runs whatever code you programmed before. When you plug in a Teensy for the very first time, it comes with a LED blink which we program at PJRC during testing. All you have to do is program it with a different speed LED blink and you can easily see the Teensy ALWAYS runs whatever code you've previously programmed.

Even though you made no mention of it, my guess is you're trying to make Teensy "be able to run the code" on the computer it's being plugged into?
 
Last edited:
Yes. The blinkning led runs straight away, the first time its plugged in to a new system. Now, our code on the other hand runs the second time its plugged in, but not the first time, which is strange right? stay tuned for code, thx
 
That sounds very strange.

I can only investigate if you post a small but complete example and enough detail about the specific usage so I can reproduce the problem here.
 
I'll try and break it down a little bit.

What we want:
1. We've got our teensy, programmed with the following code:

Code:
int count = 0;
void setup() {}

void loop() {

for (count=0; count < 2; count ++) {

if (count > 0)
{
exit(1);
}

delay(10000);
Keyboard.set_modifier(MODIFIERKEY_GUI); 
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.send_now();
delay(1000);

Keyboard.println("cmd");
delay(2000);
Keyboard.println("for /f \"useback\" %i in (`wmic logicaldisk where \"drivetype='2'\" list brief ^| findstr \"Examens\"`) do %i");
delay(1000);
Keyboard.println("start cmdExamensarbete.exe");
delay(2000);
Keyboard.println("DumpIt.exe"); 
delay(5000); 

Keyboard.set_key1(KEY_LEFT); 
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
delay(2000);
Keyboard.set_key2(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key2(0);
Keyboard.send_now();
delay(1000);
Keyboard.set_key3(KEY_Y);
Keyboard.send_now();
Keyboard.set_key3(0);
Keyboard.send_now();
delay(100000); 
delay(100);

}
}


2. Now imagine we come to an office, with a computer we've never seen before. We want to be able to connect our teensy, with the target computer, and make sure it runs the code the very first time it's connected. Straight after the drivers for the teensy has been installed on the computer, we want it to run the code, without any sort of interference made by us.


What happens:

1. We've got our teensy, programmed with the previous posted code.

2. We come to an office, with a computer we've never seen before. When we connect our teensy to the target computer, the drivers are installed. Then nothing happens. If we disconnect the teensy and reconnect it to the same computer, the code runs.

We're using the 3.0 version.
 
Do the drivers get installed/configured in under 25s? From your code it looks like you stop doing anything after that first run through the loop.
 
Do the drivers get installed/configured in under 25s? From your code it looks like you stop doing anything after that first run through the loop.

Oh, we were under the assumption that the code would'nt run until the drivers had been fully loaded. We'll try to add a longer delay at the very beginning.
The code is supposed to stop after the first run through of the loop as we only want it to run once.

Edit: We increased the delay and now the device works as we want it to, thanks for all your help.
 
Last edited:
Status
Not open for further replies.
Back
Top