I am not sure if I can safe my little guy, but thought it was worth a post. I was running the sketch linked below which was a I2C test to try to interface with a Lidar Lite device. After a few runs, it stopped writing to Serial, as well as no longer triggering any activity when plugged into usb.
Any suggestions?
Any suggestions?
Code:
#include <i2c_t3.h>
#define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite.
#define RegisterMeasure 0x00 // Register to write to initiate ranging.
#define MeasureValue 0x04 // Value to initiate ranging.
#define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call.
int reading = 0;
void setup()
{
Wire.begin(); // join i2c bus
Serial1.begin(115200); // start serial communication at 9600bps
}
void loop(){
Serial1.print(">");
Serial1.println(readDistance());
delay(500);
}
int readDistance(){
uint8_t nackack = 100; // Setup variable to hold ACK/NACK resopnses
while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
Wire.beginTransmission(LIDARLite_ADDRESS);
Wire.write(RegisterMeasure);
Wire.write(MeasureValue);
nackack = Wire.endTransmission(I2C_STOP);
Serial1.print(".");
// print_i2c_status(nackack);
delay(1); // Wait 1 ms to prevent overpolling
}
Serial1.print("-");
byte distanceArray[2]; // array to store distance bytes from read function
// Read 2byte distance from register 0x8f
nackack = 100; // Setup variable to hold ACK/NACK responses
Serial1.write (RegisterHighLowB);
while (nackack != 1){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
Wire.beginTransmission(LIDARLite_ADDRESS);
Wire.write(RegisterHighLowB);
nackack = Wire.endTransmission(I2C_NOSTOP);
Wire.sendRequest(LIDARLite_ADDRESS,2,I2C_STOP);
Serial1.print(":");
// print_i2c_status(nackack);
// nackack = I2c.read(LIDARLite_ADDRESS,RegisterHighLowB, 2, distanceArray); // Read 2 Bytes from LIDAR-Lite Address and store in array
delay(1); // Wait 1 ms to prevent overpolling
}
distanceArray[1] = Wire.readByte();
distanceArray[0] = Wire.readByte();
int distance = (distanceArray[0] << 8) + distanceArray[1]; // Shift high byte [0] 8 to the left and add low byte [1] to create 16-bit int
return distance; // Print Sensor Name & Distance
}