Where's the source ?

Hi,

I have been trying to find the source code for anaologwrite()

I have wasted a lot of time and just seem to be running round in circles only finding the description not the a link to the source :

This is called "language reference" why is there not link to the source code?

I also looked at the fade example code expecting to find include statements or something but there's nothing.

avr-libc does not seem to have anything to do with these "helper functions" either , so where is the real code that the IDE is hiding from the naive user who does not know how to program?

The examples are nice what to "get something to happen".

I have run the "fade" example but I do not want a PWM running at 490Hz.

The IDE would be a lot more use if I could click on "analogwrite" function name and it would open a new window displaying the code of that function.

These libs are fine for blinking LEDs but it would be of much more use if it gave an easy path to the details of what you need when you want to start doing some real world hardware control

If someone could point me at the source code for these high level functions it would be very helpful.

thx.

[EDIT]

Short answer is:

http://code.google.com/p/arduino/source/browse/

/usr/share/arduino-1.0.1

I have been trying to find the source code for anaologwrite()

Yeah, I had problems with that one too.

Tricky one, providing URLs to files on your PC.

under the arduino directory:
$(ARDUINO_DIR)/hardware/arduino/cores/arduino

analogRead is under wiring_analog.c

or here:
https://github.com/arduino/Arduino/tree/master/hardware/arduino/cores/arduino

AWOL:

I have been trying to find the source code for anaologwrite()

Yeah, I had problems with that one too.

Tricky one, providing URLs to files on your PC.

yeah , cute.

I assume that this code does not ONLY exist in my PC so it would not be impossible to find link to add to the so-called language reference.

WizenedEE:
under the arduino directory:
$(ARDUINO_DIR)/hardware/arduino/cores/arduino

analogRead is under wiring_analog.c

or here:
https://github.com/arduino/Arduino/tree/master/hardware/arduino/cores/arduino

Thanks wizened.

how silly of me not to look in a file called wiring_analog.c for code that programs a digital output.

:wink:

I'd found the header declaration in Arduino.h but was having trouble finding the actual c code.

I'm still trying to understand the structure of Arduino code. The on-line doc is not much help when it calls a sketch a program when it does not have any includes or anything. There is an implicit structure that I have not found documented. I'm sure it is , it's just well hidden, rather than being clearly stated in the "language reference".

As far as I have found in several hours trudging around the so-called language reference it does not map out an overview of the true structure of an arduino program in terms a programmer looks for.

thanks for the help.

ardnut:
I'd found the header declaration in Arduino.h but was having trouble finding the actual c code.

Can't you just use grep? Or "windows search"?

$ grep analogRead *

I had not found out where this source gets installed at that point.

That was the basic question that was the subject of this post. I don't see anywhere obviously visible that says : the source code is installed locally in ..... and a copy of the current stable release is to be found here http ....

Sure, now I know there is a locally installed copy of the source I can search it with grep.

maybe I have not woken up properly yet but...

#'Arduino.h
void analogWrite(uint8_t, int);

#wiring_analog.c
void analogWrite(uint8_t pin, int val)

:?

ardnut:
maybe I have not woken up properly yet but...

#'Arduino.h
void analogWrite(uint8_t, int);

#wiring_analog.c
void analogWrite(uint8_t pin, int val)

In C++ the names of the arguments aren't necessary in the declarations. They're also not necessary (or recommended) in the definitions if you don't want to use the passed values in the function.

Ah , thanks. So these *.c files are c++ ? Isn't it more conventional to name them *.cpp ?

In fact , since there don't seem to be any makefiles in this process I again find the overview of how all this is put together is missing.

Maybe I'm just being old fashioned but I kind of expect this sort of thing to be clearly documented when I start reading a "language reference".

I know Arduino is about making it as simple as possible to get results but that does not seem to negate the need for documentation.

In fact I always find it easier to achieve something with documentation than without it.

Is there a clear overall description of how Arduino IDE really builds an executable ?

Enable verbose mode in the IDE, and you can see it happen. All the commands used are shown.

http://arduino.cc/en/Hacking/BuildProcess

how silly of me not to look in a file called wiring_analog.c for code that programs a digital output.

Putting all the analogxxxx() functionality in the same file, with analog in the name makes sense to me.

true structure of an arduino program in terms a programmer looks for.

Can you explain this? I, like many here, have been a programmer for many, many, years, but I'm not sure what you are looking for.

I guess after a while through forums googling etc. you finally get to figure out how it all works. I just don't find it clearly documented.

A "sketch" is not a program. It does not have main() and does not have any #includes to indicate where it finds the various helper functions it uses.

Now it's fine to load and example and flash a LED. Cool. Now I want to find out how to control the hardware to do a real job.

Rather than pretending a GPIO line is an analog output, I need a PWM.

First thing I need to know is the frequency it operates at. I need to look at the full source code , not the noddy helper helper function descriptions that carefully don't tell you anything that might frighten me.

Where is main(), what is the search path for source and include files?

Assuming I need more control than just blindly calling high level helper functions, I need the big picture and source code from the top down , not sanitised "script" files which is essentially what a sketch is.

This is not a high school discovery project , I want to use the hardware.

Now the IDE offers some degree of hardware abstraction avoiding porting between different boards and also communicates with the bootloader. No need to reinvent the wheel.

Some of the high level functions will be handy and should speed up development but I will also need to dig deeper at certain points like PWM frequency. Is it suitable out of the box, if not how do I change it?

Maybe I just haven't found it.

thx

PS I now know some of this but the key question is one of documentation. I should not have to be posting forum questions and trawling google for snippets of information. Where's the doc?

I will also need to dig deeper at certain points like PWM frequency.

http://arduino.cc/playground/Code/PwmFrequency
http://arduino.cc/playground/Main/TimerPWMCheatsheet
http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Maybe I just haven't found it.

So it would seem.

This is not a high school discovery project

Really, it is. Use AVR Studio, if you don't like the way the IDE works. Head over to AVR Freaks (http://www.avrfreaks.net/). Nobody is forcing you to use the Arduino IDE.

You could look up PWM on the Arduino site and find the frequency is about 490 Hz. And then find what you can do to change that -and- the timing consequences. All that without reading a line of source.
You might find it simpler to turn a pin on and off yourself. Someone who can check the IDE source should have No Problem doing that.

Or you can do like some others; set up a PWM and use another pin to see what it's doing. Or if you have a scope then find out even quicker and easier.

If you really want to 'get serious' then get to the ATMEL site and download the docs on the MCU you're running then get the tools to do AVR assembly, join the AVR Freaks forum and get as close to the metal as you can, or mix Arduino C++ and AVR assembly -- there's a nice get-you-started page on the AVR LibC site linked to down on the lower right of the Reference (for beginners) page of the Arduino site.

ATMEL has loads of docs, never short you on docs, it does cost some but maybe that's why you get the complete serious-up professional bundle. They give you everything but talent!

ardnut:
I have been trying to find the source code for anaologwrite()

No such function.

If someone could point me at the source code for these high level functions it would be very helpful.

Hey, I had to look too. I used Crimson Editor "find in files" function. Root directory: where Arduino was installed. Search. Found.

It's not that hard.

ardnut:
This is called "language reference" why is there not link to the source code?

I also looked at the fade example code expecting to find include statements or something but there's nothing.

Here's a tip. If you want help without putting a whole lot of people offside, ask a simple question. Example:

Please tell me where to find the source for analogWrite.

That's it. Spell the function right, huh? And lay off the sledging of the way things are organized.

The people on this forum have no control over the language reference section. Nada. So being aggressive is just going to annoy the very people who might help you, and be ignored by whoever writes the reference.

dxw00d:

I will also need to dig deeper at certain points like PWM frequency.

Arduino Playground - HomePage
Arduino Playground - HomePage
http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Like I said I've found most of that now but only by trawling google and the forums and it took a long time find it.

If you strip the last element of those URLs it seems none of those articles is linked from its parent directory. Indeed Code directory itself is not linked from playground homepage.

That confirms my point that a lot of this is hit and miss , not properly documented.

Maybe I just haven't found it.

So it would seem.

It would seem what? That is there is clear centralised documentation that I have not yet found? That you post three unlinked snippets rather than one URL I had missed, seems to suggest the opposite.

This is not a high school discovery project

Really, it is. Use AVR Studio, if you don't like the way the IDE works. Head over to AVR Freaks (http://www.avrfreaks.net/). Nobody is forcing you to use the Arduino IDE.

Yeah right , the step in that logic is : of course it's documented it's open source.

Or, it's free, what more do you want?

It seems clear from the replies here that the answer is "No. There's not clear doc but after about six months you find you way around , then you become a guru like us. "

It seems a few replies are sincerely trying to be helpful but there is not short answer like I've missed key reference site.

Trawling google and the forums seems to be about all you get.

The idea of a rapid development board seems appealing and I noted a couple of advantages for what I'm doing above. That's why I've bought one and spent a lot of time looking into the feasibility of using it.

Lack of documentation does seem to be a downside.

GoForSmoke:
Or you can do like some others; set up a PWM and use another pin to see what it's doing. Or if you have a scope then find out even quicker and easier.

LOL, Yeah, like I could use a scope to work out the frequency response of an op-amp if I really wanted to. The usual way is read the doc. Most products provide this in a clear centralised place.

dxw00d:
Enable verbose mode in the IDE, and you can see it happen. All the commands used are shown.

Redirecting

Thanks, very helpful. That explains why there's no includes or anything in a sketch !

It also provides the link to the online source that I was seeking earlier and only got a smart reply to. Thanks again.
http://code.google.com/p/arduino/source/browse/

one step forward :wink: