Pages: [1]   Go Down
Author Topic: Detection of Arduino Board  (Read 1204 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am wondering if there is a constant of which board your sketch is currently running on or is there constants for the amount of total sram/eeprom along with cpu. Also, the boards firmware number might be nice to know during execution, allowing people to write more compatible code across the different boards.

Thanks for any help!
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 462
I am a amateur.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I know that my49plymouth will not respond, or even see this post, but http://arduino.cc/playground/Code/AvailableMemory lets you see how many bytes of SRAM is remaining.
Quote from: my49plymouth
I am wondering if there is a constant of which board your sketch is currently running on ... [and/or a variable for] amount of eeprom [remaining]
I would like to know that too!
P.S. This post has been unanswered for 159 days! Why do some posts get ignored?
Logged


California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3443
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

P.S. This post has been unanswered for 159 days! Why do some posts get ignored?
Because questions on forums are answered at will.

I'm not sure why age of the post matters, I don't go perusing for 6 month old threads to answer...
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 462
I am a amateur.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm not sure why age of the post matters, I don't go perusing for 6 month old threads to answer...
It doesn't! I was just saying. I was actually looking at some unanswered threads.
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote from: my49plymouth
I am wondering if there is a constant of which board your sketch is currently running on ... [and/or a variable for] amount of eeprom [remaining]
I would like to know that too!

There is no way to know the board but there is a way to determine the processor...

#if defined( __AVR_ATmega328P__ )
  // 328 stuff goes here (probably an Uno compatible board)
#elif defined( __AVR_ATtiny85__ )
  // 85 stuff goes here
#else
  //
#endif

E2END+1 is the total EEPROM space available (in bytes).  It's up to you, the programmer, to determine how much of that space is "remaining".
« Last Edit: June 05, 2012, 05:07:47 pm by Coding Badly » Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1285
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

But surely the #defines are resolved at compile time and don't tell you what your are running on? It has to be predetermined.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But surely the #defines are resolved at compile time

Yup.

Quote
and don't tell you what your are running on? It has to be predetermined.

Yup.  At compile time.
Logged

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

Also, the boards firmware number might be nice to know during execution, allowing people to write more compatible code across the different boards.
What firmware?  The code your wrote or the bootloader?  Why would the running program care what bootloader is on the board?
Logged

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

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2745
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

James,
I assume he meant what version of Arduino core code and libraries is being used.

For that, as long as the IDE is being used to build the image, you can look at the define ARDUINO.
Well unless you are unlucky enough to have revisions in the 0016 to 0018 range
in which case the ARDUINO define was messed up and stuck at 0016.

to check for pre 1.0 and post 1.0 you can use:

Code:
#if ARDUINO < 100
// pre 1.0 code here
#else
//post 1.0 code here
#endif



For the board, what is usually more important is to know the core or "variant" being using.
And what is truely sad is that (at least with post 1.0) the IDE knows both the core and the variant because it is is specified
in the boards.txt file, but neither the IDE nor the variant header files bother to set any type of define
to let the code being compiled to know about it.
So it is very difficult to tell what board/core/variant is being used. To fully qualify a board you not only have
to look at the processor type as Coding Badly pointed out but you have to potentially also look around at
some other defines as well.
This is because there are multiple boards that can use the same processor that can use different cores or different pinouts.
Examples of this are Teensy vs Leonardo
Sanguino vs BobDuino, vs Mighty 1284p.

While it is possible to be able to determine a board type/variant at compile time, it isn't as simple as just looking at processor type.
Currently it is a PITA as depending on the processor type you sometimes also have to look around for some
unique defines in that core/variant files to help figure out the variant as well.
This can be a special define that is unique (this works for Teensy) or you can peek into pin mapping defines by checking things like
pwm support on pins or analog to digital pin number mappings which works for the Sanguino, et al boards.


--- bill
Logged

Pages: [1]   Go Up
Jump to: