Category Archives: Computers

PlatformIO part 2

I hope you guys enjoyed my first posting about the PlatformIO IDE. Given the complexity of the product, I thought I’d better split stuff up and give some insights on the more advanced features. In this post I’d like to give some clues away about the usage of the integrated Terminal. This is, on any given platform, a very nice thing to know about.

If you open up a project or create a new one, you can add Terminals to the user interface. I’m gonna show you some things using the “platformio” command, which is the basic thing to know about.

Via the PlatformIO menu you can add more terminals to your screen:

It will add a terminal to your editing environment on the bottom part:

This terminal works like any old terminal would on the OS layer. This basically means that if you are on Windows (which is why I’m showing this on the Mac, haha) you can’t use tab-completion. There are a couple of buttons around the edges, as you might have noticed. They can take you full screen, change the coding table and so on, it’s all very self-explanatory.

Any of the actions you can do with pointing and clicking can also be achieved with this terminal. Sometimes it’s faster, sometimes it’s not. I’ve noticed a difference on Windows and Mac as far as shortcuts go, they tend to be better on the Mac. For example Command-Shift-B builds your project, but in Windows you have to find the menu entry and click it.

Anyway, all this boils down to the use of the command “platformio”. If given without any parameters it will display a list of possible options:

There are lots of options here to use and I’ll show you a couple. Let’s start with the “lib” command. This handles anything to do with the libraries. Again, if given without a parameter (e.g. platformio lib) it will display a list of possible options:

The library option/command can have different flags. For one, the -g is good to keep in mind. It shows you the global value of the command you give. So if you want to check which libraries are installed for global usage, you’d type in “platformio lib -g list”. This will list all globally stored libraries and where they are stored:


As you can see I have no global libraries because I’m using my “old” Arduino path with existing libraries. I’ve set it up that way so I always have access to my most important libraries. The reason I’m not using the PIO directory is that I have my libraries on my Google Drive.

Anyway, we could, if we want to, install a library from the repository into the global library path. But first, we need to find the library. “platformio lib search <libraryname>” can sort that for us! We are gonna install the VirtualWire library into the global storage location, so, we find it first:

So, now we know it exists in the repository (at this point I have no idea where this repository comes from, but I suspect it’s from the Arduino Library Manager). On Windows this screen will look a bit different by the way. You can see a short description here and the ID of the library. Each library has a unique ID (really strange, I know … ). It also lists the compatibility with the platforms and framework(s).

There are two ways to install the library. You can install it by name or by ID. This comes in handy when there are libraries which have similar names (try and search for “DHT” … ). “platformio lib -g install 251” will install the library in the global storage location, so all your projects can access it. If you omit the “-g” part it will install the library in a folder called “.piolibdeps” in the current project directory. Make a mental note of this, because with this terminal you can do the same as with a regular terminal. You can cd and so on.

In my example you see I’m working on a project called “ClockLamp_v5”. So, I will install the library in the global location:

You can see it downloaded the library and added it to the global storage location. I can now use it in any project I like.

You can see it doesn’t list the library when you omit the “-g” and vice versa:

It may be a bit confusing in the beginning, but it definitely has it’s merits.

So, how does all this interact? That’s the big question. In part 1 of my tutorials I’ve showed you how to use the an environment variable to point to the Arduino library (since I’m on two platforms, the libraries will always be in sync that way). For the purpose of this tutorial I’ve created several copies of the TFT library and changed the version numbers, so we can see what happens when we put a library in a certain storage location.

This part is, by the way, all done with a default platformio.ini, nothing fancy, just a description of the used board:

First off, I’ve created/copied the libraries to (and changed their version numbers):

  1. My Arduino library directory on Google Drive (1.0.5)
  2. The general storage location (<homedir>/.platformio/lib, 1.0.2)
  3. The deps directory of the project (project/.piolibdeps, 1.0.4)
  4. The lib directory of the project (project/lib,  1.0.3)
  5. Lastly, there is a built-in version (1.0.6, most recent) somewhere…

Because I have the environment variable that overrides all cases, at compile time I will see it uses the “1.0.5” version from my Google Drive:

You’ll notice it also gives a nice tree of dependencies from other libraries. So, let’s start messing about! I removed the environment variable from my system and now it compiles to the “1.0.3” version from the lib directory!

Ok, but suppose we removed it from the lib directory and still with a default platformio.ini? Ok, let’s see what happens:

Ok, now it compiles the library from the (hidden) .piolibdeps directory. We are getting somewhere… I remove that too and re-compile:

Going to the “1.0.2” version now, or as we know it, the global storage location (as per the PIO default). We remove that too now:

And the runner-up is the built-in loction for libraries (like we know from the Arduino environment). Awesome! Now we know in which order the library locations are processed and we also know that the PLATFORMIO_LIB_EXTRA_DIRS overrules them all. With this knowledge we can do very good tests to see how libraries interact with each other. This is somewhat of an advanced feature, but nonetheless a very important one.

Of course it depends a bit on what sort of developer you are. Do you want to be bleeding edge or just make some stable stuff? PIO gives you all those possibilities. I hope this little write-up makes it a bit more clear how the libraries interact and in the mean time I’ve shown you a couple of terminal commands too!

It’s way too much to handle everything here (and I’m only just a beginner too). The PIO library system is well developed and offers a wide range of library management possibilities. The one thing I’ve mentioned in the first tutorial (to access all your Arduino libraries with the environment variable) lead to somewhat of a discussion on Twitter with PIO. I like to keep it KISS, hence, that is why I used the lib_ldf_mode = deep and the environment variable. WIth those basic settings you can access the PIO projects from all of your machines. Wether it be Linux, macOs or Windows.

But as we’ve seen here there is much more too it to setup the PIO to yor prefered method of working. Well, enjoy and see you next time with something else (I’m not sure what yet, haha, so much to explore!).

For more information you can always visit the very good documentation pages at

Using PlatformIO for your Arduino projects

Lately the default Arduino IDE has been bugging me more and more. So I decided it was time for an alternative. A couple of months ago I tried PlatformIO. It wasn’t the best back then. I think it was in it’s early stages of supporting the Arduino hardware and so on. So recently I decided to go nuts and install it again to see what has changed…

I was very surprised to see it actually made vast improvements over the last version (where I couldn’t even get a library integrated in a sketch…). My goal at this point is to have a cross-platform development solution where I don’t have to fiddle with too much libraries and such things and it needs to look fancy. Well, mission accomplished!

So, here are a few pointers for configuring the PlatforIO editor (based on Atom, b.t.w., incredibly powerful text editor) to get you started without too much of a hassle and thinking about libraries and such.

I assume you all know how to install software, so we’ll skip that. After you opened up Atom for the first time there will probably be a few updates (check the bottom right corner). If you install all the updates it will require several restarts of Atom, so don’t go updating in the middle of coding.

It may ask you to install a couple of side dishes like Clang, Python and maybe some more. You need to install those too! But every time it needs something it gives you a link to the download page, very user-friendly! Also, some are absolutely essential (like Python) and some (like Clang) are there for neat code completion and so on.

Anyway, after all updates you’ll be confronted with the start screen, it should look somewhat like this:

So, there you have it! There are a couple of key differences between the Arduino IDE and the PlatformIO IDE (actually, it’s a plugin for Atom). First of all, it’s so much more flexible in the way you setup your projects. You can have a different set of libraries for each project or global ones. This way you can easily test new versions of libraries.

Now, when you click “New Project” it has a couple of questions for you:

Now comes the really good stuff. You can choose several boards here! With this feature, you can cross compile for different platforms at once. If you are into serious Atmel programming (or ESP’s) this may come in handy. What’s more, you can specify different libraries for each board in the same project (more about that later).

So, we choose a board and a directory where to store it. The directory structure will be a bit different from what we are used to, but you’ll adapt (as the Borg say):

After you click “Process” it will download some files for the avr platform and you will see the created project on the left:

You’ll notice a couple of things, there is lib directory, a src directory and a couple files. Of course, this plugin has support for Git but I don’t know anything about that, so we’ll skip that for now ;-).

One of the nicest things about this is the “platformio.ini” file. This file stores all the settings for your project. If you click on it, it will open the file and you can see there is already something configured for you:

It’s the basic settings for configuring the avr compiler to actually know what to compile for. You can add more environments here (which would’ve been the case if we had selected more than one board), but for the purpose of this post it’s not really relevant.

Now, we all know the Arduino has a couple of default libraries on board like Wire. The PlatformIO IDE has those too, so we don’t need to worry about those. What we do need to worry about are the regular libraries we use for all our projects. What is also important to know, the PlatformIO IDE has a bad way of dealing with nested libraries (or maybe the developers of the libraries are bad, I don’t know, either way, we are gonna solve it).

There are several ways to go about this library thing:

  1. Add each library for only your current project
  2. Use the Arduino (or any other) library folder for all the projects
  3. Mix them up all together

Because I personally work on two platforms (Mac and Windows) I’ve decided to put all my Arduino libraries on my Google Drive and link them from there. The only way to achieve this is with environment variables. PlatformIO has a bunch of environment variables it listens too. You can use those to setup the whole thing as you like.

For the libraries, we only need to worry about one: PLATFORMIO_LIB_EXTRA_DIRS. This one will be pointed to the location of our libraries on, in this case, my Google Drive. In Windows it looks like this:

And on the Mac, well, it’s Linux, export etc.

After this has been done any old code with the libraries should be able to be build. So, we are gonna add a source file in the, how’d you guess, src folder. Right-click the src folder and choose New File. You can name it any way you like. If you want to retain compatibility with the Arduino IDE I’d suggest you just name it with the extension INO, like so:

Now press enter, ét voilá, a new file has been born! Now you can go about and produce your brilliant code for the thing you are trying to do. So, now we have some brilliant piece of code, something like this (mind you, D1 as an alias for pin Digital 1 doesn’t exist, so it’s just 1, A0 does exist of course):

Now you go to the platformio Menu and click “Build”. This compiles the code for you, but nothing more. You will notice in the bottom part some text will fly by, just like the Arduino IDE, with warnings and such. If you choose “Upload” it will upload it to the Board, if it’s attached to your computer. In most cases, it can decide for you on which port the Board is, but if not, don’t worry, you can change that in the platformio.ini file, like so:

Note though, that the names of the ports differ on Mac and Windows, so I guess I’m stuck on Automatic choosing, but so far it works great. If you need more libraries for this project, but just this one, you can add another line:

The lib_extra_dirs directive can be placed here too. So now it will know to look there too.

In my endeavors to make it cross platform, I ran into another library thing. If you deep link libraries (from one to the other, with #include and such) it’s possible that the compiler cannot find all the libraries it needs because the dependencies are “missing”. What it actually is, the compiler stops looking after it runs into one link. To fix this, change the platformio.ini as follows:

Unfortunately, there is no environment variable for this (lib_ldf_mode), so I think I’ll make it a habit to just add this line to whatever project I’m doing since creators of libraries often don’t care about this problem.

One more thing to know about environment variables versus the platformio.ini directives. The environment variables take precedence over the ini files!

Well, I do hope this has been informational and that you will give this a chance. It’s looking way better than the Arduino IDE and the support for the boards is also very advanced at this moment. Enjoy!

Monitoring CPU Wait Time in SCOM 2012 R2

Dear readers,

For the purpose of this article and readability I will write in English (or Engrish …). First of all, in the default Hyper-V MPE 2012 SCOM MP there are a lot of nice things and monitors. One of them, however, is missing from this bunch. This is the CPU Wait Time Per Dispatch. This counter is read from the Virtual CPU instance of the Hyper-V host. The counter itself means “how much time does it take before my vCPU can get some real CPU time”. In VMWare they call this the CPU Ready counter by the way. One of our consultants mentioned we need to monitor this thing. So, all good and well, let’s get to it!

Within SCOM I will show you two things, basically eveyone can do this. How to create a rule for measuring Performance. This will output some nice graphs and might be handy in troubleshooting or judging performance base lines. After that we’ll be making a Monitor to send out alerts if VM’s bite of more than they can chew.

First, the rule. Start by creating a new Performance Based Rule and select your destination management pack.


The target for this rule is not a default target, so don’t forget to select “View all targets” and search for the Hyper-V MPE 2012 Virtual Processor:


After that, set the counter to “CPU Wait Time Per Dispatch”. This name is exactly as it comes from the perfmon counters (really weird huh…?), so type that in. This way you can also create other counters if you’d like to do that 🙂

As a rule of thumb I set the interval to 5 minutes. You shouldn’t go to fast because you will take up too much time processing all the requests. The other Hyper-V MP rules also are set for five minute intervals in most case, hence my choice. For the target select “VP Instance” from the Arrow-ed menu. Also, type in the object manually. I’ve done this whole rule based on the “% Guest Run Time” rule (which is bullocks if you ask me) and it was in there like that. I figured I’d do that too.


Well, next and finish!

For the performance view I used the following settings. Note the “Show data related to” setting. Select your rule, et voilá! It can take some time before the stats start piling up. In my case I had to take a big lunch break of about 45 minutes…


After that, we create a Performance Based monitor. It’s a single treshold monitor, nothing too fancy. I like to use consectutive samples because that way you can tweak your monitor pretty good when all is setup. It allows for maximum flexibility when overriding.


I like my custom monitor disabled so I can tweak a bit before I turn them on, your choice!


Here I also set the interval at five minutes because I will override the monitor anyway when I enable it.


I basically set the monitor to 100.000. From what I’ve seen, a starting VM will rise up to about 80k and running VM’s between 30k ~ 50k. But you can see for yourself and see what counters work for your enviroment.


I like to see this as a warning. After all, your VM is just like a snail breaking before a corner, but it’s still working.


And finish up by making a really cool message of sorts.


So, after this, override the Monitor to whatever group you see fit. Here’s an example of a performance graph (these machines just restarted after a Host reboot):