SCHEDA D1 R32 AZ-DELIVER        

 

Scheda di sviluppo D1 R32 ESP32:

Test di funzionamento con ESP32  LIDAR e LCD OLED:

 

TFMini Plus Lidar (Rilevatore di distanza Laser)

 

 

ESP32 UTILIZZATO (30 pin)

N.B. Non bisogna confondere la numerazione dei PIN dell'ESP con la numerazione dei GPIO.

N.B.Nella programmazione si utilizza la numerazione dei GPIO.

N.B. I pin  GPIO non tollerano i 5 volt , sono 3,3 volt per logica ALTA (1).

 

PIN  GPIO:

OLED :   21 (SDA)  e   22 (SCL)               Alimentazione 3.3 Volt dalla scheda

LIDAR: Verde 16 (RXD2)   Bianco 17( TXD2)   Alimentazione 5 Volt  dalla scheda

 

// File:LIDAR_ESP32_18_GIUGNO_2022
// con oled 164x48
#include <Wire.h>
#include "SSD1306.h"
SSD1306 display(0x3c, 21, 22);

#define RXD2 16
#define TXD2 17
int dist; /*—actual distance measurements of LiDAR—*/
int strength; /*—signal strength of LiDAR */
float temprature;
unsigned char check; /*—save check value */
int i;
unsigned char uart[9]; /*—save data measured by LiDAR */
const int HEADER=0x59; /*—frame header of data package */
int rec_debug_state = 0x01;//receive state for frame
void setup() {
delay(2000);
Serial.begin(115200);
Serial.println("\nBenewake TFmini-PLUS UART LiDAR Program");
Serial2.begin(115200);

//******************************************************************
//Next section includes processing LiDARs Data and printing it to the terminal.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);

}
void loop() {
Get_Lidar_data();

}
void Get_Lidar_data(){
// display.init();
display.clear();

if (Serial2.available()) //check if serial port has data input
{
if(rec_debug_state == 0x01)
{ //the first byte
uart[0]=Serial2.read();
if(uart[0] == 0x59)
{
check = uart[0];
rec_debug_state = 0x02;
}
}
else if(rec_debug_state == 0x02)
{//the second byte
uart[1]=Serial2.read();
if(uart[1] == 0x59)
{
check += uart[1];
rec_debug_state = 0x03;
}
else{
rec_debug_state = 0x01;
}
}
else if(rec_debug_state == 0x03)
{
uart[2]=Serial2.read();
check += uart[2];
rec_debug_state = 0x04;
}
else if(rec_debug_state == 0x04)
{
uart[3]=Serial2.read();
check += uart[3];
rec_debug_state = 0x05;
}
else if(rec_debug_state == 0x05)
{
uart[4]=Serial2.read();
check += uart[4];
rec_debug_state = 0x06;
}
else if(rec_debug_state == 0x06)
{
uart[5]=Serial2.read();
check += uart[5];
rec_debug_state = 0x07;
}
//Benewake
else if(rec_debug_state == 0x07)
{
uart[6]=Serial2.read();
check += uart[6];
rec_debug_state = 0x08;
}
else if(rec_debug_state == 0x08)
{
uart[7]=Serial2.read();
check += uart[7];
rec_debug_state = 0x09;
}
else if(rec_debug_state == 0x09)
{
uart[8]=Serial2.read();
if(uart[8] == check)
{
dist = uart[2] + uart[3]*256;//the distance
strength = uart[4] + uart[5]*256;//the strength
temprature = uart[6] + uart[7] *256;//calculate chip temprature
temprature = temprature/8 - 256;
Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print('\n');
//Benewake
Serial.print("strength = ");
Serial.print(strength); //output signal strength value
Serial.print('\n');
Serial.print("\t Chip Temprature = ");
Serial.print(temprature);
Serial.println(" celcius degree"); //output chip temperature of Lidar

display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_16);
display.drawString(0, 0, "DISTANZA cm. ");
display.setFont(ArialMT_Plain_24);
String myStr;
myStr = String(dist);

display.drawString(32, 28, myStr);
display.display();
while(Serial2.available()){Serial2.read();}

}
rec_debug_state = 0x01;
}
}
}

Questo č il risultato: