This Arduino and Raspberry Pi based project takes sensor data from the Arduino and sends it over USB to the Raspberry Pi. The data is then formed into a web page on the Pi. The web page is fully customizable. Here we use the Freetronics IR Thermometer Module to supply a stream of data to the Arduino then to the Pi. Its good if you want to have the Arduino host webpages that contain sensor data but you donât have a Ethernet Shield. Just send it to the Pi to take advantage of more computing power.
You Will Need:
• Raspberry Pi B, B+, 2 (So long as it has a USB port and Ethernet) & Power Supply
• Arduino (Any model with USB connectivity will work) & USB Cable
• IR Thermometer from Freetronics (Or you can use any sensor compatible with the Arduino. Just modify the code to suit)
• Cable to connect sensor to Arduino
Part 1 – Construction and Programming
Step 1: Wire up the sensor to the Arduino. If you are using the IRTEMP module you may like to refer to here. Alternatively you can connect the IRTEMP module directly to the Arduino by connecting it to pins 3 â 6 on the Arduino (Refer to image).
Step 2: Flash an SD card with the latest version of Raspbian. Refer to this guide for more information
Step 3: If you are NOT using the IRTEMP module then you will need to write a piece of code for the Arduino that sends the output of the sensor over serial at a speed of 9600. If you ARE using the IRTEMP module then download the IRTEMPUSB.ino file from the downloads page.
Step 4: Now we will program the Raspberry Pi, so make sure that you have flashed the SD card with Raspbian and connected the Pi to your local network (Internet access required on Pi) and plug into power. Wait a minute for the raspberry pi to boot then find the IP address of the Pi. You can do this by logging into your router and looking at a list of devices on your network. Once you have found the IP address proceed.
Step 6: We now need to setup the Pi as a web server. We do this by first updating the Pi with
sudo apt-get update then
sudo apt-get upgrade. Then we install the packages required;
sudo apt-get install apache2 libapache2-mod-wsgi python-setuptools python-flask python-serial. This may take a while depending on your Pi and internet connection.
Step 7: Once installed we need to make changes to the Virtual Host file in
/etc/apache2/sites-available/000-default. This can be done by first making a copy of the original file with
cd /etc/apache2/sites-available then
sudo cp 000-default 000-default.orig. Use
ls to ensure that the new file was created. Now that we have a backup lets get and install the file changes with
wget -O 000-default https://raw.githubusercontent.com/jedhodson/arduino-and-pi-in-harmony/master/pi/000-default-mod.
This will update the
000-default file with the changes needed for this project. Take a look at them with
nano 000-default and
CTRL+X to exit.
Step 8: Now we need to make some changes to the user permissions. We do this by typing
sudo usermod -a -G dialout www-data then
sudo a2enmod wsgi. Now we restart apache with
sudo /etc/init.d/apache2 restart. Now you have set up apache
Step 9: Now for the last part in setting up the software on the pi, we need to install the html files that will server the webpages and the python script to make the magic happen. First get to the home directory with
cd then clone the GitHub repository with
git clone https://github.com/jedhodson/arduino-and-pi-in-harmony.git. Now we make the directory to store the web server files with
sudo mkdir /var/www/serialData followed by
sudo cp ~/arduino-and-pi-in-harmony/pi/serialData/* /var/www/serialData/.
Step 10: Congrats! You have setup the Pi. Now all you have to do is start the script with
python /var/www/serialData/index.py then plug in the set-up Arduino and navigate to http://YOURIP/serialData/index.py and you should see something similar like that shown below. To stop the script use