RPLidar A1M8 with ESP8266

Has anyone had any success using an A1 (or any RPLidar for that matter) with an ESP8266 based processor using Arduino? Apparently they work with an UNO but I’d like to use a chip with wifi onboard. I’ve also seen a project where someone successfully used an ESP-32, so I might try that route. But for now, I’m trying to get there with a NodeMCU or WEMOS D1 Mini board.

The only drivers/library that I can find for Arduino are from 2014. Leads me to believe that they have abandoned it, or maybe I’m the only person on the planet who wants to do this.

Anyways, I’ve been at it for a while, swapping serial ports, changing uart pins, etc but it always crashes and reboots when the rplidar tries to start communication with the serial port. Code compiles and uploads fine.

Thanks!

Hello @rick_s!

You can try using this tool to get an idea of what the issue might be:

If you are not able to solve the issue and you really need to use Arduino I suggest contacting Slamtec directly and ask if they have support for the ESP8266.
http://www.slamtec.com/en/Home/About

And if you are open to not use Arduino you might be interested in this:

Also, this user was interested in something similar so you might want to contact him:

I hope that helps!

Thanks for the reply.

I did make some progress but decided to take the ESP32 route, which is working fine.

For anyone wanting to use an ESP8266, you will need to modify the core libraries in the Arduino IDE that deal with the ESP8266 UART. I rolled the IDE’s ESP8266 board library back to version 2.7.0 and was able to get a connection between Serial and the RPLidar but downgrading the core that much created a whole bunch of other challenges.

The ESP32 (I’m using the WROOM version) has multiple hardware UARTs so it is much easier to debug via USB Serial with the RPLidar connected to Serial2. The only issue is the ESP32 library does not have a analogWrite() function, so you can settle for two motor speeds (on and off) using digitalWrite(LOW or HIGH) or explore the work arounds to write a PWM value if you need a variable motor speed. The work arounds are easily found with a little searching for “ESP32 analogWrite”.

1 Like

Hey there I’m trying to use the RPLidar A2 with an esp32 using the Arduino IDE but everytime I call lidar.begin() the esp32 crashes, do you have any idea what could be the problem or would you mind sharing the code you’re using? Thank you very much.

Here is a sample of the code I used with the A1. I’m sure the ESP32 libraries have been updated since I used this. If your ESP32 crashes with this code then you might try selecting an older version of the esp32 board core library. It could also be a hardware issue. Some of the esp32 proto boards have weak voltage regulators that can’t supply enough current in certain situations. To solve that, try powering the lidar and esp32 with an external power supply (not just the usb port on the esp32). Finally, there are certain gpio pins on the esp32 that must be high (or low?) during bootup or it will just remain in an endless boot-reboot cycle. Refer to any of the esp32 pinout websites for that info.

// This sketch code is based on the RPLIDAR driver library provided by RoboPeak

// Connect RPLIDAR to UART2 PINS (depends on ESP32 board, but typically GPIO16 and 17)

// RPLIDAR motor is not variable speed, just on/off. Use LEDC library for variable speed motor

#include <RPLidar.h>

// create a driver instance
RPLidar lidar;

#define RPLIDAR_MOTOR 23

void setup() {

Serial.begin(115200);
delay(1000);

lidar.begin(Serial2);

pinMode(RPLIDAR_MOTOR, OUTPUT);

//Start with motor off
digitalWrite(RPLIDAR_MOTOR, LOW);
delay(1000);

if (IS_OK(lidar.startScan())) {Serial.println(“Scan Started”);}
delay(1000);
}

void loop() {
if (IS_OK(lidar.waitPoint())) {
float distance = lidar.getCurrentPoint().distance;
float angle = lidar.getCurrentPoint().angle;
bool startBit = lidar.getCurrentPoint().startBit;
byte quality = lidar.getCurrentPoint().quality;

//perform data processing here... 

Serial.print(distance);
Serial.print(", ");
Serial.println(angle);

} else {
digitalWrite(RPLIDAR_MOTOR, LOW); //stop the rplidar motor

// try to detect RPLIDAR... 
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100))) {
   // detected...
   Serial.println("Restarting scan"); 
   lidar.startScan();
   
   digitalWrite(RPLIDAR_MOTOR, HIGH);
   delay(1000);
}

}
}

Thank you very much, I actually found the solution, I modified the RPLidar.h and RPLidar.cpp files in the RPLidarDriver library folder.