0-5V Analog Input From Raspberry Pi Graphed on Web

Introduction: 0-5V Analog Input From Raspberry Pi Graphed on Web

Using the PIC PI expansion board combined with your Raspberry Pi i will show you how you can Graph analog Voltages to Cosm 

Hardware needed for this project 
1 x Raspberry Pi
1 x PIC PI development board ( you will be able to purchase this soon )
1 x Microchip Programmer
1 x 10k Ohm Trimpot
1 x Soldering Iron
1 x Solder  
1 x Wire 

The open source schematic for the PIC PI expansion board is provided in the pdf attached more information provided on our  website

Step 1: Setting Up the Raspberry Pi Operating System

Installing the Raspbian image onto the Raspberry pi in Windows
1. Download the latest raspbian image from the raspberry pi website
2. Download the binary (not the source) image writer for windows
3. Put your Sd card into your PC
4. Run image writer software 
5. Browse the image file
6. Select the drive letter from which your sd card is on
7. Click the write button to flash the image to the sd card this takes a while so be patient

For installing on Mac an Linux there are plenty of tutorials you can follow on the internet 

Step 2: SSH Into You Raspberry Pi

I have found that the easiest way to work with the PIC PI and Raspberry PI at the same time is to ssh into you Raspberry Pi to do this you will need to download Putty which is free to download off the internet. To ssh into your Raspberry Pi you will need to find out the ip address of you raspberry pi you can do this by running the command ifconfig your ip address the inet address of eth0 as show in the picture. Then type your ip address into your putty session and make sure your Port is set to 22

Step 3: Unblacklisting the I2c Module

I2C is blacklisted by default in the Raspberry Pi. To disable the blacklisting you need to edit the raspi-blacklist.config file to open the file run the command sudo nano /etc/modprobe.d/raspi-blacklist.conf     Unblacklist the i2c module by commenting ( placing a hash tag in front ) the  blacklist i2c-bcm2708 line ie. #blacklist i2c-bcm2708

After you have done this save the file by  pressing ctrl X  which prompts you to save and enter Y to save 

Step 4: Enable I2C Module in the Kernel

The i2c module is not included in the Raspberry PI kernel yet so to add it you must open the modules file  to open it run this command  sudo nano /etc/modules and to add it you must type the linei2c-dev into the text editor and again make sure you save the file 

Step 5: Install the I2c Packages

For Python to run our code we will have to install a few packages but before you do do an update of the system using   sudo apt-get update then install the i2c tools using the command  sudo apt-get install i2c-tools and the smbus using the command sudo apt-get install python-smbus  and add a user using the command sudo adduser pi i2c then do a reboot of your systemusing the command 
sudo reboot -n   then python requires you add the i2c-dev do this using this command sudo modprobe i2c-dev

Step 6: Installing the Cosm Packages

1.Install python-pip Pip Installs python packages by running this command 
   sudo apt-get install python-pip

2.Copy the code from github to your Raspberry pi using this command  
     git clone git://github.com/petervizi/python-eeml.git

3. Open the package folder using this command
      cd python-eeml/

4.  Install the package using this command 
     sudo python setup.py install

Step 7: Loading the Software Into the PIC

Attached are the project files. We are using the MPLAB X IDE to develop the code and the XC8 compiler to compile the code, these are both free to install available from the microchip website you will need these to get your project to work! You will also need a microchip programmer that supports the PIC16F1519 

Steps to programming the PIC PI Board
1. Download and install MPLAB X IDE from micro chip 
2. Download and install the free version of the XC8 compiler for microchip
3. Download the code from below 
4. Unzip the code 
5. Open MPLAB X 
6. File > Open project 
7. Browse for where you saved the project 
8. Build the code 
9. Plug in the PICKIT3 to the JTAG header on the PIC PI 
10. Program the PIC chip 

Step 8: Setting Up Your Cosm Account

Follow this simple tuorial to set up your own cosm account. The most important thing is that you make sure you remember your FEED ID and your API_KEY 

Step 9: Entering Your Account Keys and Executing the Code

1. Download the code form Github using the command   git clone https://github.com/PICPIelectronics/picpi.git
2. Open picpi using cd picpi
3. Open up the text editor by running the command sudo nano simple_example.py 
4. Enter your own  feed id and your api key into the code 
5. Save the code 
6. Turn the code into an executable by running the command chmod +x simple_example.py
7. Run the code using the command   ./simple_example.py

Step 10: Wiring Up the Power and Connecting the PIC PI

Connect the Raspberry Pi to the PIC PI and apply 5V and GND to the PICPI also wire up a 10k Trimpot with leads as show in the second image  

Step 11: Viewing Your Feed

1. Login into your Cosm account click on your raspberry pi feed 
2. Enter the units as voltage and the symbol as V and click click save account. 
3. Adjust your Trimpot to different values every 30 seconds ( cosm takes a while to update)

If your feed reflects the changes in voltage then congratulations you have successfully logged Adc data to your cosm feed!  

You can look on our website for more infromation and you can purchase the boards on ebay we are currently out of stock at the moment but will be getting some more in soon

Be the First to Share


    • For the Home Contest

      For the Home Contest
    • Big and Small Contest

      Big and Small Contest
    • Make It Bridge

      Make It Bridge