I'm trying to read data from a ST L3G4200D gyro, which is connected via 2-wire I2C to a Teensy2, on pins D0 and D1. I'm using the L3G library from https://github.com/pololu/l3g-arduino for convenience.
Everything works fine as long as the call to the library's gyro.read() function is in the main loop. If I put this call inside an interrupt using a TimerOne instance every 100ms, the Teensy virtual serial port fails to come up after programming and in Windows I get a popup saying "The USB device is not recognized". Reprogramming is still possible by pressing the button on the Teensy2 though.
I'm running out of ideas to try... Maybe anyone has a suggestion on where to look?
A minimal "nonworking" example of what I'm doing:
Everything works fine as long as the call to the library's gyro.read() function is in the main loop. If I put this call inside an interrupt using a TimerOne instance every 100ms, the Teensy virtual serial port fails to come up after programming and in Windows I get a popup saying "The USB device is not recognized". Reprogramming is still possible by pressing the button on the Teensy2 though.
I'm running out of ideas to try... Maybe anyone has a suggestion on where to look?
A minimal "nonworking" example of what I'm doing:
Code:
#include <Wire.h>
#include <L3G.h>
#include <math.h>
#include <TimerOne.h>
L3G gyro;
void setup() {
Wire.begin();
/* Enable gyro, default 250 deg/sec, ODR 100Hz, cutoff 12.5 Hz */
if (!gyro.init()){
Serial.println("Failed to autodetect gyro type!");
while (1);
}
gyro.enableDefault();
/* Setup interrupt */
Timer1.initialize(100000);
Timer1.attachInterrupt(interruptCode);
Serial.begin(115200);
}
void loop() {
}
void interruptCode(){
gyro.read();
//Serial.print(gyro.g.y);
}