Send Raspberry Pi Data to COSM

The combination of connecting a Raspberry Pi to COSM makes creating a internet of things much easier than it has been in the past. The Pi with it's easy access to ethernet / WiFi and COSM's drop dead simple usability will graph all sensor data you send to it.
This tutorial explains how to connect a analog temperature sensor to the Pi and use a small python script to upload that data for storage and graphing on COSM.

Send Raspberry Pi Data to COSM

To follow this tutorial you will need

Connecting the Cobbler to the MCP3008 and TMP36

Please Note: Xively no longer has free developer access to their system, so this tutorial is only for historical research. Please check out our other IoT tutorials for alternative services!

Why we need an ADC

The Raspberry Pi computer does not have a way to read analog inputs. It's a digital-only computer. Compare this to the Arduino, AVR or PIC microcontrollers that often have 6 or more analog inputs! Analog inputs are handy because many sensors are analog outputs, so we need a way to make the Pi analog-friendly.

We'll do that by wiring up anĀ MCP3008 chipĀ to it. TheĀ MCP3008Ā acts like a ā€˜bridge' between digital and analog. It has 8 analog inputs and the Pi can query it using 4 digital pins. That makes it a perfect addition to the Pi for integrating simple sensors likeĀ photocells,Ā FSRsĀ orĀ potentiometers,Ā thermistors, etc.!

Lets check the datasheet of the MCP3008 chip.Ā On the first page in the lower right corner there's a pinout diagram showing the names of the pins.

Wiring Diagram

In order to read analog data we need to use the following pins: VDD (power), DGND (digital ground) to power the MCP3008 chip. We also need four ā€˜SPI' data pins: DOUT (Data Out from MCP3008), CLK (Clock pin), DIN (Data In from Raspberry Pi), and /CS (Chip Select). Finally of course, a source of analog data, we'll be using the TMP36 temperature sensor

The MCP3008 has a few more pins we need to connect: AGND (analog ground, used sometimes in precision circuitry, which this is not) connects to GND, and VREF (analog voltage reference, used for changing the ā€˜scale' ā€“ we want the full scale so tie it to 3.3V)

Below is a wiring diagram. Connect the 3.3V cobbler pin to the left + rail and the GND pin to the right ā€“ rail. Connect the following pins for the MCP chip

  • MCP3008 VDD -> 3.3V (red)
  • MCP3008 VREF -> 3.3V (red)
  • MCP3008 AGND -> GND (green)
  • MCP3008 CLK -> #18
  • MCP3008 DOUT -> #23
  • MCP3008 DIN -> #24
  • MCP3008 CS -> #25
  • MCP3008 DGND -> GND (green)

Advanced users may note that the Raspberry Pi does have a hardware SPI interface (the cobbler pins are labeled MISO/MOSI/SCLK/CE0/CE1). The hardware SPI interface is super fast but not included in all distributions. For that reason we are using a bit banged SPI implementation so the SPI pins can be any of the raspberry pi's GPIOs (assuming you update the script). Once you get this project working with the above pinout, feel free to edit the python code to change the pins as you'd like to have them!

Send Raspberry Pi Data to COSM schematic

TMP36

Finally the TMP36 has three pins that need to be connected. They are numbered from left to right in ascending order when the text of the sensor is facing you.

  • pin1: 3.3v
  • pin2: analog out ā€“> channel0 on mcp3008 (pin1)
  • pin3: gnd

Necessary Packages

Please Note: Xively no longer has free developer access to their system, so this tutorial is only for historical research. Please check out our other IoT tutorials for alternative services!
This guide is based on Debian's ā€œWheezyā€ release for Raspberry Pi. It was made available inĀ Mid July 2012. The following items must be installed in order to utilize the Raspberry Pi's GPIO pins and to uploadĀ data to COSM.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top