Pages: [1] 2 3 ... 6   Go Down
Author Topic: Programming in C  (Read 4668 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, the Arduino platform introduced me to the world of digital electronics - both in terms of hardware and software.

I've got a good grip on hardware now I believe, and am currently working on a somewhat complex design for a project. However - I plan to start programming in C or C++ now as opposed to the Arduino programming language, to actually develop a 'real-world' skill I can add to my portfolio.

I believe the Arduino language is a type of C++, so - what's the recommendation? Start writing C or C++? Seems logical to start at C, before ++?

I know the AVRs can be programmed in C, is it the 'GNU' IDE/compiler or something, or C can also be written straight into Atmel Studio? ...but can they also be programmed in C++?

Does anybody know of a link to an Arduino blink sketch for example, shown right next to a C program to do exactly the same function?

Many thanks in advance
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I plan to start programming in C or C++ now as opposed to the Arduino programming language
There's no such thing as the "Arduino language."  Arduino is programmed in C++.

Functions like digitalWrite() are just that, C++ functions.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah... I alays thought it was C++ but the functions such as digitalWrite were "Arduino added" functions.

Things like Serial.begin, are they also standard C++ functions?

I suppose my question is now somewhat different, I believe the Arduino IDE allows one to omit certain parts that initialise things from a program?
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well technically there are NO standard functions in C/C++.  All functions need to be included. 

The Arduino "library" adds functions like digitalWrite and Serial.begin.

Instead of the standard libc, avr-gcc compiles in avr-libc for many of the "standard" C-type functions.

I'm not trying to understate the Arduino functions.  However, they aren't magic.  Just look at the source code included with the IDE.  (Java/hardware/arduino/cores/arduino).  You can see how functions like digitalWrite() work.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can we say Arduino is a combination of a hw platform + its own SDK ?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah... I alays thought it was C++ but the functions such as digitalWrite were "Arduino added" functions.

 There are functions that come standard with the C and C++ programming languages, there are functions that come with 'standard libraries' supplied by compiler tool chain providers, and their are functions and libraries that Arduino includes with installation of the IDE and lastly there are any functions you yourself develop. Because a new function is developed and given to you for your use doesn't make the programming language being used not standard C++. Such functions are usually written in just standard C or C++ language.

Things like Serial.begin, are they also standard C++ functions?

No that 'standard' C++ functions. They are functions from libraries specifically developed for arduino that you can use or not use as you please. These functions are written in C++ and the source code for the functions are provided to you in the IDE distribution, if you wish to read them.

I suppose my question is now somewhat different, I believe the Arduino IDE allows one to omit certain parts that initialise things from a program?

Yes, there is an arduino pre-processor that supplies main() function and an initialization function that starts up timer0 interrupts to support the millis() and micros() functions. The pre-process also writes any needed function prototypes required for any functions you wrote in your sketch. I thinks that the limit of what it adds.
Lefty

« Last Edit: November 22, 2012, 06:42:25 pm by retrolefty » Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty, you (mis)use of quote tags is terrible smiley-grin Just copy-n-paste the generated quote header over each paragraph, or use anon quote tags. Bold answers look a bit like SHOUTING to be...
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can we say Arduino is a combination of a hw platform + its own SDK ?
I think this is the most appropriate description.


Lefty, you (mis)use of quote tags is terrible smiley-grin Just copy-n-paste the generated quote header over each paragraph, or use anon quote tags. Bold answers look a bit like SHOUTING to be...
With over 12k posts, you haven't noticed that's how he responds?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I shouldn't worry - I don't feel shouted at.

In the cores > arduino folder, which is the file that includes the source code for the functions such as digitalWrite?

Just downloading Notepad++ now to make things like this a little easier.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty, you (mis)use of quote tags is terrible smiley-grin Just copy-n-paste the generated quote header over each paragraph, or use anon quote tags. Bold answers look a bit like SHOUTING to be...
With over 12k posts, you haven't noticed that's how he responds?

If something is wrong, repeating it 12k times doesn't make it right. Anyway that's the first and last time I'm going to complain about it. Tonight I just failed to keep myself from ot-posting... sorry smiley-razz
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I shouldn't worry - I don't feel shouted at.

In the cores > arduino folder, which is the file that includes the source code for the functions such as digitalWrite?

Just downloading Notepad++ now to make things like this a little easier.

Take a look at the files you find here:

arduino-1.0.2/hardware/arduino/cores/arduino

(arduino-1.0.2 is the folder where I uncompressed the archive).
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty, you (mis)use of quote tags is terrible smiley-grin Just copy-n-paste the generated quote header over each paragraph, or use anon quote tags. Bold answers look a bit like SHOUTING to be...

I consider it a style choice. Bolding is just to clearly separate the OP questions from my responses. It works much faster then copy and pasting for me. I usually limit it to postings that have many questions embedded in a single posting and often use the format you suggest for short questions. So there you go, and I'm not even shouting about it.  smiley-grin

Lefty
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, back on track...

Well technically there are NO standard functions in C/C++.  All functions need to be.

So, C++ is essentially an incredibly 'customisable' language for lack of a better expression, with functions included as either custom or standard libraries?

Instead of the standard libc, avr-gcc compiles in avr-libc for many of the "standard" C-type functions.

Please explain this statement a little more? I don't follow.
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well technically there are NO standard functions in C/C++.  All functions need to be.

So, C++ is essentially an incredibly 'customisable' language for lack of a better expression, with functions included as either custom or standard libraries?
Yes, exactly.  On many systems these "standard" libraries are known as "libc".  These include things like math functions, printf(), etc.

Instead of the standard libc, avr-gcc compiles in avr-libc for many of the "standard" C-type functions.
Please explain this statement a little more? I don't follow.
[/quote]
libc exists for PC-operating systems.  avr-libc exists for AVR processors like the ATmega328.  That's why the same math functions that work on your PC work on your Arduino.  There is a library specific for the platform (well processor).
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@lefty smiley

@op: the issue is not limited to C/C++. You always have language + standard libraries. They provide (at least) the absolute minimum to manipulate data (think str* family for C-strings), interact with the OS and the user, ecc. Java is an example where the standard libraries can be considered part of the language. C++ instead is more towards the "naked language" end of the scale.

So an Arduino board is programmed in C++, but the SDK includes a set of functions that make it very easy (compared to non-arduino specific software development environments) to perform certain common operations, like driving a digital pin, reading an analog value, communicating via a serial interface and so on.
Those functions create what is called an abstraction layer, that is code that hides the gory details of how certain subsystems work or certain hw functionality is exploited, so that you don't think anymore in terms of bit n of PORTx, but just refer to Arduino pin 1.
Logged

Pages: [1] 2 3 ... 6   Go Up
Jump to: