Now - finally - let's create a C program that talks to the I/O lines of the MICA.

image source: HAIIC MICA Hardware Development Guide

This is the end goal of this blog series (hang on, there's an extra one that shows a solution that uses much less memory and disk space): How to set up an interactive environment where you can write code, deploy, test and debug.

In this post, it's expected that you did the steps described in post 2 (to prepare the MICA) and post 3 (to prepare the cross-development environment on Windows).

There are only two additional steps to do:

make the GPIO dependencies (we need 3 Linux libraries and an API header file) available on Windows

make a program that talks to the I/O lines, build it and run it on the MICA.

Set Up GPIO Library and Header Files in Windows

The program will use shared libraries - the libraries we depend on are referenced but aren't linked in the executable.

At run time, Linux will take care that our program can access these libraries and can execute the functions provided by them.

But the linker needs to know these libraries, so we have to make them available on Windows at build-time.

There are two groups we have to provide:

the mica gpio library and the header file that describes its API: libmica-gpio and mica_gpio.h

All these files are installed in the Debian Stretch container during the setup done in part 2.

To get them downloaded to windows, you can use an sFTP client (such as winSCP).

For this moment, I have copied all the files to a single directory on my Windows computer.

Here are the locations of the files you have to get (for those with a version number in their name - no worries, get the one that you find. We create a symbolic link later on):

/usr/include/mica-gpio.h

/usr/lib/libmica-gpio.so

/lib/arm-linux-gnueabihf/libudev.so.1.6.5

/lib/arm-linux-gnueabihf/libusb-1.0.so.0.1.0

/usr/lib/arm-linux-gnueabihf/libhidapi-libusb.so.0.0.0

While you are on the sFTP server, you might as well get the example file we'll use in our project:

/usr/share/doc/libmica-gpio/main.c

You can copy it to the same directory for now. We'll move it into the Eclipse project later.

Once the files are moved over, we want to make symbolic links to the ones that have a version number at the end of their name.

That takes care that our code is not dependent on a specific release of the libraries.

I'm expecting that you run a Windows version that supports it ( Vista, 7, 8 and 10 - you'd know by now, because the installation of the tool chain of post 3 would have failed if your system doesn't support it).

Open a Windows command prompt as ADMINISTRATOR and navigate to the directory where you downloaded the libraries.