I've been wanting to play around with an Arduino for quite some time. Here's what I want to do... send and receive data via RS-485 and have a simple webpage gui that will be able to display the results and send the commands. I'm thinking of using an Arduino Mega 2560 with an ethernet shield. Does this sound feasable before I go and buy the wrong stuff?
have a simple webpage gui that will be able to display the results and send the commands. I'm thinking of using an Arduino Mega 2560 with an ethernet shield.
What else is the Arduino going to be doing? The ethernet shield is not exactly plu-and-play on the Mega, which seems like overkill anyway. A UNO, on which the ethernet shield IS plug-and-play should be more than adequate. Unless there is more to the project than you have described.
I will be sending and receiving data from the 485 bus of my Jandy Aqualink pool controller. I want to create a webpage to control the pool. I have been given a parser for the Jandy protocol that was written in C. If you still think the UNO is better for this, I'll have to see if I can change my order, I got excited and hit the buy button prematurely
Thanks again!
If you still think the UNO is better for this, I'll have to see if I can change my order, I got excited and hit the buy button prematurely
The UNO will be sufficient. Depending on which ethernet shield you are getting, it may play better with the UNO than the Mega. You could always order the UNO, too. Always nice to have a second Arduino sitting around, when you want to know "What if I...".
I have .C code that runs in Linux and updates a webpage. How similar is this code to what I will need for the Arduino? I've attached the code if anyone wants to take a look.
Thanks
Not bad for my first project. I'm pleasantly surprised at how easy this little Arduino is to work with. I ordered this 485 breakout board from sparkfun; SparkFun Transceiver Breakout - RS-485 - BOB-10124 - SparkFun Electronics It uses an SP3485 chip to convert the TTL to rs485. Got it connected and it works well. I was also able to use the ethernet shield and a form method=get to create a webpage that controls and LED, reports the status on the webpage, and also send the status over a serial port and the 485 chip. I connected a 485 to usb adapter and was able to read the status to verify that it is all working. Here is the code if anyone is interested. Most of it is snippets of other code I found on the net. I just had to write a few lines.
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 220 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
int ledPin = 13; // LED pin
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 13 to output
pinMode(ledPin, OUTPUT);
//enable Serial1 datada print
Serial.begin(9600);
Serial1.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c; //replaces readString.append(c);
}
//output chars to Serial1 port
Serial1.print(c);
//if HTTP request has ended
if (c == '\n') {
//dirty skip of "GET /favicon.ico HTTP/1.1"
if (readString.indexOf("?") <0)
{
//skip everything
}
else
//lets check if LED should be lighted
if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
{
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFF
LEDON = false;
}
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//controlling led via checkbox
client.println("<h1>LED control</h1>");
//address will look like http://192.168.1.110/?L=1 when submited
if (LEDON)
client.println("<form method=get name=LED><input type=checkbox name=L value=0>LED
<input type=submit value=submit></form>");
else
/* prints value as string in hexadecimal (base 16) */
client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED
<input type=submit value=submit></form>");
client.println("
");
//printing LED status
client.print("<font size='5'>LED status: ");
if (LEDON)
{
client.println("<font color='green' size='5'>ON");
Serial.println("LED ON");
}
else
{
client.println("<font color='grey' size='5'>OFF");
Serial.println("LED OFF");
}
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}