Skip to content

blasterbug/DistNx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dist-Nx

About

Dist-Nx is a Arduino library to use Dist-Nx sensors.

Distance registers provide Distance information in millimeters.
Voltage registers provide the raw voltage in milli-volts.

Requirements

You need Arduino I2C master library to use the library because the Wire library issued with the Arduino IDE does not support the whole I2C protocol, for instance repeat start.

Features

  • LSB distance (long distance)
  • LSB voltage
  • MSB distance (medium distance)
  • MSD voltage
  • ADPA mode
  • Get sensors data
  • Switch off/on sensor
  • Connect to an I2C customized Address
  • Change I2C address
  • Calibration
  • Data point measures

Installation (Unix like systems)

Open a terminal and run :

$ cd <UserDirectory>/Arduino/libraries
$ git clone https://github.com/blasterbug/Dist-Nx.git

Or if you prefer, download the zip (of the last release) and directly unzip it in the Arduino/libraries folder.

Now after (re)starting the Arduino IDE you should see Dist-Nx in Arduino libraries menu. Two exemples are provided with the library.

Get more details on Arduino libraries installation guide.

Example

Here is an exemple of the minimal code to use the sensor. The programme display every second the measured long distance.

// import libraries
#include <I2C.h>
#include <DistNx.h>

DistNx sensor;
int distance;

void setup()
{
  // start serial communication
  Serial.begin( 9600 );
  // join I2C bus
  I2c.begin();
}

void loop()
{
  // get long distance
  distance = sensor.longDistance();
  // display distance
  Serial.print( F("long distance = ") );
  Serial.print( distance );
  Serial.println( F(" mm") );
  // wait 1 second
  delay( 1000 );
}

Documentation

Read the documentation on the repository wiki here or you can generate it with Doxygen as follow.

$ doxygen Doxyfile

After printing some ouput, you should get a html folder. Then open index.htmlin your favorite web browser. Of course, source code is commented.

About ADPA

This sensor supports Auto Detecting Parallel Architecture (ADPA) for sensors. This means that DIST-Nx can coexist with LEGO or third party digital sensors on a single I2C bus. This enables user to employ several sensors on the same bus without the need of external sensor multiplexer, reducing the overall size and cost. By default, the ADPA mode is disabled.