Communicating to and from a microSD card
hi! name renato , apprentice regards arduino. have project doing school requires me have website can send commands arduino board have motor spin. i m having problem figuring out how can have function or on website code call arduino code make motor move. how communicate website in sd. card , arduino code outside of it? want have function moves motor when alarm on website sounds. in snippet of website:
heres code. website on sd card can accessed through website:www.itcup.skuttcatholic.com. can inspect source on website see code of it.
here code on arduino. reads sd card:
code: [select]
if (typeof this.hourwake!="undefined"){ //if alarm set
if (this.ctref.title==(this.hourwake+":"+this.minutewake+":"+this.secondwake)){
clearinterval(jsalarm.timer)
countdowntimer()
}
}
heres code. website on sd card can accessed through website:www.itcup.skuttcatholic.com. can inspect source on website see code of it.
here code on arduino. reads sd card:
code: [select]
#include <spi.h>
#include <ethernet.h>
#include <sd.h>
// mac address ethernet shield sticker under board
byte mac[] = { 0x90, 0xa2, 0xda, 0x0f, 0x01, 0xe8 };
ipaddress ip(192,168,0,38);// ip address, may need change depending on network
ethernetserver server(80); // create server @ port 80
file webfile;
void setup()
{
ethernet.begin(mac, ip); // initialize ethernet device
server.begin(); // start listen clients
serial.begin(9600); // debugging
pinmode(9,output);
// initialize sd card
serial.println("initializing sd card...");
if (!sd.begin(4)) {
serial.println("error - sd card initialization failed!");
return; // init failed
}
serial.println("success - sd card initialized.");
// check index.htm file
if (!sd.exists("index.htm")) {
serial.println("error - can't find index.htm file!");
return; // can't find index file
}
serial.println("success - found index.htm file.");
}
void loop()
{
ethernetclient client = server.available(); // try client
if (client) { // got client?
boolean currentlineisblank = true;
while (client.connected()) {
if (client.available()) { // client data available read
char c = client.read(); // read 1 byte (character) client
// last line of client request blank , ends \n
// respond client after last line received
if (c == '\n' && currentlineisblank) {
// send standard http response header
client.println("http/1.1 200 ok");
client.println("content-type: text/html");
client.println("connection: close");
client.println();
// send web page
webfile = sd.open("index.htm"); // open web page file
if (webfile) {
while(webfile.available()) {
client.write(webfile.read()); // send web page client
}
webfile.close();
}
break;
}
// every line of text received client ends \r\n
if (c == '\n') {
// last character on line of received text
// starting new line next character read
currentlineisblank = true;
}
else if (c != '\r') {
// text character received client
currentlineisblank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give web browser time receive data
client.stop(); // close connection
} // end if (client)
}
the simplest approach have web app open arduino's serial port , send messages arduino, , have arduino respond via serial port. there whole section of forum dedicated interfacing arduino software on pc , i'm sure you'll find examples in playground showing how in various types of web server.
Arduino Forum > Using Arduino > Project Guidance > Communicating to and from a microSD card
arduino
Comments
Post a Comment