# TFmini lidar simulation

**URL:** <https://discourse.processing.org/t/tfmini-lidar-simulation/22608>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [July 14, 2020, 11:20am UTC](https://discourse.processing.org/t/tfmini-lidar-simulation/22608 "2020-07-14T11:20:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eladsoll](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@eladsoll](https://discourse.processing.org/u/eladsoll)\
**Post date:** [July 14, 2020, 11:20am UTC](https://discourse.processing.org/t/tfmini-lidar-simulation/22608/1 "2020-07-14T11:20:12Z")

</div>

Hi, I’m a begginer and I’m tring to create a room simulation with my TFmini Lidar, the device works with serial communication.  
I diffeculties with my code, I’m trying to read from arduino and plot 3D as is.  
\</\>  
import processing.serial._;  
import peasy._;  
Serial serial;  
PeasyCam cam;  
ArrayList ptCloud;  
float angle = 6.5f;  
float angleIncrement = 0;  
float xOffset = 3.0;  
float xOffsetIncrement = 0;  
float yOffset = 152.0f;  
float yOffsetIncrement = 0;  
float scale = 2.6f;  
float scaleIncrement = 0;  
void setup(){  
size(800,640,P3D);  
colorMode(RGB,255,255,255);  
ptCloud = new ArrayList();  
cam = new PeasyCam(this,800);  
cam.rotateZ(-3.1415/4);  
cam.rotateY(-3.1415/4);  
//serial = new Serial(this,Serial.list()[0],115200);  
[//serial.bufferUntil](https://serial.bufferUntil)(’\n’);  
}  
void draw(){  
background(33);  
stroke(255,255,255);  
String input = serial.readStringUntil(’\n’);  
if(input!=null){  
String[] coordinates = split(input,’ ');  
if(coordinates.length==3){  
ptCloud.add(new PVector(float(coordinates[0]),float(coordinates[1]),float(coordinates[2])));  
}  
}  
pushMatrix();  
translate(width/2, height/2, -50);  
rotateY(angle);  
beginShape(POINTS);  
for(int idx=0;idx\<ptCloud.size();idx++){  
PVector p = ptCloud.get(idx);  
if(idx == ptCloud.size()-1){  
stroke(255,0,0);  
line(0,0,0,p.x,p.y,p.z);  
}  
stroke(255-p.x,255-p.y,255-p.z);  
//point(p.x \* scale + xOffset, -p.z \* scale + yOffset, -p.y \* scale);  
vertex(p.x \* scale + xOffset,-p.z \* scale + yOffset, -p.y \* scale);  
}  
endShape();  
popMatrix();  
angle += angleIncrement;  
xOffset += xOffsetIncrement;  
yOffset += yOffsetIncrement;  
scale += scaleIncrement;  
}  
void keyPressed() {  
if (key == ‘q’) {  
// zoom in  
scaleIncrement = 0.02f;  
} else if (key == ‘z’) {  
// zoom out  
scaleIncrement = -0.02f;  
} else if (key == ‘a’) {  
// move left  
xOffsetIncrement = -1f;  
} else if (key == ‘d’) {  
// move right  
xOffsetIncrement = 1f;  
} else if (key == ‘w’) {  
// move up  
yOffsetIncrement = -1f;  
} else if (key == ‘s’) {  
// move down  
yOffsetIncrement = 1f;  
} else if (key ==‘x’) {  
// erase all points  
ptCloud.clear();  
} else if (key == CODED) {  
if (keyCode == LEFT) {  
// rotate left  
angleIncrement = -0.015f;  
} else if (keyCode == RIGHT) {  
// rotate right  
angleIncrement = 0.015f;  
}  
}  
}

void keyReleased() {  
if (key == ‘q’) {  
scaleIncrement = 0f;  
} else if (key == ‘z’) {  
scaleIncrement = 0f;  
} else if (key == ‘a’) {  
xOffsetIncrement = 0f;  
} else if (key == ‘d’) {  
xOffsetIncrement = 0f;  
} else if (key == ‘w’) {  
yOffsetIncrement = 0f;  
} else if (key == ‘s’) {  
yOffsetIncrement = 0f;  
} else if (key == CODED) {  
if (keyCode == LEFT) {  
angleIncrement = 0f;  
} else if (keyCode == RIGHT) {  
angleIncrement = 0f;  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [July 15, 2020, 5:20pm UTC](https://discourse.processing.org/t/tfmini-lidar-simulation/22608/2 "2020-07-15T17:20:42Z")

</div>

Hi @eladsoll, You need to make it a little easier for people to help you. I think you tried to format you code, but it failed. Please edit the post and try again. When it looks like a block of code as in all the other topics, it’s easy for anyone to look at it in place, or lift it into Processing.

I don’t have a TFmini Lidar so can only help generally. I’m not sure if the comms between Ard and PC is managed by you or Peasy. What program is in the Ard? Did you write it? You could post it.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 19, 2020, 11:45am UTC](https://discourse.processing.org/t/tfmini-lidar-simulation/22608/3 "2020-07-19T11:45:50Z")

</div>

The original poster formatted code and continued here:

> [@3D room map by TFmini Lidar](https://discourse.processing.org/t/3d-room-map-by-tfmini-lidar/22709):
>
> Hi, I’m a beginner so I hope this time I worte as should. I’m trying to simulate room with TFmini lidar by using arduino Mega with serial port communication. The simulation is not good at all. I need help. My Arduino code: #include \<Servo.h\> #include \<arduino.h\>\<br\>#include "TeensyThreads.h" Servo yaw, pitch; volatile int liDARval; char s[15]; double x, y, z; float theta, phi; #define MATH\_PI 3.1415f #define msec 10 unsigned int pitchPos, yawPos; unsigned int flag; unsigned long yawCurrentT…

Please continue there…
