Arduino libruarys in plain C code

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am relatively new to the AVR range of micro controlers by many years ago used to work on 6800 & 8051 bassed systems (assembler)

 

I do not fine the Arduino environment particularly comfortable, mainly because it hides too much - even the generated hex file needs a search of /tmp to locate.

 

I much prefer the traditional aproach of a simple text editor & mkefile but 3rd party librarys most often seemed to be aimed at the Arduino environment.

 

so the simple question is can these be used outside the Arduino environment (if I hgave to Migrate to C++ so be it) without an excessive amount of effort & if so can someone point me in the right direction?

 

* Moved to the Arduino forum. Moderator *

 

 

Last Edited: Sun. Jan 17, 2016 - 11:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sure.  Turn on "verbose" compilation and watch what it does.

(better use an older IDE version; the latest obscures the build even more.)

 

Various other IDEs (including simple Makefiles) have been adapted to allow for building arduino "scripts."  It's not that big a deal.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google "libcore.a" and you'll find endless tutorials about this (because they almost all involve arrange for your C++ code to link against a pre-built libcore.a).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many thanks for the replys

 

 

Although this is probably considered basic it is some way outside my comfort zone at present

 

for now i will stick with (ab)using whichever environment most fits me needs @ the time until my familiarity increase

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well you can always switch to "plain C". So something like:

void setup() {
    pinMode(13, OUTPUT);
}

int state = 0;

void loop() {
    if (state) {
        digitalWrite(13, 1);
    }
    else {
        digitalWrite(13, 0);
    }
    state = !state;
}

becomes:

void setup(void) {
    DDRB = (1 << 5); // PB5 output
}

int state = 0;

void loop() {
    if (state) {
        PORTB |= (1 << 5); // set output high
    }
    else {
        PORTB &= ~(1 << 5); // set output low
    }
    state = !state;
}

int main(void) {
    setup();
    while(1) {
        loop();
    }
}

Quite a lot of what you do in Arduino can fairly easily be accomplished in plain C like this. (things like Serial.begin(9600) are going to take a BIT more work though!).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I already do most of my programming in C like this

using Geany as my editor and a basic make file.

 

what  I was interested in was the posibility of using Arduino librarys from within this type of setup.

 

although it looks like it is possible I an nolonger sure that the gains would be worth the pain involved in configuring everthing, especialy as i have a mix of avr  processors

(mostly tiny85 tiny2313 & mega328)

 

I think I will simply keep the arduino environment as a fallback for when i cannot locate a suitable library elsewhere.

 

in many cases I prefer to talk directly to the hardware anyway.

 

 

thanks to all anyway

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 I an nolonger sure that the gains would be worth the pain involved

For something simple like UART or ADC there's probably nothing to be gained but for something complex like Wi-Fi or Bluetooth it is worth the effort to leverage what already exists for Arduino.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson

That pretty much sumes up my opinion

 

Wifi & Bluetooth are not an issue at present. the areas of concern are  Neopixels, Touch sensors & usi-I2C

I have already found a number of alternatives to Neopixel & usi-I2c I just need to find the time to experiment

 

I am coming to the conclusion that  I am probably just being (un Justly) snobbish wrt the Arduino environment.

especially as my C knowledge on a scale of 1-10 probably only rates about 4  or 5 maximum

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just located http://hardwarefun.com/tutorials... which seems to be working (for initial examples at least)

I am going to play with this

Many thanks to all for the suggestions which have pointed me in the correct direction.

 

Last Edited: Wed. Jan 20, 2016 - 04:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IPguru wrote:
that I am probably just being (un Justly) snobbish wrt the Arduino environment

Possibly - if you are just going to use library code from others what does it matter whether it comes from Arduino or from some other 3rd party? The advantage Arduino has is that as I downloaded another copy of the IDE this morning it told me I was something like the 5.3millionth person to do this - that means any code used in Arduino probably has been WIDELY tested!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are using linux you could take a look at
http://mithatkonar.com/wiki/doku...
In the geany section you find a link to
https://bitbucket.org/mithat/avr...
it works for me .
.
Wim

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my dislike of the Arduino environment is mainly due to 2 reasons

 

1) The editor is Horrible! (setting Use external editor in preferences does not seem to do anything on my Linux system except prevent me from making changes!)

