Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 539
61  Using Arduino / Sensors / Re: Problems with Ultrasonic Range Finder - Maxbotix LV-EZ1 on: April 07, 2014, 09:22:27 am
Ok, I have just discovered something. Every fourth reading, is significantly lower than the other readings. For example:

What would be causing this to happen?

Very strange result.  With multiple sensors I would worry about a sensor receiving an echo from another sensor.  Are you sure the sensitivity patterns don't overlap at all?
62  Using Arduino / Project Guidance / Re: More accelorometer Help on: April 06, 2014, 07:49:30 am
From what I understand as well the output data rate will obtain data at whatever rate I put it at, but all the ones I don't measure will essentially be discarded.

That is my understanding as well.  There is a FIFO buffer to hold on to some readings until you can red them but if you expect to not use as many readings as you are generating you should probably turn the FIFO feature off.  If you want to use every reading you can use an interrupt to tell you when  new reading is available.and use the overflow flag to let you know if your code is running too slow to process all the readings.
63  Using Arduino / Programming Questions / Re: Arduino timer disaster on: April 05, 2014, 08:41:07 am
Your sketch won't format (Tools -> Auto Format) because "Too many left parentheses."  Fixing that leads to "Too many left curly braces."  Try something like this:
Code:
const byte ledPin = 13;
boolean ledOn;
const byte buttPin = 2;

unsigned long randOnStart;
unsigned long randOnInterval;                  // Initialize a variable for the ON time
unsigned long reactionTimeStart;

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);   
  digitalWrite(ledPin, LOW);
  ledOn = false;

  // initialize the pushbutton pin as an input:
  pinMode(buttPin, INPUT);
  Serial.begin(9600);
  randOnInterval = random (1000, 10000);    // generate ON time between 1 and 10 seconds
  randOnStart = millis();

}

void loop() {
  if (ledOn) {
    // LED is on so check the button
    if (digitalRead(buttPin)) {     
      // LED on and Button pressed so turn the LED off   
      digitalWrite(ledPin, LOW);
      ledOn = false;
      // Display the time between LED On and LED Off
      unsigned long reactionTime = millis() - reactionTimeStart;
      Serial.print("Reaction time: ");
        Serial.println(reactionTime);
      // Start another cycle
      randOnInterval = random (1000, 10000);    // generate ON time between 1 and 10 seconds
      randOnStart = millis();
    }
  }
  else {// LED is off
    // Did someone press the button early?
    if (millis() - randOnStart > 500) { // Allow half a second
      Serial.println("You pressed too early!");
      // Re-start the LED On timer
      randOnStart = millis();
    }

    // Is it time to turn the LED on?
    if (millis() - randOnStart > randOnInterval) {
      digitalWrite(ledPin, HIGH);
      ledOn = true;
      reactionTimeStart = millis();
    }
  }
}
64  Using Arduino / Project Guidance / Re: More accelorometer Help on: April 05, 2014, 08:09:05 am
Looks like you set the Output Data Rate (ODR) in Register 44: "Data rate and power mode control".  I don't think the power use goes down if you don't read the data as fast as it is generated.

Looks like there are lots of power saving features if you want to save power.
65  Using Arduino / Sensors / Re: IR sensor for arduino on: April 04, 2014, 04:34:04 pm
You could use a pressure-mat switch instead of an IR break-beam switch.
66  Using Arduino / Sensors / Re: Problems with Ultrasonic Range Finder - Maxbotix LV-EZ1 on: April 03, 2014, 03:13:40 pm
I did that and I greatly increased the speed but now the readings are all messed up. For example, when looking at the distances in the serial monitor, there would be times when the inches was at 192, but there was 0 cm.
Code:
  inches = inches/AvgRange;
  int cmAway1 = inches * 2.54;
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cmAway1);
  Serial.println("cm");
