Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Can you use main() in a regular Arduino program? on: February 04, 2010, 12:17:47 pm
Okay, finally got the word from the horse's mouth.

This is an accident and not a feature of Arduino.

From David Mellis:
Quote:
>
> The reason it's not supported is *because* it might change. It
> happened as accidental by-product of other changes and could disappear
> in the same way.
>

This means that if you are going to use the Arduino you should only use code in the Arduino format. That is no main() function and you use setup() and loop() instead. The main function is added to your code and has an ioinit() function before calling setup() and loop(). If you use this accidental bypass then the Arduino ioinit() won't get called and the Arduino library functions might mess up in unpredictable way.

Bottom line:
1. Don't use code with the int main(void) function in it.
2. Do read the Arduino introductory materials.
3. Only use code in the Arduino Sketch format.

Smiley
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Can you use main() in a regular Arduino program? on: February 02, 2010, 11:45:23 pm
The fellow said he was using Arduino 0018, so I just tried it and it works. I posted the following:
Quote
Holy Poop! It does compile in Arduino 0018.

This is not a quibble because it doesn't compile in earlier versions and this is major news to me. I need to investigate this further, but if the Arduino has done away with their earlier way of doing things such that regular C code compiles okay, then I'm in deep doo for reasons irrelevant to this thread. I know this isn't your issue, but tomorrow I'll try to see how this uploads and behaves on my Arduino and maybe I can help you with the specific issues you mention.

BTW - I've seen your error messages before when I didn't properly sync pressing the reset button with starting AVRDude. What I do is get the AVRDude script ready to run, press the reset button on the Arduino then immediately hit the return button to run AVRDude. The Arduino board sends a pulse on the DTR line to reset the Arduino just before it calls AVRDude so that happens automatically, but since you are building your own board, you'll need to do your own reset.

Sorry, for the confusion.

Smiley

I hope somebody here knows more about this. It seems I've missed a big issue.

Smiley
3  Forum 2005-2010 (read only) / Syntax & Programs / Can you use main() in a regular Arduino program? on: February 02, 2010, 07:20:20 pm
On another forum someone says they used the following program with the Arduino IDE and that it compiled and uploaded properly:
Code:
/*
    5-10-07
    Copyright Spark Fun Electronics© 2007
    Nathan Seidle
    nathan at sparkfun.com
  
    ATmega168
  
   Example Blink
   Toggles all IO pins at 1Hz
*/

#include <avr/io.h>

//Define functions
//======================
void ioinit(void);      //Initializes IO
void delay_ms(uint16_t x); //General purpose delay
//======================

int main (void)
{
    ioinit(); //Setup IO pins and defaults

    while(1)
    {
      PORTC = 0xFF;
      PORTB = 0xFF;
      PORTD = 0xFF;
      delay_ms(500);

      PORTC = 0x00;
      PORTB = 0x00;
      PORTD = 0x00;
      delay_ms(500);
    }
  
    return(0);
}

void ioinit (void)
{
    //1 = output, 0 = input
    DDRB = 0b11111111; //All outputs
    DDRC = 0b11111111; //All outputs
    DDRD = 0b11111110; //PORTD (RX on PD0)
}

//General short delays
void delay_ms(uint16_t x)
{
  uint8_t y, z;
  for ( ; x > 0 ; x--){
    for ( y = 0 ; y < 90 ; y++){
      for ( z = 0 ; z < 6 ; z++){
        asm volatile ("nop");
      }
    }
  }
}

I responded that this won't work because it has the main() function in it and would cause the Arduino IDE to generate this error:
Quote
In function 'int main()':
error: redefinition of 'int main()"

To which the person responded:
Quote
As far as I'm aware, it only adds it the main() function if there isn't one present: e.g. it will make up for a number of mistakes only if they are present.

Am I missing something fundamental? I don't think so, but I thought I'd check here first.

Smiley
4  Forum 2005-2010 (read only) / Development / Re: Butterfly -> Arduino on: November 30, 2008, 10:12:22 pm
Nick,

Great news that you are doing this. I'll look at this in a few days. I've also been working on something similar off and on for a while, so it will help to look at what you are doing when I can get back to it. I suspect we may be duplicating some efforts, but let me check what you've done and I'll get back to you. No use both of us doing this.

And you are the guy with the dangly cigaretted on AVRFreaks aren't you?

Smiley
5  Forum 2005-2010 (read only) / Development / Re: Butterfly -> Arduino on: October 01, 2008, 12:31:25 pm
Thanks for the welcome smiley

I'm glad to see that Nuts&Volts is in New Zealand, I didn't realize that it is international. You can get a copy of these articles on my website, one month after they appear in the print edition.

Smiley





6  Forum 2005-2010 (read only) / Development / Re: Butterfly -> Arduino on: September 29, 2008, 12:06:30 pm
I wasn't sure where to post this so I put it in the Hardware Development forum: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222630663
It discusses what I'm planning on trying with the Butterfly - and I sure would like some feedback.

Smiley
7  Forum 2005-2010 (read only) / Development / Re: Butterfly -> Arduino on: September 26, 2008, 01:56:45 pm
Well, I can't commit to anything for sure, but I have taken several days to dig into Arduino/Wiring/Processing since I was well on my way to reinventing the wheel on 'novice friendly microcontroller engineering' with some recent work that I've been doing.

It looks like to me that the folks who have generated all this have a keen insight into the things novices want to do and have come up with ways around the many traps that prevent the novice from doing those things.

I have read several philosophical statements by the originators that make me want to sigh, 'Home at last!'. Especially after arguing with some of the buggers on AVRFreaks who think you should be able to read the data book, memorize the AVR assembly language, and program in C on a PC before even touching the microcontroller.

I've had folks there really bash ideas that I've put forward, that are very similar to the sorts of stuff that the Wiring/Arduino folks are doing so well. I think a bright and interested person with no technical background can be blinking LEDs and reading switches in a couple of hours, and be downright dangerous in a couple of days. And have fun learning this stuff.

It feels great to see a community that validates your personal prejudices. smiley

Anyway, I'm reading through some stuff and trying to see if I can bend the pins_arduino.c file into something that will work for the Butterfly and still be compatible with the Arduino philosophy.

I want to get a much better background on all this before talking too much more.

Smiley
8  Forum 2005-2010 (read only) / Development / Re: Butterfly -> Arduino on: September 25, 2008, 02:59:58 pm
Let's see if it will take it now:
[TUT] [HARD] Butterfly Alternate Pin Uses
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=45064

Smiley
9  Forum 2005-2010 (read only) / Development / Re: Butterfly -> Arduino on: September 25, 2008, 02:58:54 pm
I'm a bit late coming to the party, but I thought I'd start by saying that the statement about limits on Butterfly pins isn't exactly correct. You can see what I've got to say about this in detail at:

[TUT] [HARD] Butterfly Alternate Pin Uses

In brief, the LCD shared pins will only have a problem is the output is DC and for an extended period of time. I use these pins to run a variety of DIP switch and LED experiments and while the LCD elements do dance, they don't seem to degrade. You can also get access to some of the JTAG pins for ADC.

I think the Butterfly would be an excellent platform for the Arduino philosophy and will be looking deeper into this myself.

[edit]Oh, bother, this is my first post so I can't add an URL so I'll put that in the next post[/edit]

Smiley
10  Forum 2005-2010 (read only) / Development / Re: Arduino-izing the AVR Butterfly on: January 14, 2009, 12:16:11 pm
I copied stuff yesterday and now I need to set up a study platform to see how everything is working. I also want to take a hard look at Google Code and see if it is something I want to use. I've got other commitments so this will take a few days.
11  Forum 2005-2010 (read only) / Development / Re: Arduino-izing the AVR Butterfly on: January 13, 2009, 02:45:20 pm
For some reason that I can't fathom, I thought I'd get a notification when this thread got posts. This may be one of the stupidest things I've done lately because I thought that this thread had died back in November! Okay, now I'll check the notify box and see what happens.

I am going to carefully read all the posts I've missed then try out all the code thats been done so far.

I'm really tickled to see that this work is being done and let me apologize for the brainfart that caused me to ignore it.

Smiley
12  Forum 2005-2010 (read only) / Development / Re: Arduino-izing the AVR Butterfly on: October 01, 2008, 12:23:40 pm
I'm still tinkering under the hood of Arduino and at this point I have a pile of blackened oily parts laying about the garage floor and I'm hoping I can remember what goes where when I reassemble the thing. I'll probably drill all the way down into Processing before I allow that I understand the underlying infrastructure enough to trust that I know what I'm doing, so this may take a while. A lot of what I am seeing looks simple enough, but there are still some WTFs that I have to figure out before I feel confident.

I'm not sure about the libraries yet. I, of course, intend to use what is already available, but I think I'll have to build my own for the Butterfly LCD since it is a weirdly custom job and probably something for the joystick, the piezo speaker, and the voltage, temperature, and light sensors.

Smiley

13  Forum 2005-2010 (read only) / Development / Arduino-izing the AVR Butterfly on: September 28, 2008, 02:37:43 pm
[size=12]Arduino-izing the AVR Butterfly[/size]

Forgive me for converting Arduino into a verb, but I think this is actually acknowledging an existing fact: Arduino has evolved into an action rather than a thing.

It seems to me that Arduino started out applying the Wiring IDE, libraries and simplification of C syntax to a specific hardware platform with 14 Digital I/O and 6 Analog I/O pins. There seems to be a movement to retain the Arduino-ness of a device while moving to different pin numbers, such as talk of an ATmega644 or Xmega Arduino.

Personally, I think that this transition has the potential of either destroying the core value of the Arduino brand, or cementing is as the best way to get started with physical computing. I hope to be able to participate in this process by porting everything Arduino to the AVR Butterfly platform. But, I am very new with the Arduino, so I will need guidance.

[size=12]What you lose by using an AVR Butterfly[/size]
 Most of the available Butterfly pins are multipurpose so if you want to use them one way, you lose the ability to use them another way (see Butterfly Alternate Pin Use in the download menu of www.smileymicros.com).

For instance, the digital I/O pins on Port D which conform to Arduino pins 0 to 7 are available on the Butterfly for general purpose I/O on a 10 pin dual row pad (8 signal, 1 Vcc, 1 Gnd), but these lines are also used for LCD pins 9,11-16,18 so if you use them for digital I/O you will see the pin state reflected in those LCD elements. This probably won't hurt anything since LCDs use very little current, they won't affect the I/O for the alternate use. There is some concern that the LCD may be damaged if you keep a DC voltage on them for too long, but in my experience (and I have a lot with these things) I have yet to see any damage occur. Then again, I've never plugged one of these pins into a wall socket, something I'm sure some newbie will try.

Also, in order to get 14 digital I/O pins, it will be necessary to re-map Arduino pins 12 and 13 to Port E where we have pins 4,5,6 available.

Finally, we lose 2 of the 6 Analog pins.

[size=12]What we gain by using the AVR Butterfly[/size]
We gain three Analog pins that are connected to sensors: a resister divider for measuring voltage, a NTC resistor for measuring temperature, and a light dependent resistor for measuring light. The latter can be left off the board and the pad can be used to replace one of the two analog pins we lost above.

We gain the 5-way joystick button and a piezo speaker (both at the expense of re-mapping pins form Port B to Port E).

We gain the LCD with the caveat that we can only use it if we are willing to sacrifice 8 of the 15 digital I/O pins in order to be able to use the LCD.

We gain a real-time-clock since we have a 32.768 kHz crystal that is used for calibrating the internal oscillator and can be used for accurate counting of seconds.
[size=12]
What needs to be done.[/size]

A Butterfly-Arduino library should be written to allow Arduino-style use of the LCD, joystick, speaker, sensors, and real-time-clock.

Investigate the clock speed to conform to Arduino. I'm not sure how easy it is to adjust Arduiono libraries for clock speeds other than 16 MHz, nor do I know off the top of my head how to adjust the Butterfly to run at 16 MHz which at first glance I think should be doable, but I'll have to dig a bit to see how.[edit]The ATmega169 in the Butterfly can be calibrated to 8 MHz, so I'll need to figure out how to make the Arduino libraries work at lower clock speeds.[/edit]

If it is possible to Arduino-ize the Butterfly, then I need to learn more about how to get this chimera approved by the owners of the Arduino imprimatur. I would like early information on this process since I was already well on my way to creating something similar and if what I am doing is not actually Arduino-able then I should get back on that track and not waste anymore time here.

Oh, and I promise that even though my last name is Pardue, I will not to call this thing Parduino.

So, what do you folks think?

Smiley



14  Forum 2005-2010 (read only) / News / Re: Comparison of Arduino Starter kits on: March 28, 2010, 03:07:10 pm
An Arduino Projects Kit (and The book: An Arduino Workshop) is available from www.smileymicros.com and Nut&Volts
15  Forum 2005-2010 (read only) / News / Re: New book and projects kit: An Arduino Workshop on: September 29, 2010, 02:30:39 pm
Sorry about the delay getting back on this. I thought I had set this thread to notify me when it got a post, but I didn't.

I just realized that the source isn't available in one place. Most of the code in the book was posted along with the Nuts&Volts Smiley's Workshop article series and I intended to put it all in one place, but haven't done so to date. Since the code uses the Arduino libraries, it tends to be fairly short and easy to input, so I don't think its abscense should be a problem, but I'll make a TODO to get it all together in one place ASAP.

Thanks for the interest,
Smiley smiley
Pages: [1] 2 3