blog.robotmotion.gr
ethernet temperature sensor with arduino
Tuesday 24 November 2009 @ 11:33 am

In this article I will describe a small hack that I put together a couple of days ago. I wanted some sort of Network enabled temperature sensor to measure the temperature in my storage basement. I was fascinated by the idea of having the measurements stored in a database in order to do some server side processing and generate charts of temperature over time.

I am going to describe the system and show the source code needed for such a task.

My system consists of the following parts

1. Arduino board. I used the Duemilanove wi

th the atme

ga328. But any arduino board will do as well.

2. An ethernet shield.

3. a temperature sensor (MCP9700) from microchip.

5. a server running Lighttpd, php, mysql. I used an

NSLU2 running Debian etch.

The system’s architecture is really sim

ple. The arduino board measures the temperature every minute. Everytime a measurement is taken, the adruino acts as a web client and calls a PHP file which is located on a small server (NSLU2). This file inserts the measurement in a mysql database.

Thats pretty well it.

A user can access the webserver at any time to see a temperature graph which is created with the help of the Google Chart API.

There are also some similar projects out there to

get you inspired:

http://www.youritronics.com/arduino-temperature-sensor/

http://jarv.org/pwrmon.shtml

The code running on arduino, connects to the webserver on NSLU2, and issues a “GET /script.php?…..” in order to submit the measurements to the database. When I started working on the code, I came across a strange bug that spoils the reliability of the webclient connection.

There is a relevant conversation here. Anyway, to rectify the problem I did two things.

1) Modified the Client.cpp file from the Ethernet library, so that the transmission includes the whole string and not one by one byte. Informat

ion about these modifications can be found here

In case the link break in the future,

I will show t

he modifications that I followed below.

Client.cpp , add the following code

void Client::print(const char c[]) {

send(_sock, (uint8_t *) c, strlen(c));

}

void Client::println(const char c[]) {

print(c);

print(“\r\n”);

}

Client.h, add the following code

friend class Server;

//new code

void print(const char c[]);

void println(const char c[]);

using Print::print;

using Print::println;

#endif

};

These modifications improve the transmission efficiency of the ethernet library.

2) The next thing I did was to prepare the ‘G

ET’ string before sending it to the server, and avoid breaking the transmission by calling client.print more than once.

The code of the arduino is shown below. Pay attention on how the string with the GET request is pre-formatted with sprintf() and sent at once to the server.

Once the Arduino was programmed, I did some performance tests, and confirmed that there was no connection failure ever through 24 hou

rs.

The next part was to create a new mysql database with 1 table for the measurements logging.

The table looks like this

mysql> describe measurements;

+—————-+———+——+—–+———+—————-+

| Field | Type | Null | Key | Default | Extra |

+—————-+———+——+—–+———+

—————-+

| ID | int(11) | NO | PRI | NULL | auto_increment |

| measurement_id | int(11) | YES | | NULL | |

| timeposted | int(11) | YES | | NULL | |

| temperature | int(11) | YES | | NULL | |

+—————-+———+——+—–+———+—————-+

4 rows in set (0.39 sec)

While the ‘ID’ is auto incremented, the ‘measu

rement_id’ is only a serial number

sent by the arduino for every measurement. Keep in mind that this serial starts from zero every time the arduino power up. The only reason to have this field is to look for power ups of the board, and for the fun of it.

As I already mentioned before, there are 2 .php files on the server.

enter.php – called from the arduino to insert the values in the database

index.php – called by the user to see the measurements over time

The code of the ‘enter.php” is shown below

When this file is called, it gets the two parameters (measurement_id and temperature) and together with the current system time, it inserts them in the database as a now row into the table.

The index.php does all the nice work. It reads a number of rows from the table and uses the google chart API to display a nice chart of th

e measurements.

To avoid pasting the code here and having problems with the blog editor, all the files can be found here

Comments (0) - Posted in hardware,software by admin  



FreeRTOS on LPC2106
Monday 22 October 2007 @ 9:40 am

FreeRTOS is a small portable, open source kernel. I downloaded and tested this excellent real-time kernel on the LPC2106. You can find more information on the FreeRTOS homepage.

In the freely available software package you can find examples for a list of processors. Setting up my tool environment and programming he LCP2106 was a very smooth experience.

The kernel is accompanied by a very detailed documentation that will help anybody get started. Within minuted I was able o create my own tasks and start evaluating the system.

I would like to say a big thanks to all people that contributed in the development of this kernel.

My first test program creates two tasks. Each one of them toggles a LED at a different rate. At run time, you can see the difference in their flash rate. The kernel tick is configurable and initially I set it to 8ms. A reasonable value with more than enough precision for my simple test’s needs.

(photos will be added)

Comments (0) - Posted in hardware,software by admin  



Playing with the LPC2106
Saturday 20 October 2007 @ 9:37 am

The delivery was very fast and the product quality outstanding. I also ordered a prototype board which serves as a motherboard for sticking the LPC2106 on and speeding up the development. The prototype board features among others, a SD card connector, SMD LEDS, push buttons, a buzzer etc. Together with a lot of software which can be downloaded from their website (once you become a registered customer) I was able to start developing my projects immediately.

The LPC2106 is an ARM7TDMI based microcontroller, power efficient and capable of running at speeds up to 58MHz. The processing power of this little beast is awesome. With 128KB Flash on chip and 64KB RAM, the possibilities for home little projects are endless. I have used this evaluation tool to test applications such as real-time MP3 software decoder (Helix engine), EFSL file system accessing files in an SD card, FreeRTOS operating system, and many more.

If I find the time, I will write about my latest homemade project which is an Embedded MUD (MultiUserDungeon) server running on the LPC2106.

Comments (0) - Posted in hardware,software by admin  



Older Posts »