Commit 316d9aba authored by --replace-all's avatar --replace-all
Browse files

first pass

parent b1c82a83
/*------------------------------------------------------------------------------
LIDARLite Arduino Library
GetDistancePwm
This example shows how to read distance from a LIDAR-Lite connected over the
PWM interface.
Connections:
LIDAR-Lite 5 Vdc (red) to Arduino 5v
LIDAR-Lite Ground (black) to Arduino GND
LIDAR-Lite Mode control (yellow) to Arduino digital input (pin 3)
LIDAR-Lite Mode control (yellow) to 1 kOhm resistor lead 1
1 kOhm resistor lead 2 to Arduino digital output (pin 2)
(Capacitor recommended to mitigate inrush current when device is enabled)
680uF capacitor (+) to Arduino 5v
680uF capacitor (-) to Arduino GND
See the Operation Manual for wiring diagrams and more information:
http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf
SD card datalogger
This example shows how to log data from three analog sensors to an SD card using the SD library.
The circuit:
* analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created 24 Nov 2010, modified 9 Apr 2012 by Tom Igoe
This example code is in the public domain.
------------------------------------------------------------------------------*/
// xxx open and write every 10 passes? (use an array to buffer the values)
// xxx consider pulsing rather than continuos read
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
unsigned long averageDistance = 0;
unsigned long loopCount = 0;
const float eta = .4;
const int delayTime = 50;
void setup() {
Serial.begin(115200); // Start serial communications, xxx 9600 in SD code
// SD card
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
Serial.print("Initializing ToF sensor...");
pinMode(2, OUTPUT); // Set pin 2 as trigger pin
digitalWrite(2, LOW); // Set trigger LOW for continuous read
pinMode(3, INPUT); // Set pin 3 as monitor pin
Serial.print("sensor initialized.");
}
void loop() {
unsigned long pulseWidth = pulseIn(3, HIGH); // Count how long the pulse is high in microseconds
String dataString = "";
if (pulseWidth != 0) {
pulseWidth = pulseWidth / 10; // 10usec = 1 cm of distance
averageDistance = (eta * (pulseWidth)) + ((1 - eta) * averageDistance);
}
dataString += String(loopCount++);
dataString += ", ";
dataString += String(averageDistance);
Serial.println(averageDistance);
File dataFile = SD.open("tof-log.csv", FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
} else {
Serial.println("error opening datalog.txt");
}
delayMicroseconds(delayTime);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment