Alguem pode me dar um help. To tantan fazer com que o ardino apague um led via comunicação com o ethernet Shield. Estou fazendo com o post: 

http://labdegaragem.com/profiles/blogs/tutorial-acendendo-um-lampad...

Fiz tentando ascender um led e não consegui pode me ajudar? Não consigo pingar o arduino e acesso  a pagina e clico nos botoes e nada é grava no comando.txt.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x33, 0xA2, 0x33, 0x00, 0x33, 0x7A };
byte ip[] = { 192, 168, 0, 60 };
byte server[] = { 192, 168, 0, 19 };
char temp[2];
int x=0;
int r5pin=5;
int r6pin=6;
int r7pin=7;
int r8pin=8;
int r9pin=9;
int powerOn=HIGH;
int powerOff=LOW;

EthernetClient client;

void setup() {
pinMode(r5pin,OUTPUT);
pinMode(r6pin,OUTPUT);
pinMode(r7pin,OUTPUT);
pinMode(r8pin,OUTPUT);
pinMode(r9pin,OUTPUT);
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect(server,80)) {
Serial.println("connected");
client.println("GET /robo.php HTTP/1.0");
client.println(); 
} else {
Serial.println("connection failed");
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}

void loop(){
if (client.connect(server,80)) {
Serial.println("connected");
client.println("GET /robo.php HTTP/1.0");
client.println();
}
do {
if (client.available()) {
char c = client.read();
temp[x]=c;
Serial.print(temp[x]);
x++;
}
}
while(x<2);
x=0;
if(temp[0]=='L' && temp[1]=='1') {
Serial.println("Liga relay1");
digitalWrite(r7pin,powerOn);
}
if(temp[0]=='L' && temp[1]=='2') {
Serial.println("Liga relay2");
digitalWrite(r7pin,powerOn);
}
if(temp[0]=='D' && temp[1]=='1') {
Serial.println("Desliga relay1");
digitalWrite(r7pin,powerOff);
}
if(temp[0]=='D' && temp[1]=='2') {
Serial.println("Desliga relay2");
digitalWrite(r7pin,powerOff);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(500);
}
}

Exibições: 1497

Responder esta

Respostas a este tópico

cara, tenta abrir o serial monitor e veja se o arduino está imprimindo conected ou conection failed

Como faço isso. Sou esse é o meu primeiro projetos com ardino.

Cara recomendo você começar mais por baixo, mas enfim se quiser msm saber faça o seguinte:
1º Compile o código e faça o upload para o arduino.
2º na IDE do arduno aperte crtl+shift+m, la abre o monitor serial. O monitor serial serve pra mostrar todos os dados enviados e recebidos do arduino via serial.

3º com o arduino conectado no computador via usb, conectado com o cabo azul (RJ45) e com o monitor serial aberto, aperte reset no arduino. Isso "forçará" o arduino a executar a rotina void setup() e consequentemente mostrar na tela se ele se conectou ou não na rede.

pode aparecer conected ou conection failed

vc fala aki oq apareceu

De onde vc tirou esses ips?? sua rede eh dhcp?? olhou o padrão no cmd ou shell?

To usando um roteador, e com o exemplo do próprio Arduíno funcionou  só esse que não ta funcionando.

conectou, mas não coseguiu acessar a pagina php.

connected
HTTP/1.1 403 Forbidden
Date: Thu, 21 Mar 2013 00:17:14 GMT
Server: Apache/2.4.2 (Win64) PHP/5.4.3
Content-Length: 218
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /arduino/robo.php
on this server.</p>
</body></html>

cara faz o seguinte ao invés de usar /arduino/robo

Pessoal eu adaptei esse codigo para minha rede e ficou assim:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:

byte mac[] = { 0x54, 0x55, 0x58, 0x10, 0x00, 0x24 }; //Put here the Ethernet's Mac Address
byte ip[] = { 192,168,1,119 }; //Put here the IP of Ethernet
byte server[] = { 192,168,1,1 }; // Put the http adress that Arduino will access.
char temp[2];
int x=0;
int r1pin=7;
int r2pin=8;
int relay1=LOW;
int relay2=LOW;

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):

EthernetClient client;

void setup() {
// start the Ethernet connection:
pinMode(r1pin,OUTPUT);
pinMode(r2pin,OUTPUT);
Ethernet.begin(mac, ip);

// start the serial library:
Serial.begin(9600);
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server,80)) {
Serial.println("connected");

// Make a HTTP request:

client.println("GET /robo.php HTTP/1.0");
client.println();

}

else {

// kf you didn't get a connection to the server:

Serial.println("connection failed");

Serial.println();

Serial.println("disconnecting.");

client.stop();

}

}

void loop(){

// if there are incoming bytes available
// from the server, read them and print them:
if (client.connect(server,80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /robo.php HTTP/1.0"); //Put here the page to turn on/off the lamp //GET /robo.php HTTP/1.0
client.println();
}
do
{
if (client.available())
{
char c = client.read();
temp[x]=c;
Serial.print(temp[x]);
x++;

}
} while(x<2);
x=0;
if(temp[0]=='L' && temp[1]=='1') //Turn on relay 1
{
relay1=HIGH;
Serial.println("Liga relay1");
digitalWrite(r1pin,relay1);
}
if(temp[0]=='L' && temp[1]=='2') //Turn on relay 2
{
relay2=HIGH;
Serial.println("Liga relay2");
digitalWrite(r2pin,relay2);
}
if(temp[0]=='D' && temp[1]=='1') //Turn off relay 1
{
relay1=LOW;
Serial.println("Desliga relay1");
digitalWrite(r1pin,relay1);
}
if(temp[0]=='D' && temp[1]=='2') //Turn off relay 2
{
relay2=LOW;
Serial.println("Desliga relay2");
digitalWrite(r2pin,relay2);
}
// Disconnect the Ethernet Shield and delay 0.5 seconds
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(500);
}
}

Os 3 arquivos criados aparentemente estao funcionando, o TXT recebe os comandos etc mas nada acontece. Eu abro o monitor serial e aparece o seguinte:

disconnecting.
connected
<html>
<head>
<script language='javascript'>
top.location.href='mainlogin.html';
</script></head><body></body></html>

Alguém poderia me ajudar?

me passa seu e-mail que eu te passo um esquema legal

Opá Boa, aproveitando o tópico já criado


Estou com o seguinte problema ao utilizar a Ethernet Shield

Ontem utilizei o shield com o arduino uno, usei o exemplo do webserver para ler as entradas das portas analógicas através do navegador,até ai tudo bem, funcionou certinho,porem hoje fui testa novamente e quando digito o endereço de ip o navegador da erro, e diz que o servidor não enviou os dados., Já compilei novamente o código e mesmo assim da o mesmo erro. Se alguém poder me ajudar fico muito grato, obg.

Obs:(Só não entendi o pq que na primeira vez funcionou certinho e depois que fui testa novamente já não aconteceu o mesmo)

Alguém já passou pelo mesmo problema?

verifica o porta muda pra 8090 p pode ser que algo estava sendo usada nela 

Não funcionou =\\

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço