Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Two Dimensional Arrays.... on: November 09, 2009, 11:41:46 pm
How do you access the data in an array like this?  Is it like:
my2dArray[1][1] is 3
my2dArray[0][2] is 3
my2dArray[1][2] is 4?
I'm assuming both the columns and rows are zero-indexed, but I don't know about the bracket setup.
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Bike Speedometer on: November 09, 2009, 08:58:23 pm
Quote
From time[0] to time[4] there is 4 revolutions not 5.

Thanks, this fixed it!  At least within reasonable bounds (.05 mph)
3  Forum 2005-2010 (read only) / Syntax & Programs / Bike Speedometer on: November 09, 2009, 11:52:46 am
I am testing code for a bike speedometer (using a reed switch and magnet on the wheel).  The problem is, the code returns a speed that is always higher than the actual speed.  Right now I have it set up with a button acting as the reed switch, and with an estimate of an 80in wheel circumference.  I calculated that the speed at one revolution per second should be 4.56 mph:
80 inches / 63360 inches = .0012626 miles, the circumference in miles
1 second / 3600 seconds = .000277 hours, the time for one revolution
.0012626 miles / .000277 hours = 4.558 mph, the speed at 1 rps
I have modified the code to automatically act as if the wheel is turning at one revolution per second, and it returns 5.6mph, the same result as when I simply press the button once per second.  I have noticed that when the revolutions per second are doubled, so is the difference between the theoretical speed and the speed returned by the code.
Here's the code, both the original and the code modified for 1 rps:
Code:
const int inputPin = 8;
unsigned long time[5] = {
  0, 0, 0, 0, 0};
int lastButtonState = LOW;
float curSpeed = 0;

void setup() {
  pinMode(inputPin, INPUT);
  Serial.begin(19200);
}

void loop(){
    int reading = digitalRead(inputPin);
    if (reading != lastButtonState) {
      if (reading == HIGH) {
        unsigned long curTime = millis();
        for(int i=4; i>0; i--) {
          time[i] = time[(i-1)];
        }
        time[0] = curTime;
        curSpeed = getSpeed();
        Serial.println(curSpeed);
      }
      lastButtonState = reading;
    }
}

float getSpeed() {
  float avgSpeed;
  avgSpeed = (time[0] - time[4]); //Difference in time b/w first and fifth rev.
  avgSpeed = (avgSpeed / 3600000); //Convert to hours
  //Divide circumference in miles by hours, gives mph (80 inches per rev. times 5 revs, then converted to miles)
  avgSpeed = (.006313131313131313131313 / avgSpeed);
  //This line was for debugging, it takes away the need to convert to hours
  //avgSpeed = (22727.27273 / avgSpeed);
  return avgSpeed;
}
Modified:
Code:
const int inputPin = 8;
unsigned long time[5] = {
  0, 0, 0, 0, 0};
int lastButtonState = LOW;
float curSpeed = 0;

void setup() {
  pinMode(inputPin, INPUT);
  Serial.begin(19200);
}

void loop(){
  while(true) {
    delay(1000);
    int reading = HIGH;
    //int reading = digitalRead(inputPin);
    //unsigned long curTime = millis();
    if (reading != lastButtonState) {
      if (reading == HIGH) {
        unsigned long curTime = millis();
        for(int i=4; i>0; i--) {
          time[i] = time[(i-1)];
        }
        time[0] = curTime;
        curSpeed = getSpeed();
        Serial.println(curSpeed);
      }
      //lastButtonState = reading;
      reading = LOW;
    }
  }
}

