Ola pessoal.

Fiquei um bom tempo sem trabalhar com arduino, mas resolvi voltar. Comprei um modulo esp8266 e queria fazer um link com ele para controlar o arduino pelo wifi, nao entendo nada da programação em na ide mas sem um pouco de labview. Se alguém tiver alguma ideia de como fazer isso agradeço pois ja dei uma pesquisada por ae e nao achei muita coisa, muitos projetos prontos nao funcionam.

Exibições: 1326

Responder esta

Respostas a este tópico

Carlos vlw pela ajuda. Entrei la e peguei o codigo meio que adaptei ele pois tenho um uno r3 e ate onde vi esse código era pro mega2560. Bom meu problema agora e que depois que faço o upload do código pro Arduíno o mesmo deixa de se comunicar com o esp8266 sem o código consigo comunicação normal. Estou usando ligação direta tx,rx com o arduino somente coloquei um regulador de 3,3v no esp8266. Vou postar o código pois nao entendo muito de programação no Arduíno.   

/* ====== ESP8266 Demo ======
* Print out analog values
* (Updated Dec 14, 2014)
* ==========================
*
* Change SSID and PASS to match your WiFi settings.
* The IP address is displayed to soft serial upon successful connection.
*
* Ray Wang @ Rayshobby LLC
* http://rayshobby.net/?p=9734
*/

// comment this part out if not using LCD debug

#define BUFFER_SIZE 512

#define SSID "BRAGA" // change this to match your WiFi SSID
#define PASS "BRAGA1155224433665511" // change this to match your WiFi password
#define PORT "8080" // using port 8080 by default

char buffer[BUFFER_SIZE];

/*
// If using Software Serial for debug
// Use the definitions below
//#include <SoftwareSerial.h>
//SoftwareSerial dbg(7,8); // use pins 7, 8 for software serial
//#define esp Serial
*/

// If your MCU has dual USARTs (e.g. ATmega644)
// Use the definitions below
#define dbg Serial // use Serial for debug
#define esp Serial // use Serial1 to talk to esp8266

// By default we are looking for OK\r\n
char OKrn[] = "OK\r\n";
byte wait_for_esp_response(int timeout, char* term=OKrn) {
unsigned long t=millis();
bool found=false;
int i=0;
int len=strlen(term);
// wait for at most timeout milliseconds
// or if OK\r\n is found
while(millis()<t+timeout) {
if(esp.available()) {
buffer[i++]=esp.read();
if(i>=len) {
if(strncmp(buffer+i-len, term, len)==0) {
found=true;
break;
}
}
}
}
buffer[i]=0;
dbg.print(buffer);
return found;
}

void setup() {

// assume esp8266 operates at 115200 baud rate
// change if necessary to match your modules' baud rate
esp.begin(9600);

dbg.begin(9600);
dbg.println("begin.");

setupWiFi();

// print device IP address
dbg.print("192.168.0.11:");
esp.println("AT+CIFSR");
wait_for_esp_response(1000);
}

bool read_till_eol() {
static int i=0;
if(esp.available()) {
buffer[i++]=esp.read();
if(i==BUFFER_SIZE) i=0;
if(i>1 && buffer[i-2]==13 && buffer[i-1]==10) {
buffer[i]=0;
i=0;
dbg.print(buffer);
return true;
}
}
return false;
}

void loop() {
int ch_id, packet_len;
char *pb;
if(read_till_eol()) {
if(strncmp(buffer, "+IPD,", 5)==0) {
// request: +IPD,ch,len:data
sscanf(buffer+5, "%d,%d", &ch_id, &packet_len);
if (packet_len > 0) {
// read serial until packet_len character received
// start from :
pb = buffer+5;
while(*pb!=':') pb++;
pb++;
if (strncmp(pb, "GET /", 5) == 0) {
wait_for_esp_response(1000);
dbg.println("-> serve homepage");
serve_homepage(ch_id);
}
}
}
}
}

void serve_homepage(int ch_id) {
String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\nRefresh: 5\r\n";

String content="";
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
content += "analog input ";
content += analogChannel;
content += " is ";
content += sensorReading;
content += "<br />\n";
}

header += "Content-Length:";
header += (int)(content.length());
header += "\r\n\r\n";
esp.print("AT+CIPSEND=");
esp.print(ch_id);
esp.print(",");
esp.println(header.length()+content.length());
if(wait_for_esp_response(2000, "> ")) {
esp.print(header);
esp.print(content);
} else {
esp.print("AT+CIPCLOSE=");
esp.println(ch_id);
}
}


void setupWiFi() {
// try empty AT command
esp.println("AT");
wait_for_esp_response(1000);

// set mode 1 (client)
esp.println("AT+CWMODE=1");
wait_for_esp_response(1000);

// reset WiFi module
esp.print("AT+RST\r\n");
wait_for_esp_response(1500);
delay(3000);

// join AP
esp.print("AT+CWJAP=\"");
esp.print(SSID);
esp.print("\",\"");
esp.print(PASS);
esp.println("\"");
// this may take a while, so wait for 5 seconds
wait_for_esp_response(5000);

esp.println("AT+CIPSTO=30");
wait_for_esp_response(1000);

// start server
esp.println("AT+CIPMUX=1");
wait_for_esp_response(1000);

esp.print("AT+CIPSERVER=1,"); // turn on TCP service
esp.println(PORT);
wait_for_esp_response(1000);


}

Bruno,

A intenção da criação  do grupo é justamente porque muitos não tem experiência ainda com o ESP, mas vamos ver o se eu e outros colegas que já tem alguma experiência, podem te ajudar já que esta é a melhor maneira de aprender também mais sobre ele, no entanto eu te convido a fazer o seguinte, copie e cole seu código no www.pastebin.com, aqui o programa fica bagunçado e alguns caracteres são trocados, por isso evitamos colar programas aqui no forum, caso não conheça e não saiba como fazer, por favor veja este video no meu canal do YT, Note que você deve copiar da IDE e não copiar daqui mesmo seu código como fiz no video, a intenção foi somente mostrar, depois cole o link aqui.

https://www.youtube.com/watch?v=IhGSDhIbIFA&feature=youtu.be ou siga as orientações do colega Rui Viana e envie seu arquivo em um txt.

Abs.

Carlos vlw pela ajuda mais uma vez.

Seque o link do codigo.

http://pastebin.com/SP2mwtk2

Mesmo nao sabendo usar a ide do arduino ja consegui alguns avanços, como usar softwareserial.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço