Hi! I am trying to map data from a proximity sensor via I2C. Unfortunately I'm not that experienced with this protocol. I've played with the capacitive touch example but I might need a bit more help than that. All I need really is to be able to read my sensor's data and map it into a range of sound output frequencies. Any tips or maybe examples that you know about?

Thanks!

You will need to provide more details, such as the model of the sensor you are using, a link to its documentation and possibly some example C++ code provided by the manufacturer, along with a description of what you tried already.

Hi, thanks for your reply!
I’m using a LIDARlite v3 (https://www.sparkfun.com/products/14032?_ga=2.233004062.1699631706.1502097723-276105907.1498468007) distance sensor, I found the c++ and the python libraries to interface with the sensor (https://github.com/Sanderi44/Lidar-Lite), but one of the dependencies of the python library requires the python-smbus library to be installed in the Beagle. I have not been able to install the smbus library, I'm getting the error: ‘python-smbus has no installation candidate’, any suggestions?

Thanks!

    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.

      Hi again,

      I managed to run your example, and everything seems to be running well, however, I'm getting only zeros when reading the distance.
      I found in a comment here https://www.sparkfun.com/products/retired/13167 that it could be due to the need for a delay after reading the data, but that's what usleep is doing in the example.
      Any idea if this could be code-related? Or perhaps lack of power to run the sensor? A similar issue with RPI is discussed here http://www.robotshop.com/forum/post-p129307 but no straight answer is given.

      Thanks!

      From what I read, I would exclude a power issue, as the device is detected.

      To check that the sensor is working you could try on an Arduino with the official library. Alternatively / additionally I would encourage you to run the test they provide, as mentioned above:

      giuliomoro 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.

      that RPi issue seems to be very Pi-specific (it is an issue int the kernel module for their chipset).

      It may well be an issue with "repeated starts" (whatever that is in I2C parlance), as mentioned in the page you link, but the I2C library you are using does not seem to contemplate them.

      Hi again!

      I tried with Arduino and the official library and it works, so the sensor is ok. I tried with the test provided by the library and it didn't work, keeps returning zeros. I have tried this Beaglebone Black example and it does the same: https://pedronf65.wordpress.com/2015/03/15/lidar-lite-with-beaglebone-black-and-arch-linux/

      I'm trying to add stops in my code to avoid the "repeated starts" issue, but it just keeps giving me a zero. Perhaps is something that has to be implemented in the I2C library.

      so did you try the bash script provided there:

      #!/bin/sh
      date >> lidar.txt
      
      while :
      do
      i2cset -y 1 0x62 0x00 0x04
      
      sleep 2
      
      i2cget -y 1 0x62 0x8f w
      i2cget -y 1 0x62 0x8f w >> lidar.txt
      done

      It would be good if you could try this both by booting from the SD card and booting without it (therefore using the stock BeagleBone Black image).

      I did, yes, and I only got zeros again.
      I have also tried with a RPI and got the same result.

      I am thinking it could be an issue with the logic levels, while Arduino works with 5V logic, both BBB and RPI use 3.3V logic (as far as know) and the LIDARLite V3 works only with 5V logic? Does that make sense? If so, is it possible to read the sensor with an Arduino and then read the Arduino with my Bela (receiveing serial data into the USB host port)?

      Have you tried this before?

      Thanks!