Hi mates, I'm developing a firmware for an Arduino, I want to receive the distance data from a V-LD1 sensor. I understand It needs to use a list of commands in hex format, I've tried with a evaluation V-LD1 that has a connection to the PC and I can send the commands, but I haven't found a way to connect the V-LD1 to the Arduino's UART, I'm a new Arduino developer. Thanks in advance.
Why did you choose an Arduino Uno, since the serial port is already used to upload a new program and to communicate with the PC while you are debugging your program? There are many other Arduino devices with multiple serial ports.
assuming this is the sensor ur using, there are a couple of examples in there:
for example:
using a UNO is debatable but putting that aside, if you can that the chip off the board you could simply use it a as USB-to-UART converter and TRY sending those commands (those are hexadecimal values btw!) from you PC and see if you get the corresponding response for starters...
hope that helps....
Yes, thanks for your answer, I've tried on an Arduino Uno, an esp32-S3 and a RakWireless 11720, but I can't get a response to the commands I've sent, I also tried the way ur saying (using it a as USB-to-UART to the pc) and I've received the data that I want, but what can I try next? Since I want to communicate the mcu and the sensor using uart communication.
that is good news then!
first as suggested by other user, I would find/get and arduino which has more that one hardware serial port (e.g Leonardo or MEGA). reason for that is that for the baudrate you require to communicate with your sensor software serial would not be very reliable.
then I would try a 'simple' sketch like this one and see how it goes!
uint8_t INIT_frame[8] ={0x49,0x4E,0x49,0x54,0x01,0x00,0x00,0x00};
void setup() {
// initialize both serial ports:
Serial.begin(115200); //this is for PC (serial monitor)
Serial1.begin(115200); //connected to sensor
// send frame to sensor from port 1
for(uint8_t i = 0; i < 8; ++i){
Serial1.write(INIT_frame[i]);
}
while(!Serial1.available()); //wait for response
//print out serial response to Serial Monitor
while (Serial1.available()) {
uint8_t inByte = Serial1.read();
char buf[6];
sprintf(buf,"0x%.2X",inByte); //format received byte as a hexadecimal string
Serial.println(buf);
}
}
void loop() {
}
hope that helps...
I have the same problem here i work with a Arduino MEGA but i dont get anything out of the sensor. Is it possible to have this sensor communicate with something else? I cant find nothing online about this.
Agree that an Uno is a horrible choice for this. The V-LD1 runs on 1.8v logic levels. How are you shifting the levels to 5V for the Uno? Even if you're using RFBeam's eval board that only shifts them to 3.3V.
I just finished writing an ESP32-based driver for V-LD1. It works fine. I'll post it up to GitHub when I get a chance.
I have it working using this code in a Rak11720, you can adapt it to your Arduino Mega, I've found out that it works using Hex commands, you need to send the init INIT, then if you want distance data you can send GNFD, It will answer in hex too, so you need to decode the data ( read the datasheet, there you have the structure and how to decode it ) Also you need to use Serial_8E1, not standard.
uint8_t INIT_frame[9] = {0x49,0x4E,0x49,0x54,0x01,0x00,0x00,0x00,0x00};
uint8_t GNFD[9] = {0x47,0x4E,0x46,0x44,0x01,0x00,0x00,0x00,0x04};
uint8_t GRAO[8] = {0x47,0x52,0x41,0x4F,0x00,0x00,0x00,0x00};
void setup() {
// initialize both serial ports:
Serial.begin(115200); //this is for PC (serial monitor)
delay(5000);
Serial.print("Encendido");
Serial1.begin(115200, SERIAL_8E1); //connected to sensor
for(uint8_t i = 0; i < 9; ++i){
Serial1.write(INIT_frame[i]);
}
// send frame to sensor from port 1
delay(1000);
ReadData();
}
void loop() {
for(uint8_t i = 0; i < 9; ++i){
Serial1.write(GNFD[i]);
}
while(!Serial1.available()); //wait for response
ReadData2();
}
void ReadData(){
uint8_t buffer[36]; // Adjust buffer size as needed
if (Serial1.available() >= sizeof(buffer)) {
int bytesRead = Serial1.readBytes(buffer, sizeof(buffer));
// Convert each byte to hexadecimal string format and print to Serial
for (int i = 0; i < bytesRead; i++) {
char hexString[3]; // Create a string to hold the hex value
snprintf(hexString, sizeof(hexString), "%02X", buffer[i]);
Serial.print(hexString);
}
Serial.println(" -------------------- "); // Add a newline for readability
}
delay(1000);
}
void ReadData2(){
uint8_t buffer2[23]; // Adjust buffer size as needed
if (Serial1.available() >= sizeof(buffer2)) {
int bytesRead = Serial1.readBytes(buffer2, sizeof(buffer2));
// Convert each byte to hexadecimal string format and print to Serial
for (int i = 0; i < bytesRead; i++) {
char hexString[3]; // Create a string to hold the hex value
snprintf(hexString, sizeof(hexString), "%02X", buffer2[i]);
Serial.print(hexString);
}
Serial.println(" -------------------- "); // Add a newline for readability
}
delay(1000);
}
I just uploaded my ESP32 driver library for the RFBeam V-LD1 to GitHub: https://github.com/gfvalvo/RFbeamVld1
Admittedly, it’s pretty spartan right now with no documentation other than the source code. But, I’m happy to answer questions here on the forum. There is also one example code.
One thing I found working with the device is that when the ESP32’s UART port is first initialized, it spits out some seemingly random chatter. This gets the V-LD1 quite upset and it then refuses to respond to UART commands. I don’t know if this is a function of the ESP32 and V-LD1-EVAL boards I’m using or is more generic. My sample size is one.
To address this, I connected the V-LD1 eval board's VCC pin to +5V through a high-side switch using a P-Channel MOSFET. The MOSFET’s gate is driven by the ESP32 through an SN74AHCT125 buffer to provide full 5V gate drive. This ensures that the MOSFET is fully off when the ESP32's GPIO output is HIGH.
With this setup I can keep the V-LD1 powered off while the ESP32’s UART is configured for the first time. After configuring the UART, the code powers up the V-LD1.
The library requires the user code to provide a function pointer that controls power to the V-LD1. That way it can be customized to the particular powering setup without changing the library. This is shown in the example code.
Hello everyone,
Sorry for reopening this thread, but I'm going crazy.
I have the RFBeam V-LD1 evaluation board.
I am able to send the "INIT10000" command and get a response from my PC via the FTDI USB-to-UART cable.
But I can't get a response using an Arduino via UART. I have an MKR WiFi 1010 and an MKR NB 1500. Both have a logic level of 3.3V (same as eval board ?), and I have powered the eval board with the Arduino's 5V output. Serial1 is desperately silent.
Arduino boards are working, i'm able to messages from one to the other using Serial1 and RX/TX pins.
I've read and tried everything in this thread (thanks for your advice).
I've tried 2 different computers.
What am I missing? What could be wrong?
As your device uses only 1.8 volts, I suspect it's UART signals are too low voltage for the Arduino to see the data. on the other side, I suspect the Arduino output signal is too high for the device to see the data. 1.8 volt does not play well with higher voltages.
This:
The Eval Board contains 3.3V <--> 1.8V logic level converts. It also contains a DC/DC converter so it can be powered by 5V supply.
You haven't posted your code.
I haven't really any code to share since I'm still trying to have it work.
I tried the SerialPassthrough example (with the good Serials baudrate and config), and typing directly the INIT command in the serial monitor (tried in Arduino IDE and VS code)
I tried sherzaad 'simple' sketch (post #5) :
then I would try a 'simple' sketch like this one and see how it goes!
The minimum code I tried and would expect to run is this :
#include <Arduino.h>
void setup() {
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8E1); //I've tried with and without SERIAL_8E1
while(!Serial){;}
Serial.println("Send INIT message"); // This prints correctly
byte message[] = {0x49, 0x4e, 0x49, 0x54, 0x01, 0x00, 0x00, 0x00, 0x00};
Serial1.write(message, sizeof(message));
}
void loop() {
if (Serial1.available()) {
Serial.write(Serial1.read()); // I don't care about bytes conversion, i just want to see something in Serial
}
}
As I said, nothing of this works, and nothing prints to Serial.
Get a low-cost USB logic analyzer (amazon) and monitor the UART RX / TX lines between the processor and the Radar EVB.
Also, I noticed that random garbage on the UART lines during the UART's begin()
function caused the V-LD1 to go into some kind on non-responsive state. Try powering it down before begin()
and power it up after that call.
Finally, get an ESP32 board with PSRAM and try the code I posted on GitHub.
Sorry for the delay, i was on vacation.
Thank you for the suggestions. I will try this USB logic analyzer.
Also, I noticed that random garbage on the UART lines during the UART's
begin()
function caused the V-LD1 to go into some kind on non-responsive state. Try powering it down beforebegin()
and power it up after that call.
I tried to put a 10s delay after the begin()
function, and during this delay, connect the power jumper wire of Radar EVB. WIth no success.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.