Show Posts
Pages: 1 ... 54 55 [56] 57 58 ... 115
826  Using Arduino / Programming Questions / Re: Why does this work in a .h but not in a .ino? on: January 06, 2013, 02:47:59 pm
Does this mean that every function prototype I have in an .ino file is worthless and always get's superseded by one created by the IDE?

Wrong! The IDE only creates prototypes for functions in the .ino which do not already have one.

Observe:
Code:
void doState1()
{
  //..some code  same with 2 and 3
}
void doState2()
{
  //..some code
}
void doState3()
{
  //..some code
}

typedef void (*S_Function)();

S_Function State_Functions[] = {
  &doState1, &doState2, &doState3};

S_Function getCallback(int _state); //create function prototype here, and the IDE wont add one at the top.
S_Function getCallback(int _state)
{
  return State_Functions[_state];
}

smiley
827  Using Arduino / Programming Questions / Re: Can someone help me figure out what this loop is doing? on: January 06, 2013, 02:44:55 pm
If the card did return 0, then you would get:

0x00 & 0x80 = 0 = false, which means the loop would be broken.
828  Using Arduino / Programming Questions / Re: Tick Tock Another Binary Clock on: January 06, 2013, 12:53:32 pm
Edit:

I have just noticed you are trying to have the clock automatically turn off the display, then turn it back on when the user presses a switch or something. In which case use method (1) or (2) of those i mentioned in the last post. If you make the external resistor something like 10k to 100k.
829  Using Arduino / Programming Questions / Re: Tick Tock Another Binary Clock on: January 06, 2013, 12:48:24 pm
Basically to trigger the uC to wake up, you have to cause an interrupt. To make a pin change interrupt occur, you need to simply toggle the logic state of the pin.
You can do that in a number of ways:
(1) add an external pullup resistor, then to wake up, simply pull the pin to ground with a switch.
(2) add an external pulldown resistor, then to wake up, simply connect the pin to +5v with a switch.
(3) If you went for a DS1307 based RTC, then you could connect its SQW output to Digital 0, and configure the DS1307 to output 1Hz. That way the microcontroller gets woken up once every second.

The third method would seem to me to be an ideal solution. You can put the arduino to sleep. Then when it is woken back up by the DS1307, you can read in the current time, output it to the clock display, then put the arduino back to sleep.
That way the arduino would sleep saving power for most of the time, but the clock would update once every second. You could probably accomplish reading in the time and updating the clock within a few milliseconds, meaning the arduino would sleep for about 99% of the time.
830  Using Arduino / LEDs and Multiplexing / Re: LED cube,shift registers and fun. on: January 06, 2013, 11:27:41 am
I think I am right in saying that there is an important omission from the example you posted.
This:
Code:
void myMethod(){
    char buffer* = malloc(256);
    for(int I=0; I<256;I++){
        buffer[l]=I;
    }
   //When the function returns, the 'buffer' memory remains allocated, but the pointer to this memory is lost.
   //As nothing now knows the address of the allocated memory, nothing can use it. This is known as a memory leak.
}
Should be:
Code:
void myMethod(){
    char buffer* = malloc(256);
    for(int I=0; I<256;I++){
        buffer[l]=I;
    }
    free(buffer); //free the memory otherwise there is a memory leak.
}
831  Using Arduino / Programming Questions / Re: Tick Tock Another Binary Clock on: January 06, 2013, 09:07:10 am
According to the datasheets, Pin change interrupts can be used to wake from sleep, which means you can use Digital Pin 0 to wake from power down and sleep modes.
Digital0 is PCINT16 (pin change interrupt source 16). Which means its interrupt can be enabled with:
Code:
 PCMSK2 = _BV(0); //set PCINT16 as enabled, others disabled
  PCICR |= _BV(2); //enable pin change interrupt source 2.

And disabled with:
Code:
 PCICR &= ~_BV(2); //disable pin change interrupt source 2.

