Show Posts
Pages: 1 2 [3] 4 5 ... 30
31  Using Arduino / Project Guidance / Re: Arduino-powered bike computer on: March 09, 2013, 02:20:38 am
I'm working on a bike computer to replace my really terrible Bell computer. I'm only doing simple speed, distance, Calorie stuff but I've managed to getting it running on a 3v coin battery and sleeping it at low enough power to not need to physically switch it off, the wheel rotating can wake it up. Unfortunately I finally wore out my graphic LCD running it at 5v during programming so now I'm waiting for replacement to finish this thing. As soon as I get it it'll be ready to go on an printed board and mounted to my bike, as wonky as it will look.

Running off a 3v coin battery probably wont work for you if need GPS. However if you could settle simply for distance then that would really simplify your project. REALLY simplify it. In fact I'd even suggest that you omit it at first simply until you have more of it worked out.

I'd also suggest using a reed switch instead of a hall effect sensor. That's what bike computers usually use. A hall effect sensor would be to tell you how far away the magnet is. But you only need to know when it is passing by. A reed switch will simply switch on as it passes by.

A bike speedometer that uses a Hall sensor and one magnet is going to be lame. Think how much you change speed in 7 feet.
I disagree, at just 10mph that's two updates per second. You wouldn't want it updating any faster, you wouldn't be able to read it.
32  Community / Bar Sport / Re: Youtube bar jokes series: on: March 06, 2013, 01:18:42 am
Wow I just sat here and watched 32 episodes of that. Thanks for throwing me in that pit of wasted time!
33  Using Arduino / Programming Questions / Re: adding up millis on: March 01, 2013, 05:42:46 pm
Code:
byte timeEarlier = 250;
byte timeNow = 5;
byte timeDifference;
void setup(){
 Serial.begin(9600);
 timeDifference = timeNow - timeEarlier;
 Serial.println(timeDifference);
}

void loop(){
 
 
}

returns 11

That's the difference, despite the fact that the byte rolled over.
34  Using Arduino / Programming Questions / Re: adding up millis on: March 01, 2013, 03:38:42 pm
I think the point is, though, that as long as they are all unsigned longs, if millis() were to rollover. Then when you subtract timeEarlier from timeNow, it will rollover backwards and still give you the difference. The only thing that would mess this up is if you tried to subtract more than 49 days, then your actual calculation would "rollover". But like I said, I'm not worried about that. I'm only worried about millis() rolling over.
35  Using Arduino / Programming Questions / Re: adding up millis on: March 01, 2013, 02:49:07 pm
If your math is all done in the form of

elapsedTime = (timeNow - timeEarlier);  // add elaspedTime to add  rideTime summary
where timeNow is the stopped time, and timeEarlier is the time you started

and all time related variable are unsigned long,
then there will not be a rollover problem.

Ah yes, I get it, that makes perfect sense... I was just over complicating it. Thanks!
36  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
37  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.
38  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.
39  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.
40  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
41  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
42  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.
43  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.
44  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!
45  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.
Pages: 1 2 [3] 4 5 ... 30