Show Posts
Pages: [1]
1  Using Arduino / Storage / Re: Storage card micro SD and internet W5100 working together on: July 07, 2013, 02:38:46 pm
Hi,

   I can't believe it. Now it's working like smooth! It's great, thank you. I just deleted one Serial.begin because it was two times as mistake, and I used for print "F" function. This is strange to not use SDRAM, why not any error indication, why not a different function name than "F" attached to print???

   Thank you again for your help, now I'm happy that NTP and my sensor is working great to trace logs to SD card.

   Best regards,
2  Using Arduino / Networking, Protocols, and Devices / Re: ntp and sd card write, incompatible? (probably solved) on: July 07, 2013, 04:20:53 am
I have the same problem, but I don't know how to solve it. Trying to get NTP and process to have date and time for adding to my variable to a file in SD card. The NTP is got, the file is created on SD card, but nothing inside. If I don't use internet connection everything is fine.
What could be the problem?
Below is size of sketch after compilation, could be this a problem? What the strategy for optimization.
 31.072 bytes (din maxim 32.256 bytes)

thank you,
3  Using Arduino / Storage / Re: Storage card micro SD and internet W5100 working together on: July 07, 2013, 01:21:35 am
Here below is the code:
Code:
#include <SPI.h>        
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <dht11.h>
#include <SD.h>

File myFile;
/*-----( Declare objects )-----*/
dht11 DHT11;

/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN A1
int count_filew = 0;

byte mac[] = {  
  0xDE, 0xAD, 0xAC, 0xDE, 0xFE, 0xED };

unsigned int localPort = 8888;      // local port to listen for UDP packets

IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup()
{
  Serial.begin(9600);
   while (!Serial) {
    ;
  }
  pinMode(10, OUTPUT);//sets w5100chip
  digitalWrite(10,HIGH);//disables w5100
  pinMode(4, OUTPUT);//sets SD chip
  digitalWrite(4,HIGH);//disables SD chip

  // start Ethernet and UDP
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    for(;;)
      ;
  }
  Udp.begin(localPort);
  
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print(F("LIBRARY VERSION: "));
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
   Serial.println("initialization failed");
   return;
  }
  Serial.println("Initialization done");
  
  
}

void loop()
{
  sendNTPpacket(timeServer); // send an NTP packet to a time server
int no_years = 0;
int no_months = 0;
int month = 1;
int theday;
int themonth;
int theyear;
int curfeb;
int epoch_st = 1970;
String date;
int partdate;
  delay(1000);  
  if ( Udp.parsePacket() ) {  
    // We've received a packet, read the data from it
    Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer

    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);  
    unsigned long secsSince1900 = highWord << 16 | lowWord;               

    const unsigned long seventyYears = 2208988800UL;    
    unsigned long epoch = secsSince1900 - seventyYears;                      
    Serial.print("today is: ");
    epoch=epoch+3*60*60;
    int u_days=epoch/60/60/24+1;
    while(u_days > 364){
      if(epoch_st%4 == 0){
         u_days-=366;
         epoch_st+=1;
      }
      else{
        u_days-=365;
        epoch_st+=1;
      }  
    }
    theyear=epoch_st;
    if(theyear%4 == 0){
       curfeb=29;
    }
    else{
       curfeb=28;
    }
    //ianuarie
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }
    //februarie
    if(u_days>curfeb){
    month+=1;
    u_days-=curfeb;
    }
    else{
    theday=u_days;
    }
    //martie
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }
    //aprilie
    if(u_days > 30){
    month+=1;
    u_days-=30;
    }
    else{
    theday=u_days;
    }
    //mai
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }    
    //iunie
    if(u_days > 30){
    month+=1;
    u_days-=30;
    }
    else{
    theday=u_days;
    }  
    //iulie
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }  
    //august
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }  
    //septembrie
    if(u_days > 30){
    month+=1;
    u_days-=30;
    }
    else{
    theday=u_days;
    }  
    //octombrie
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }  
    //noiembrie
    if(u_days > 30){
    month+=1;
    u_days-=30;
    }
    else{
    theday=u_days;
    }  
    //decembrie
    if(u_days > 31){
    month+=1;
    u_days-=31;
    }
    else{
    theday=u_days;
    }  
    themonth=month;
    theday=u_days;
    if(theday < 10){
    date="0";
    }    
    date=date + theday + '/';
        if(themonth < 10){
    date+='0';
    }

    date=date + themonth + '/';
    date=date + theyear + ' ';

    partdate = (epoch  % 86400L) / 3600;
    date = date + partdate + ':';
    if ( ((epoch % 3600) / 60) < 10 ) {
      date+='0';
    }

    partdate=(epoch  % 3600) / 60;
    date=date + partdate + ':';
    if ( (epoch % 60) < 10 ) {
      date+="0";
    }
    partdate=epoch %60;
    date+=partdate;
  }
  Serial.println(date);
  count_filew=count_filew+1;
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

    Serial.print("count is ");
    Serial.println(count_filew);
    Serial.println(count_filew % 6);
   delay(10000);
  if (count_filew % 6 == 0){
  Serial.println("Just wrote to the file");
//digitalWrite(10,HIGH);
//digitalWrite(4,LOW);
  myFile = SD.open("monit.txt", FILE_WRITE);
     if (myFile) {
        myFile.print(date);
        myFile.print(" ===> Humidity (%):");
        myFile.print((float)DHT11.humidity, 2);
        myFile.print(", Temperature (oC):");
        myFile.print((float)DHT11.temperature, 2);
        myFile.print(", Temperature (oF):");
        myFile.print(Fahrenheit(DHT11.temperature), 2);
        myFile.print(", Temperature (K):");
        myFile.print(Kelvin(DHT11.temperature), 2);
        myFile.print(", DewPoint (oC):");
        myFile.print(dewPoint(DHT11.temperature, DHT11.humidity));
        myFile.print(", DewPointFast (oC):");
        myFile.print(dewPointFast(DHT11.temperature, DHT11.humidity));
        myFile.println(";");
        myFile.close();  
      //digitalWrite(10,LOW);
      //digitalWrite(4,HIGH);  
     }  
  delay(20000);
  }
}/* --(end main loop )-- */
/*-----( Declare User-written Functions )-----*/

