Show Posts
Pages: 1 ... 399 400 [401] 402 403 ... 597
6001  Using Arduino / Programming Questions / Re: teensy to arduino on: March 18, 2012, 05:44:47 pm
The Teensy 2.0 uses an ATmega32U4 processor that has a built-in USB interface.   If you have an Arduino based on that chip or on a very similar chip you should be able to port the teensy libraries fairly easily.  For example:
6002  Using Arduino / Project Guidance / Re: asynchronous inputs & loops on: March 18, 2012, 05:34:36 pm
It's not clear what you mean by "asynchronous inputs and loops".   Did you want multiple execution threads?  It's not generally done because the RAM/Stack space is so limited.

The problem you are trying to solve might be solvable with multiple state machines. is non-blocking (return -1 if no character is ready to read).
6003  Using Arduino / Programming Questions / Re: Question about the usage of F() on: March 18, 2012, 05:24:42 pm
> And I don't need the PROGMEM keyword for any of that?

The PROGMEM keyword is in the F() macro and in the Print object.

And on the function example, if I want it to be able to work with either RAM or flash, I could just use an overload one with char* and one with __FlashStringHelper?

Yes, I think that will work.
6004  Using Arduino / Microcontrollers / Re: ATTiny + PROGMEM on: March 18, 2012, 04:06:16 pm
> Is there a difference between reading from RAM and reading from Flash?