And if needed, the corresponding interrupt routine is:
Code:
ISR(PCINT2_vect){
  //code executed on pin change.
}
832  Using Arduino / Microcontrollers / Re: Reset flags in MCUSR not mutually exclusive? on: January 04, 2013, 06:57:29 pm
As an example, this is at the start of my modified optiboot:

Code:
  ch = MCUSR;
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
  if (!(ch & (_BV(EXTRF) | _BV(PORF)))) appStart(); //Power on reset loads bootloader as well - allows bootloader even if reset pin is disabled //(1)
#else
  if (!(ch & _BV(EXTRF))) appStart(); //(2)
#endif

The normal optiboot just (2), which says that if the reset button was pressed, run the bootloader, otherwise skip the bootloader.
I added (1) which means that in the event of a power-on reset, the bootloader still runs - this is because I needed optiboot to work on an attiny with the reset pin disabled so EXTRF could never be set.
833  Using Arduino / Microcontrollers / Re: Messed up some fuses on: January 04, 2013, 02:26:36 pm
Fortunately it looks like you haven't disabled SPI or the reset pin.

You have however selected 'External Clock' as the oscillator which means you cannot at the moment use a crystal.

What you need to do is remove the crystal (carefully so you can put it back on later), and feed a clock signal into XTAL1 (Pin1 of the IC). The clock will need to be say 8MHz. It may be possible to feed the clock signal in to Pin1 without removing the crystal, so you might want to try it before removing the crystal.
I have attached a picture which shows a place where you can solder a wire on to the board to get access to pin 1.

If you have a spare arduino which can still be programmed with via USB, you can use that to provide a clock signal. Alternatively you can burn new fuse settings into the Atmega328 that is on the board to output its system clock and feed that output into the 8u2.

Once you have got a clock source into the chip, you can use ISP to correct the fuse settings. I believe the correct settings for the 8u2 are:
Low = 0xFF
High = 0xD9
Extended = 0xFF (or 0xCB if you want brown out enabled)
834  Using Arduino / Microcontrollers / Re: Messed up some fuses on: January 04, 2013, 01:08:49 pm
If ISP is not working then it means you have most likely disabled either the reset pin, or serial programming. In which case the only way to recover them is to use a high voltage programmer to burn the correct fuse settings.

Do you know what fuse values you actually set?
835  Using Arduino / Programming Questions / Re: Weird compiler error after adding yet another delay statement on: January 04, 2013, 11:04:15 am
Code size isn't the real issue, i got to 95kB in one of my projects on a mega and never ran into this problem. Something is confusing the compiler with regards to where it puts interrupt service routines.
836  Using Arduino / Programming Questions / Re: What is wrong with my code? on: January 04, 2013, 08:42:33 am
How about this? It will put a weak pullup resistor on the wire pin. That way it will not float.
Code:
void setup() {
  pinMode(wire, INPUT);
  pinMode(Led, OUTPUT);
  // set weak pullup
  digitalWrite(wire,HIGH);
}

I think on the new versions of arduino, you can just call:
Code:
  pinMode(wire, INPUT_PULLUP);
To get the pullup enabled.

It flickers because you have nothing to pull the input one way or another when there is no wire connected. If you bring your finger close to the input, you act as a capacitor. Any charge on your finger will be transferred to the input and trick the arduino into thinking there is a logic 1 or a logic 0.

One more thing:
Code:
if (digitalRead(wire) != LOW && digitalRead(wire)!= HIGH)
Will almost certainly never be true, unless you are applying signals which change from high to low in the fraction of a second between the two digital reads. Boolean by definition is either yes or no, aka high or low, there is no maybe.
837  Using Arduino / Programming Questions / Re: Weird compiler error after adding yet another delay statement on: January 04, 2013, 08:34:05 am
There is a temporary work around, but without testing I don't know if it will have any unforseen side effects - it shouldn't I don't think.

Open the directory in which the arduino program files are stored, then go to:
hardware\arduino\cores\arduino

