Introduction: Processing Data With RasPi and Particle (formerly Spark)
Greetings! Welcome to another Instructable from NextFab. In this Instructable we will be switching gears a little bit and doing an Instructable that's much more fundamentals based that anyone can pick up then expand upon.
The Raspberry Pi 2 B is a pretty impressive little computer for $35. It has a quad core processor that runs at 900 MHz and has1 GB of RAM which equates to a nice little processing punch in a small package. That's why when given the chance we couldn't think of a better way to take advantage of that processing power than hooking it up and pulling data from a Particle (formerly spark) micro-controller.
Particle is a wifi capable micro-controller that makes sending, receiving, and logging data very easy. With the new Particle Photon in the hands of makers, we thought this would be a nice opportunity to revisit the platform. Unfortunately our Photons were still in the mail at the time of this writing so we went with the Spark Core (see our SparkCore Instructable here!) but it was more than enough for this Instructable. We connected it to an accelerometer and used the RasPi 2 to get the data from the API we set up using the sparkCore. With this data we could then, if we choose to, log it on the RasPi and do some neat things with Processing or Wolfram track it with a touchscreen interface, or even use it as the start of a much larger controls system. So sit back and enjoy this quick exercise we worked out for your education and enjoyment.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Circuit and Particle Source Code
We attached the accelerometer to the spark core on a separate breadboard and connected the following wires
xOut - A0
yOut - A1
zOut - A2
GND - GND
3Vo - 3V3 (as reference voltage)
We then plugged it in and wrote the code (attached) to send the data to an online source by using the spark variable, simple as that. This code can be used in multiple ways with multiple sensors, just update and make the appropriate changes. More on using Particle's cloud API services here. Now onto the Pi and Python part.
Step 2: Working With the Pi and Python
In this exercise we used the JSON, urllib2 and Unirest libraries from our PiHub project to take the data from the Particle API and parse it. You shouldn't need to install any additional libraries other than Unirest as JSON and urllib2 should both be included within Python 2.7, that said you will still need to import them, but fortunately we have a good base code to get you started
To acquire your device name and authentication key from the Particle Controller, follow the documentation on the https://www.particle.io/ website. In a nutshell you're going to want to go into the IDE (online or offline versions) and look for the crosshairs icon to get your device ID. To get you're authentication code you're going to want to click on the gear in the bottom left corner. Once these are found just put them into the python script that is attached and now you're set to start taking advantage of the Pi 2's higher processing power.
Step 3: Going Further
This exercise is a starting off point for numerous things. Have a sensor array you want to track? You can tweak the code however you want. Don't want to use the Particle controllers? No worries, there are plenty of wifi capable boards out there (we're especially fond of this one and this one that are both under $5 and adafruit has that last controller with a breakout board for $10) . This project opens up a massive amount of all manners of IoT projects. Create GUIs with tkinter, export data to csv, do really great interactive art pieces using processing, just don't forget to visit us if you're around Philadelphia and tell us all about the really cool things you're doing and always keep an eye on our Instructables page for more great projects like this one. Thanks for reading and happy making.