Show Posts
Pages: 1 ... 8 9 [10]
136  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Writing a function on: January 25, 2007, 11:27:03 am
Most C++ features seem to be supported, with the following caveats:

- I have not tried using templates yet.

- Exceptions are disabled... i.e. no "throw" or "catch" statements will work.

- I had a weird linker problem once trying to use pure virtual class methods.  It was easy to work around by replacing the pure virtual method with a do-nothing virtual method: the sketch linked successfully and the virtual methods were overridden properly at run-time.  See the following for more on this topic:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1167672075
137  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Serial comm help! on: January 24, 2007, 06:01:56 pm
First of all, I built my own Arduino board based on specs I found here on the Arduino web site.  Mine is based on RS-232 serial, not USB.  I'm not sure what the implications are for USB.  But, to answer your question for RS-232, I cannot run both HyperTerminal and the IDE at the same time, because then the IDE cannot upload new versions of code to the board.  In short, once someone opens a handle to a serial port, all other programs are locked out and cannot open it.
138  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Serial comm help! on: January 24, 2007, 03:35:16 pm
I use HyperTerminal all the time with Arduino and it works fine.  You just need to define a "connection" in HyperTerminal with the correct baud rate, plus No Parity, 8 data bits, 1 stop bit, and no hardware flow control.  Then save that as a ".ht" file from inside HyperTerminal for future use.  You may want to tweak some of the other settings, such as auto-echoing all the characters you type so that you can see what you are typing.
139  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino board & stability on: January 18, 2007, 03:51:58 pm
See here for how to reset the timer back to zero:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1167861718/4#4

Actually, now that I look at the code for delay(), I'm not sure a hang will occur after all:

Code:
void delay(unsigned long ms)
{
    unsigned long start = millis();
    
    while (millis() - start < ms)
        ;
}

