What is Raspberry Pi?
The Raspberry Pi computer is the size of a credit card, completely silent and costs under INR 4,000. The operating system runs from an SD flash card, allowing its personality to instantly be switched by swapping cards. Its potential uses are staggering, and as yet, not fully
explored, but it has already been tested as a multimedia player with streaming capabilities, a games machine, an internet browser and a
hardware development board. It is intended to be used as an educational device for people of all ages and skill levels.
Hardware Setup
The Arduino is plugged into the Raspberry Pi via the USB port. The Raspberry Pi communicates with the Arduino (via the USB port) using serial communication programmed using Python (requiring the module pySerial). The Python program logs the data from the Arduino and saves the data to a file which can then be read by a web server running on the Raspberry Pi.
Step-1:Setting Up Ardiuno with a powered USB hub
Step-2:A Raspberry Pi with SD Micro card and a 5V/~1A power supply connected to powered USB hub
Step-3:An internet connection(LAN Connectivity)
Step-4:Connecting Temperature Sensor LM35/PT500 with the Arduino
Software Setup
Step 1. Install Debian Linux onto the SD Micro card for the Raspberry Pi: http://elinux.org/RPi_Easy_SD_Card_Setup
Step 2. Make sure you can boot into your Raspberry Pi system (default username/password: pi/raspberry)
Step 3. Change default password: pi@raspberrypi:~$ passwd [enter] [type your new password]
Step 4. Configure your Raspberry Pi by installing:
pi@raspberrypi:~$ sudo apt-get install gnuplot
pi@raspberrypi:~$ sudo apt-get install python-serial
Step 5. Upload a program to your Arduino . To help you out, I've made a simple program that logs 6 temperature Just copy/paste into the Arduino IDE and upload to your Arduino device:
/* By Abhishe Bhardwaj IIIT-Jabalpur - December 2013 */ void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
int sensorValue2 = analogRead(A2);
int sensorValue3 = analogRead(A3);
int sensorValue4 = analogRead(A4);
int sensorValue5= analogRead(A5);
int outputValue0 = map(sensorValue0, 0, 1023, 0, 255);
int outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
int outputValue3 = map(sensorValue3, 0, 1023, 0, 255);
int outputValue4 = map(sensorValue4, 0, 1023, 0, 255);
int outputValue5 = map(sensorValue5, 0, 1023, 0, 255);
int outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
//Since I am using LM35 Therefor Temperature=ADC/2
Serial.print(outputValue0/2);
Serial.print(" ");
Serial.print(outputValue1/2);
Serial.print(" ");
Serial.print(outputValue2/2);
Serial.print(" ");
Serial.print(outputValue3/2);
Serial.print(" ");
Serial.print(outputValue4/2);
Serial.print(" ");
Serial.print(outputValue5/2);
Serial.print("\n");
delay(2000);
}
Step 6. Hook up the Temperature Sensor to your breadboard and Arduino:
Step 7. On the Raspberry Pi, make a python program that uses the serial module to read data coming out of the Arduino. The program should then write this data to disk. Something like this should work (name it something like dataLogger.py):
#!/usr/bin/python ''' Abhishek Bhardwaj IIIT-Jabalpur This program reads data coming from the serial port and saves that data to a text file. It assumes that the Arduino shows up in /dev/ttyACM0(instead u can use com PORT Number) on the Raspberry Pi which should happen if you're using Debian. ''' import serial
import array
ser = serial.Serial(
port=41,
baudrate=9600
# parity=serial.PARITY_ODD,
# stopbits=serial.STOPBITS_TWO,
# bytesize=serial.SEVENBITS
)
#ser.open()
ser.isOpen()
while 1:
command=ser.readline()
temp=command.split()
print(temp)
file=open('Temperature1.dat','a')
file.write("%d\n"%int(temp[0]))
file=open('Temperature2.dat','a')
file.write("%d\n"%int(temp[1]))
file=open('Temperature3.dat','a')
file.write("%d\n"%int(temp[2]))
file=open('Temperature4.dat','a')
file.write("%d\n"%int(temp[3]))
file=open('Temperature5.dat','a')
file.write("%d\n"%int(temp[4]))
file=open('Temperature6.dat','a')
file.write("%d\n"%int(temp[5]))
file.close()
python program to log data (note: I suggest you run this program within screen so that you can do other things with your Raspberry Pi while it's collecting data):
pi@raspberrypi:~$ sudo apt-get install screen
pi@raspberrypi:~$ screen -S collectData -d -m python dataLogger.py
Step 11. Use Gnuplot (which was installed in step 4.5) to make a graph of the data. To do this, make a small gnuplot script (call it something like plotData.plt):
reset
set term wxt enhanced set autoscale xy set timefmt "%Y-%m-%d %H:%M:%S" set format x "%b %d %H:%M" set style data line set xlabel "" set ylabel "Temperature (C)" plot 'Temperature1.dat','Temperature2.dat','Temperature3.dat','Temperature4.dat','Temperature5.dat','Temperature6.dat' set output "data.png" set key left
and make the graph using:
pi@raspberrypi:~$ gnuplot plotData.plt
This will make the file "data.png".
Step 12. Move the file data.png into your web server directory, which defaults to /var/www/
pi@raspberrypi:~$ cp data.png /var/www
This can be set up in a shell script and run automatically using cron.
********************************************************************************************************************************************