Pages: [1]   Go Down
Author Topic: How to Reset milli() function?  (Read 1477 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Code:
cat /dev/ttyUSB0
value time has not been reset.

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

Cheers
« Last Edit: April 03, 2008, 09:47:44 am by regomodo » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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().
Logged

Amsterdam
Offline Offline
Full Member
***
Karma: 1
Posts: 138
he's looking at you, kiddy...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

--
"We're all in this together..."

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: May 04, 2008, 06:25:00 pm by regomodo » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

According to the Arduino Environment guide:
Quote
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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 116
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 116
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Underhill Center, Vermont, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Central Florida, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

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

should be

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

and all later references changed to match.

HTH


Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Pages: [1]   Go Up
Jump to: