平台
- 硬件:ESP-01
- 开发环境:[Arduino IDE|
- 操作系统:[Windows|
IDE 中的设置
- 模块:[通用 ESP8266 模块|
- 闪光模式:[DOUT]
- 闪存大小:[512KB]
- lwip 变体:|v2 低内存|
- 重置方法:[ck]
- 闪光频率:[40Mhz]
- CPU频率:[80Mhz]
- 上传使用:[SERIAL]
- 上传速度:[115200]
问题描述
我使用 8 个超声波传感器和 esp8266-01 在arduino uno 的智能停车项目中工作,我将 TX ESP-01 连接到 arduino uno TX,将 RX 连接到 RX,每个传感器连接到一个 arduino 引脚,上传代码时,我将 GPIO0 连接到 GND,上传后删除它,当打开串行监视器时,它会打开重新连接(重新启动)的循环并仅显示 5 个值为 0 的传感器,
结果:
connecting..... connected:
192.168.1.11
Distance0 : 0
setting /number failed:
Distance1 : 0
setting /number failed:
Distance2 : 0
setting /number failed:
Distance3 : 0
setting /number failed:
Distance4 :
ets Jan 8 2013,rst cause:4, boot mode:(3,7)
wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld
我的代码
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define FIREBASE_HOST "ْْْXXXXXXXXXXXXXXXXXX"
#define FIREBASE_AUTH "XXXXXXXXXXXXXX"
#define WIFI_SSID "AYMAN"
#define WIFI_PASSWORD "01357911"
//#include <Servo.h>
//Servo myservo;
const int ULTRASONIC_PIN[] = {2,3,4,5,6,7,8,9};
void setup(){
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop(){
for(int x=0;x<8;x++){
Serial.print("Distance");
Serial.print(x);
Serial.print(" : ");
int result = readUltrasonic(ULTRASONIC_PIN[x]);
Serial.print(result);
Serial.println();
if(result<150){
Firebase_Setup(x);
}
delay(1000);
}
Serial.println("---------------------------------------------------------------------------------------");
delay(1000);
}
int readUltrasonic(int pin){
//Returns distance in cm
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
delayMicroseconds(10);
digitalWrite(pin, LOW);
pinMode(pin, INPUT);
return pulseIn(pin, HIGH, (unsigned long)60000) / 29 / 2;
}
//>--------------------------------------------------------------------------------------
void Firebase_Setup(int number){
Firebase.set("Slot 1", 1);
if (Firebase.failed()) {
Serial.println("setting /number failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
}