2) my main purpose in experimenting with AVR's (mostly tiny85's) is for self education so I want to understand as much as possible, studying the code of external librarys if possible, the Arduino philosophy of abstracting the bare metal does not lend itself to this approach. I may even return to assembler soon (I was programming 6800 & 8051 systems in assembler 35 years ago).

 

 

As I have said I think I am going to mix & match environments depending on my exact usage case, possibly amending this as my knowledge increases

who knows I may begin to like the Arduino IDE in time

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IPguru wrote:
he Arduino philosophy of abstracting the bare metal does not lend itself to this approach

Curious. I would say the exact opposite. I like the modular way the Arduino library codes are written and the way they all use common functions (so you only have to learn about pinMode/digitalWrite/etc. once). A lot of the Arduino library code is very easy to read and see what it is they are actually doing to the device in question. (too often people employ lots of "clever tricks" in driver code that tends to obfuscate the operation of the thing.

 

I agree that the Arduino IDE/editor could benefit from an injection of a bit of Scintilla though! (if it was as good as Notepad++ I think we'd all be happy).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(setting Use external editor in preferences does not seem to do anything on my Linux system except prevent me from making changes!)

 It does one other thing.  Each time you click "verify" or "upload", it will check for a new version of the source, and load it before doing the preprocessing and compile.

That means you can start your favorite editor by whatever means necessary, edit your code, save it, and then use the arduino IDE as a "click to compile" panel.   The arduino IDE isn't smart enough to actually START your external editor for you, but then it also doesn't have problems with starting multiple copies of your editor either (like some other SW I've used.)  I actually find it to work pretty well, and think it's a nice compromise in complexity vs usability.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I actually find it to work pretty well, and think it's a nice compromise in complexity vs usability.

+1

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel Studio 7 has the option to import a sketch file and setup the project for you(works for AVR based boards for now). You can use that as your development environment, advanced editing features, look through all the dependencies, arduino core files etc..

(Note : The download size of atmel studio is not as little as that of Arduino)

 

Steps:

Install Atmel Studio 

File Menu -> New project -> Create project from arduino sketch. (Arduino IDE should be pre installed)

 

Then follow instructions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

soundararajan wrote:

Atmel Studio 7 has the option to import a sketch file and setup the project for you(works for AVR based boards for now). You can use that as your development environment, advanced editing features, look through all the dependencies, arduino core files etc..

(Note : The download size of atmel studio is not as little as that of Arduino)

 

Steps:

Install Atmel Studio 

File Menu -> New project -> Create project from arduino sketch. (Arduino IDE should be pre installed)

 

Then follow instructions.

Wonder why my copy of AS7 does not have that option?!?

 

I went through all the possible entries on the File and Project menus last night looking for this method they mentioned to import Arduino and I have no such thing in my copy.

 

Does this only appear if you install the Visual Micro extension? (something I will not do because of the spam).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does this only appear if you install the Visual Micro extension?

 No; I get it on my never-had-AS6-or-VM W10 VM.  I think I DID have arduino installed in its standard place before I installed AS7; it could have decided during install.

(If I move ProgramFiles\Arduino to a non-standard place, it still appears, though.)  (and it has worked for me, using the AVR Blink example.)

However, it does not seem to support the Arduino Zero yet - looks like only AVR boards?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
I think I DID have arduino installed in its standard place before I installed AS7; it could have decided during install.

Ah maybe that's it. I installed AS7 before I installed Arduino 1.6.7.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I just fired up a virgin W10 VM, installed AS7 (latest) on it BEFORE installing Arduino, and it stlll gave me an "import arduino sketch" menu item...

 

Someone mentioned in the Arduino forums that you'll get the SAMD options on that import if you use the arduino.org IDE instead of the arduino.cc IDE.  That makes sense - the .cc IDE has new features to add "boards" (the "board manager", with extensive support for 3rd party additions, sort of like the AS software manager), but this ends up using an entirely new directory layout for the "core" files and libraries for all of the non-AVR boards.   The .org IDE is still using the old directory structure, which seems to be what AS understands.  (Sigh.  What an annoying place for Atmel to be!)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunatly  AS7 (or any variant)  does not seem to be available for Linux (Fedora 23)