Tuesday, August 18, 2015

Testing out raspberry pi with temperature sensor

So my role in the senior design project is to have an Arduino measure power from a home distribution panel and send the data to a raspberry pi to relay to a website and if time permits, also to a dedicated mobile app. Note: I do realize that I can skip the RaspPi, and accomplish all of this with only the Arduino, but I decided to go with the raspberry pi since I don't have the Ethernet shield for the Arduino but I do have a RaspPi that is lying around. Therefore, as a test run, since I don't have the materials/equipment to measure power nor do I have access to my home panel at this moment, I decided to improvise by measuring temperature in my room using an Arduino. With this setup, I can setup a mock system that will essentially do all the tasks that the power measuring system would need to do. So with the arduino measuring temperature, I can send the data over to a raspberry pi and finally have the RaspPi send that data over to a web server where I can plot the data on a website.

 With a bit of research, I found my way of accomplishing this. Using a TMP36 - Analog Temperature sensor which i have available in my room, I set up a basic circuit seen above:
Then using code seen below from ardx.org. I got my circuit running. From here, I connected my raspberry pi through usb to the arduino. Using putty, to connect via SSH, I setup Raspberry to listen for data by opening up a terminal window, and typing:
pi@raspberrypi ~ $ python
                             >>> import serial
                                                                          >>> ser = serial.Serial('/dev/ttyACM0', 9600)
                      >>> while 1:
                              ...     ser.readline()
    ...

From there, you should see data listing showing you temperature values. Success! Now we need to use an API to graph the data online. I found plotly to be the easiest to use. I went to plotly. I actually found a nice tutorial by plotly on using the tmp36 sensor. Straight to the point, I signed up, obtained a username,API key, and a token, and some code to send the data over to plotly...



Raspberry Pi Streaming Sensor Data