BASIC4MCU | 질문게시판 | 아두이노 와이파이 사용 질문입니다.
페이지 정보
작성자 호호미 작성일2021-11-24 14:14 조회1,017회 댓글2건본문
첫번째 그림은 제가 esp8266-01 adaptor를 arduino UNO와 연결한 그림입니다.
저는 UNO보드, ESP8266-01 Adaptor, DHT11센서, MQ-7센서,미세먼지 센서등을
ThingSpeak 채널에 wifi로 업로드하려고 합니다.
첫번째 질문입니다.
오류 화면처럼 Arduino UNO보드에서는 Thingspeak library와 esp8266WIFI Library를 사용할 수 없나요?
라이브러리가 정상적으로 추가되어 있음에도 자꾸 에러가 나옵니다.
두번째 질문입니다.
그리고 다양한 센서를 연결했을때, 컴퓨터 USB로 연결한 경우 전력이 부족해서
작동이 안할 수도 있나요?
#include <SoftwareSerial.h> //Software Serial library
SoftwareSerial espSerial(2, 3); //Pin 2 and 3 act as RX and TX. Connect them to TX and RX of ESP8266
#define DEBUG true
String mySSID = "tablet"; // WiFi SSID
String myPWD = "a010801"; // WiFi Password
String myAPI = "AVA5WXP"; // API Key
String myHOST = "api.thingspeak.com";
String myPORT = "80";
String myFIELD = "field1";
int sendVal;
void setup()
{
Serial.begin(9600);
espSerial.begin(9600);
espData("AT+RST", 1000, DEBUG); //Reset the ESP8266 module
espData("AT+CWMODE=1", 1000, DEBUG); //Set the ESP mode as station mode
espData("AT+CWJAP=\""+ mySSID +"\",\""+ myPWD +"\"", 1000, DEBUG); //Connect to WiFi network
/*while(!esp.find("OK"))
{
//Wait for connection
}*/
delay(1000);
}
void loop()
{
sendVal = random(1000); // Send a random number between 1 and 1000
String sendData = "GET /update?api_key="+ myAPI +"&"+ myFIELD +"="+String(sendVal);
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections
espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);
espData("AT+CIPSEND=0," +String(sendData.length()+4),1000,DEBUG);
espSerial.find(">");
espSerial.println(sendData);
Serial.print("Value to be sent: ");
Serial.println(sendVal);
espData("AT+CIPCLOSE=0",1000,DEBUG);
delay(10000);
}
String espData(String command, const int timeout, boolean debug)
{
Serial.print("AT Command ==> ");
Serial.print(command);
Serial.println(" ");
String response = "";
espSerial.println(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (espSerial.available())
{
char c = espSerial.read();
response += c;
}
}
if (debug)
{
//Serial.print(response);
}
return response;
}
댓글 2
조회수 1,017master님의 댓글
master 작성일
wifi 오류가 발생한다면 wifi 예제만 돌려서 오류가 발생하는지 체크하세요
라이브러리는 여러가지가 있을 수 있으며 라이브러리마다 코드가 조금씩 다를 수 있습니다.
master님의 댓글
master 작성일
각 회로의 소모전류의 합이 USB 공급전류보다 큰 경우에는 전압 강하되거나, USB전원이 차단되기도 합니다.
심하면 노트북 윈도우가 손상되거나 하드디스크가 손상되기도 합니다.