Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Programming Questions / Re: Arduino Keeps Restarting within Setup() on: January 13, 2013, 01:47:47 pm
I'm also including my code as an attached file here...
32  Using Arduino / Programming Questions / Re: Arduino Keeps Restarting within Setup() on: January 13, 2013, 01:46:13 pm
I couldn't get the code to fit in one message here. So I am trying to upload it Github...

Here it is:

https://gist.github.com/4525631

As it restarts within Setup() and every function appears to execute fine without returning any errors I don't even know where to start debugging this thing...

Help?
33  Using Arduino / Programming Questions / Arduino Keeps Restarting within Setup() on: January 13, 2013, 01:38:55 pm
I've been learning various functions here and I've gotten them to work in individual sketches for individual functions:

I learned how to connect my EthernetShield and my EthernetPOE to the network with a fixed IP address and connect to the Internet. I learned how to do the same with my WiFi shield but with DHCP as Fixed IP doesn't work on the WiFi shield (a separate matter). I created an individual sketch for each of these functions (3 sketches) and they worked fine.

I learned how to access the SD card, create and write to files on the SD card, set the datetime stamps (created, modified & accessed) on the files with set values, read the files' sizes and read the amount of free space on the SD card. I put all of this in to one sketch and it worked fine.

I learned how to get the time from a fixed NTP server, adjust it for a given time zone (mine), store it in a time variable and display the various time elements properly formatted. I put all of this in to one sketch and it worked fine.

Then I got ambitious ... and it seems to have fallen apart.

I put all of these functions in to one big sketch as it is part of a long-term goal for an actually functional project... It compiles fine although it is much bigger than I thought it would be at this stage (25,516 byte). But I certainly haven't even started optimising any of it... I'm just trying to get it to run.

When it runs it gets to the part where it sets the IP address on the card and display the address info. As it displays the DNS it only displays the first digit of the address, then one random character and ... the whole sketch starts up again ... and again ... and again ...

[The code's too big to put in this message I'm going to try putting it in a separate message]
34  Using Arduino / Storage / Re: SD Card - Read available space? on: January 08, 2013, 06:24:23 pm
Wow! Thank you for your prompt and oh so helpful reply. The most important info I needed was the fact that I wasn't going to see a change in the free space until another cluster was allocated to the file. My code was therefore actually already working from that point of view...

The simple fileSize() call was also the simple answer to what I needed. I had tried without the uppercase S...

I have removed the timestamp stuff from my code, for brevity here, it does just what I want it to...

[I got bored waiting for that new cluster to appear so I made it write 100 lines at a time and reduced the delay to 10 seconds)

Code:
#include <SdFat.h>

// Arduino Ethernet Shield = pin 4
const int iSDPin = 4;

// Global card and file variables
SdFat sd;
SdFile file;
char strFname[] = "WRITETST.TXT";  // File name

int i = 1;  // Global counter

//
// Display space available on SD card
//

void ShowFreeSpace() {
  // Calculate free space (volume free clusters * blocks per clusters / 2)
  long lFreeKB = sd.vol()->freeClusterCount();
  lFreeKB *= sd.vol()->blocksPerCluster()/2;

  // Display free space
  Serial.print("Free space: ");
  Serial.print(lFreeKB);
  Serial.println(" KB");
}

void setup(void) {
  // Setup serial monitor
  Serial.begin(9600);
  // Wait 3 seconds
  delay(3000);
  // Some declaring text
  Serial.println("\nSD Card - SD Fat Library - File date-time stamp testing");
 
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(iSDPin, SPI_HALF_SPEED))
    sd.initErrorHalt();

  // remove files if they exist
  sd.remove(strFname);
}

void loop(void){
 
  Serial.println("\nReading free space...");
  ShowFreeSpace();

  // Open file for writing (appending)
  if (!file.open(strFname, O_CREAT | O_WRITE | O_AT_END)) {
    Serial.print("ERROR : open ");
    Serial.print(strFname);
    Serial.print(" failed");
  }
  // Write to file ... 100 lines
  Serial.print("\nWriting to the file...\tLine : ");
  Serial.println(i+=100);
  for (int j = 0; j < 100; j++) {
    file.print("\"FILE WRITE TEST\",1234");
    file.print(i);
    file.println(",\"LINE WRITTEN\",\"ARDUINO FILE TIMESTAMP TESTING\"");
  }
  file.close();
  Serial.print("File Size :\t");
  Serial.print(file.fileSize());
  Serial.println(" b");
 
  // Wait 10 seconds 
  Serial.println("Waiting 10 seconds...");
  delay(10000);
}

Thank You for all of your help!
35  Using Arduino / Storage / Re: SD Card - Read available space? on: January 08, 2013, 12:44:49 pm
I have finally gotten back to this...

I have installed the SdFat library and have been having fun seeing what I can do with it.

I got a FreeSpace function up and running very quickly. I then found a TimeStamp function in the library examples and that was something I was really looking for so I played around with that, for way too long, and can now set file creation, modification and accessed datetime stamps.

I went back to my file I/O operations and played with opening, writing to and closing my files with the new library. That works fine.

However all of this leads me to 2 questions:

How can I read/display the size of my file?
With the SD library I would probably use the ls object with a LS_SIZE call. But how do I do this for my individual file object?

How do I recalculate the FreeSpace as I get the feeling it's showing me cached info or something.

In my loop() I read the free space, write a line to my file wait 10 seconds and do it all again. The amount of free space never changes although I can see, afterwards, that my lines are being properly appended to my file and its size is getting bigger and bigger.

What I would like to do is:

loop{
  ShowFreeSpace();
  WriteLineToFile();
  ShowFileSize();
  delay(10000);
}

That ShowFreeSpace() function currently returns the same value each time.
WriteLineToFile() works fine
ShowFileSize() I don't know how to do

Once I can learn these 2 points my next step will be getting date and time from an NTP server and using that to datetime stamp my files.

Thanks!
36  Using Arduino / Programming Questions / Re: Setting Arduino's date and time? on: January 02, 2013, 06:40:57 am
hi there can i ask a question,the DS1307 RTC have battery backup so it doesnt lose the time...but what about hour change?(when clock turn fwd and bckwd) do i have to change the arduino values allways?or is there any way to do it buy it self..thankyou

For my network (NTP) version I always use a timer which reverifies and resets the time. Once every 24 hours, for example, it gets the time from the NTP server and sets the internal clock. The frequency of your timer reset would be based on how much, or little, overhead you want to add to your loop()

For a version which isn't using the network you would have to build-in DST calculations, with additional location-based and timezone-based modifications, in to your code...
37  Using Arduino / Networking, Protocols, and Devices / Re: WiFi Shield - Can't set IP Address on: January 02, 2013, 03:42:55 am
Bonne année Pat !

Quote
Same situation here, I wanted to access a simple web server runnning on my newly acquired Uno / WiFi shield sitting on my home network from the internet, and this won't work. Until a new version of the WiFi library comes out?

You might want to take a look at the DHCP setup on your router. Many routers allow you to attribute a static IP address, coming from the DHCP system, by the unique MAC address of the client. In this way you could be able to tell your router to always give a given IP address to your Uno/WiFi based on its MAC address which will always be the same.

It might be worth a try?
38  Using Arduino / Programming Questions / Re: Setting Arduino's date and time? on: January 02, 2013, 03:40:05 am
For most of my uses I'm not worried about the date/time surviving a board reset as each of my current and foreseen boards is either Ethernet or WiFi based. I will get the current time, via NTP, in setup() every time the board is reset.

The date and time of the file creation, and modification, are not primordial for me. I just wanted to know where and how to be able to control that for future operations and, most importantly, if it is possible. The date and time recordings I need will be in fields inside my files, mostly CSVs, and that's not a problem as I control that inside the files. But when transferring those files from the SD card to my computers I would prefer it is the last modification date and time were correct.

My next project, as soon as I get some more time, is to start working on moving my SD routines from the SD library to the SdFat library as I already need that to correctly return the amount of space available on the SD card. At that time I'll look in to how to possibly set both the file creation date/time and the file modification date/time ... if it's possible.

Thanks all.
39  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet - Problem setting fixed IP address on: December 31, 2012, 09:42:07 am
Quote
Shouldn't that be 192,168,0,50?

<hiding head in shame>
    Duh.  smiley-red Of course that should have been 192 and not 196...
</hiding head in shame>

All of the other values were fine.

Changed the IP address to 192,168,0,50 and EVERYTHING WORKS FINE. I can see the Arduino on the net and ping it correctly.

I should have listened to my own words spoken so often to programmers: Step away from the code for a while, come back to it, read it again, then, and only then, do you consider it a problem.

Thank you for spotting this!
40  Using Arduino / Storage / Re: SD Card - Read available space? on: December 31, 2012, 08:22:13 am
Paul,

From what I understand, which is obviously less than I think, all of the classes I mentioned (Sd2Card, SdVolume and SdFile) must be part of the SD.H library. They are used in the classic tutorial example of getting card info:

http://arduino.cc/en/Tutorial/CardInfo

That sketch doesn't seem to include any library other than SD.H...
41  Using Arduino / Programming Questions / Re: Quick suggestion on approaching this problem on: December 31, 2012, 08:15:59 am
I'm new to Arduino but old to C programming... could this possibly just be the simple assignment rather than test?

As you're already setting store to HIGH or LOW before the test...