For example, suppose the first call to millis(), where "start" is initialized, returns the maximum possible value right before the overflow (something like 0xffffffff).  Then the wraparound occurs, and millis() starts returning values just above 0 again.  Then (0 - 0xffffffff) == 1 (i.e. two's complement underflow occurs during the subtraction), but that is the correct result, because 1 millisecond has elapsed.  So it looks like this might work right even during a wraparound.
140  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino board & stability on: January 16, 2007, 04:16:26 pm
One thing to watch out for is that the time function millis() will overflow and wrap around every 9 hours or so.  This could cause programs to crash/misbehave.  For example, calling delay() right before the overflow occurs could possibly cause a permanent hang, in which case reset would be the only way out.
141  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: set pins with shift and pin 13 for an ext. LED on: January 03, 2007, 10:05:24 pm
Hey libhart,

Take a look at the tutorial I wrote, in the section called "A word about port registers in the Atmega8 microcontroller":

http://www.arduino.cc/playground/Code/BitMath#registers
142  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Arduino running Game of Life? on: December 24, 2006, 09:48:22 pm
Funny, I had thought of the same thing a few weeks back.  It occurred to me that there are some challenges:

- How to drive lots of LEDs independently... would require external shift register support circuitry, and probably data buffers to latch the current state of each LED while new bits were being shifted into place.

- Memory consumption:  each LED would require 2 bits of SRAM: you would need one array of bits for the current state of all LEDs, and another array for the next frame being calculated.  Given the less than 1K of SRAM you have in Atmega8, that leaves at best 500 bits per frame.  If you wanted a square array, that work work out to a grid of 22x22 LEDs, for a total of 484.

- You would need some way of editing the original image, telling the processor to start updating, pause, etc.  I guess you could start out with a serial port interface, just sending character commands to the board.  Later, you would want to add buttons for start, stop, edit, move "cursor" around and edit (cursor could be a blinking LED, indicating which pixel will be toggled).

- It would be interesting to consider tiling multiple Arduino boards together to patch together multiple 22x22 grids of LEDs.  This would require interfacing the boards so that the edges of each 22x22 grid can be accessed by another Arduino board.  You would have to synchronize each board to wait for others to be done calculating a frame before proceeding.  This would be quite a challenge!

Another possibility might be to figure out how to use external RAM chips to allow a single Arduino board to remember (and therefore control) even more LEDs.  This should be possible in theory.

Hope this helps spark some ideas!

- Don
143  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: bootloader and/in new boards on: December 29, 2006, 05:11:43 pm
I had a similar thought before, which is that the bootloader could be modified to look at another digital pin, perhaps digital pin 2.  If the pin were LOW, it could do its usual thing of looking for new firmware being uploaded.  If it were HIGH, it would immediately start executing whatever sketch was already in flash memory.  Then the hardware could be modified to have either a pushbutton or a slider switch to select between these two modes.  The bad thing is that this would tie up an entire digital pin, unless the same switch/button could be overloaded to do something useful after the program started running.  But this would be ideal if you wanted to make a permanent version of a design, especially if you (a) wanted it to reboot very quickly, or (b) it had to talk to something else via the serial port without getting confused by the bootloader.
144  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: A good use for ardunio..? on: December 29, 2006, 04:59:49 pm
I was also curious about what happens when you do weird things with the pins, so I wrote my own little program that does nothing but receive simple commands over the serial port and execute them.  Using this, I have found that yes, you can read input from a digital pin defined as output, and it actually works!  It will return the last value you wrote to it.  Writing to an input pin does something a little surprising: it enables/disables the state of an internal pull-up resistor for that pin.

So far the only seriously confusing thing I have encountered is when I use up too much SRAM (as opposed to program flash memory).  There is no compiler warning, only bizarre behavior when I try to upload and run the sketch.

Pretty much everything is straightforward C++ code, only exceptions are apparently not supported (no big deal).
145  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: max7313 more than 3 pwm on: December 26, 2006, 04:40:46 pm
You could try software PWM.  I was able to do this with two so-called tricolor LEDs (both red and green in a single package, yellow if both turned on).  This code fades colors so that one LED starts out all red and the other green, then they gradually swap colors back and forth.  Even though I'm using only 4 pins, I can see no reason you couldn't expand this to as many output pins as you have available in your design.

Warning:  I copied and mangled this code from inside a much more complex sketch.  My code had extra stuff for detecting when to quit based on an input pin changing state.  The code snippet here will keep looping forever, so no doubt you will need to do something about that!

Code:
const int    pin_LED_ga     =  7;       // phyiscal pin 13 (ga = green a : tri-color on right)
const int    pin_LED_ra     =  6;       // physical pin 12 (ra = red   a : tri-color on right)

const int    pin_LED_gb     =  5;       // phyiscal pin 11 (gb = green a : tri-color on left)
const int    pin_LED_rb     = 12;       // physical pin 12 (rb = red   a : tri-color on left)

void ColorFade()
{
    int     duty;

    while (true) {
        for (duty=0; duty<100; ++duty) {
            ColorDutyCycle (50, duty, 99-duty, 99-duty, duty);
        }

        for (; duty>=0; --duty) {
            ColorDutyCycle (50, duty, 99-duty, 99-duty, duty);
        }
    }
}

void ColorDutyCycle (
    int delay_us,
    int duty_ra, int duty_ga,
    int duty_rb, int duty_gb )
{
    for (char count=0; count < 100; ++count) {
        delayMicroseconds (delay_us);
        digitalWrite (pin_LED_ra, (count < duty_ra) ? HIGH : LOW);
        digitalWrite (pin_LED_ga, (count < duty_ga) ? HIGH : LOW);
        digitalWrite (pin_LED_rb, (count < duty_rb) ? HIGH : LOW);
        digitalWrite (pin_LED_gb, (count < duty_gb) ? HIGH : LOW);
    }
}
146  Forum 2005-2010 (read only) / Bar Sport / Re: Required reading in electronics on: January 01, 2007, 07:14:20 pm
I have started a section for electronics books in the Playground:

http://www.arduino.cc/playground/Learning/Electronics

Feel free to add other entries.
Pages: 1 ... 8 9 [10]