The C++ library looks in good shape, though they could have totally put some extra effort in the documentation (there is no description of what the methods in include/lidar_lite.h
do).
So, first thing you want to do, as the README file says, is to install the libi2c-dev
package. If your BBB is connected to the internet (e.g.: with a wifi dongle or an ethernet cable), simply do
apt-get install libi2c-dev
otherwise, run
apt-get install --print-uris libi2c-dev
this will return a URL at which you can find the needed package. In this case the URL is this: http://ftp.us.debian.org/debian/pool/main/i/i2c-tools/libi2c-dev_3.1.1-1_all.deb . You should download the file at that URL and copy it on your board, either through scp
or by drag-and-drop on the IDE window.
You then need to manually install it. Assuming you dragged and dropped it on the IDE while a project called `PROJECTNAME", run this in the console at the bottom of the IDE:
dpkg -i projects/PROJECTNAME/libi2c-dev_3.1.1-1_all.deb && rm projects/PROJECTNAME/libi2c-dev_3.1.1-1_all.deb
If you are terminal-savy you would then copy the whole codebase from https://github.com/Sanderi44/Lidar-Lite to the board, then run
cd Lidar-Lite/test && make && ./test
to build and run the test program. You can also skip this step if you want and come back to it only if you find troubles in the next step.
To include the sensor in a Bela project, you would first create a new C++ project, then drag and drop the files Lidar-Lite/src/lidar_lite.cpp
and Lidar-Lite/include/lidar_lite.h
on the Bela IDE. Then you should open the file lidar_lite.cpp
and edit the first line from
#include <include/lidar_lite.h>
to
#include <lidar_lite.h>
Then in your render.cpp
file try to add something like what is in the Lidar-Lite/test/test.cpp
file, for instance a quick test can be made by editing the setup()
function as follows:
#include <lidar_lite.h>
bool setup(BelaContext *context, void *userData)
{
Lidar_Lite l1(1);
int err = l1.connect();
if (err < 0){
printf("%d", l1.err);
} else {
for(int n = 0; n < 40; ++n){
int dist = l1.getDistance();
if(l1.err)
{
break;
}
printf("%d\n", dist);
usleep(100000);
}
}
return true;
}
I managed to compile the above, but of course I don't have the sensor so I cannot test it.
The above is a quick test which will take 40 measurements over 4 seconds before starting the audio.
Not very useful if you want to use the distance sensor to affect the audio in real time.
To do that you should create an auxiliary task and run the content of the function above in the AuxiliaryTask instead of in setup()
, then pass the values to the audio thread, e.g.: using global variables.
But first, try to get here and see that it works.