Show Posts
Pages: 1 2 3 [4] 5 6 ... 30
46  Using Arduino / Programming Questions / adding up millis on: March 01, 2013, 02:29:10 pm
I am working on a speedometer and trying to keep track of "ride time". Below is my code for when the speedometer has stopped. Previously when it started, "time2" was set to the value of millis().

I am trying to make sure that the time is still added correctly if millis() rolls over. I know that "time" itself will not keep track of more than 49 days of milliseconds and that this code will not work if the speedometer doesn't stop for 49 days. "time" will likely be reset to 0 fairly frequently anyway. But the arduino will only ever sleep, not restart. So I do need to worry about millis() rolling over.

"time" is the millis() that I have tallied up. "time2" is the value of millis() when I started counting last. Both are unsigned longs.
Code:
 void (stoppedMoving){
    if(millis() >= time2){//if time has NOT rolled over
      time += (millis()-time2);//add the difference between time2 and millis().
    }
    else{////if time has rolled over
      time += (4294967295 - time2) + millis();//if millis() has rolled over, add the number of milliseconds before it rolled over plus the milliseconds since it rolled over.
      }//end if time has rolled over
      moving=false;
  }//end stoppedMoving

Will this work?

Thanks
47  Using Arduino / Programming Questions / Re: Why use int instead of byte for pin numbers? on: February 25, 2013, 07:05:47 pm
Quote
Well now that we are dissing Arduino, allow me to add my gripes!

Yes, very good, but the design is good enough that they are selling tens of thousands. The good points are that it is aimed at the beginner market, the shields are a useful add-on, and it was an excellent decision to use the open-source g++ compiler.

Compare that to other boards where you have to buy their own (dodgy) compilers, or get a cut-down "beginner" version, and put up with an IDE that is so complex it's almost impossible to get a project up quickly.

Yeah I figure, maybe they weren't the best programmers or engineers but they did create the best, most successful beginner development board and IDE so there's something to be said about that.
48  Using Arduino / Programming Questions / Re: Why use int instead of byte for pin numbers? on: February 25, 2013, 01:16:26 am
I'm thinking that's the best idea unless there is something I'm missing. Which is likely.

It's just that's the way it's done in most examples, even the arduino default ones. So I figured there may be a reason.
49  Using Arduino / Programming Questions / Why use int instead of byte for pin numbers? on: February 25, 2013, 01:11:40 am
Why do we use:
Code:
int led = 13;
instead of
Code:
byte led = 13;

If you would never need to define more than 256 pins, why use the extra space for int? Is there a reason?

Thanks.
50  Using Arduino / Programming Questions / Interchanging HIGH/LOW with true/false on: February 21, 2013, 02:48:17 am
I notice that both of these lines work:

Code:
boolean pressed = (digitalRead(3)==HIGH);

boolean pressed = digitalRead(3);

I would assume that the first is more correct unless HIGH and LOW were interchangeable with true and false in which case the second line would be a better way to write it.

Which is correct? or more correct? Can I always trust that second one to work?

Thanks
51  Using Arduino / Programming Questions / How often to write to EEPROM on: February 20, 2013, 02:11:16 am
I will be using the EEPROM to store distance and time for a bike speedometer, and load them at startup in case of switching off. But switching off may not have a warning. These values will change just about every second, or even more at times. Is it safe/recommended to write to the EEPROM that often? Is there a finite amount of times it can be written to before failing? Should I limit it to writing only when the rider has stopped, so maybe once every few minutes? If it makes any difference I am storing two longs split up into the first 8 bytes of the EEPROM.

A second side question: If I plan to use power down sleep mode a lot, can I trust my variables to stay in tact or should I read from the EEPROM when waking from power down? I suppose if that was a problem, I would have bigger problems to worry about so I would assume that is not necessary.

Thanks
52  Using Arduino / Programming Questions / Re: Why does Power Down not work here? on: February 19, 2013, 08:00:22 pm
Ah, ok my problem first was that I didn't realize I was using "IDLE" so I wasn't getting the multimeter readings I was expecting. Then I added the serial out to double check and like you said, that doesn't work. I changed it to power down and everything it behaving now. Thanks.
53  Using Arduino / Programming Questions / Why does Power Down not work here? on: February 19, 2013, 07:14:47 pm
Code:
#include <avr/sleep.h>

void setup(){
  // disable ADC
  ADCSRA = 0; 
  pinMode(2,INPUT);
  attachInterrupt (0, gotoSleep, RISING);
  Serial.begin(9600);
  Serial.println("reset");
}

void loop(){

 
}

void gotoSleep(){
  Serial.println("gotoSleep");
  detachInterrupt (0);
  attachInterrupt (0, wake, RISING);
  set_sleep_mode (SLEEP_MODE_IDLE); 
  sleep_enable();
  sleep_cpu ();
 detachInterrupt (0);
 attachInterrupt (0, gotoSleep, RISING);
}

void wake(){
  Serial.println("wake");
  sleep_disable();
}

This simply doesn't work for me and I don't know why. After "reset", serial wont print anything. I have a multimeter hooked up to it so I know it's not going to sleep. I can get it to sleep fine if I put the sleep stuff in the setup. But if I comment out all of the sleep and interrupt lines in the gotoSleep function, it calls gotoSleep just fine when I press the button.

