Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Time library on: February 05, 2011, 10:50:45 am
@mem
In classic fashion as soon as I tried to reproduce the problem I found the error in my code! But subtle enough to make it worth posting for others
Code:
#include <Time.h> 
int curr_min, prev_min;

int store[15]; // array for storing elements
int store_count = 0; // keep track of storage
boolean ack = false;

// store values in array
void saveVal(int val){
  store[store_count] = val;
  //store[store_count%15] = val;
  store_count = store_count+1; // increment index
}


// make rand value
int rand(){
  return int(random(500,12345));
}


// Format time
String getTime() {
  int h = hour();
  int m = minute();
  int s = second();
  String h_string = (String)h;
  String m_string;
  String s_string;
  if(m <= 9) {
    m_string = "0" + (String)m;
  }
  else {
    m_string = (String)m;
  }
  if(s <= 9) {
    s_string = "0" + (String)s;
  }
  else {
    s_string = (String)s;
  }
  String time_string = h_string+":"+m_string+":"+s_string;
  return time_string;
}


////
void setup(){
  Serial.begin(9600);
  setTime(1296915473); // the time I wrote this
}

void loop(){
  // write time value to array
  if(second()%10 == 0){
    curr_min = minute();
    //if(curr_min != prev_min){
      prev_min = minute();
      int new_val = rand();
      saveVal(new_val);
      String date_time = (String)month() + "/" + (String)day() + "/" + (String)year() + " " + getTime();
      Serial.println(date_time);
    //}
    delay(9000);
  }
}

Run this code and after a few minutes you'll see the date values go wonky.
If you look at the storeVal function you'll see that I am incrementing the array. However note that the array is a static 15 elements, yet I forgot to reset my incrementer, so after 15 ticks or so these stored values go wandering off into the memory space used by the Time library thus corrupting the data!
The fix is in the second line of the storeVal function (commented out) where store_count%15 prevents walking off the end of the array. Swap it for the one above and everything is fine.

mem I'm posting this just in case you ever get reports of corrupt time data you'll know something to look for.

-rd
2  Using Arduino / Programming Questions / Re: Time library on: February 05, 2011, 08:57:25 am
@crites yes you kind of did (but I'm glad you got your question answered)
@PaulS, @mem I didn't post code because it's not exactly a code based problem. Hopefully a description will suffice:
For a current project I am using the time library to send sensor data at the top of the minute, complete with a timestamp from the values from Time.h
So far this has been working fine and I have been able to run it for a long time (days) with no problems. I then decided that I wanted to start storing the sensor values in case I needed to resend them and so I set up an array for storage. This is where the problem begins: leaving the code to run for a while, as the array begins to fill the date values start changing, eventually resetting to 1/1/70.
At first I thought the problem was my own but when I couldn't fix it I simply removed the function that wrote to the array, and the date was once again fine.
So it seems, although I have no idea how one would prove this, that writing to an array is clobbering the variables (memory space?) of the Time library. I've looked at the C code for something obvious (like duplicate variable names) but can't see a reason. So @mem I thought I'd contact you and see if you might have some insight.
I'm not sure I kept any of the broken code, but because it was fairly reproducible I'll see if I can break it again.
3  Using Arduino / Programming Questions / Time library on: January 26, 2011, 07:34:14 pm
Can anyone get my in touch with the person/people who wrote the Time Library?
I may, or may not, have found a bug or at least have a reproducible error in a specific situation.
4  Forum 2005-2010 (read only) / Troubleshooting / Re: more OSX uploading problems on: January 24, 2006, 09:18:37 pm
David,
Yes I will be glad to assist in adding content to the wiki.

Re the problems with my boards: how do I contact Gianluca? I will be glad to send him a detailed description of everything if you can provide me with an address (you can contact off list if you need to).

Robb
5  Forum 2005-2010 (read only) / Troubleshooting / problems and progress on: January 18, 2006, 10:39:35 pm
mellis,
So here's where things are at so far:
Seems I was facing down a number of problems,
1) Under 10.4.3 I checked the preferences.txt file and serial.download_rate was set to 115200 by default. I changed it to 9600, assuming the slowest speed should work, but with no results. Then, just to be thorough I set it to 19200... and it worked! Knowing then that it does indeed (as you said) work in Tiger (10.4) I decided to upgrade my machine to 10.4.4, just to see if that would have any bearing. While I was waiting for the upgrade to finish I switched a few things around and...
2) ... when I tried it again, it didn't work (only the TX light and a "not responding" message). I of course wondered if it might be due to the new OS... but also stopped and thought about what else I had changed... which included hooking up a different board (we purchased 10). So out of curiosity I figured out which board it was that was working before, hooked it up... and that one worked!
I then proceeded to test each board one by one.... unfortunately the news is not good:
Of the eight that I have on hand* only four work correctly. Of the other four that do not work, three only flash the TX light... and I tried all three boards at all five rates; none worked. The eigth board appears to be truly defective: the RX light comes on solid, Arudino locks up, and I have to force quit the application and restart my computer.
* and I can not report on the ninth and tenth boards as one has already gone to another instructor (he will test it tonight), and the other is still at my house (where I got it to work last night using 10.3.9... so it is probably safe to assume it will work under 10.4.4. I will try this evening and let you know.)

