This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5529 + lidar lite for measuring distance using PWM

Other Parts Discussed in Thread: ENERGIA

im having some issue that this sensor is not measuring exactly the distance... the first reading is fine until a minute the reading goes up like it increment by 1.. im new here . i need some advise guys. :) i

  • Hello Cyril,

    Can you please provide more details about your issue? Why do you believe the MSP430 is causing the problem? Are you using a capture timer to read in the PWM duty cycle? Can you provide o-scope screen shots that prove that the PWM outputs from the LIDEAR-Lite v2 are as expected? Also, why not use I2C communication which is better suited for the MSP430? Since your issue involves an error in the firmware, providing some sections of your code would be helpful.

    Regards,
    Ryan
  • const int numReadings =100;
    int readings[numReadings];
    int readIndex = 0;
    int total = 0 ;
    float average = 0;
    int inputPin = P6_0;
    float pw1;

    void setup () {
    Serial.begin(9600);
    pinMode(P6_1,OUTPUT);
    pinMode(P6_0,INPUT);
    digitalWrite(P6_1,LOW);
    for (int thisReading = 0; thisReading < numReadings ; thisReading ++)
    readings[thisReading] = 0;

    }

    void loop ()

    {pw1=pulseIn (P6_0,HIGH);
    if (pw1 !=0){
    pw1= (pw1/10)-5;
    Serial.println(pw1);

    }


    delay(20);

    total = total + analogRead (inputPin);
    readIndex = readIndex + 1;

    if (readIndex >= numReadings) {
    readIndex = 0;


    average = total/numReadings;
    Serial.println(average);
    Serial.print("average:");
    delay (100);
    total = 0;
    }
    }

    i measure a distance of 43 cm but it gives me 40,41,42,43,44 even though i already average it.

  • or should i put capacitor? like in other IR sensors so that there will be a stable reading?
  • You should be following this LIDARLite_V2 guide but replacing Arduino components with Energia & the F5529 LaunchPad: github.com/.../LIDARLite_v2_Arduino_Library

    Energia has been designed such that porting the provided Arduino code should be relatively simple. It will at least give you some helpful PWM algorithms that you can implement in your code. However the LIDAR-Lite v2 operates at 5 V DC and the MSP430 has a maximum I/O voltage of 3.6 V so you will have to use a level shifter in between the two components if you want them to communicate with one another.

    Regards,
    Ryan
  • Hello Cyril,

    Have you been able to work around your issue? Is there any further support I can help provide?

    Regards,
    Ryan
  • ive already controlled the 3 sensors .. works perfectly fine but i need to get the average of each sensor im lost in the middle of my programming.. here take a look. i want to learn more because im new here.

    const int numReadings = 5;
    int readings[numReadings];
    int readIndex = 0;
    int total = 0;
    int average = 0;

    int ave1,ave2,ave3;

    unsigned long lsrdistance ;
    int Lsr1,Lsr2,Lsr3;


    void setup ()
    {
    Serial.begin(9600);
    pinMode(P3_6,OUTPUT);
    pinMode(P6_1,INPUT);
    digitalWrite(P3_6,LOW);

    pinMode(P3_5,OUTPUT);
    pinMode(P6_2,INPUT);
    digitalWrite(P3_5,LOW);

    pinMode(P7_0,OUTPUT);
    pinMode(P6_3,INPUT);
    digitalWrite(P7_0,LOW);

    for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
    }
    }

    void loop()
    {

    Lidarlite (P6_1,HIGH);
    Lsr1=lsrdistance;
    Lidarlite (P6_2,HIGH);
    Lsr2=lsrdistance;
    Lidarlite (P6_3,HIGH);
    Lsr3=lsrdistance;

    Serial.print("Lsr1=");
    Serial.println(Lsr1);
    Serial.print("ave1=");
    Serial.println(ave1);

    Serial.print("Lsr2=");
    Serial.println(Lsr2);
    Serial.print("ave2=");
    Serial.println(ave2);

    Serial.print("Lsr3=");
    Serial.println(Lsr3);
    Serial.print("ave3=");
    Serial.println(ave3);

    }

    void Lidarlite ( int Pin , int pin3)
    {
    lsrdistance = pulseIn (Pin,HIGH);
    if(lsrdistance != 0){
    lsrdistance=(lsrdistance)/10;//cm na output nya ni//
    }
    delay(20);

    total = total - readings[readIndex];
    readings[readIndex] = analogRead (Pin);
    total = total + readings[readIndex];
    readIndex = readIndex + 1;
    if(readIndex >= numReadings){
    readIndex = 0;
    }
    average = total / numReadings;
    delay(1);
    }

  • ive been working this for about two weeks.. i think my code is correct(for now) .. the data shows in the serial monitor is quite accurate.. but sometimes it goes up (like very high) and i dont want to use that while in averaging.. im having some trouble with the electronics parts. i need suggestions so that it would be perfect.




    const int numReadings1 =10;
    int readings1[numReadings1];
    int readIndex1 = 0;
    int total1 = 0 ;
    float average1 = 0;
    int inputPin1 = P6_1;
    float lsrdistance1;

    const int numReadings2 =10;
    int readings2[numReadings2];
    int readIndex2 = 0;
    int total2 = 0 ;
    float average2 = 0;
    int inputPin2 = P6_2;
    float lsrdistance2;

    const int numReadings3 =10;
    int readings3[numReadings3];
    int readIndex3 = 0;
    int total3 = 0 ;
    float average3 = 0;
    int inputPin3 = P6_3;
    float lsrdistance3;



    void setup () {
    Serial.begin(9600);

    pinMode(P3_6,OUTPUT);
    pinMode(P6_1,INPUT);
    digitalWrite(P3_6,LOW);
    for (int thisReading1 = 0; thisReading1 < numReadings1 ; thisReading1 ++)
    readings1[thisReading1] = 0;

    pinMode(P3_5,OUTPUT);
    pinMode(P6_2,INPUT);
    digitalWrite(P3_5,LOW);
    for (int thisReading2 = 0; thisReading2 < numReadings2 ; thisReading2 ++)
    readings2[thisReading2] = 0;


    pinMode(P7_0,OUTPUT);
    pinMode(P6_3,INPUT);
    digitalWrite(P7_0,LOW);
    for (int thisReading3 = 0; thisReading3 < numReadings3 ; thisReading3 ++)
    readings3[thisReading3] = 0;
    }

    void lsr1 ()
    {
    lsrdistance1=pulseIn (P6_1,HIGH);
    if (lsrdistance1 !=0){
    lsrdistance1= (lsrdistance1/10);
    Serial.println(lsrdistance1);
    Serial.print("Lsr1=");
    }
    delay(20);


    total1 = total1 + analogRead (inputPin1);
    readIndex1 = readIndex1 + 1;

    if (readIndex1 >= numReadings1) {
    readIndex1 = 0;


    average1 = total1/numReadings1;
    Serial.println(average1);
    Serial.print("average:");
    delay (1);
    total1 = 0;
    }
    }

    void lsr2 ()
    {
    lsrdistance2=pulseIn (P6_2,HIGH);
    if (lsrdistance2 !=0){
    lsrdistance2= (lsrdistance2/10);
    Serial.println(lsrdistance2);
    Serial.print("Lsr2=");
    }
    delay(20);


    total2 = total2 + analogRead (inputPin2);
    readIndex2 = readIndex2 + 1;

    if (readIndex2 >= numReadings2) {
    readIndex2 = 0;


    average2 = total2/numReadings2;
    Serial.println(average2);
    Serial.print("average2:");
    delay (1);
    total2 = 0;
    }
    }

    void lsr3 ()
    {
    lsrdistance3=pulseIn (P6_3,HIGH);
    if (lsrdistance3 !=0){
    lsrdistance3= (lsrdistance3/10);
    Serial.println(lsrdistance3);
    Serial.print("Lsr3=");
    }
    delay(20);


    total3 = total3 + analogRead (inputPin3);
    readIndex3 = readIndex3 + 1;

    if (readIndex3 >= numReadings3) {
    readIndex3 = 0;


    average3 = total3/numReadings3;
    Serial.println(average3);
    Serial.print("average3:");
    delay (1);
    total3 = 0;
    }
    }

    void loop () {
    lsr1 ();
    lsr2 ();
    lsr3 ();
    }
  • Cyril,

    Does this error occur constantly? If infrequent then it is probably safe to simply ignore these samples as they come. Since you can recognize those readings as being much higher than expected, perhaps use a software-implemented low-pass filter to not include them in the average.

    Regards,
    Ryan

**Attention** This is a public forum