Rather than
Code:
if ((store=HIGH) && (chqC>=thres)){

Shouldn't it be?
Code:
if ((store==HIGH) && (chqC>=thres)) {
42  Using Arduino / Networking, Protocols, and Devices / Arduino Ethernet - Problem setting fixed IP address on: December 31, 2012, 08:08:43 am
I have an Arduino Ethernet PoE. It took me a few days to get the USB2SERIAL adaptor to start playing with it...

I have no problems in connecting it using DHCP.
Ethernet.begin(mac);
I can then read the received IP address.
Ethernet.localIP();
I can then ping the card from elsewhere on the network using that IP address.
I can renew the DHCP lease with maintain() and everything continues to work as expected and I can ping it again.

When I try to do the same with a fixed IP address I can't see the card on the network. It doesn't show up in the list of connected devices on the switch / router and I can't ping it.

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

void setup() {
  // Ethernet's MAC
  byte byMAC[] = { 0x90, 0xA2, 0xDA, 0x00, 0xEC, 0x8D };
 
  // Fixed IP address config
  byte byDNS[] = { 8, 8, 8, 8 };
  byte byGateway[] = { 192, 168, 0, 1 };
  byte bySubnet[] = { 255, 255, 255, 0 };
   
  IPAddress ip(196,168,0,50);
 
 // Open serial communications
  Serial.begin(9600);
  // Wait 3 seconds
  delay(3000);

  // Some declaring text
  Serial.println("\nArduino Ethernet - Ethernet Fixed IP Connection");
 
  Ethernet.begin(byMAC, ip);
  // Ethernet.begin(byMAC, ip, byDNS);
  //  Ethernet.begin(byMAC, ip, byDNS, byGateway);
  // Ethernet.begin(byMAC, ip, byDNS, byGateway, bySubnet);

  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("Connecting...\n");
 
  // Local IP address
  Serial.println("Local IP info : ");
  Serial.print("IP address : ");
  Serial.print(Ethernet.localIP());
  Serial.print("\nSubnet : ");
  PrintIP(bySubnet);
  Serial.print("\nGateway : ");
  PrintIP(byGateway);
  Serial.print("\nDNS : ");
  PrintIP(byDNS);
}

void loop() {
}

void PrintIP(byte byArr[]) {
  Serial.print(byArr[0]);
  Serial.print(".");
  Serial.print(byArr[1]);
  Serial.print(".");
  Serial.print(byArr[2]);
  Serial.print(".");
  Serial.print(byArr[3]);
}

As you can see I've tried just passing it the MAC and the local IP address, then added the DNS, then added the Gateway, then added the Subnet. None of these combinations makes the card show up on my network.

43  Topics / Home Automation and Networked Objects / Re: Garage Door : is it open or closed? on: December 31, 2012, 06:13:36 am
Thank you all for your great ideas!

I am going to first try learning how to read, and react to, buttons. Then I'll find and add a couple of these magnetic reed switches. Funny enough I just received a magnetic switch very similar to that with my reaDIYmate a couple of days ago.

My biggest hurdles with all of this is knowing which wires to use, where to plug them in and I still don't understand how you know what type of resistor to use... but I'm sure I'll get there slowly but surely.

When I was young, a very long time ago, you were either a hardware guy or a software guy in Computer Sciences. I was very much a software guy as there just wasn't a great variety of hardware back then and I lacked the imagination necessary to foresee all of the various possibilities to come 30 years later! I now deeply regret the countless electronics and electrical classes I slept through...

I really like the thinking behind extending the binary open/closed to "nearly open", "nearly closed", "moving between = none of the above" and "error = simultaneously open and closed".

I'm finding this addition of the physical (real) world to my programming creates a whole new approach and I am very much enjoying it!

Thanks!

Draythomp: Your setup is just about precisely what I am looking to implement in the long-term. I'll be using Ethernet (PoE) to both power and communicate with my web server. Once I get to the programming part of sending the messages and responding to those messages on my web server I will feel much more at ease...

PS: The part which scares the 'bejeesus' (remaining SFW) out of me is connecting my Arduino to my garage's actual push button. I am worried about roasting my Arduino. But that's easy to replace. I am really, really worried about damaging the garage's push button as there is only one tiny company left here in France which supports this product!
44  Using Arduino / Storage / Re: SD Card - Read available space? on: December 31, 2012, 05:55:20 am
Quote
You could add something like this to the SdVolume object:

Where would I find the SdVolume object to work with?

I am on day 4 or 5 with my first Arduino so still finding out all about the various programming structures...

I naïvely thought I might be able to at least use the SdFile.ls() function, as it recurses through all files and folders on the card, and deduct each file size from the total size to give a file-based free size amount. Then I realised I have no idea where any of these undocumented classes from the SD.H library (Sd2Card, SdVolume and SdFile) are...

I assume this, relatively basic, free / available space functionality will be added to an upgraded version of the sd.h library?

Thanks for all the info and assistance!
45  Using Arduino / Storage / Re: SD Card - Read available space? on: December 31, 2012, 05:26:18 am
Quote
Note that uint32_t is too small for free byte count for cards larger than 4GB.

I just went through the Arduino data types. The two biggest highest max values I found are unsigned int and unsigned long which both have a max value of approximately 4 GB.

What data type does one use for calculations requiring values greater than 4 GB?

I have 8 GB, 16 GB and 32 GB SD cards and I assume I am not alone.

Thanks!
Pages: 1 2 [3] 4