Open 'HardwareSerial.h' and add the following lines to the VERY TOP of the file:
Code:
#ifndef HardwareSerial_h
#if defined(USART_RX_vect)
  SIGNAL(USART_RX_vect)  __attribute__ ((section (".init8")));
#elif defined(SIG_USART0_RECV)
  SIGNAL(SIG_USART0_RECV)  __attribute__ ((section (".init8")));
#elif defined(SIG_UART0_RECV)
  SIGNAL(SIG_UART0_RECV)  __attribute__ ((section (".init8")));
#elif defined(USART0_RX_vect)
  SIGNAL(USART0_RX_vect)  __attribute__ ((section (".init8")));
#elif defined(SIG_UART_RECV)
  SIGNAL(SIG_UART_RECV)  __attribute__ ((section (".init8")));
#endif
#endif
838  Using Arduino / Programming Questions / Re: Weird compiler error after adding yet another delay statement on: January 04, 2013, 08:01:24 am
Its to do with where the compiler places the hardware serial interrupt routines (ISRs) in the flash. Something causes it to put the ISRs too far away from the start of the program for the vector table (a lookup table for where the ISRs are) to call them.
(See here for full explaination: http://arduino.cc/forum/index.php/topic,140314.msg1054437.html#msg1054437 )

There is something weird going on as someone else reported a similar problem. By any chance if you enable verbose output during complilation (File->Preferences), do you get any other warnings?
839  Using Arduino / Programming Questions / Re: Totally puzzled by infinite loop on: January 04, 2013, 07:08:31 am
Code:
while (comboFile.available()) {
      if (comboFile.peek() == ':') {  // If entering a zone
        ignoreFlag = !ignoreFlag;
        if (ignoreFlag) currPosition++; // When it switches to high
        comboFile.read();
      }
      // If not in an ignore zone write the stuff
      else if (!ignoreFlag)  Serial.write(comboFile.read());
    }

Where in that bit of code does ignoreFlag get cleared? When it comes across a ':', ok, but you missed something important.

What happens if you have this:

:Hi: :Low:

It will first detect the ':' and read it to move on to the next character. 'ignoreFlag' will be clear so it will read and print 'Hi'. Then it sees a ':' and 'ignoreFlag' becomes set. Now what? It will sit there constantly peeking at the ' ' between the colons, but it will never move on. There is nothing to increment the index in the file.

Code:
    while (comboFile.available()) {
      if (comboFile.peek() == ':') {  // If entering a zone
        ignoreFlag = !ignoreFlag;
        if (ignoreFlag) {
          currPosition++; // When it switches to high
        }
        comboFile.read();
      } else if (!ignoreFlag)  {
        Serial.write(comboFile.read()); // If not in an ignore zone write the stuff
      } else {
        comboFile.read(); //work through all characters that are in the ignore region by reading them.
      }
    }

An simpler alternative would be this:
Code:
    while (comboFile.available()) {
      char in = comboFile.read(); //read in the character
      if (in == ':') {  // If entering a zone
        ignoreFlag = !ignoreFlag;
        if (ignoreFlag) {
          currPosition++; // When it switches to high
        }
      } else if (!ignoreFlag)  {
        Serial.write(in); // If not in an ignore zone write the stuff
      }
    }



One last thing. I know it is a valid syntax, but it is best to not do things like:
Code:
if() code;

and stick to the more readable
Code:
if() {
  code
}
It makes it much clearer as to what is going on.
840  Using Arduino / Microcontrollers / Re: core13: An Arduino core for the Attiny13 *testers wanted* on: January 03, 2013, 09:01:30 am
Is it possible to write the fuses from within the code on the chip? (eg: set the reset pin enabled or disabled from your sketch, say... on a spi command received)
No, you can't. The device can only be programmed when held in Reset (ISP), or with a high voltage programmer.
Furthermore, if the reset pin is disabled, then the ISP won't work as there is no way for it to hold the chip in reset.
Pages: 1 ... 54 55 [56] 57 58 ... 115