unsigned long sendNTPpacket(IPAddress& address)
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:        
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket();
}

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

4  Using Arduino / Storage / Storage card micro SD and internet W5100 working together on: July 06, 2013, 01:06:49 am
Hi all,

   I have a big problem very hard to understand and to make it to work. I was searching on internet and forum a lot to find a solution to my problem but, still nothing.

   My device is Arduino UNO with internet shield attached W5100. WebServer works great, I mean reading from microSD files and displaying to internet clients has no conflicts. The problem is when I try to make a trace with an internet variable. I connect my arduino to internet, get the variable value and then I try to write the value to SD card. This is not working. I tried with all suggestions to activate and disable digital pins 10 and 4 for w5100 and SD, high/low all tests but nothing.

   The most approach result was that the variable is got from internet, and when I try to write to my micro SD card file, it is created an empty file with the name trace.txt, nothing inside. If I try to write more variables to SD card without using internet, the file is written very well.

   What can be the problem as soon as the file is created but nothing is written inside???

   Thank you,
5  Using Arduino / Networking, Protocols, and Devices / Re: Arduino uno + W5100 + SD to load the image jpg on: April 14, 2013, 01:31:32 pm
When I try to write the arduino I have the following errors:
arduino-1.0.3\libraries\SD\SdFatUtil.cpp: In function 'void SdFatUtil::SerialPrint_P(const prog_char*)':
arduino-1.0.3\libraries\SD\SdFatUtil.cpp:65: error: 'SdFat' has not been declared
arduino-1.0.3\libraries\SD\SdFatUtil.cpp: In function 'void SdFatUtil::SerialPrintln_P(const prog_char*)':
arduino-1.0.3\libraries\SD\SdFatUtil.cpp:73: error: 'SdFat' has not been declared

   How could I solve these errors?

thank you,
6  Using Arduino / Networking, Protocols, and Devices / Arduino uno + W5100 + SD to load the image jpg on: April 05, 2013, 05:56:49 pm
Hi,

   I was looking for hours and hours in this forum, I saw a lot of discusses about this problem but with no solution, no example. For an open source, and for a simple loading image through webserver with arduino, I think it should be an example with the arduino package.

   Please give me a simple example index.htm file to be accessed by a client, file located onto microSD of the shield W5100 which has an image tag <src=image.jpg> also for the image having the location onto microSD. How can be the page loaded in browser having the image displayed. Please give a short example, explain very shortly the example for everybody to understand a small needed thing for next development steps.

   Thank you a lot for any help,
    Best regards,
7  Topics / Home Automation and Networked Objects / internet monitor and internet logger on: March 27, 2013, 01:06:16 am
Hi all,

    one of the interesting and needed project for arduino would be: how could I connect arduino as internet client to a site, getting the entire site index.htm and to search a word in the main page, filter the word (as data) and send it to SD file (logger file)? Is it possible for arduino to do this logger? I couldn't yet obtain a connection to a site via router.

    Could you please help me in this way?

Thank you,
Best regards,
Pages: [1]