float getSpeed() {
  float avgSpeed;
  avgSpeed = (time[0] - time[4]); //Difference in time b/w first and fifth rev.
  avgSpeed = (avgSpeed / 3600000); //Convert to hours
  //Divide circumference in miles by hours, gives mph (80 inches per rev. times 5 revs, then converted to miles)
  avgSpeed = (.006313131313131313131313 / avgSpeed);
  //This line was for debugging, it takes away the need to convert to hours
  //avgSpeed = (22727.27273 / avgSpeed);
  return avgSpeed;
}
What is the cause of this difference between theoretical speed and the speed returned by the code?
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Removing Serial.println() causes errors on: July 15, 2009, 07:24:19 am
Yeah, I found map after posting this.  They were float because integers/longs wouldn't work properly for some reason (you can tell I'm new to this).  Anyways, I changed the setup to add in the Calibration example and used map for the interval, and now it works.  Thanks for the reply
5  Forum 2005-2010 (read only) / Syntax & Programs / Removing Serial.println() causes errors on: July 14, 2009, 06:58:11 pm
For my second attempt with Arduino (Blink being the first), I tried combining the AnalogInput and BlinkWithoutDelay examples to make the blink speed controlled by a potentiometer.  I got it working, and I had a Serial.println(interval); in there for debugging.  Once I took it out, the blinking would start at the correct interval, then would quickly speed up and go constant-on (or a very small interval).  With the attached code, can anybody help me?  Thanks!
Quote
#define potPin 2
#define ledPin 13
float val = 0;
float interval = 0;
long previousMillis = 0;
int value = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //280-630 : Approxamate range of my pot
  val = analogRead(potPin);
  interval = long((((val)-270)/360)*1000);  //Change the val to an interval, approx 0-1000
  Serial.println(interval);  //The debug line that, when removed, causes error
  if (millis() - previousMillis > interval) {
    previousMillis = millis();

    if (value == LOW)
      value = HIGH;
    else
      value = LOW;

    digitalWrite(ledPin, value);
  }
}
6  Forum 2005-2010 (read only) / Interfacing / Re: Where to buy 3-4 digit 7-segment display? on: November 12, 2009, 04:36:31 pm
I think I'll just go with a 10uF and change it if I have problems.  Thanks
7  Forum 2005-2010 (read only) / Interfacing / Re: Where to buy 3-4 digit 7-segment display? on: November 11, 2009, 07:00:29 pm
I'm confused by what looks like two capacitors in this schematic:
http://www.arduino.cc/playground/Main/MAX72XXHardware#Wiring
I just realized that 100nF is .1uF, so that makes sense.  What about the 10uF one?  Wouldn't these two in parallel essentially be a 10.1uF cap?
8  Forum 2005-2010 (read only) / Interfacing / Re: Where to buy 3-4 digit 7-segment display? on: November 11, 2009, 06:04:27 pm
I think I understand everything except the capacitors in the MAX7219 schematic.  Are they 10uF and 100nF?
9  Forum 2005-2010 (read only) / Interfacing / Re: Where to buy 3-4 digit 7-segment display? on: November 11, 2009, 05:09:48 pm
Bump, any help?
10  Forum 2005-2010 (read only) / Interfacing / Re: Where to buy 3-4 digit 7-segment display? on: November 10, 2009, 09:27:42 pm
I thought about it, and it's stupid to buy things pre-assembled when I can assemble them...
So I think I need a cheap source for the driver (MAX72XX right?) and help setting up the circuit to make it work.  I can do surface-mount or through-hole soldering and I have perf circuit board.  How is one of these chips set up?
11  Forum 2005-2010 (read only) / Interfacing / Where to buy 3-4 digit 7-segment display? on: November 10, 2009, 08:43:06 pm
Hey,
I'm working on a project that I would like to have 3 or 4 digits of 7 segment displays.  I currently have one digit set up using 8 pins, but that obviously won't work for 3 or 4 digits.  I read about the libraries to control MAX72xx drivers, but where do I get this?  Ideally it would be all assembled and I would just have to connect the four (right?) pins and use one of the libraries from this website.
Thanks
12  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Does ATMega 328 require 16mHz oscillator? on: November 21, 2009, 10:08:25 am
Ok, thanks for the link.  I didn't know about the 22pF caps for the crystal.  I think I read somewhere that the serial rx pin should be pulled down (or was it up?) to avoid the floating pin overwriting the program, is that right?
13  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Does ATMega 328 require 16mHz oscillator? on: November 21, 2009, 12:15:35 am
Yes, I forgot to capitalize the M.  The point was, is an oscillator required.  Thanks for your answer, this one will work correct?
http://www.sparkfun.com/commerce/product_info.php?products_id=536
14  Forum 2005-2010 (read only) / Frequently-Asked Questions / Does ATMega 328 require 16mHz oscillator? on: November 20, 2009, 09:17:31 am
If I want to take the ATMega out of the Arduino and use it seperately, do I need to include the 16mHz oscillator?  The only precision I need is the millis() method for recording the time a sensor was triggered.
Pages: [1]