DigitalExperience

R. Berry Bash

by on ott.25, 2012, under Hardware lab

The , a pretty interesting piece of hardware (half micro controller, half computer), is here used as a sampler (via ). The data collected is then employed  to draw a graph and send it to your e-mail account using wifi connection. All this is performed using only some useful open programs and a little bash scripting.

I sadly have one of the first release of raspberry so I had to short the fuses that limit the current through USB and add a capacitor to stabilize the voltage on current peaks. The hardware I used is pretty simple and not even necessary. In a perfboard connected to the GPIO header I soldered a molex connector to power the board from any ATX and some external HD power supply. As you can see in the below image, between 5V and ground there is a LED-RESISTOR-TRANSISTOR series with the base of the PDTC114ET wired to gpio4, only for debug purpose.

The SOIC-8 in the middle of the image is a PCA9517, an I2C buffer from TI, is very interesting because isolate the capacitance of the serial line, source the power instead of the micro and let you select the voltage you desire for the bus, allowing 5V operation (or 3.3, or 2.7, or ..).

The 4 wire line bus is bring out through 4 white wires and soldered to an ps/2 connector of an old mother board. There I used two cable (from mouse and keyboard) to bring the signal to the sensors. The MCP9805 series is here used because I need more than one sampling point and they can be configured with different addresses by pulling high or low some pins. They have a grater precision on high temperature compared to similar one, too.

  

Once you have set up your OS (wheezy in my case) and internet connection, you need to install few programs in order to achieve bus access and data manipulation.

installation (as root):
edit /etc/modprobe.d/raspi-blacklist.conf and comment line: i2c-bcm2708
edit /etc/modules and add line: i2c-dev
#reboot

#apt-get update
#apt-get install i2c-tools
#apt-get install bc
#apt-get install gnuplot
#apt-get install sendemail
#apt-get install libio-socket-ssl-perl libnet-ssleay-perl perl
#apt-get clean

Sendemail fail with latest versions of “libio-socket-ssl-perl” so you may need to downgrade to an older release. To do this just download “libio-socket-ssl-perl_1.53-1_all.deb” from the web and install it like this:
#dpkg –install libio-socket-ssl-perl_1.53-1_all.deb

Test the i2c bus:
#i2cdetect -y 0
You should get an all-zero table with the address of found devices. In my case I got 0×19 and 0x1A, which I used in the i2c-get command. As from datasheet of MCP9805 the 16-bit temperature register is the number 5, so to get it you must type (w means word, two byte):
i2cget -y 0 0×19 0×05 w
i2cget -y sda-channel device-address register-number [b|w]

I have made three simple bash scripts in order to handle data collection, conversion and to send the email. In “temp.batch” there are the commands for gnuplot with instructions on how to compose the graph from the log file.

Convert the 2-byte data from the sensor to human-like celsius format.
mcp9805_converter.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
temp=$1
 
#estrapolo il segno
segno=$(($temp & 0x0010 ? 1 : 0))
if [ "$segno" -eq "0" ]; then
  echo -n "+"
else
  echo -n "-"
fi
 
#faccio la conversione
result=$(( (( $temp & 0x000F ) << 8 ) + (($temp & 0xFF00) >> 8 ) ))
echo -e "scale=3 \n $result / 16" | bc

Create an image with the data found in the .log file.
temp.batch

1
2
3
4
5
6
7
8
9
10
11
12
13
set title 'Temp'
set xlabel 'time (20 s)'
set ylabel 'Celsius'
set grid
 
plot 'temp-1a.log' using 1 with lines title 'Room'
replot 'temp-1a.log' using 1 with lines smooth bezier notitle
replot 'temp-19.log' using 1 with lines title 'wifi Dongle'
replot 'temp-19.log' using 1 with lines smooth bezier notitle
 
set term png size 1024, 768
set output 'temp.png'
replot

Send the image file to my gmail account as an attachment.
mail.sh

1
sendEmail -f USERID@gmail.com -t USERID@gmail.com -u R. Berry Bash -m "Last temp log" -s smtp.gmail.com -o tls=yes -xu USERID -xp PASSWORD -a temp.png

Read the data from the sensors every 20s, convert it in celsius, log them in a file. Every 2 hours create an image from the log files and send it to my gmail account.
sample.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#/bin/bash
#per sempre
while [ true ]; do
 
  #pulisco
  echo -n "" > temp-19.log
  echo -n "" > temp-1a.log
 
  #campiono
  for i in {1..360}
  do
    ./mcp9805_converter.sh $(i2cget -y 0 0x19 0x05 w) >> temp-19.log
    ./mcp9805_converter.sh $(i2cget -y 0 0x1a 0x05 w) >> temp-1a.log
    echo -n "s$i"
    sleep 20
  done
 
  #faccio il grafico
  gnuplot temp.batch
 
  #mando il grafico per email
  ./mail.sh
 
done

And this is the result image found in my mail box.

Simple and effective.

Zaion

:, , ,
No comments for this entry yet...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!