Tips and Tricks (Part19)

Previous tip and trick

The aim of this tip is to help you to avoid to fall in pretty confusing trap. Here is how.

Upgrading a complex library, even with minor changes, may lead to very complex debugging. This is even more true when tight timings, subtle proprietary protocols and many variables are involved. Secure Data card driver library is part of it, and I recently decided to optimize both the performances and the code size of PlainSDC  in a new version (which will be described in the next days and which will be available on request). What I usually  do in such cases  is to perform a copy of the original library by copying the original directory in a new directory with a slightly different name such as PlainSDCb. I may recall here that on Windows systems, Arduino libraries must settle in the ‘libraries’ folder under the ‘My document folder\Arduino’  folder (e.g.  ‘My Documents\Arduino\libraries\PlainSDCb’).

And then, you can work on the newly copied files (code and examples)  and you can also still flip back to the original version (without reloading your last backup) or check its content if necessary (and it is very often necessary!). For some reasons, I had a persistent bug that I could not get rid of. After many attempts, I decided to include some good ol’ Serial.prints within the library code (blah!) and I had the big surprise to get… no prints!

The reason is trivial once you know why! In fact, both the original code and the new code where still holding the same prefixes, within the files (e.g.  PlainSDC::) And in fact, Arduino is fetching any library from the ‘libraries’ folder and will silently agree to read duplicates from differently named files! In my case, the code that I was changing was not the code Arduino was compiling!

In other words, I used two books located in the same library. These books had different names but the same content, and Arduino arbitrary decided to retain the content the content of one without noticing me! This is how I explained the trick to my wife who was complaining about my delay for lunch…

There are at least two ways to easily bypass this problem:  Within the work version of the library, change the prefixes! Or, if you want to avoid to mix-up names, just compress the original folder so that you will still easily get to the files for reading their content, but Arduino will not try to get into them!

HTH

 Next tip and trick

 

 

Leave a Reply

You must be logged in to post a comment.