Hardware Reference
In-Depth Information
you look without changing, like exists() , size() , and peek() ,
which keep track of what you're doing when you write
more complex file-handling sketches.
even have one built in. Most microSD cards come with an
adapter to allow you to fit them into a regular SD card slot.
Some cards even come with their own readers.
Indicate when you're accessing the card, and when
you can't. Using LEDs to indicate when the Arduino is
accessing the card and when there's an error is a handy
way to know what's going on when you can't see the
output on a screen.
Once you've formatted your card, make a text file called
index.htm and save it to the card. Then insert it into your
shield. When the sketch runs, it should print the file out
once at the end of setup() , then proceed to read the
temperature sensor and control the relay as it did before.
When that's working, you're ready to write the server. This
code can be added to the sketch you've already got in
progress.
For this project, you'll only read from the card from
the microcontroller. To write to the card, you'll need an
SD card reader/writer that can handle MicroSD cards.
Readers are cheap, and they are becoming more and
more ubiqitous. If your computer is a recent model, it may
Serve It
At the beginning of
the sketch, add the Ethernet library
and the necessary constants and
global variables to use it and to set up
a server. New lines, as usual, shown in
blue.
/*
GET/POST Web server with SD card read
Context: Arduino
*/
#include <EEPROM.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
// configuration for the Ethernet connection:
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress ip(192,168,1,20);
// Initialize the Ethernet server library:
Server server(80);
8 Change these to
match your own device
and router.
const int inputLength = 16; // length of the file requested
const int typeLength = 6; // length of GET or POST
const int sdChipSelect = 4; // SD card chipSelect
const long tempCheckInterval = 10000; // time between checks (in ms)
const int thermostatAddress = 10; // EEPROM address for thermostat
8 These will be used
to manage the incoming
HTTP requests.
char inputString[inputLength]; // for input from the browser
char requestTypeString[typeLength]; // what type of request: GET or POST
int nextChar = 0; // index counter for requestTypeString
const int fileStringLength = 16; // length of the file requested
char fileString[fileStringLength]; // for input from the browser
long now; // last temperature check time
 
Search WWH ::




Custom Search