I must be missing something very obvious.
54  Using Arduino / Project Guidance / Re: Soft switch on: February 18, 2013, 06:28:29 pm
You may find it useful to read Nick Gammon's page on sleep mode power saving.  There are some functions that are not turned off by POWER_DOWN that you can turn off in other ways.  Ciao, Lenny
http://www.gammon.com.au/forum/?id=11497

Hey wow, disabling ADC got me down to 37uA. That helps a whole lot!
55  Using Arduino / Project Guidance / Re: Soft switch on: February 17, 2013, 11:54:59 pm
Read the datasheet on the cpu for insight on lowering the sleep current more.  You may wish to power down some internal features before going to sleep.
I'll take a look. Edit: I'm using avr/sleep.h and avr/power.h to call "SLEEP_MODE_PWR_DOWN". I thought that powered down the most stuff.

Maybe I'm missing something, but how do you get the ATmega to read an input when it doesn't have a ground connection?

It wouldn't be doing anything until the switch cause the NPN to saturate, then the arduino set the output to high, keeping it saturated when the button isn't pushed anymore.
56  Using Arduino / Project Guidance / Soft switch on: February 17, 2013, 10:54:12 pm
I've got an ATmega328 running off 3v at 8MHz. I'm hoping to get my project powering on and off from a tactile button that will also have functions during the program. I also have limited space left on my board so I'm trying to keep the number of components low. I came up with this circuit and was hoping that it, or something similar might work. I've been trying it out (not the input part yet) and found two issues. First, it takes about 3 seconds for the arduino to set the pin high and keep it on with the pin being set high in startup. Second, it seems to stop working when I go from 3.3 to <3v from the cr3032 battery.

Using the power down function only brings me down to 0.17mA which only gives me about 40 days of "standby time." I'm hoping there's some way to get my circuit to work.
57  Using Arduino / Project Guidance / Re: best way to sense someone entering a room on: February 03, 2013, 11:31:21 pm
Yes there are some issue with PIR. It's only going to tell you if someone in front of it is moving. You can't just point it at the room and count the people. PIR would be easy if you just want to know if someone is in there or not. But to count people going in you are going to need to set it up someway just as you would a trip laser or something. a PIR sensor still isn't going to tell the difference between one or two people.

So you need to figure out these things:
-Is there more than one entry to the room?
-Is it possible for more than one person to enter it at a time, or for them to be so close that conditions don't change between them.
-Do you need to know if someone is leaving? Can they leave out the same way they came? Can someone be leaving while someone else is entering?
-Is it okay to occasionally have errors due to people leaving/entering at the same time?

Basically if you can't control all of these conditions you're going to have some trouble unless you are okay with the occasional error. If you can't get people in and out one at a time per door, you can't really tell exactly whats going on. You would either need video recognition, or enough of those pads to have a high enough resolution to actually see where people are stepping.

If you can control how people enter and leave the room, or you are ok with these errors then just get two trip lasers or two sonar sensors. The two sensors are set up so that as you walk in, you pass one, then the other. If sensor 1 detects something, then sensor 2, someone has walked in. If sensor 2 then sensor 1, someone has walked out. I wouldn't do this with PIR sensors because they detect change so they will bounce around when someone walks in front, then when someone walks away. Both send the same signal, "hey something changed.... hey something changed again, maybe someone is there, maybe not." Whereas with a sonar you can see "something is 6 ft away... ok something is 1 ft away... ok something is 6ft away again" you know that someone just walked by. Plus PIR will bounce around multiple times per change anyway, they are really only any good if you just want to know if someone is around, not anything with accuracy like this.
58  Using Arduino / Project Guidance / Re: Need to build a rotating mirror like this on: February 02, 2013, 08:23:54 pm
Anyone know of places to buy this kind of thing in NYC? I'm sick of shipping stuff from China ;p
I love the optical sensor idea... have an opaque tab pass by it once per mirror rotation, yeah? Maybe I can source one from a discarded object. I believe old mouse wheels use this... what else?
newark.com? How far of a drive is it to Jersey from where you are?
59  Using Arduino / Project Guidance / Re: 12V automotive project on: February 02, 2013, 08:18:27 pm
I made a brake light for a motorcycle. In order to detect when the brakes were being pressed I used a voltage divider. But I think If I were to do it again I would use a transistor and attach the 12v to the base with a large valued resistor and have the transistor pull the arduino pin to ground. That way if there is variation in the vehicle voltage, the pin still either sees 5v or 0v. My voltage divider would go from 3-5v depending on the motorcycles voltage. Works great but I think the transistor is a better idea. I guess the voltage divider would be good if you wanted to actually see about what the cars voltage was.
60  Using Arduino / Project Guidance / Re: RGB LED Matrix spread over 400 square feet (43 square meters) on: January 29, 2013, 04:04:49 am
(40 / 0.2)^2 = 40,000 LED's * 3 channels = 120,000 channels. On it's own that's a lot of things to control, a lot of things to wire up, a lot of things to solder, a lot of things to buy. Buy you must do all of those things for each LED.

It took me hours to wire up 15 RGB LEDs in strands like Christmas lights. Each lead: cut, strip, tin, clip, align, solder, insulate, test.... 40,000 may take a lifetime.

Edit:
Whoops i misread, but that still comes out to something like 900 LEDs. Not so out there, but we are still talking about weeks or months of work just to wire them together.
Pages: 1 2 3 [4] 5 6 ... 30