It shouldn't be possible to get 192 inches and 0 cm at the same time.
67  Using Arduino / Sensors / Re: Problems with Ultrasonic Range Finder - Maxbotix LV-EZ1 on: April 03, 2014, 06:50:37 am
Because of delays you put in it takes at least 1.1 seconds for each analog input (60 * 0.01 + 500).  I would take out the delays and reduce the number of samples being averaged to 10 to see if that makes the code responsive enough.
68  Using Arduino / Installation & Troubleshooting / Re: Newbie with Mega upload problems on: April 03, 2014, 06:40:57 am
The EtherTen schematic (http://www.practicalarduino.com/freetronics/EtherTen-schematic-worksheet.pdf) shows that they are using the ATmega8u2 as the USB-to-Serial chip.  If that firmware has gotten damaged You may be able to recover by re-uploading the firmware.  See: http://arduino.cc/en/Hacking/DFUProgramming8U2
69  Using Arduino / Installation & Troubleshooting / Re: Newbie with Mega upload problems on: April 02, 2014, 06:38:43 pm
Confused - you say "what are you using for the USB-to-Serial adapter?" -  my Ethernet and Mega both come with USB sockets, and a USB lead, presumably to connect straight to my computer - have I got this wrong?

The official "Arduino Ethernet" (http://arduino.cc/en/Main/ArduinoBoardEthernet) doesn't
have a USB connector.  What board do you have?
70  Using Arduino / Programming Questions / Re: Fast PWM - Compare to OCR1A on: April 01, 2014, 03:16:29 pm
It wil be very rare for "CheckFrequency()" to do anything since it is called when frequency and oldFrequency are almost always equal.
Code:
if (frequency != oldFrequency) {    // Did frequency cahnge?
  // DO SOME STUFF
    oldFrequency = frequency;    // So we don't update unless needed
  }
  CheckFrequency();
Code:
void CheckFrequency()
{
  if (frequency == oldFrequency)  // Nothing's changed...
    return;
}
71  Using Arduino / Programming Questions / Re: Fast PWM - Compare to OCR1A on: April 01, 2014, 12:30:46 pm
It should be a problem for frequencies BELOW 2.5 kHz.  Frequencies too low without a prescale will give you a value of TOP greater than 65535, the largest number that fits in a 16-bit register.
Oops.  I got 6,400 AND 64,000 confused.  Ignore this part.

16,000,000 / 2,500 = 6,400 so that should work fine in a 16-bit counter.
16,000,000 / 5,000 = 3,200 so that should work fine in a 16-bit counter.

With a 16-bit timer you should be able to get down to 244 Hz and up to 8 MHz.

Perhaps it is time to show your code.
72  Using Arduino / Programming Questions / Re: Arduino Micro OCR1C At Pin 11 instead OCR0A on: April 01, 2014, 07:56:20 am
You said Pin 11.  That is how you get PWM on Pin 11 on that board (or any other board).  I would expect it to use OCR1C internally.
73  Using Arduino / Programming Questions / Re: Fast PWM - Compare to OCR1A on: April 01, 2014, 07:54:12 am


@John: I'm using Timer1 to drive a simple pulse using the setup code:

I get a great square wave out for 1000Hz. When I want to change the frequency via period at runtime and do the assignment of a new period into OCR1A, things work fine. However, if I raise the frequency to something above 2.5KHz, the frequency doesn't change. The calculation for period should work well past 2.5KHz.  Anything ring a bell here?

It should be a problem for frequencies BELOW 2.5 kHz.  Frequencies too low without a prescale will give you a value of TOP greater than 65535, the largest number that fits in a 16-bit register.

Calculate TOP using unsigned long values.  If TOP > 65535 set the prescale to 8 and use TOP/8.  Otherwise use a prescale of 1 and use TOP directly.  For even lower frequencies expand that to higher prescales.
74  Using Arduino / Programming Questions / Re: Fast PWM - Compare to OCR1A on: March 31, 2014, 06:51:59 am
You change frequency with a combination of pre-scale and TOP.  Depending on the mode you set the TOP value is stored in OCRxA or ICRx.  Note that the prescale value will also affect your pulse width.  If you have to change the prescale to get the full frequency range you will need to change the PWM value to get your desired pulse width.

The base clock is 16 MHz so 16 clocks per microsecond so 32 counts per pulse with a prescale of 1.  If you go to a prescale of 8 you are down to 4 counts per pulse.

50 kHz is 320 counts at a prescale of 1.  That means you have to use a 16-bit timer or a prescale.  If you use a prescale of 8 you can use an 8-bit timer and would set TOP to 40.

450 kHz is 35.555 counts at a prescale of 1.  That will work fine with an 8-bit timer. Of course you can't use 35.555 so you should use 36 (444.44 kHz) or 35 (457.143 kHz).
75  Using Arduino / Programming Questions / Re: Variable timer / constant amount of Pixels available drawing issue? on: March 31, 2014, 06:33:44 am
Adding up delays is not an accurate way of keeping time since it ignores the time taken with instructions between the delay() calls.  Use the millis() function for timing.  It gives you the number of milliseconds since the Arduino started.  To measure a time interval you create an unsigned long variable to contain the time at the start of the interval:
Code:
unsigned long StartOfTimer = millis();

Then subtract that from the current time to determine the length of the interval.
Code:
unsigned long interval = millis() - StartOfTimer;

If you want to count off seconds:
Code:
    if (millis() - StartOfTimer > 1000) {
        // A second has passed
        SecondsCounter++;
        // Display the seconds here
       StartOfTimer += 1000;
    }
Pages: 1 ... 3 4 [5] 6 7 ... 539