Ok so
I have the Lidar-Luna sensor now.
I am using this code to display distance in cm in the serial monitor and it works fine.
* File Name: TFMP_example.ino
* Developer: Bud Ryerson
* Inception: 29JAN2019
* Last work: 10SEP2021
* Description: Arduino sketch to test the Benewake TFMini Plus
* time-of-flight Lidar ranging sensor using the TFMPlus Library.
* Default settings for the TFMini Plus are a 115200 serial baud rate
* and a 100Hz measurement frame rate. The device will begin returning
* measurement data right away:
* Distance in centimeters,
* Signal strength in arbitrary units,
* and an encoded number for Temperature in degrees centigrade.
* Use the 'sendCommand()' to send commands and return a status code.
* Commands are selected from the library's list of defined commands.
* Parameters can be entered directly (115200, 250, etc) but for
* safety, they should be chosen from the library's defined lists.
*/
#include <TFMPlus.h> // Include TFMini Plus Library v1.5.0
TFMPlus tfmP; // Create a TFMini Plus object
#include "printf.h" // Modified to support Intel based Arduino
// devices such as the Galileo. Download from:
// https://github.com/spaniakos/AES/blob/master/printf.h
// The Software Serial library is an alternative for devices that
// have only one hardware serial port. Delete the comment slashes
// on lines 37 and 38 to invoke the library, and be sure to choose
// the correct RX and TX pins: pins 10 and 11 in this example. Then
// in the 'setup' section, change the name of the hardware 'Serial2'
// port to match the name of your software serial port, such as:
// 'mySerial.begin(115200); etc.
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial( 10, 11);
void setup()
{
Serial.begin( 115200); // Intialize terminal serial port
delay(20); // Give port time to initalize
printf_begin(); // Initialize printf.
Serial2.begin( 115200); // Initialize TFMPLus device serial port.
delay(20); // Give port time to initalize
tfmP.begin( &Serial2); // Initialize device library object and...
}
// Initialize variables
int16_t tfDist = 0; // Distance to object in centimeters
// Use the 'getData' function to pass back device data.
void loop()
{
delay(100); // Loop delay to match the 20Hz data frame rate
if( tfmP.getData( tfDist)) // Get data from the device.
{
printf( "Dist:%04icm ", tfDist); // display distance,
printf( "\r\n"); // end-of-line.
}
}
next I tried to introduce the Adafruit_neopixel library. and adapt the code previously used for the HC-SR04.
so it looks like this
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#include "printf.h"
#include <TFMPlus.h> // Include TFMini Plus Library v1.5.0
#define PIN 6 // Which pin on the Arduino is connected to the NeoPixels?
#define NUMPIXELS 10 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
TFMPlus tfmP; // Create a TFMini Plus object
int16_t tfDist = 0; // Distance to object in centimeters
void setup()
{
pixels.begin();
}
void loop()
{
pixels.clear(); // Set all pixel colors to 'off'
tfDist=tfmP.getData( tfDist)*0.8;
for(int16_t i=0; i<tfDist; i++) // For each pixel in strip...
{
pixels.setPixelColor(i, 0,0,255);
}
pixels.show(); // Send the updated pixel colors to the hardware.
}
Ive wired it like this.
The button is 5v power supply.
The Ws2812B is the LED
The sensor is not the Lidar-lunar pins are like this
Pin 1 (red) -----> 5V----- to arduino 5v
Pin 2 (black) ---> D2 (SDA)---- to arduino pin18TX1
Pin 3 (yellow) --> D1 (SCL)---- to arduino 17RX2
Pin 4 (white) ---> GND---- to arduino GND
Pin 5 (green) ---> D4
Pin 6 (blue) ----> unused
So I can get the lights working separately and I can get the lidar-luna to send just distance in cm, but Im not sure why it does not translate.
I used this code for theHC-SR04
#include <Adafruit_NeoPixel.h>
#include <HCSR04.h>
#define PIN 6 // Which pin on the Arduino is connected to the NeoPixels?
#define NUMPIXELS 29 // How many NeoPixels are attached to the Arduino?
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
UltraSonicDistanceSensor distanceSensor(9, 10); // Initialize sensor that uses digital pins 9 and 10.
int current_Last_LED=0;
void setup()
{
pixels.begin();
}
void loop()
{
pixels.clear(); // Set all pixel colors to 'off'
current_Last_LED=distanceSensor.measureDistanceCm()*0.8;
for(int i=0; i<current_Last_LED; i++) // For each pixel in strip...
{
pixels.setPixelColor(i, 0,0,255);
}
pixels.show(); // Send the updated pixel colors to the hardware.
}
In line 10,
UltraSonicDistanceSensor distanceSensor(9, 10); // Initialize sensor that uses digital pins 9 and 10.
this line is to initialize the sensor and I done know when or how to do that with the lidar.
any ideas