Arduino and rplidar A1M8need help (It won't work)

I downloaded the library from github GitHub - robopeak/rplidar_arduino: RoboPeak RPLIDAR driver for Arduino and Arduino-compatible devices and it seems the code doesn’t work, I tried many things. I read from some posts that I need to change serial to (lidar.begin(Serial3); ) (i am using mega 2560) still no use and instead show this error (stk500v2_ReceiveMessage(): timeout ). As well only this library works #include <RPLidar.h> while other libraries like (#include <rplidar_driver_impl.h> #include <rplidar_driver_serial.h>) don’t work. I don’t have much experience in programming only the basics of C++. when I uploaded the program (leaving lidar.begin(Serial); unchanged and removing other libraries because other libraries besides #include <RPLidar.h> is not recognised and the program won’t upload)and go to serial monitor to see the results which I expected it to be showing distance and angles, it showed something like this (//?//). Sometimes it won’t work and show this error (avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
An error occurred while uploading the sketch).

I am stuck any help or advice will be thankful, I have been trying for days now.

simple_connect.ino (2.68 KB)

Well you can help us help you by posting your formatted code (right click Auto Format) in between code tags.

From reading your crazy jumble of a post, I can tell that you’re not taking the methodical approach that is essential if you want to achieve any success with programming and electronics. Please spend a few minutes to take some deep breaths, step back from the project, and collect yourself.

3ath:
Sometimes it won’t work and show this error (avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
An error occurred while uploading the sketch).

Except for one very rare case, which I don’t think applies here, upload errors like this have absolutely nothing to do with your sketch. So you have two unrelated problems:

  • Sketch is not working as you expect it to.
  • Upload failures.

You need to troubleshoot each of these independently.

3ath:
when I uploaded the program (leaving lidar.begin(Serial); unchanged and removing other libraries because other libraries besides #include <RPLidar.h> is not recognised

That’s not surprising, since the library you’re using doesn’t contain any of those files. Please post a link to where you found the code you’re trying to compile.

Why aren’t you using one of the examples that came with the RPLidar library?