Arduino Libraries Tutorial - Quick guide
Nick Velasquez
Cofounder at DeepSea Developments | Maker | Passionate about product development
Arduino is a free hardware and firmware platform, it is offered as a development platform for hobbyists and professionals that has been positioning itself in recent years as a general reference for creating electronic projects quickly and easily. But you don't have to be an electronic engineer to use it, its applications range from educational to industrial environments, and today it is widely used in IoT. Based on Wiring, a Colombian project born in 2003, the project has been incredibly useful for almost anyone to build an idea or test a concept quickly and economically, with a wide range of options for sizes, shapes, capacities, and functionalities according to the needs of those who want to experiment with it.
But how has Arduino achieved such fame? Why do both an electronic engineer and an inexperienced maker turn to Arduino? The answer is in their libraries.
Arduino, like Wiring, was born as a simple and quick way to create a project that required a micro-controller but without the arduous work of learning to use it, or at least reducing the time necessary to have a functional prototype since it offered a language simple, direct and very high level to do almost anything. It doesn't even matter which micro-controller reference you use, if it has Arduino compatibility it will be programmed the same and the system will take care of configuring the specific board while you focus on the functionality.
But although the programming language is easy to use, there were still challenges to be solved such as the integration of peripherals, sensors, chips, drivers, or communication with other devices; It was always necessary to resort to the data sheets and manuals of each manufacturer to discover how you could add it to your project. And here everything got complicated because you would surely need to understand many complex and boring concepts just to have a “hello world of a sensor”.
In this lack of libraries and drivers, Arduino found out the community needed a large repository of examples and libraries for those additional components and accessories. The best way to do this was by providing “plug n’ play” libraries ready to be used with a simple instruction, no configurations, strange protocols, or handling of unknown registers (and yet the libraries offer options for advanced users).
Just like that, a developer can add a library of a colored LED and only indicate what color he wants to display, or the driver of an encoder and directly obtain the speed or position value of a motor. With this, you achieve a functional prototype in a fraction of the original time.
But let's get into the matter, how can I use an Arduino library?
The Arduino library manager is a compilation of countless libraries that the community has accumulated over the years, and each one usually has regular updates and improvements. You simply have to write the reference or the name of the one you need in the search field and that's it.
2. Choose the library you want to use:
In this example, we are looking for a library to use the Hx711 weight sensor. Several options appear, we will choose the first one and click on Install.
3. Install the library:
领英推荐
A black box will appear and show information regarding the correct installation of the library you chose, also displaying the imported version.
4. Invoke the library:
Each library has its name and sometimes it differs slightly, for example here it is not simply called “hx711” but rather “HX711_ADC”, it is always advisable to search for the library on Google to obtain more information.
You may wonder why two options are shown to call the function, you must choose one and here it does not matter if you use the “<>” symbols or simply the double quotes, however, there is a slight difference between the two.
5. Using the library:
The use of the library depends of course on the library itself, each one offers different functions or function names so you will have to refer to the documentation for each one to know how to use it. It is advisable to also look for examples in addition to the documentation itself. That will help resolve many doubts.
In the case of the HX711, I only want to take the weight measurement, skipping the calibration step.
As you can see, the program is very reduced, we simply create the LoadCell object and initialize it.
The start() function waits a while to start the sensor measurements and then in the main loop we wait for a sensor update to be available, or in other words, for a measurement to be ready.
Finally, we read the value through getData and send it to the computer with Serial.println.
I hope you enjoyed this Arduino libraries tutorial. If you follow the recommendations given here, I’m sure you will get amazing results with your projects.
Keep making great stuff!
We Design & Build Your Hardware (USA, Mexico, & China)
11 个月This is great.
Edtech lead designer | Empowering everyone to learn robotics, design thinking and 3d printing
11 个月Right on point that libraries really build a reputation for Arduino and still do it nowadays, even against faster and simple programming language like in micropython (which now they started implementing too) but now is overflowed with libraries that have similar names, some don't even work are not even tested properly or curated, it is really overwhelming and confusing to find the right library for the application and for beginners this is even more complicated.