PDA

View Full Version : Dead Teensy 2.0 & 2.0++



soward
01-08-2013, 02:26 AM
I was working on a fairly simple bit of code using RawHID via Arduino on a 2.0. I pushed it down, the various LEDs lit, etc. I started the usb code on the desktop side. couldn't connect. went back to the code, put in some Serial.Printlns, tried to build -- teensy loader couldn't find the device. Tried the 'hold-the-button-down-while-plugging-in' trick, as well as other ports and machines. USB Prober sees nothing. Oh, well, maybe it caught a spark or something.

Grabbed a 2.0++, rejiggered the simple connections and the Pin #s in the code. Compiled and pushed it down -- same thing, device is no longer communicating.

Did I whack the halfkay somehow? Did the cat jump up and rub across both of them when I wasn't looking?

I ordered a few more, but obviously don't want the same thing to happen.

T3 still works, of course, no RawHID in Arduino for it :)

I can post the code if anyone thinks that's actually the issue.

Also, FWIW, I built the little bits of code for the buttons/leds first and all was well, then I tried some basic RawHID tests, which also worked well, this was essentially just the grafting together of the two.

thanx,
JpS

soward
01-09-2013, 11:26 PM
Below is the code I was using. As for the wiring, two LEDs from pins 4 and 5 to ground with a small resist on each. a voltage divider resist coming off 5v to a push button switch and going back to 19 and 20. (different pins on 2.0 and ++2.0).

Obviously parts were cut-n-pasted from the RawHID example.



#define ACK 0x10
#define B1 0x20
#define B2 0x30
#define BER 0x40

#define B1Pin 19
#define B2Pin 20

#define LED1 4
#define LED2 5

void setup() {
Serial.begin(9600);
Serial.println("RawHID Example");
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(B1Pin, INPUT);
pinMode(B2Pin, INPUT);
}


// RawHID packets are always 64 bytes
//elapsedMillis msUntilNextSend;
int tripped = 0;
int blink = 0;
byte buffer[64];
int n;

void loop() {
int n;
n = RawHID.recv(buffer, 0); // 0 timeout = do not wait
if (n > 0) {
// the computer sent a message.
// See what the command is....
Serial.print(F("Received packet, first byte: "));
Serial.println((int)buffer[0]);
switch((int)buffer[0]) {
case 0x10: // clear both LEDS
Serial.println("Clearing");
digitalWrite(LED1,0);
digitalWrite(LED2,0);
tripped = 0;
break;
case 0x20: // blink both LEDS
Serial.println("Blinking");
break;
case 0x30: // swap LEDS
Serial.println("Swap");
if (tripped == 1) {
tripped = 2;
digitalWrite(LED1,0);
digitalWrite(LED2,255);
}
if (tripped == 2) {
tripped = 1;
digitalWrite(LED2,0);
digitalWrite(LED1,255);
}
break;
default:
Serial.println("UNKNOWN COMMAND!");
break;
}
sendPacket(ACK);
}
if (!tripped && (digitalRead(B1Pin) == HIGH)) {
tripped=1;
sendPacket(B1);
digitalWrite(LED1,255);
}
if (!tripped && (digitalRead(B2Pin) == HIGH)) {
tripped=2;
sendPacket(B2);
digitalWrite(LED2,255);
}
}

void sendPacket(int command) {

byte buffer[64];

// first 2 bytes are a signature
buffer[0] = 0xAB;
buffer[1] = 0xCD;

buffer[2] = command;
// fill the rest with zeros
for (int i=3; i<64; i++) {
buffer[i] = 0;
}
// actually send the packet
n = RawHID.send(buffer, 100);
if (n > 0) {
Serial.println(F("Transmitted packet"));
} else {
Serial.println(F("Unable to transmit packet"));
}
}