I just got a new MEGA 1280 and an Ethernet shield for it and fired it up...
Worked nice with just the LCD, so I added the Ethernet Shield and ran it as a web-server. I moved the LCD pins to 52, 40, 50, 44, 45, 46, 47 and now I can get anaything on it. I am fairly confident it is a programing problem since this is my fist attempt.
Anyone see any problems?
/*
LCD voltage meter and ethernet interface
with under and over voltage alarms
*/#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>// LiquidCrystal display with:
// rs on pin 52
// rw on pin 40
// enable on pin 50
// d4, d5, d6, d7 on pins 44, 45, 46, 47
//LiquidCrystal lcd(52, 40, 50, 44, 45, 46, 47);int analoginput = 1; // Analog Vin for volt meter 1
int ledPin30 = 30; // LED to indacate over voltage
int ledPin32 = 32; // LED to indacate under voltage
LiquidCrystal lcd(52, 40, 50, 44, 45, 46, 47); // Set LCD Pins
int count = 0;byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Enter a MAC address and IP address for your controller below.
byte ip[] = { 192,168,1, 177 }; // The IP address will be dependent on your local network:
Server server(80); // (port 80 is default for HTTP):float vout = 0.0; // set default to 0.0
int value = 0;
float R1 = 10000.0; // !! resistance of R1 !!
float R2 = 5000.0; // !! resistance of R2 !!
float vin = 0.0; // vin is the caculated Input voltage if analog 1void setup(){
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();// declaration of pin modes
pinMode(analoginput, INPUT);
pinMode(ledPin30, OUTPUT);
pinMode(ledPin32, OUTPUT);
lcd.begin(16, 2); // fire up the LCD, it is 16 char. x 2 linedelay(100); // make sure LCD is up
// start up message (optional)
lcd.setCursor(0,0); // set cursor at position 0 and colum 0
lcd.print(" REPEATER "); // first line of text
lcd.setCursor(0,1); // set cursor at position 0 and colum 1
lcd.print("INTERFACE v1.0"); // second line of text
delay(2000); // keeps message on screen in mili sec. 1000 = 1 sec.
lcd.clear(); // clear the screen
}void loop(){
// read the value on analog input
value = analogRead(analoginput); // value (raw) from analog pin)
vout= (value * 5.0)/1024.0;
vin = vout / (R2/(R1+R2));lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(vin, 1);lcd.setCursor(11,0); // start cursor at charactor 11 on line 0 (first)
lcd.print("Volts");// check for under voltage
if (vin < 2.0)
{ digitalWrite (ledPin32, HIGH);
lcd.setCursor(0,1);
lcd.print(" LOW WARNING!! ");
}
else {
digitalWrite (ledPin32, LOW);
}// check for Over voltage
if (vin > 4.0)
{ digitalWrite (ledPin30, HIGH);
lcd.setCursor(0,1);
lcd.print(" OVER VOLTAGE!");
}
else {
digitalWrite (ledPin30, LOW);
}// clear the 2nd line if ther is no alarm
if (digitalRead(ledPin30) == LOW && (digitalRead(ledPin32) == LOW)) {
lcd.setCursor(0,1);
lcd.print(" ");
}// end LCD volt meter code start ethernet ...
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
//for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
//client.print("analog input ");
//client.print(analogChannel);
//client.print(" is ");
// client.print(analogRead(analogChannel));
// client.println("
");
//}
client.print("Battery Voltage ");
client.print(vin);
client.print(" Volts ");
client.println("
");
client.print("Status = ");
client.print("");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
//////// END ETHERNET CODE ///////////delay(30);
}