I've recently had some errors on my program so I've changed the board, and I tried to use a reduced the code to find the error.
Right now I am testing the WebServer Example of the Ethernet Library. Well, I've used Serial.print and even mySerial.print (SoftwareSerial.h) to detect the error. Anyway with an Arduino Ethernet board (Arduino 1.0 IDE) when I write on a browser the IP address of the board nothing happens. Trying to understand what happens I added a print instruction to see where the program stops.
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x5E, 0xF4 };
IPAddress ip(192,168,112, 31);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
mySerial.begin(9600);
mySerial.print("webserver");
}
void loop()
{
// listen for incoming clients
EthernetClient 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();
mySerial.print(c); <<<<<----------------
// 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("
");
}
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();
}
}
As you can see I introduce mySerial.print(c) and c is client.read() a char... It doesn't matter if it is mySerial.print (using SoftwareSerial library) or just using a Serial.print the result is this:
What is connected to pins 2 and 3? Where is this data supposed to go?
// 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("
");
}
Do you have something connected to these pins? Or is this just garbage?
or if I change the instruction to mySerial.print(client.read());
Why can't you be bothered to separate the values being printed?
No. Meaningless crap, since you haven't a clue where each number starts and ends. Lacking that clue, you have no way of determining a meaning for the numbers, which is an essential piece of information.
No. The example doesn't use mySerial and it doesn't print the value of client.read().
If you are going to modify the example, feel free to do a good job.
mySerial.print(client.read());
if fine IF you follow that with
mySerial.print(" ");
so that you see something like
webserver13 59 80 20 21 51 72 3551163616664147128352011369512340
or
webserver135 98 0 20 21 51723551163616664147128352011369512340
See, it's how the numbers break apart that is important.
I only connect the tx y rx ports to pins 2 y 3.
And ground, too?
Why aren't you using the standard USB cable to connect the Arduino to the PC?
more information:
*the IP address is not used. I've tried with a ping.
*I change the ethernet cable.
*when I connect the board I ping it and it responds.
*My operating system is Ubuntu 11 and since a week I 'm using arduino 1.0 IDE. So I erase the 022 ide version. I thought that maybe the libraries were causing some conflits...
I do not know what is the problem. Maybe you know basic tips I didn't realize.
No. The example doesn't use mySerial and it doesn't print the value of client.read().
If you are going to modify the example, feel free to do a good job.
I was answering to your question about if there were something connecting to the ports.
I thought that maybe it could be a conflict using the Serial for that reason I prove with the SoftwareSerial library. But if I use the normal serial instructions it happens the same.
Arduino Ethernet, the FTDI board and the usb cable using just
char c = client.print() ;
Serial.print(c);
Serial.print(" ");
it prints the strange symbols. Or if I change it for
char c = client.print() ;
Serial.print(client.print());
Serial.print(" ");
it prints the numbers as you said with a space between then.
The strage thing is that when I tried this before no matter with which board it prints the http frame-
http://192.168.112.31/
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/535.19
*My operating system is Ubuntu 11 and since a week I 'm using arduino 1.0 IDE.
IDE v0022 and v1.0 had a bug in the ethernet library that caused problems like that. Try downloading the new IDE v1.0.1 from the Arduino site and unpack it in a local directory. Then navigate to that directory and run the arduino shell script there.