Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 27
211  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: April 01, 2012, 04:07:16 pm
Then, you should probably send a close connection after the host. If you send an HTTP/1.1 request, the server may not close that end unless you send that.
Code:
  client.println("Host: www.myserver.com");
  client.println("Connection: close");
  client.println();

wouldn't the client.stop command achieve the same result as Connection: close ?

Anyway, as soon as I commented out the section starting with :
Code:
while(client.connected() && !client.available()) delay(1);

then everything worked as expected. I just can't figure out why the erratic behaviour before that.
212  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: April 01, 2012, 03:45:47 pm
OK. Trying to understand why strange behaviour on the board.

I have the code working, but still don't understand why I had problems.

My setup :
Mega 2560
new Ethernet Shield
Port forwarding for port 82 set in the router.
Current IP xx.xx.xx.xx:82 viewed from a browser which displays the test page from the Arduino 100% OK :  Zoomkat's simple Arduino 1.0 button ON OFF
 
I had the inputs for my home panic system ( linked to a remote security company ) on pins 14 & 15
The relay that activates the radio signal is on pin 9
LCD was on 2,3,4,5,6,7
 
I moved the LCD to 18,17,16,5,6,7
Also moved the panic inputs to 2,3
 
pins 4 and 10 both empty
 
System works fine, until I try to GET data to my php page.
 
in my temperature sensor reading code, I have added the LogItWeb line here :

Code:
  float tempC1 = readTemperature(outsideThermometer);
  float tempC2 = readTemperature(insideThermometer);
  LogItC("Temp In : ",0);
  LogItF(1,tempC2,0,4);
  LogItWeb(1,tempC2);
  LogItC(" -- Out : ",0);
  LogItF(2,tempC1,1,4);

The LogItWeb goes to :
 
Code:
void LogItWeb(int Location, float LogTxt){
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.myserver.com/serveit.php?data=");
    client.print(Location);
    client.print("--");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.myserver.com");  // i found my server rejects the connection if this line is not present
    client.println();
 
    while(client.connected() && !client.available()) delay(1); //waits for data
    while (client.connected() || client.available()) { //connected or data available
      char c = client.read();
      Serial.print(c);
    }
    client.stop();
    Serial.println("disconnected");
    Serial.println("==================");
  }
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}

I can see that the ethernet code is calling the php file and writing to the txt file on my web server.
I am getting exactly as expected :
IP address : xx.xx.xx.xx 2012-04-01---12:02:27 1--26.25
 
However, once it has run once, it seems to activate my panic system relay ( pin 9) and then freezes the system. The temp readings on the LCD are not updating and I have to re-set the system.
 
Can you see anything in the LogItWeb function that would cause this erratic behaviour ?
 
What I am seeing in the Serial Monitor as soon as I reset is :
 
server/client 1.0 test 12/08/11
Send get1 in serial monitor to test client
Setup Completed - System Operational
Setup Completed - Checking SMS state
EEProm read
EEProm = 0 (sms OFF, Home)
Temp In : 26.25
connected
HTTP/1.1 200 OK
Date: Sun, 01 Apr 2012 10:02:56 GMT
Server: Apache/2.2.16 (Debian) mod_fcgid/2.3.6 mod_ssl/2.2.16 OpenSSL/0.9.8o mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.3-7+squeeze8
Content-Length: 0
Content-Type: text/html

I would expect the next line to be :
-- Out : 26.25
but it would appear that the sketch is freezing in the section where it waits for a reply from the web server.


Next, I added a short delay (250) and commented out the section of code that I think waits for a response from the web server. Everything seems to be working fine now. Could it be that because my web side php script receives the data and writes it to a web side txt file, but doesn't actually send anything back to the Arduino ?
 
I found that before this mod the Rx LED on the ethernet board was on constantly. Was that because it was always waiting for incoming data ?
 
I just don't understand why the unmodified code would activate my panic system relay on pin 9 ( activates the relay with a ground / low signal ).
 
The new function :
 
