03. Time Stamp
2022. 8. 28. 01:11
โ๏ธ๋ชฉํ
NTP(Network Time Protocol) ์๋ฒ์์ ์๊ฐ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๊ธฐ
[TimeStamp][Lidar1] . . [Lidar4] ํํ์ ๋ฐ์ดํฐ ๋ฝ๊ธฐ
โ๏ธArduino Model
Arduino Uno WiFi Rev2(WiFi ๋ด์ฅ ๋ชจ๋)
โจ Wire.h์์ ์ถฉ๋์ด ๋ฐ์
โจ Arduino Uno + ESP32 ์กฐํฉ์ผ๋ก ๋ณ๊ฒฝ
โ๏ธESP32 Code
#include <WiFi.h>
#include "time.h"
#include <Wire.h>
#include <LIDARLite.h>
LIDARLite lidarLite, lidarLite2;
int cal_cnt = 0;
const char* ssid = "myssid";
const char* password = "mypassword";
const char* ntpServer = "pool.ntp.org";
unsigned long epochTime;
unsigned long getTime() {
time_t now;
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
return(0);
}
time(&now);
return now;
}
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
initWiFi();
configTime(0, 0, ntpServer);
lidarLite.begin(0, true, 0x62);
lidarLite.configure(0, 0x62);
lidarLite.setI2Caddr(0x64, 0x08, 0x62);
Serial.println("initial_1");
delay(5000);
lidarLite2.begin(0, true, 0x62);
lidarLite2.configure(0, 0x62);
Serial.println("initial_2");
}
void loop() {
epochTime = getTime();
Serial.print("Epoch Time: ");
Serial.println(epochTime);
int dist;
int dist2;
if ( cal_cnt == 0 ) {
dist = lidarLite.distance(true, 0x64);
dist2 = lidarLite2.distance(true, 0x62);
} else {
dist = lidarLite.distance(false, 0x64);
dist2 = lidarLite2.distance(false, 0x62);
}
cal_cnt++;
cal_cnt = cal_cnt % 100;
Serial.print("dist1:");
Serial.print(dist);
Serial.println(" cm");
Serial.print("dist2:");
Serial.print(dist2);
Serial.println(" cm");
delay(1000);
}
'๐ญ Project > ๐ Lidar-Lite V3' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
04. Power Enable (0) | 2022.08.28 |
---|---|
02. I2C Address (0) | 2022.08.28 |
01. Survey (0) | 2022.08.28 |