Hey
i am trying to built a lidar scanner for the 2D-Mapping of a room.
i tried to run the code without the stepper motor and it works fine.
as soon as i plug in the motor the distance value is default at 1200cm.
Is the Motor overwriting the received value?
#include <SoftwareSerial.h>
#include "TFMini.h"
int delaylegnth= 25;
// Setup software serial port
SoftwareSerial mySerial(50, 51);Â Â Â // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
TFMini tfmini;
void setup() {
///MOTOR SETUPÂ Â
 //establish motor direction toggle pins
 pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
 pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???
Â
 //establish motor brake pins
 pinMode(9, OUTPUT); //brake (disable) CH A
 pinMode(8, OUTPUT); //brake (disable) CH B
//// LIDAR SETUP
 // Step 1: Initialize hardware serial port (serial debug port)
 Serial.begin(115200);
 // wait for serial port to connect. Needed for native USB port only
 while (!Serial);
 Â
 Serial.println ("Initializing...");
 // Step 2: Initialize the data rate for the SoftwareSerial port
 mySerial.begin(TFMINI_BAUDRATE);
 // Step 3: Initialize the TF Mini sensor
 tfmini.begin(&mySerial);Â
}
void loop() {
 double i=0;
 double degree= 0;
 // Take one TF Mini distance measurement
 uint16_t dist = tfmini.getDistance();
 Serial.print(degree);
 Serial.print("° ");
 Serial.print(dist);
 Serial.println(" cm");
 // Starte while Loop bis i=400
 while (i < 400)
 {
 digitalWrite(9, LOW); //ENABLE CH A
 digitalWrite(8, HIGH); //DISABLE CH B
 digitalWrite(12, HIGH); //Sets direction of CH A
 analogWrite(3, 255); //Moves CH A
 ++i;
 uint16_t dist1 = tfmini.getDistance();
 degree = i * 0.9;
 Serial.print(degree);
 Serial.print("° ");
 Serial.print(dist1);
 Serial.println(" cm");
Â
 delay(delaylegnth);
 digitalWrite(9, HIGH); //DISABLE CH A
 digitalWrite(8, LOW); //ENABLE CH B
 digitalWrite(13, LOW); //Sets direction of CH B
 analogWrite(11, 255); //Moves CH B
++i;
uint16_t dist2 = tfmini.getDistance();
degree = i * 0.9;
 Serial.print(degree);
 Serial.print("° ");
 Serial.print(dist2);
 Serial.println(" cm");
 delay(delaylegnth);
Â
 digitalWrite(9, LOW); //ENABLE CH A
 digitalWrite(8, HIGH); //DISABLE CH B
 digitalWrite(12, LOW); //Sets direction of CH A
 analogWrite(3, 255); //Moves CH A
++i;
 uint16_t dist3 = tfmini.getDistance();
degree = i * 0.9;
 Serial.print(degree);
 Serial.print("° ");
 Serial.print(dist3);
 Serial.println(" cm");
 delay(delaylegnth);
 Â
 digitalWrite(9, HIGH); //DISABLE CH A
 digitalWrite(8, LOW); //ENABLE CH B
 digitalWrite(13, HIGH); //Sets direction of CH B
 analogWrite(11, 255); //Moves CH B
++i;
 uint16_t dist4 = tfmini.getDistance();
 degree = i * 0.9;
 Serial.print(degree);
 Serial.print("° ");
 Serial.print(dist4);
 Serial.println(" cm");
 delay(delaylegnth);
 }
 ////ENDE LOOP BEI i = 400
Â
Â
}
´
thanks for your help
92Rockstar