The proper way to add Arduino libraries to C++ projects in Studio 7

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

I'm trying to use an Arduino library for TFT driving in a "normal" C++ project.

I've copied the files to my project and directory and added them. The library uses the Arduino SPI library, so I added it using add Arduino library.

The SPI library needed Arduino.h so I've added the directory to the compiler search path. Arduino.h in turn needs other files which are not on the search path - so this starts to get annoying.

 

Is there a more proper way to add Arduino libraries with their dependencies in a single click (or several for that matter)?

 

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

Start by creating an Arduino project - in the Arduino IDE - and then import that into AS7 ?

 

Note that what you describe is not unique to Arduino code - you will end up with the same sequence when trying to use any third-party code with dependencies ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes. Select "add Arduino library"
You click on the relevant library.
AS7 copies the source code to your project directory. Adds search path.
.
I would be far happier if AS7 could "add as link".
If that is what you want, you have to do everything by hand e.g. add search path
.
Life is much simpler in the Arduino IDE.
.
David.

Last Edited: Sat. Aug 5, 2017 - 06:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David, I can copy the TFT library to where the Arduino installation keeps all the libraries and add through the "add Arduino library" but that won't add the dependencies. I have added SPI library that way and it did not include anything else, not even adding the Arduino.h file path to the search path.

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

I will try it for myself later.
.
David.

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

I created an empty sketch:

void setup()
{
    // empty sketch
}

void loop()
{
}

Then imported this into AS7.   Which created a regular "core" library project and the actual "sketch" application project in the normal way.

 

I then "Add Arduino Library".   Selected SPI.h Adafruit_GFX.h and Adafruit_ILI9341.h from the available "avr" libraries.

And edited the empty sketch to "do something"

/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>

/*End of auto generated code by Atmel studio */

//Beginning of Auto generated function prototypes by Atmel Studio
//End of Auto generated function prototypes by Atmel Studio
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
Adafruit_ILI9341 tft(10, 9, 8);

void setup()
{
    // empty sketch
	tft.begin();
	tft.fillScreen(0xF800);   //paint it RED
}

void loop()
{
}

Built with AS7.   Uploaded to a Seeeduino via the Uno Bootloader (which I have added to my AS7 External Tools)

 

Everything worked fine.    With one caveat:   you must remove the fontconvert folder from the Adafruit_GFX source tree (because it is a Unix source code).

 

David.

Last Edited: Sat. Aug 5, 2017 - 08:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, today i posted a new topic because i found that the "Add arduino library" to a project just ends up with the error message "The given key was not present in the dictionary".

Very clear, the error message itself immediately directed me to the solution. <ROFL>

Seriously: the only way i know to develop an Arduino project with libraries is to create an empty sketch with all the required libraries in the Arduino IDE, then import this template in AS7 and start development from here.

When my project grew and i had to add another library to it, the only way to do it was to add to the Arduino IDE empty sketch the new library, import again in AS7, then move all the source files from the old AS7 solution to the new one.

Not impressing, Atmel...

To make the scenario a bit darker, i heard from users that with MPLAB X things are even worse, so they prefer struggling to survive with AS7...

Tested again today with latest Arduino IDE and latest AS7 with all the updates on a Win10 pro machine to confirm.

 

Regards,

nomadic68

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

nomadic68 wrote:
 today i posted a new topic

So why not give a link to it?

 

https://www.avrfreaks.net/forum/add-arduino-libratry-existing-studio-project-does-not-work

 

the only way i know to develop an Arduino project with libraries

apart from just staying in the Arduino IDE ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops!

Here:

 

https://www.avrfreaks.net/forum/...

 

 

Regards

Last Edited: Fri. Feb 21, 2020 - 06:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Stay here.

 

Your other thread duplication has been locked.

 

https://www.avrfreaks.net/forum/...

 

Moderator

 

Ross McKenzie ValuSoft Melbourne Australia

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

If you want a nice editor the try platformio. There’s also ArduinoPro, but i’ve not looked at it.

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

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Personally,   I build sketch code in the Arduino IDE.    After all,  this is going to be what and where the sketch will be built by the rest of the world.

 

If I want to trace the hardware,  I build for STM32 Nucleo boards.    Then debug the ELF file in Rowley CrossWorks.

 

I could build for Arduino Due and trace the hardware in AS7.0 but it involves a separate USB cable and ribbon connection for the ATMEL-ICE.

Likewise,  for Uno.

But an XMINI-mega328P with Arduino headers gives a neat one cable solution for debugging an external ELF.

 

Yes,  you can import an Arduino sketch into AS7.0 but it is a bit flaky.

And any changes you make to the (sketch) CPP or library CPP will be outside the "Arduino environment"

It becomes very messy but a Source Control System can help.

 

If you are having a specific AS7.0 problem,   ZIP up your project.   Attach the ZIP file.   Some readers might help.   (if your hardware and libraries are standard)

 

I have not used PlatformIO.     I presume that it uses the same Java tools as the reliable Arduino IDE.   But you get a better editor, ...

Likewise,  I have never set up the  Arduino IDE for an External Editor.    But this might suit you.

 

David.

Last Edited: Fri. Feb 21, 2020 - 09:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
After all,  this is going to be what and where the sketch will be built by the rest of the world.

Indeed.

 

And it will be how and where the library was intended to be used.

 

And any changes you make to the (sketch) CPP or library CPP will be outside the "Arduino environment"

I guess the intention of the AS7 import feature is when you say, "right! I'm done with the Arduino stuff now; I'm moving on to AS7"

 

ie, there is no intention of going back.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am also trying to work out adding Arduino libraries to an AS7 project.  I started with Arduino and several libs, imported that to AS7 for debug tools.  That part worked fine.  I now need to add another Arduino library.   From the now larger AS7 project, I added a zip of OneWire and another of DS1307.  Both seemed to import fine and show up in the same directory.  (C:\Users\xxxx\Documents\Arduino\libraries) Both show up as "installed" user libs in Micro Explorer.  **Both give no such file error on build...

 

Has anyone made this work consistently?   So what is the proper way to add a NEW arduino lib to an existing AS7 project??  Where exactly do others  "Add Arduino Library" to make this work??

 

TIA!

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

Go on.   Arduino user libraries are installed under user_sketch_directory/libraries.

 

AS7.0 looks under install/libraries and user_sketch_directory/libraries

 

If you want to add an Arduino library to your AS7.0 project,   install the library properly in the Arduino IDE.   i.e. with the IDE Library Manager.

 

A subsequent "Add Arduino Library" to your AS7.0 project will know where to look.   And prompt you accordingly to select the one that you want.

 

David.

Last Edited: Thu. May 6, 2021 - 09:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all

 

I have recently tested the new "Microchip Studio" (basically, a rebranding of the latest AS7) and found that now it is possible to import libraries seamlessly either in the ArduinoCore project (created when importing an Arduino sketch) or in the user project (where the .ino files end). Also, the order of importing libraries is not relevant: if you import the Ethernet library only and try to compile, you will get a "SPI.h file not found" error, because the Ethernet library requires the SPI library. At this point you have just to add it and you are good to go.

Please note that you need to select (highlight) the desired project root before import the Arduino library.

 

Hope this helps.

BR

Last Edited: Sun. May 9, 2021 - 09:28 AM