How to Reset milli() function?

Hi,
at the moment i've created a small application to log data from the arduino and send it to a log file using linux

The code(messy) looks like this

int a [3] = {0,0,0};
int b [3] = {0,0,0};
int c [3] = {0,0,0};
int p0, p1, p2, time = 0;
void setup()
{
  Serial.begin(1200);
}

void loop()
{
  a[1] = analogRead(0);
  b[1] = analogRead(1);
  c[1] = analogRead(2);
  delay(10);
  a[2] = analogRead(0);
  b[2] = analogRead(1);
  c[2] = analogRead(2);
  delay(10);
  a[3] = analogRead(0);
  b[3] = analogRead(1);
  c[3] = analogRead(2);
  p0 = (a[1]+a[2]+a[3])/3;
  p1 = (b[1]+b[2]+b[3])/3;
  p2 = (b[1]+b[2]+b[3])/3;
  time = millis()/1000;
  Serial.print(time);
  Serial.print(",");
  Serial.print(p0); 
  Serial.print(",");
  Serial.print(p1);
  Serial.print(",");
  Serial.print(p2);
  Serial.print("\n");
  delay(980);
}

However, if i use the Arduino IDE, value time (function milli()) is reset each time i go to use the serial monitor. If i use a bash command such as cat /dev/ttyUSB0 value time has not been reset.

Do i have to echo something to my Arduino for milli to reset?

Cheers

I believe the Arduino IDE sends a reset command to the Arduino when you open the Serial Monitor. So, the entire program is resetting, not just the millis().

I believe the Arduino IDE sends a reset command to the Arduino when you open the Serial Monitor. So, the entire program is resetting, not just the millis().

That is not true. the arduino is not aware of the monitor. it just sends data your way if you told it to do so with the serial library.

would that mean i would have to close the serial connection and then re-configure it in order to reset it? I'm using the pyserial module now

According to the Arduino Environment guide:

Note that on Mac or Linux, the Arduino board will reset (rerun your sketch from the beginning) when you connect with the serial monitor.

The Arduino itself doesn't know it's being monitored but the computer does send a reset command, I think.

Looks to me like the IDE sends a reset when you connect the serial monitor and when you disconnect. I'm having the opposite problem. I'd like to turn the serial monitor on and off without resetting because I've gone to the trouble of coding up a real time clock. I even have 5 buttons connected to set the time. So I get it set to the correct time, but then it's back to the default time every time I click the serial port monitor in the IDE.

I'm weak on unix, but is there an easy way to have the serial data echo to the terminal and also get logged to a file?

The Arduino IDE does not send a 'reset' when the serial monitor port is opened. However in the Arduino 0009 and later compatible hardware DTR (or RTS on boards made for the FTDI TTL-232R cable) gets asserted when the serial port is opened and a hardware reset is generated.

So, on the one hand, you are right in that a reset IS generated, BUT, on the other hand, you are wrong, because it IS NOT generated by the Arduino IDE.

I hope this helps make it clear.

cheers ... BBR

Doesn't answer your question, but I think that you don't realize that you are overrunning your array and results will be unexpected.

Valid index of C arrays run from 0 to size - 1

i.e.

  a[1] = analogRead(0);
  b[1] = analogRead(1);
  c[1] = analogRead(2);

should be

  a[0] = analogRead(0);
  b[0] = analogRead(1);
  c[0] = analogRead(2);

and all later references changed to match.

HTH

Looks to me like the IDE sends a reset when you connect the serial monitor and when you disconnect. I'm having the opposite problem. I'd like to turn the serial monitor on and off without resetting because I've gone to the trouble of coding up a real time clock. I even have 5 buttons connected to set the time. So I get it set to the correct time, but then it's back to the default time every time I click the serial port monitor in the IDE.

I believe you want to to what regomodo is doing, cat /dev/ttyUSB0 from a unix command line, so that you monitor the port without the IDE.