ESP826601使用blinker与arduino通信控制灯
arduino端的代码:#include<SoftwareSerial.h>
SoftwareSerial mySerial(5,6);
String Serial_String="";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
mySerial.begin(115200);
pinMode(3,OUTPUT);
}
void read_string(){
while(mySerial.available()>0){
Serial_String+=(char)(mySerial.read());
delay(2);}
}
void loop() {
// put your main code here, to run repeatedly:
if(mySerial.available()>0){
Serial_String="";
read_string();
}
Serial.println(Serial_String);
delay (1000);
if(Serial_String=="Turn on LED")
digitalWrite(3,HIGH);
else if(Serial_String=="Turn off LED")
digitalWrite(3,LOW);
}
ESP8266端的代码
#define BLINKER_WIFI
#include <Blinker.h>
#include<SoftwareSerial.h>
SoftwareSerial mySerial(13,15);
char auth[] = "f785232a72e5";
char ssid[] = "TP-LINK_67C596";
char pswd[] = "07938208201";
#define BUTTON_1 "ABC"
BlinkerButton Button1(BUTTON_1);
void button1_callback(const String & state)
{
if (state == BLINKER_CMD_ON) {
BLINKER_LOG("Toggle on!");
Button1.icon("icon_1");
Button1.color("#FFFFFF");
Button1.text("Your button name or describe");
// Button1.text("Your button name", "describe");
Button1.print("on");
mySerial.print("Turn on LED");//程序的关键部分,串口通讯,至于你要发送的内容,不要管,只要在nano方面判断就好
}
else if (state == BLINKER_CMD_OFF) {
BLINKER_LOG("Toggle off!");
Button1.icon("icon_1");
Button1.color("#FFFFFF");
Button1.text("Your button name or describe");
// Button1.text("Your button name", "describe");
Button1.print("off");
mySerial.print("Turn off LED");//程序的关键部分,串口通讯,至于你要发送的内容,不要管,只要在nano方面判断就好
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
mySerial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
设计思路就是ESP8266收到按钮的指令后,通过软串口向Arduino发送Turn on LED,在Adruino端识别指令控制灯点亮。
在串口监视器中反馈的数据竟然是 Toggle on! Toggle off! 没看懂想问啥 奈何col 发表于 2019-8-3 20:26
没看懂想问啥
我测试以后,在BLINKER端 按钮开关有变化,但是Adruino控制的灯无反应,打开串口调试器没看到Turn on LED,所以不知到问题出在哪里了 fwl190612 发表于 2019-8-3 20:40
我测试以后,在BLINKER端 按钮开关有变化,但是Adruino控制的灯无反应,打开串口调试器没看到Turn on LED ...
你的8266端看样子是正常的,blinker已经正常通信了,至于arduino上程序怎么写,这个只有靠你自己学习了
页:
[1]