Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 3.2 - I2C and PWM issues with Lidar Lite V3

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    3

    Teensy 3.2 - I2C and PWM issues with Lidar Lite V3

    Hello all,

    I have 2 Lidar Lite v3's connected together in an attempt to make a spinning lidar using a teensy 3.2. I had originally tried this on an Arduino Nano, but it seemed to need a little more horsepower.

    I can get the units to communicate, can readdress them and get telemetry via I2C, but I have 2 issues:

    1st: I am using PWM to drive a MOSFET for the motor that spins the lidar. As soon as I activate PWM output on any pin (I say any but I tested 3) my I2C immediately goes all nacks. Pretty solid until I activate the PWM output, though it does eventually fail at some point much later.

    2nd: I am getting rather slow results from the units, at around 100 reads\s from both units combined. Garmin says typical should be over 250/s (600/s with high speed) and I'd assume since I have 2 I'd get close to twice that. Is there some trick to getting these to update faster? I have tried standard mode and higher speed standard mode, but not full High speed as I need better longer range performance. I am using 400k I2C.

    Code is below: (note: I have modified the lidar lite library to work with the i2c_t3 libraries.) This is just a basic sketch that addresses the two units and begins getting readings. I'ts nearly a copy of the default lidarLite sketch tests.

    I'm hoping there are people here who have experience with both the lidar lites and teensy's. Any advice or help would be greatly appreciated. Thanks!

    /*
    Initial setup and port of testing routines to teensy 3.2
    */
    #include <Arduino.h>
    #include <i2c_t3.h>
    #include <LIDARLite.h>

    LIDARLite myLidarLite;
    byte add1[1];
    byte add2[1];
    byte arr[1];


    void setup() {

    Serial.begin(115200); // Initialize serial connection to display distance readings
    /*
    begin(int configuration, bool fasti2c, char lidarliteAddress)
    Starts the sensor and I2C.
    Parameters
    ----------------------------------------------------------------------------
    configuration: Default 0. Selects one of several preset configurations.
    fasti2c: Default 100 kHz. I2C base frequency.
    If true I2C frequency is set to 400kHz.
    lidarliteAddress: Default 0x62. Fill in new address here if changed. See
    operating manual for instructions.
    */
    Wire.setDefaultTimeout(200);
    myLidarLite.begin(2, true); // Set configuration to higher speed normal and I2C to 400 kHz
    SetAddresses();
    delay(2000);
    runScan();
    //delay(2000);
    /*
    configure(int configuration, char lidarliteAddress)
    Selects one of several preset configurations.
    Parameters
    ----------------------------------------------------------------------------
    configuration: Default 0.
    0: Default mode, balanced performance.
    1: Short range, high speed. Uses 0x1d maximum acquisition count.
    2: Default range, higher speed short range. Turns on quick termination
    detection for faster measurements at short range (with decreased
    accuracy)
    3: Maximum range. Uses 0xff maximum acquisition count.
    4: High sensitivity detection. Overrides default valid measurement detection
    algorithm, and uses a threshold value for high sensitivity and noise.
    5: Low sensitivity detection. Overrides default valid measurement detection
    algorithm, and uses a threshold value for low sensitivity and noise.
    lidarliteAddress: Default 0x62. Fill in new address here if changed. See
    operating manual for instructions.
    */
    //myLidarLite.configure(2); // Change this number to try out alternate configurations if not set at begin

    // Motor speed control

    // analogWrite(3, 80); / This command kills the I2C on pins 3, 22, and 23

    }

    void SetAddresses()
    {
    pinMode(14, OUTPUT); pinMode(15, OUTPUT);
    LIDARLite myLidarLite;
    delay(40);
    digitalWrite(14, LOW); //Reset PW_En Pin top LL
    Serial.println("top low");
    delay(40);
    digitalWrite(15, LOW); //Reset PW_EN Pin Bottom LL
    Serial.println("bottom low");
    delay(40);
    digitalWrite(14, HIGH); //En top LL
    delay(40);
    myLidarLite.setI2Caddr(0x66, true, 0x62);Serial.println("address changed 66"); //Set Top LL Add to 0x66
    delay(20);
    digitalWrite(15, HIGH); //En bottom LL
    delay(40);
    myLidarLite.setI2Caddr(0x64, true, 0x62);Serial.println("address changed 64"); //Set Bottom LL Add to 0x64

    }

    void runScan()
    {
    byte error, address;
    int nDevices;

    Serial.println("Scanning...");

    nDevices = 0;
    for(address = 1; address < 127; address++ )
    {
    //Serial.print(address);
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
    Serial.print("I2C device found at address 0x");
    if (address<16)
    Serial.print("0");
    Serial.print(address,HEX);
    Serial.println(" !");

    nDevices++;
    }
    else if (error==4)
    {
    Serial.print("Unknown error at address 0x");
    if (address<16)
    Serial.print("0");
    Serial.println(address,HEX);
    }
    }
    if (nDevices == 0)
    Serial.println("No I2C devices found\n");
    else
    Serial.println("done\n");

    delay(5000); // wait 5 seconds for next scan
    }



    void loop() {
    // put your main code here, to run repeatedly:

    Serial.print(myLidarLite.distance(true,0x64));Seri al.println(" bottom");
    //delay(1);
    Serial.print(myLidarLite.distance(true,0x66));Seri al.println(" top");
    //delay(1);
    //Take 99 measurements without receiver bias correction and print to serial terminal
    for(int i = 0; i < 99; i++)
    {
    Serial.println(myLidarLite.distance(false,0x64));
    //delay(1);
    Serial.println(myLidarLite.distance(false,0x66));
    //delay(1);
    }
    //*/

    }

  2. #2
    Junior Member
    Join Date
    Feb 2019
    Posts
    3
    Nothing at all? Sigh

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    3
    I have changed my Lidar code, and still have the same problem.

    I have isolated it a little further though. I can have i2C humming along giving me hudreds of measurements a second now, but as soon as I activate PWM on any pin, the I2C dies immediately. If the pin I'm activating is just floating, the I2C will be ok, but the second I try to do anything with the PWM signal, the I2C dies. I've tried using caps to filter the PWM line which cleans up the PWM, but i2C is still dead. Just putting a .1uF cap to ground on the PWM output pin kills the I2C. I have tried this on every 3.2 PWM pin with the same results.

    I can either have one or the other so it seems - I2C comm, or a PWM output. I assume that I2C and PWM can be used at the same time on a teensy 3.2, so I'm curious as to what's causing this. Surely there's someone here who's used I2C and PWM at the same time?? At this point I'd just be happy to know they can coexist!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •