Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Creating a new library (Read 6178 times)
Gilles Plante
Full Member
***
Offline


Posts: 156
Location: Québec, Canada
Joined: Oct 31st, 2013
Creating a new library
Jan 3rd, 2014 at 5:50pm
Print Post  
Hi all,

what would be the best way to create a new library for Arduino with Atmel Studio/Visual Micro ?

I am asking because files are stored under libraries with a certain naming and tree.

Is there a way to create and maintain the library right under ...\libraries\... or is it better first to integrate the code in in the project (.ino) file and later to create a library from the code, but then you still need to maintain it  Shocked.

Thanks

Gilles Plante
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Creating a new library
Reply #1 - Jan 3rd, 2014 at 6:38pm
Print Post  
Hi,

This is a little easier in VS but it is up to you how you work. I am not sure of the best workflow but can give some tips...

1) You can create your own libraries in documents\arduino\libraries (or where ever your main SketchBook folder is). This is the best place because the libraries folder under the Arduino Ide is lost when you upgrade Arduino.

2) The Refresh option on "Project>Add/import Arduino Library" will detect new libraries and library sources without need to re-start the ide

3) You can create more than one project in the same Atmel solution so one could be a sketch and one project could contain the library sources.

4) You are right that library folder name should match a .h in the lib sources.

5) Newer versions of Arduino support various sub folders below each library. This new spec. is still being discussed on the Arduino dev channel so I suggest you run with the older structure which is supported in both new and old Arduino versions. This structure is a single folder for each library with optional /utility sub folder.

6) It doesn't much matter to the compiler if your lib sources are local to the sketch or included in a library. I am not sure how responsive the Atmel intellisense engine is to detecting source code changes in referenced non-project source files.

7) I am sure there are other considerations but can't think of them off the top of my head  Smiley
  
Back to top
IP Logged
 
Gilles Plante
Full Member
***
Offline


Posts: 156
Location: Québec, Canada
Joined: Oct 31st, 2013
Re: Creating a new library
Reply #2 - Jan 14th, 2014 at 7:29pm
Print Post  
I found out a very easy way:

Project > Add New Sketch Item > Add New cpp Item

The provide a name and the .h and .cpp are create for you, even with some code in it. Just add an #include, and you are un business  Smiley. Later on all you need to do is to move the two files under the library ditectory and you can use your code in any project.

Gilles Plante
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Creating a new library
Reply #3 - Jan 14th, 2014 at 7:40pm
Print Post  
That's a good idea.

Tip

If you make the name of the .cpp end with a name ending with Class, then Visual Micro will also create a class and instantiate as an external object adding an init() method as a public method example.

For example:- 

Create a new cpp with the name MyButtonClass and then in the .ino sketch code type MyButton. this will give intellisense for MyButton. 

Look into the cpp and you will see MyButtonClass with MyButton being created ready to go. It's not always the way users want to work but it is a reminder of how to do some stuff.

  
Back to top
IP Logged
 
Gilles Plante
Full Member
***
Offline


Posts: 156
Location: Québec, Canada
Joined: Oct 31st, 2013
Re: Creating a new library
Reply #4 - Jan 14th, 2014 at 8:02pm
Print Post  
Yes, very neat.

I like VisualMicro quite a lot. It's the kind of tool that does (much of ) the work for you  Smiley. With some other environments, you have to do all of the work (I am working with Dynamic C, very prehistoric compared to AtmelStudio + VisualMicro  Cry).

Gilles Plante
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12187
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Creating a new library
Reply #5 - Jan 14th, 2014 at 8:05pm
Print Post  
Great to hear that thanks
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint