CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to get VL53L0x working?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

How to get VL53L0x working?
PostPosted: Tue May 10, 2022 6:22 am     Reply with quote

I have tried for two weeks to get the ST VL53L0x Time of Flight device working on CCS-complier and PIC.

I have looked at this service. no help.
I have written to ST, but no help.
They only give a link to other language.

I need this sensor for my snow meter.

I have done a very simple test circuit and it will give output to the serial port.
The device is here http://probyte.fi/VL530X.jpg
It is cheap, it I got it working

A schematic is here http://probyte.fi/VL53L0XSchematic.jpg
It has a PIC16F18857 cpu.

I have modified ST made program, so that it works with CCS (version 5.092).
I have checked that address is normal 0x52. with I2C_scanner.c

I have put my revised code to http://probyte.fi/VL53L0z.zip

What I got is here http://probyte.fi/VL530XTest.jpg
So it will give a big distance, but then it goes to 0.

So I ask if any others have used CCS in the VL53L0X device.

Regards
Pekka Ritamaki
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 12, 2022 2:35 am     Reply with quote

Pekka1234 wrote:

I have tried for two weeks to get the ST VL53L0x Time of Flight
device working on CCS compiler and PIC.

Post a table of the results you would expect vs. the results you get.
Example: The VL53L0X can measure distances up to 2 meters away.
Post a table similar to below:
Code:

True           Measured
Object         distance with
distance       my circuit
(mm)             (mm)

100               50
200               60
300               70
400               80
500              100
1000             300
1500             550
2000             800

You can put in more true distance values in the table if you think it
will help us.


Also give us a link to the ST program that you converted to CCS.

Also, what is the Vdd voltage of your PIC ?
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

VL53L0X
PostPosted: Thu May 12, 2022 11:02 am     Reply with quote

PCM programmer, thank you for the first answer to VL53L0X question.

I tried to take results, but I got only these results:
Code:

Object distance   The result
[mm]
=======================
50 mm   = 59392, 2307. 3. 0, 0, 0, 0, 0
100mm   = 59392, 2307, 3. 0, 0, 0, 0, 0
150mm   = 59392, 2307, 3. 0, 0, 0, 0, 0
300mm   = 59392, 2307, 3. 0, 0, 0, 0, 0
400mm   = 59392, 2307, 3. 0, 0, 0, 0, 0
1000mm  = 59392, 2307, 3. 0, 0, 0, 0, 0

So there were no questions about the distance, the result goes to 0 after a few seconds.
I know that it is my fault, but the code is so big.
==
The program is what ST recommend to me when I asked for help.
It was not CCS program.

The program is one of ST examples
I have to modify it, maybe I have done something wrong?

== The first rows of ST program ====
Copyright (c) 2021, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L4CD Ultra Lite Driver and is dual licensed,
==== A bit later
This example shows how to get single-shot range
measurements from the VL53L0X. The sensor can optionally be
configured with different ranging profiles, as described in
the VL53L0X API user manual, to get better performance for
a certain application. This code is based on the four
VL53L4CD ULD ready !

==
The PIC16F18857 is enough
This is what I got after compiler:

Compiling D:\PIC\2022\ST32\TestST on 12-touko-22 at 12.38
Memory usage: ROM=11% RAM=1% - 4%
0 Errors, 0 Warnings.
Build Successful.
====
Then you ask about the voltage of my test circuit.
I used 5V was a seller (Aliexpess) said.

I could use also 3.3V if you suggest.

==
Then I modified my program and got this result:

VL53L4CD starting
VL53L4CD_IDENTIFICATION__MODEL_ID =0F DEV 2e
sensor_id 8000 status FF
52VL53L4CD not detected at requested address
VL53L4CD_IDENTIFICATION__MODEL_ID =0F DEV 19
VL53L4CD not detected at requested address 52
VL53L4CD ULD Loading failed
VL53L4CD ULD ready !
Sensor runs in autonomous mode
VL53L4CD_StartRanging !
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
status=ff, isReady= 00, loop 0 Distance = 22272 sigma_mm 5568
==
This program doesn't find itself in 0x52 address.
VL53L4CD is not compatible with my VL53L0X device.
==
I have started to read VL53L0X datasheet and started to write code.
It is quite difficult to write the right code.
==
I checked that I have the right address with I2C-scanner

Start I2C Scanner..
ACK addr: 0x52
Number of i2c chips found: 1
===
I know how difficult is to give the right help.

Regatds
Pekka Ritamaki
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: VL53L0X
PostPosted: Thu May 12, 2022 12:03 pm     Reply with quote

pekka1234 wrote:

50 mm = 59392, 2307, 3. 0, 0, 0, 0, 0

What do these numbers mean ? Is 59392 the raw result from the
sensor ? is 2307 the result after calculations ? What is it supposed
to represent ? You have got to give us some explanations of these
numbers if you want help.

pekka1234 wrote:

So there were no questions about the distance
What does this mean ?

Quote:
the result goes to 0 after a few seconds.
Does this mean that the 59392 value goes to 0 ?
How many seconds does it take for it to go to 0 ?
This sounds like a hardware problem. Like maybe the VL53L0X is
counterfeit, or maybe there's a power supply problem.

pekka1234 wrote:

The program is what ST recommend to me when I asked for help.
It was not CCS program.

== The first rows of ST program ====
Copyright (c) 2021, STMicroelectronics - All Rights Reserved

Why can't you post a link to the code ? Did you have to sign an
NDA (non-disclosure) agreement to get it ? If so, tell us that !
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Thu May 12, 2022 12:59 pm     Reply with quote

I lost (wasted) a month translating the code for this sensor and at the end the result was terrible. You can find my efforts here:

https://www.ccsinfo.com/forum/viewtopic.php?t=56925&highlight=vl53l0x

Way, way too complicated piece of hardware, nothing but trouble. If you don't need a snowflake accuracy, there must be other sensors.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 18, 2022 4:01 pm     Reply with quote

I was able to get it working.

I bought the Adafruit VL53L0X board on Amazon. I connected it to a
PicDemPlus development board. I used pin C3 for SCL, and pin C4 for SDA.
I also connected it to +5v and Ground on the board.

I downloaded the 3 source files for a VL53L0X driver for CCS from here:
https://github.com/LILCMU/vl53l0x-ccs

The VL53L0X.c and VL53L0X.h files are unchanged.
I edited their SINGLE.c file to look like this:
Code:
#include <18F46K22.h>
#fuses NOWDT
#use delay(internal=8M)
#use rs232(baud=9600, UART1, ERRORS)
#use i2c(Master, I2C1, SLOW)

int32 msTimer=0;
#define millis() (msTimer)

#include <VL53L0X.h>
#include <VL53L0X.c>

#int_timer1
void timer1_isr(void)
{
set_timer1(65286); // keep period at 1 ms (at 8 MHz)
msTimer++;
}

// Uncomment this line to use long range mode. This
// increases the sensitivity of the sensor and extends its
// potential range, but increases the likelihood of getting
// an inaccurate reading because of reflections from objects
// other than the intended target. It works best in dark
// conditions.

#define LONG_RANGE


// Uncomment ONE of these two lines to get
// - higher speed at the cost of lower accuracy OR
// - higher accuracy at the cost of lower speed

//#define HIGH_SPEED
#define HIGH_ACCURACY


void setup_VL53L0X(void)
{
printf("Starting\r\n");
   
init();

setTimeout(200);

#if defined LONG_RANGE
  // lower the return signal rate limit (default is 0.25 MCPS)
  setSignalRateLimit(0.1);
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  setVcselPulsePeriod(VcselPeriodPreRange, 18);
  setVcselPulsePeriod(VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
  // reduce timing budget to 20 ms (default is about 33 ms)
  setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
  // increase timing budget to 200 ms
  setMeasurementTimingBudget(200000);
#endif
}


//==============================
void main()
{
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(65286); // keep period at 1 ms (at 8 MHz)
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

setup_VL53L0X();


while(TRUE)
  {
   printf("%lu\r\n", readRangeSingleMillimeters());
 
   if(timeoutOccurred())
      printf(" TIMEOUT\r\n");

   delay_ms(500);
  }

}

I compiled the files with CCS vs. 5.108.

Here are the test results. There is an offset of about 60 when it should
read 0 mm.

64 // Starting with sensor close to the desk surface.
61
54
71 // Then slowing raising the sensor above the desk
69
68
88
102
130
147
161
167
184
200
229
246
265
279
294
310
326
345
359
374 // Now at about 12 inches (305 mm) above the desk
358
339
326 // Slowly lowering the sensor
305
273
249
213
186
158
133
119
101
85
82
80
73
63
65
58
70
64 // Sensor is now back down at the desk level

Test board:
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

Fine PCM Programmer!
PostPosted: Thu May 19, 2022 1:14 pm     Reply with quote

Hurraa, I got VL53L0X finaly working.

I modified a little single.c file and
VL53L0x.c a little
#separate boolean init2() to int1 boolean init2()
I also changed in each file
#include<VL53L0X.h>"
#include <VL53L0X.c>
to
#include "VL53L0X.h"
#include "VL53L0X.c"

A new Single.c code is here
Code:

//#include <18F46K22.h>
#include <16F18857.h>
#fuses NOWDT
#use delay(internal=8M)
#pin_select U1TX = PIN_C6              // RS232 uses C6 as tx
#pin_select U1RX = PIN_C7              // RS232 uses C7 as rx
 
#use rs232(baud=9600, UART1, ERRORS)
#pin_select SCL1OUT=PIN_C3            // I2C uses CLK as C3
#pin_select SDA1OUT=PIN_C4            // I2C uses DTA as C4
 
//#USE I2C(I2C1, MASTER,SLOW, FORCE_HW) // normal I2C functions
#use i2c(Master, I2C1, SLOW)

int32 msTimer=0;
#define millis() (msTimer)

#include "VL53L0X.h"
#include "VL53L0X.c"

#int_timer1
void timer1_isr(void)
{
set_timer1(65286); // keep period at 1 ms (at 8 MHz)
msTimer++;
}

// Uncomment this line to use long range mode. This
// increases the sensitivity of the sensor and extends its
// potential range, but increases the likelihood of getting
// an inaccurate reading because of reflections from objects
// other than the intended target. It works best in dark
// conditions.

#define LONG_RANGE


// Uncomment ONE of these two lines to get
// - higher speed at the cost of lower accuracy OR
// - higher accuracy at the cost of lower speed

//#define HIGH_SPEED
#define HIGH_ACCURACY


void setup_VL53L0X(void)
{
printf("Starting\r\n");
   
init();

setTimeout(200);

#if defined LONG_RANGE
  // lower the return signal rate limit (default is 0.25 MCPS)
  setSignalRateLimit(0.1);
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  setVcselPulsePeriod(VcselPeriodPreRange, 18);
  setVcselPulsePeriod(VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
  // reduce timing budget to 20 ms (default is about 33 ms)
  setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
  // increase timing budget to 200 ms
  setMeasurementTimingBudget(200000);
#endif
}


//==============================
void main()
{
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(65286); // keep period at 1 ms (at 8 MHz)
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

setup_VL53L0X();


while(TRUE)
  {
   printf("%lu\r\n", readRangeSingleMillimeters());
 
   if(timeoutOccurred())
      printf(" TIMEOUT\r\n");

   delay_ms(500);
  }

}


I tested with hand and the results is here
http://probyte.fi/ExceltestLX53L0X.jpg

I worked from 50mm to 1700 mm from table to roof quite well.
My prototype is here
http://probyte.fi/tesstVL53L0X.jpg

Thank much PCM Programmer. You a really a good fellow!

http://probyte.fi/ExceltestLX53L0X.jpg
How you add img* file ?

Regards
Pekka Ritamaki
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 19, 2022 6:46 pm     Reply with quote

You're right. I forgot that I had to remove the #separate statements to
make it compile.

To post an image on this forum, upload it to a free image hosting service
such as https://imgbb.com
Then tell it create a link for a forum. They usually have a button to do that.
Then post the link in this forum.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group