Also another note: two boards are missing the surface mount power LED. I have no idea if they came off in shipping or simply were never soldered on. However they are two of the four boards that work, so obviously the LED has nothing to do with it.

3) An important note: Working with the boards that DO work I tested all five download rates... ONLY 19200 works! None of the other speeds (and I did test all four boards at all five speeds, and then all four again @ 19K2, just to confirm they still worked).
I figured you should be aware of this. If this is not the case with PC's and Linux you may want to talk to FTDI about it. I'd also advise you make this the default speed in the prefs file for now... and you may want to post instructions for Mac users on how to manually change the prefs file. (not just here on the forum but on the site as well).

So sorry to be the bearer of bad news... I could joke and say that it is only half bad... but as you can imagine I am rather dissapointed to find that nearly half our boards are not working.

Robb

6  Forum 2005-2010 (read only) / Troubleshooting / Re: more OSX uploading problems on: January 18, 2006, 07:05:24 am
So here's some news:
I have been in the process of switching Mac laptops and accordingly operating systems, from 10.3.9 (on my old machine) to 10.4.3.
I had been trying to run Arduino on my new machine, but given Daniel's mention above about 10.3.8, I decided to try my old one instead and installed Arduino 0003 and the FTDI drivers... and it works!
I was able to compile and upload the led_blink example and have it run just fine... however a few intereting notes:
- I was able to use only the USB tty port, not cu
- The port is listed in the Tools menu as /dev/tty.usbserial-181, whereas under 10.4 it is listed as /dev/tty.usbserial-1B1 (yes the letter B instead of the number 8, I have no idea if this is significant)
- In 10.3.9 *every* time I do an upload I first get an error "Error inside Serial.<init>()..." followed by about fifty lines of java messages... and then finally "Atmel AVR..." and then the Arduino message "Done uploading."... after which my program runs fine.
[BTW I also see "Firmware Version: 1.18", so obviously there is a way to query the Atmel]
- And I was able to change the Baud Rate to 115200, so obviously this version of the firmware supports these rates (sorry Daniel).
[BTW if there isn't a way to already, it might be nice to be able to do this from within a program and do something like: if(version < 1.17) { beginSerial(9600); } else { beginSerial(115200); } ]

So the problems I originally posted seem to be related to Mac OS 10.4 and/or the FTDI 2.0.1 driver.

Hopefully the "Team" will be able to figure out wether it is Apple's implementation of USB under 10.4, the FTDI driver, or the Arduino application.
(In the mean time I am going to upgrade to 10.4.4, just see if it helps.)
7  Forum 2005-2010 (read only) / Troubleshooting / Re: more OSX uploading problems on: January 18, 2006, 01:13:56 am
Daniel, thanks for the helpful suggestions.
I saw you had similar problems and I read (and tried) all your posts before posting myself.

One Q: you said "set the Arduino IDE  speed on the Macintosh to 9600 baud". I assume you mean the Serial Monitor setting in the Tools menu.
To my thinking that would be the rate that the monitor polls at, which might be different than the actual com port speed. Is there another place to change the overall speed of the IDE (say in the txt pref file?)

So here is my continuing saga (in hopes it might help others):
I checked the file permission of FTDI driver and it was as it should be, owner: root and group: wheel.

I also connected an LED between pin 13 and GND, and yes it does blink on reset (it also blinked when I first started Arduino). I take this to mean the bootloader (thankfully) is installed.
Interestingly the LED also continues to blink about every 10 seconds... I'm curious if this might mean anything.

That said... I am still getting the same "Programmer not responding" message.
I am starting to wonder if it is either an issue with OS 10.4 (Tiger) and Arduino 0003 alpha...
or perhaps the version of the bootloader my boards came with. Is there a way to query the board and ask for the version of bootloader? (I would guess not if it is only 1k!)

Might be time for the Arduino Crew to step in.

(also might be time for them to set up a Wiki, so we can start consolidating our collective knowledge... not to mention fixing little mistakes... like the Extreme board power LED is red, not green!)
8  Forum 2005-2010 (read only) / Troubleshooting / more OSX uploading problems on: January 17, 2006, 09:50:06 pm
I have read every post related to this topic and most everyone seems to have gotten things working... still I can't. Here's my scenario:
I have just received 10 Arduino Extreme boards, serial numbers (643-652),
I have downloaded Arduino 0003 alpha (twice),
I am working on an Apple Power Book G4, 1GHz, under OS 10.4.3, and have loaded and installed the FTDI 2.0.1 drivers (and restarted).

But every time I try to upload I see the TX led blink, (but never the RX), then a moment later get "Programmer is not responding". I have tried both /cu and /tty serial ports, and every possible speed and combination.
I have reset the board every time before uploading, quit and restarted Arduino several times, and have even tried multiple boards and different USB cables, as well as using USB power and adpter power (moving the jumper accordingly)...
plus I have trimmed my code down to nothing more than void setup(){}... (as well as trying { beginSerial(...); } at different speeds...
still nothing.
And I have run out of things to try...

Anyone have any suggestions?
Pages: [1]