Hi, I am wondering if it possible to send realtime information via USB to and arduino uno. Specifically I am trying to find a way to have someone on a website be able to tell the arduino to turn on an LED. I can't find a very clear answer if something like that would be possible via USB or if a shield or serial connection would be required. Thanks for any help!
A website and USB are two different worlds.
You could use a wifi shield or ethernet shield or Arduino ethernet. The Arduino will connect to the internet, and the Arduino can run a webpage. On that webpage you could turn on a led and so.
You could use a PC in the middle.
Have a website running on a PC, and have it communicate with the Arduino via the USB.
If you connect an Arduino to the USB, it presents itself as a (virtual) serial port.
So you would have to write a program that connects the website to the serial communication via the (virtual) serial port to the Arduino.
It is not that hard. For example someone made firmata in javascript.
Firmata is a standard way to communicate with the Arduino.
http://firmata.org/wiki/Download (search for javascript).
Either you put the website on a PC and have a web application on the PC send commands to the Arduino via USB, or you give the Arduino a web interface (Ethernet, WiFi, GPRS etc) and host the website on the Arduino. Putting it on the Arduino is harder, and makes the web site much more limited, but means the Arduino would be self-contained which might be important if you need your solution to work without involving a PC.
Whichever approach you take, if the Arduino/PC hosting the website is within a private network and you want it to be accessible from the public Internet then you will need to do some extra work to make that possible.
Va voir ce site http://bildr.org/2011/06/arduino-ethernet-pin-control/
Exemple de code :
//ARDUINO 1.0+ ONLY
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;
////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
//byte ip[] = { 192, 168, 0, 199 }; //Manual setup only
//byte gateway[] = { 192, 168, 0, 1 }; //Manual setup only
//byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600);
//Pins 10,11,12 & 13 are used by the ethernet shield
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
Ethernet.begin(mac);
//Ethernet.begin(mac, ip, gateway, subnet); //for manual setup
server.begin();
Serial.println(Ethernet.localIP());
/Serial.println("allo");/
}
void loop(){
// listen for incoming clients, and process qequest.
checkForClient();
}
void checkForClient(){
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
while (client.connected()) {
if (client.available()) {
if(!sentHeader){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
sentHeader = true;
}
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
/Serial.print(c);/
switch (c) {
case '2':
//add code here to trigger on 2
triggerPin(2, client);
break;
case '3':
//add code here to trigger on 3
triggerPin(3, client);
break;
case '4':
//add code here to trigger on 4
triggerPin(4, client);
break;
case '5':
//add code here to trigger on 5
triggerPin(5, client);
break;
case '6':
//add code here to trigger on 6
triggerPin(6, client);
break;
case '7':
//add code here to trigger on 7
triggerPin(7, client);
break;
case '8':
//add code here to trigger on 8
triggerPin(8, client);
break;
case '9':
//add code here to trigger on 9
triggerPin(9, client);
break;
}
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
void triggerPin(int pin, EthernetClient client){
//blink a pin - Client needed just for HTML output purposes.
client.print("Turning on pin ");
client.println(pin);
client.print("
");
digitalWrite(pin, HIGH);
delay(25);
digitalWrite(pin, LOW);
delay(25);
}
Si tu veux sortir de ton router (LAN) et avoir accès par le NET. Tu va devoir configurer ton router pour faire un 'portFowarding'