Code:
void LogItWeb(int Location, float LogTxt){
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.imagedisk.co.za/serveit.php?data=");
   
    client.print(Location);
    client.print("--");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.imagedisk.co.za");
    client.println();
 
    delay(250);
 
//    while(client.connected() && !client.available()) delay(1); //waits for data
//    while (client.connected() || client.available()) { //connected or data available
//      char c = client.read();
//      Serial.print(c);
//    }
 
    client.stop();
 
    Serial.println("disconnected");
    Serial.println("==================");
  }
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}
213  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: March 31, 2012, 04:47:46 pm
OK. I have re-installed the IDE from a fresh download and the Ethernet sketch now compiles and uploads perfectly. Therefore I can only assume that the libraries that were installed as part of my first original ( 1.0 ) installation were not compatible with the upgrade to the latest IDE 1.0

However, I did have a problem with another sketch that uses the Dallas Temperature library. Had to make a change to the .cpp file as reply#5 here :
http://arduino.cc/forum/index.php/topic,82258.msg619480.html#msg619480


to zoomkat, my sincere thanks for the assistance.
214  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: March 31, 2012, 12:56:30 pm
Quote
Is it possible that the Ethernet or SPI Library on my PC is outdated ? If so, is there a link where I can download the latest versions of Ethernet and SPI ?

When I download a new IDE version, I make a new folder for it so there is no mixing of the librarys (I make seperate shortcuts to the arduino.exe files so I have all the old IDEs available as needed). You might reload the 1.0 IDE to make sure you have the latest files.




Thanks zoomkat. I will download and re-install the IDE.
215  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: March 31, 2012, 12:55:47 pm
Holy cow! Where have you been? If this is an ethernet shield, digital pin 4 is the Slave Select pin for the SD SPI interface. Sometimes I wonder why I do this...


@SurferTim

Very unfair comment I think.

I am a complete novice to Arduino and electronics, so please excuse me as an idiot if I'm not up on your level. I was hoping to use the forum to help learn and solve problems - just like zoomkat has kindly done with his constructive posts.

Tomorrow, I will know more that I did the day before. You, however, will most likely still be an ass.
216  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: March 31, 2012, 12:41:43 pm
There is nothing connected to pin 4.

The errors appear at the bottom of the IDE during compiling, before it starts uploading.

Isn't the SPI related to the SD card ?  I do not have an SD card in the slot on the ethernet shield.

Is it possible that the Ethernet or SPI Library on my PC is outdated ? If so, is there a link where I can download the latest versions of Ethernet and SPI ?

I do recall some IDE update a short while back that changed the file extensions for the sketches.
217  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: March 31, 2012, 11:38:45 am
Yes 1.0
218  Using Arduino / Displays / Re: Added Ethernet, LCD garbage on: March 31, 2012, 11:10:26 am
Many Thanks Don
219  Using Arduino / Displays / Re: Added Ethernet, LCD garbage on: March 31, 2012, 09:54:34 am
Thanks Don

Many Thanks for the prompt reply.

So what you're saying is that I should always keep pins 0 and 1 open ?

Would the same apply to pins 14 - 21, which are also marked for "communication", or can I use those for the LCD ?



Regards
220  Using Arduino / Networking, Protocols, and Devices / Error compiling Ethernet sketch on: March 31, 2012, 09:51:50 am
I am using the following sketch to test my new Ethernet shield, but it does not compile, giving errors see below) :

Code:
//zoomkat 12-08-11, combined client and server
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor and send an g to test client and
//see what the arduino client/server receives
//web page buttons make pin 4 high/low
//use the \ slash to escape the " in the html
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

//changed this section :
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
//IPAddress ip(192,168,1,102); // ip in lan
//IPAddress gateway(192,168,1,1); // internet access via router
//IPAddress subnet(255,255,255,0); //subnet mask
//IPAddress myserver(208,104,2,86); // zoomkat web page
//EthernetServer server(84); //server port

//changed to :
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
IPAddress ip(192,168,1,101); // ip in lan
IPAddress gateway(192,168,1,254); // internet access via router
IPAddress subnet(255,255,255,0); //subnet mask
IPAddress myserver(41,204,200,12);
EthernetServer server(82); //server port

EthernetClient client;
String readString;


//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  Ethernet.begin(mac, ip, subnet, gateway);
  server.begin();
  Serial.begin(9600);
  Serial.println("server/client 1.0 test 12/08/11"); // keep track of what is loaded
  Serial.println("Send an g in serial monitor to test client"); // what to do to test client

 
  }

void loop(){
  // check for serial input
  if (Serial.available() > 0)
  {
    byte inChar;
    inChar = Serial.read();
    if(inChar == 'g')
    {
      sendGET(); // call sendGET function
    }
  } 

  EthernetClient 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;
          //Serial.print(c);
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

            //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println("HTTP/1.1 204 Zoomkat");
            client.println();
            client.println(); 
          }
          else {
            client.println("HTTP/1.1 200 OK"); //send new page
            client.println("Content-Type: text/html");
            client.println();

            client.println("<HTML>");
            client.println("<HEAD>");
            client.println("<TITLE>Arduino GET test page</TITLE>");
            client.println("</HEAD>");
            client.println("<BODY>");

            client.println("<H1>Zoomkat's simple Arduino 1.0 button</H1>");

            client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>");
            client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>");

            //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
            client.println("<IFRAME name=inlineframe style=\"display:none\" >");         
            client.println("</IFRAME>");

            client.println("</BODY>");
            client.println("</HTML>");
          }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

//////////////////////////
void sendGET() //client function to send/receie GET request data.
{
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0");
    client.println();
  }
  else {
    Serial.println("connection failed");
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read();
    Serial.print(c);
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop();

}

However, it does not compile, giving the following errors :

Code:
In file included from C:\Program Files\arduino\libraries\Ethernet/Client.h:3,
                 from C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:5,
                 from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:7,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\hardware\arduino\cores\arduino/WProgram.h:22: error: default argument given for parameter 3 of 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/wiring.h:120: error: after previous specification in 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/WProgram.h:24: error: default argument given for parameter 3 of 'void tone(uint8_t, unsigned int, long unsigned int)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Arduino.h:201: error: after previous specification in 'void tone(uint8_t, unsigned int, long unsigned int)'
In file included from C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:5,
                 from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:7,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/Client.h:15: error: conflicting return type specified for 'virtual void Client::write(uint8_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Client.h:17: error: conflicting return type specified for 'virtual void Client::write(const uint8_t*, size_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:50: error:   overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
In file included from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:7,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:17: error: conflicting return type specified for 'virtual size_t EthernetClient::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Client.h:15: error:   overriding 'virtual void Client::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/EthernetClient.h:18: error: conflicting return type specified for 'virtual size_t EthernetClient::write(const uint8_t*, size_t)'
C:\Program Files\arduino\libraries\Ethernet/Client.h:17: error:   overriding 'virtual void Client::write(const uint8_t*, size_t)'
In file included from C:\Program Files\arduino\libraries\Ethernet/EthernetServer.h:4,
                 from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:8,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/Server.h:17: error: conflicting return type specified for 'virtual void Server::write(uint8_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Server.h:19: error: conflicting return type specified for 'virtual void Server::write(const uint8_t*, size_t)'
C:\Program Files\arduino\hardware\arduino\cores\arduino/Print.h:50: error:   overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
In file included from C:\Program Files\arduino\libraries\Ethernet/Ethernet.h:8,
                 from EtherTest.cpp:12:
C:\Program Files\arduino\libraries\Ethernet/EthernetServer.h:17: error: conflicting return type specified for 'virtual size_t EthernetServer::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/Server.h:17: error:   overriding 'virtual void Server::write(uint8_t)'
C:\Program Files\arduino\libraries\Ethernet/EthernetServer.h:18: error: conflicting return type specified for 'virtual size_t EthernetServer::write(const uint8_t*, size_t)'
C:\Program Files\arduino\libraries\Ethernet/Server.h:19: error:   overriding 'virtual void Server::write(const uint8_t*, size_t)'


I have the Ethernet and SPI libraries in place as they were installed when I originally installed the Arduino IDE.

Suggestions please.
221  Using Arduino / Displays / Added Ethernet, LCD garbage on: March 31, 2012, 09:27:45 am
I have just added an Arduino Ethernet shield to a Mega 2560 board.

My existing LCD ( working until now ) was set with :
Code:
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

From what I understand with the Ethernet board, I can't use pins 4,10,50,51,52 as thay are used for the features on the Ethernet board.

So I tried moving the LCD pins  2, 3, 4 down to  1, 2, 3 and changed the code to :
Code:
LiquidCrystal lcd(1, 2, 3, 5, 6, 7);

Now the display on the LCD is a load of garbage.

Is this something to do with pin 1 being the Tx pin ?  If so, can I disable that Tx function and use pin 1 for the LCD, or will that kill the Serial Monitor feature of the IDE ?

Appreciate any advice.
222  Using Arduino / General Electronics / Current Sensing with ACS712 on: March 28, 2012, 11:44:36 am
Hi All

being a newbee to electronics, I need guidance please.

Am wanting to add an ACS712 to my system so that I can display the amps used by the system on my LCD screen.

The info I found here :
http://wiring.org.co/learning/basics/currentacs712.html
shows 2 capacitors to be added to the circuit.

I think I have the one already ( 0.1uF ) in my box of bits - this one :
http://za.rs-online.com/web/p/ceramic-multilayer/5381449/

Would this be the correct item to use ?

For the other, I have found the following - are they the correct things, and which would you suggest I use ?

option 1: http://za.rs-online.com/web/p/ceramic-multilayer/2114987/

option 2: http://za.rs-online.com/web/p/ceramic-multilayer/6994881/

option 3: http://za.rs-online.com/web/p/ceramic-multilayer/7368820/

Advise please.
223  Using Arduino / Programming Questions / Re: Will digitalRead return the state of an Output pin ? on: March 28, 2012, 11:16:28 am
Many Thanks to all for the replies.
224  Using Arduino / Programming Questions / Will digitalRead return the state of an Output pin ? on: March 28, 2012, 07:28:42 am
At the moment, I have a number of variables in my code that keep track of the high / low state of each output pin.

Not wanting to damage the board, can anyone confirm if using digitalRead(pin no) would return the state of an output pin ?

example, if pin 12 is an Output pin.

Code:
if(digitalRead(12) == 1){
Serial.println("OUTPUT Pin 12 is HIGH");
}
225  Using Arduino / Project Guidance / Re: Arduino Web Client to External Server on: March 28, 2012, 05:45:13 am
@zoomkat

Many Thanks for the example code you posted.

I assume that the section :
Code:
          // DIY buttons
          client.println("<a href=\"/?on\"\">ON</a>");
          client.println("<a href=\"/?off\"\">OFF</a><br />");

          // mousedown buttons
          client.println("<br><input type=\"button\" value=\"ON\" onmousedown=\"location.href ('/?on');\"/>");
          client.println("<input type=\"button\" value=\"OFF\" onmousedown=\"location.href ('/?off');\"/>");       
         
          // mousedown radio buttons
          client.println("<br><br><input type=\"radio\" value=\"ON\" onmousedown=\"location.href ('/?on');\"\">ON</>");
          client.println("<input type=\"radio\" value=\"OFF\" onmousedown=\"location.href ('/?off');\"\">OFF</>");       

would be a case of selecting which 1 of the 3 types suits the application ?

Also, would it be correct to use an If() statement to determine, from an existing variable, what the current state is, and only dislpay the opposing button / option ?  For example, if the integer Relay1state == 0 ( relay is off ) then only display the options to turn it on.

I see you gave the example of the URL to call with :84 for the port number. Would this usually require port 84 on my router to be re-directed to the IP or MAC address of the ethernet shield ?

In addition to this code ( serving up the interface page from the Arduino to the web ) I also need to log some temperature readings ( DS18B20 values ) to a web server based file from within the same sketch. I have the code working for the readings, and can display to the serial monitor and to my LCD, but where / how would I add code to the sketch to send data to the web page ?  ( Ethernet board arriving tomorrow, so really keen to have code prepared )

My existing php code on the web server, that does receive data and write it to a txt file is :
Code:
$Le = "\r\n";
$eXdata = Trim($_GET["data"]);

$newdir=date("Y-m-d---H:i:s");
$writeline = $newdir . "," . $eXdata . $Le;
$handle = fopen("serveit.txt", 'a');
fwrite($handle,$writeline);
fclose($handle);
Pages: 1 ... 13 14 [15] 16 17 ... 27