Yes.  They exist in different address spaces.  You have to use special functions to get bytes out of Flash/PROGMEM:
6005  Using Arduino / Programming Questions / Re: my first binary clock not working on: March 18, 2012, 03:48:19 pm
If for some reason the time setting buttons are reading LOW, the minutes and hours will increment about twice a second (total of 500 mSec of delays).  Make sure you have a pull-up resistor on the input pins.

  valm = digitalRead(19);    // add one minute when pressed
  if(valm== LOW) {
  valh = digitalRead(14);    // add one hour when pressed
  if(valh== LOW) {
6006  Using Arduino / Programming Questions / Re: my first binary clock not working on: March 18, 2012, 03:42:14 pm
You can simplify the display code a little more:

        // --- minutes ones

        digitalWrite( 1, (minute%10)  & 0b00000001); // 1's
        digitalWrite( 2, (minute%10)  & 0b00000010); // 2's
        digitalWrite( 3, (minute%10)  & 0b00000100); // 4's
        digitalWrite( 4, (minute%10)  & 0b00001000); // 8's

        // --- minutes tens

        digitalWrite( 5, (minute/10) & 0b00000001); // 1's
        digitalWrite( 6, (minute/10) & 0b00000010); // 2's
        digitalWrite( 7, (minute/10) & 0b00000100); // 4's

        // --- hours ones

        digitalWrite( 8, (hour%10) & 0b00000001); // 1's
        digitalWrite( 9, (hour%10) & 0b00000010)); // 2's
        digitalWrite(10, (hour%10) & 0b00000100); // 4's
        digitalWrite(11, (hour%10) & 0b00001000); // 8's

        // --- hours tens

        digitalWrite(12, (hour/10)   & 0b00000001); // 1's
        digitalWrite(13, (hour/10)   & 0b00000010); // 2's

Other suggestions to the code if you don't mind them at this stage of your project.
6007  Using Arduino / LEDs and Multiplexing / Re: Multiplexed 7-segments. Can this code be faster? on: March 18, 2012, 03:17:44 pm
To get more brightness, spend more time with the LEDs on:

const unsigned long delayWhileLit = 1;  // Increase this until you get flickering, then reduce a step

void writeMinutes(){
  PORTD = segBytes[minLeft]; // display left digit
  digitalWrite(leftMinAnode, ON);
  digitalWrite(leftMinAnode, OFF);
  PORTD = segBytes[minRight]; // display right digit
  digitalWrite(rightMinAnode, ON);
  digitalWrite(leftMinAnode, OFF);

void writeSeconds(){
  PORTD = segBytes[secLeft]; // display left digit
  digitalWrite(leftSecAnode, ON);
  digitalWrite(leftSecAnode, OFF);
  PORTD = segBytes[secRight]; // display right digit
  digitalWrite(rightSecAnode, ON);
  digitalWrite(rightSecAnode, OFF);
6008  Using Arduino / Programming Questions / Re: Stopwatch for calculating time between functions on: March 18, 2012, 03:09:17 pm
Variables that store the output of millis() should be 'unsigned long'.

If the time interval is measuring as 0 milliseconds you might want to try measuring in microseconds (micros()) instead.  The Arduino can execute about 16000 instructions per milliseconds (16 per microsecond) so it is possible a millisecond timer is too crude to detect the time.
6009  Using Arduino / Programming Questions / Re: Can't figure out why certain output pins are HIGH on: March 18, 2012, 02:26:08 pm
You can't use pins 0 and 1 for digital I/O when you are also using them for serial I/O (Serial.begin(9600)).

You can't use Pin 11 for digital I/O when you are using 11, 12, and 13 for the hardware SPI interface to your SD card.  Check the documentation for whatever hardware you have attached to see what pins they use.  That might explain Pin 6 as well.
6010  Using Arduino / Installation & Troubleshooting / Re: Power Problems? on: March 18, 2012, 02:14:03 pm
Check the power at the Vin pin and at the +5V pin.  The Vin pin should be between about 7 and 12v.  +5V should be a solid 5V.  If Vin is low there is something wrong before the regulator.  If Vin is good and 5V is low there is something wrong with the regulator or something after it.
6011  Using Arduino / LEDs and Multiplexing / Re: Blinking an LED a set number of times with respect to analog input...... on: March 18, 2012, 02:06:58 pm
void blinkRed(int nr) // number of blinks
  for (int i=0; i< nr; i++)
    digitalWrite(red1, LOW);
    digitalWrite(red1, HIGH);


void loop ()

  blinkRed((int)(PPO*10);  // flash  red
6012  Community / Bar Sport / Re: attiny84 timer 1 running fast? on: March 18, 2012, 01:55:22 pm
He said he wanted an interrupt every 1 second, not a 1 Hz output square wave.
That's the point isn't it?  - You need to remove the 2 x from your formula.

8e6 / 256 = 31250 (timer clock pulses per second)

Assuming CTC (clear counter on compare match) mode 4:

For a 1s interval interrupt you need to set OCR1A to (31250 - 1) = 31249

For a 1Hz frequency out you need to set OCR1A to (31250/2 - 1) = 15624

Oops.  You're right. 
The formula that I thought was for time interval was for output frequency when using the "Toggle OC1A on Reset".  31249 is the right value for a 1-second interval between interrupts.
6013  Using Arduino / General Electronics / Re: Help with a timed relay circuit pleaaase! on: March 18, 2012, 01:32:19 pm
Works fine for me on the UNO down to at least 250 mSec.  The worry was that if the bootloader takes too long the WDT may go off again be fore your code has a chance to turn off the WDT.  Since it works at 250 mSec it should work at any longer interval.  How often do you guarantee that your loop() runs, anyway?

In your setup() turn off WDT at the start of setup() and turn it on again at the end.  Here is my test sketch:
#include <avr/wdt.h>

unsigned long ToggleDelay;

const int LEDpin = 13;

void toggle_led()
  digitalWrite(LEDpin, !digitalRead(LEDpin));

void setup()
  wdt_disable();  // Tell the watchdog to sleep
  pinMode(LEDpin, OUTPUT);
  ToggleDelay = 1;
  wdt_enable(WDTO_250MS);  // Tell the watchdog to reset if 1/4 second goes by without a pet

void loop()
  wdt_reset();   //  Pet the watchdog
  delay(ToggleDelay);  // When this delay gets up around 1/4 second the WDT should reset the Arduino
  ToggleDelay += 5;

The LED toggles on and off with the delay increasing by 5 mSec after each toggle.  After about 25 blinks (50 toggles), when the delay has gotten over 250 mSec, the WDT detects the failure and resets the Arduino.
6014  Community / Bar Sport / Re: attiny84 timer 1 running fast? on: March 18, 2012, 09:09:27 am
@johnwasser : To get a frequency you have to toggle twice, so I think your figure is out by a factor of 2.

He said he wanted an interrupt every 1 second, not a 1 Hz output square wave.

the formulas I have seen, and even a online calculator say that 31250 with a 256 prescaller IS 1Hz, but I am willing to try suggestions as they come in

Setting OCR1A to 31249 will get you an interrupt every 2 seconds.  Are you sure the online calculators weren't written for the more common 16 MHz clock?

The formula in the datasheet for CTC (Clear Timer on Compare) mode is:

--------------------------------- == F(interrupt)
2 * prescale * (OCR1A+1)

Solve for OCR1A and you get:

--------------------------------- - 1 == OCR1A
6015  Using Arduino / Project Guidance / Re: Alarm Clock Project on: March 17, 2012, 07:47:37 pm
I was gonna use the delay function and see how that could be utilized.
You will want to use the millis() function:
void loop()
    static unsigned long startOfLastSecond = 0;  // make it static so it doesn't get reset each time loop() is called.
    unsigned long currentTime = millis();
    unsigned long millisecondsSinceStartOfLastSecond = currentTime - startOfLastSecond;

    if (millisecondsSinceStartOfLastSecond >= 1000)
        startOfLastSecond = currentTime + 1000 - millisecondsSinceStartOfLastSecond; // In case we missed some milliseconds.

    if (Seconds > 59)
        Seconds -= 60;
Pages: 1 ... 399 400 [401] 402 403 ... 597