Debugging a realtime program is very difficult because generally you need to see it working at speed to see what is happening and pausing it often doesn't give you the information you need. However Eclipse has a good debugging option and it works perfectly well with the Edison.
You can insert a breakpoint in the program simply by double clicking on the left margin next to an instruction.
What is a breakpoint?
It is a location in your program where, when run in debug mode, the program will a pause for you to examine the values stored in variables, etc.
For example to set a breakpoint on the line mraa_gpio_write(pin,0) you simply double-click in the margin and a round dot appears signifying a breakpoint:
Now to see the breakpoint in action you have to click the Debug icon, use the command Run,Debug or press F11.
If you do this the layout of your workspace changes to show you additional debug windows.
The program runs but pauses when it reaches the line with the breakpoint - in fact it stops before your breakpoint because it automatically breaks on the first line.
To resume the program simply click the resume icon or use the command Run,Resume or press F8. This will allow the program to run to the first manually set breakpoint:
If you look at the variables window you will see that the pin variable is listed and it has a value shown in hexadecimal.
In a more complex program you can see all of the values of all of the variables and check that they are what you expected.
In the case of an internal value for an mraa_gpio_conext we can see that the pin value isn't null and hence the mraa_gpio_init(13) worked.
You can explore the Run menu for all of the different ways you can resume and single-step through your program. They are all fairly obvious and you will soon be using the shortcuts to move through your program checking, what is happening at each step.
To return from the debug workspace to the standard programming workspace simply use the command:
Window, Open Perspective, C/C++
You can add and remove windows to customize a perspective to create a working environment that fits in with what you do most often.
C is the most direct and efficient way of working with the Edison's hardware - it isn't a difficult programming language and well worth learning.
Download and install Intel System Studio IoT Edition, the customized version of the Eclipse IDE provided for the Edison, which is a full function IDE complete with smart editor and debug facilities.
When you create a new project you have to create a connection to the Edison as a remote system - it is worth checking that you can connect via a terminal.
C programs, and programs in most other languages make use of the mraa library and it is worth making sure it is up-to-date.
The Run,Configuration lets you specify the remote system to download and run the program on among other things. If you can't get your program to run check that the remote system corresponding to your Edison is selected.
If you forget to stop your program before you start running it again use a terminal to run the ps command and then kill the process that corresponds to your program.
You can debug your program simply by using the Run,Debug command.
Set breakpoints and use the variables window to confirm that what you think is happening is really happening.
Now that you have Eclipse set up and written the equivalent of "Hello World" for the IoT you are ready to find out more about mraa and the functions that it offers to control the GPIO. In the next chapter we look at this and the tricky problem of getting accurate timings down in the region of microseconds.
The starting point for finding out about all Intel's Internet of Things resources, including Edison, is the Intel IoT Developer Zone.
Now On Sale!
You can now buy a print edition of Exploring Intel Edison.
Meet Edison In this chapter we consider the Edison's pros and cons and get an overview of its structure and the ways in which you can make use of it. If you have ever wondered if you need an Edison or an Arduino or even a Raspberry Pi then this is the place to start.
First Contact When you are prototyping with the Edison you are going to need to use one of the two main breakout boards - the Arduino or the mini. This chapter explains how to set up the Edison for both configurations.
Mraa GPIO Using the mraa library is the direct way to work with the GPIO lines and you have to master it. Output is easy but you do need to be aware of how long everything takes. Input is also easy but using it can be more difficult. You can use polling or the Edison interrupt system which might not work exactly as you would expect.
Fast Memory Mapped I/O There is a faster way to work with GPIO lines - memory mapped I/O. Using this it is possible to generate pulses as short at 0.25 microsecond and read pulse widths of 5 microseconds. However getting things right can be tricky. We look at how to generate fast accurate pulses of a given width and how to measure pulse widths.
Near Realtime Linux You need to be aware how running your programs under a non-realtime operating system like Yocto Linux effects timings and how accurately you can create pulse trains and react to the outside world. In this chapter we look the realtime facilities in every version of Linux.
I2C - Measuring Temperature After looking at the theory of using I2C here is a complete case study using the SparkFun HTU21D hardware and software.
Life At 1.8V How to convert a 1.8V input or output to work with 5V or 3.3V including how to deal with bidirectional pull-up buses.
Using the DHT11/22 Temperature Humidity Sensor at 1.8V In this chapter we make use of all of the ideas introduced in earlier chapters to create a raw interface with the low cost DHT11/22 temperature and humidity sensor. It is an exercise in interfacing two logic families and implementing a protocol directly in C.
The DS18B20 1-Wire Temperature The Edison doesn't have built in support for the Maxim 1-Wire bus and this means you can't use the very popular DS18B20 temperature sensor. However with a little careful planning you can and you can do it from user rather than kernel space.
Using the SPI Bus The SPI bus can be something of a problem because it doesn't have a well defined standard that every device conforms to. Even so, if you only want to work with one specific device it is usually easy to find a configuration that works - as long as you understand what the possibilities are.
SPI in Practice The MCP3008 AtoD The SPI bus can be difficult to make work at first, but once you know what to look for about how the slave claims to work it gets easier. To demonstrate how its done let's add eight channels of 12-bit AtoD using the MCP3008.
Beyond mraa - Controlling the features mraa doesn't. There is a Linux-based approach to working with GPIO lines and serial buses that is worth knowing about because it provides an alternative to using the mraa library. Sometimes you need this because you are working in a language for which mraa isn't available. It also lets you access features that mraa doesn't make available.