Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrected docs, fixed baud rate, tidied code #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ http://arduino.cc/en/Guide/Libraries

## Arduino Setup

Note: the current picture is wrong with regards to SDA, SCL pin
location on the Arduino boards. This table is correct.

Arduino Board | SDA, SCL Pins
:--------------|:--------------
Uno, Pro Mini | A4 (SDA), A5 (SCL)
Mega2560 | 20 (SDA), 21 (SCL)
Leonardo | 2 (SDA), 3 (SCL)
Due |20 (SDA), 21 (SCL), SDA1, SCL1

![arduino-screenshot](http://pulsedlight3d.com/pl3d/wp-content/uploads/2014/10/arduino-setup.png)

### LIDARLite I2C Connection Setup
Expand All @@ -36,4 +46,4 @@ GND | GND
3. The distance measured in centimeters (cm) will print to the serial monitor

## Note
You can increase the baud rate for faster reads
You can increase the baud rate for faster reads
10 changes: 10 additions & 0 deletions Arduino/LIDARLite_PWM_GetDistance_ContinuousRead/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ Demonstrates taking a distance reading using Pulse-Width Modulation (PWM), does

## Arduino Setup

Note: the current picture is wrong with regards to SDA, SCL pin
location on the Arduino boards. This table is correct.

Arduino Board | SDA, SCL Pins
:--------------|:--------------
Uno, Pro Mini | A4 (SDA), A5 (SCL)
Mega2560 | 20 (SDA), 21 (SCL)
Leonardo | 2 (SDA), 3 (SCL)
Due |20 (SDA), 21 (SCL), SDA1, SCL1

![arduino-screenshot](http://pulsedlight3d.com/pl3d/wp-content/uploads/2014/11/arduino-pwm-setup2.png)

### LIDARLite I2C Connection Setup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@

/*

http://pulsedlight3d.com

This sketch demonstrates getting distance with the LIDAR-Lite Sensor

It utilizes the 'Arduino Wire Library'

(tidied up by Mark Harrison, mh@pixar.com)
*/

#include <Wire.h>
#define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite.
#define RegisterMeasure 0x00 // Register to write to initiate ranging.
#define MeasureValue 0x04 // Value to initiate ranging.
#define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call.
#define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite.
#define RegisterMeasure 0x00 // Register to write to initiate ranging.
#define MeasureValue 0x04 // Value to initiate ranging.
#define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call.

int reading = 0;

void setup()
{
Wire.begin(); // join i2c bus
Serial.begin(115200); // start serial communication at 115200bps
Wire.begin(); // join i2c bus
Serial.begin(9600); // start serial communication
}

void loop()
{
Wire.beginTransmission((int)LIDARLite_ADDRESS); // transmit to LIDAR-Lite
Wire.write((int)RegisterMeasure); // sets register pointer to (0x00)
Wire.write((int)MeasureValue); // sets register pointer to (0x00)
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(LIDARLite_ADDRESS); // transmit to LIDAR-Lite
Wire.write(RegisterMeasure); // set register pointer to 0x00
Wire.write(MeasureValue); // set register pointer to 0x00
Wire.endTransmission(); // stop transmitting

delay(20); // Wait 20ms for transmit
delay(20); // Wait 20ms for transmit

Wire.beginTransmission((int)LIDARLite_ADDRESS); // transmit to LIDAR-Lite
Wire.write((int)RegisterHighLowB); // sets register pointer to (0x8f)
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(LIDARLite_ADDRESS); // transmit to LIDAR-Lite
Wire.write(RegisterHighLowB); // set register pointer to 0x8f
Wire.endTransmission(); // stop transmitting

delay(20); // Wait 20ms for transmit
delay(20); // Wait 20ms for transmit

Wire.requestFrom((int)LIDARLite_ADDRESS, 2); // request 2 bytes from LIDAR-Lite
Wire.requestFrom(LIDARLite_ADDRESS, 2); // request 2 bytes from LIDAR-Lite

if(2 <= Wire.available()) // if two bytes were received
if(Wire.available() >= 2) // if two bytes were received
{
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits
Serial.println(reading); // print the reading
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LIDARLite_Wire_Library_GetDistance_ContinuousRead
========================================
LIDARLite\_Wire\_Library\_GetDistance\_ContinuousRead
=================================================

Demonstrates taking a distance reading using the default Arduino Wire Library (works but is not the ideal configuration)

Expand All @@ -14,6 +14,16 @@ Demonstrates taking a distance reading using the default Arduino Wire Library (w

## Arduino Setup

Note: the current picture is wrong with regards to SDA, SCL pin
location on the Arduino boards. This table is correct.

Arduino Board | SDA, SCL Pins
:--------------|:--------------
Uno, Pro Mini | A4 (SDA), A5 (SCL)
Mega2560 | 20 (SDA), 21 (SCL)
Leonardo | 2 (SDA), 3 (SCL)
Due |20 (SDA), 21 (SCL), SDA1, SCL1

![arduino-screenshot](http://pulsedlight3d.com/pl3d/wp-content/uploads/2014/10/arduino-setup.png)

### LIDARLite I2C Connection Setup
Expand All @@ -22,12 +32,12 @@ LIDARLite Cable | Arduino Pins
5V | 5V
PWR EN | _(Unused)_
MODE | _(Unused)_
SCL | SCL (topmost pin on the right hand side of Arduino)
SDA | SDA (second pin from the top on the right hand side of Arduino)
SCL | see table above
SDA | see table above
GND | GND

## Usage

1. [Connect an Arduino](#arduino-setup) and upload code
2. Open the serial monitor (Make sure baud rate is set to 9600)
3. The distance measured in centimeters (cm) will print to the serial monitor
3. The distance measured in centimeters (cm) will print to the serial monitor