Let's see step by step how to capture values from a temperature sensor using an application built in Visual Studio, plotting them by writing a simple firmware for microprocessor AVR Atmega168, used by the Arduino development board
Parts and pieces
Arduino decimilla. It is a very cheap development platform and quite easy to use which will allow you to create a very quick way to do hardware.
I also bought a Sparkfun Protoshield and a mini Breadboard to work more comfortably, but alternatively could be used an led with an appropriate resistance)http://led.linear1.org/1led.wiz) and a pushbutton in a traditional Breadboard.
Finally we need temperature sensor, in this case is a ZX-TEMP:
For the readers of Chile, all these parts are located in Olimex.
Our system of sensor circuit is quite simple. States shall inform primitively by means of a led and a pushbutton will allow to interact with small features that I would add.
Thus we have a circuit similar to the following figure (because I appointed the digital inputs and outputs according to the layout of the ProtoShield components):
Naturally the circuit would not be complete if we lack temperature sensor, but the upper circuit is sufficient if you buy the temperature sensor that I named above instead of only the thermistor (in this case a) TTC 103):
Finally we will use a digital input, an analog and a digital output.
An interesting section was arming the Sparkfun Protoshield. Does not have much difficulty, but reminded me of times when playing with my Tente. Although does not come with instructions, the next page It is extremely helpful.
Terminations were not extreme cleanliness, but plate works excellent, harmoniously integrated with Arduino. A recommendation is to get economic, low-power and thin solder.
(Wiring) language used by Arduino is identical to the traditional C, C , but with certain keywords for functions of arduino.
To write and compile the arduino code it is advisable to use the Arduino IDE.
Unfortunately, up to version 0012 thereof and not included an installer support for Aero Glass on Windows Vista.
The solution was to make a simple self-installable package that works perfectly in Windows Vista, additionally creating a shortcut such as any application:
http://servicios.ried.cl/arduino-live_setup.exe(replaced by:) http://arduino.cc/forum/index.php/topic,118440.0.html)
You download the application and press the button to start the process. Ask a few minutes after an installation path.
We must consider that we have technically only a thread of execution for what if we stop while maintaining an LED lit are precluding the detection of other events as it would happen when working in C#, with events and "simultaneous" threads.
So we must think in the States of our program. For this, nothing better than a classic diagram States:
I will first implement the basic functions, in particular a visual output that I will use. Let us first start with the function of Flash (which will be blocking):
Taking advantage of the support of polymorphic functions, the same function supporting multiple repetitions:
For the conversion of the entire sensor to temperature value provided, I will take this value and will adjust to the new margins (using the macro "map"). The only detail of this function is to support decimal I multiply, work and divided the initial value:
Values are experimental and if you can notice it calculate them using the ambient temperature (26 degrees, where the value delivered by the sensor was 438) and a reference (body temperature).
To send the temperature to the equipment we use a format in particular, specified the first comment of the function:
With these functions, sending a temperature is as simple as:
Then we must work on the interaction of the user with the button, as defined the top diagram.
To verify if the user kept pressed effectively button for the required two seconds, I iteraré with short breaks, reviewing the State of the button:
So once we know that he kept the button really pressed, we go to capture mode continuous, where every two seconds (if not replace the button) will send the data of the sensor:
Note that here there is a potential problem. The function of elapsed time (millis) has a limit given by the type of variable. So when the value can be a maximum of 32 bits, we have that 4294967296 will be the maximum milliseconds to measure, i.e. about 49,72 days.
This limit seems enough for a small project, but for a continuous workstation (although Arduino is not intended for this purpose)
Writing the application on the desktop
For graphics I used ZedGraph. This component allows you to have a fully customizable graphics box:
As we connect a serial port provided by the arduino FTDI chip, then just make a menu of connection:
The purpose is to achieve a result similar to the following:
With control of the serial port that is provided by Visual Studio, it is quite natural to receive the temperature data:
All very complex, less function that processes the information received:
The only detail of the previous code, is the incorporation of a condition for the support of multiple threads.
New versions of Visual Studio warn us about this when we relate things that involve threads. So we have to use P:System.Windows.Forms.control.InvokeRequired in conjunction with the function delegate above. This is more than anything because using some of the interface (as it is the zedGraph graphics control), can have a moment of time in which two sequences received reach to be processed so quickly (triggered asynchronously) which can cause a crash update (sending messages) to the visual component.
All other program code explains if only, including connection, redraw routines and others.
Something quick that I came to give you versatility to the program was adding a filter using regular expressions for the ports available on your computer. Clearly it would have been cleaner to find the "Arduino" reading the descriptors of hardware but it would have taken more time, and in practice it had not been necessary:
As you can see in the code, each port is compared with a regular expression. So we could run this application on Unix using Mono by adjusting our name ports filter accordingly.
By default, the filter is for Windows COM ports:
An example of using the sensor can see in the video below:
As you can see it is quite simple to start a capture of temperatures.
The code of the application C# is available in the SVN of Google Code.
I also uploaded the source code for the entire project:
TemperatureLogger v0.1 (code source)
The executable of the application:
Additionally the sources for the Arduino code:
TemperatureLogger v0.1 (source file for the Arduino IDE)
As a future engineer in computing, always interested me extend my skills in terms of hardware, automation and computer architecture, ideal which the Arduino board propped up perfectly.
After bad and uncomfortable experiences on other boards (in particular one based on PIC) I can say with certainty that Arduino is deliciously ideal for those with small projects that do not want to get involved too much or lose much time on basic and trivial things in hardware development.
The only big setback which I can highlight in arduino is strict, almost arbitrary implementation of the counting, "millis", function as discussed in more detail in the body of the article.
So, I extend the invitation for anyone interested in creating their small projects extremely easy.