Wednesday, October 5, 2016

My Photon is Sending Data to ThingSpeak! #IoT

I've been continuing to play around with my Photon, as well as trying to better understand how posts, calls, and web hooks work. After spending a couple of weeks studying and experimenting with other people's code, I've learned how to create and call my own Particle functions! This means that I'm now able to control the colors of neopixels on my Photon in a variety of ways, using HTTP web requests. This is similar to the way CheerLights works (see related blog), only my posts are limited to controlling LEDs (or a buzzer) on my device.  I can do this by typing my post information into the RESTED add-on for Firefox; I can do it through Twitter, by creating a recipe on If This Then That (IFTTT); I also figured out how to use curl (in the command line of my PC) , allowing me to test the HTML code that gets routed to my Photon.  Getting to this point has not been at all intuitive, so I'm pretty excited I've gotten this far!

Once I figured out how to use posts to control the behavior of LEDs (outputs), it occurred to me that I still didn't know how to use a Photon to read the value of sensor data (inputs). After many failed experiments, blindly attempting to alternate between digital and analog pins to figure out how they worked, I bought an ebook titled Programming the Photon: Getting Started with the Internet of Things and started reading it. In the process, I figured out why a web hook I’d created (linking my Photon to a channel on ThingSpeak) was returning nonsense data. That data was “float” data, which is generated when a microcontroller’s analog pin (in this case A0) isn’t actually attached to a sensor.  The book gave me the idea to connect a photocell and resistor to my Photon.  In the process, I discovered that the web hook actually did work, and I was actually able to get data from my device to populate a chart on a Thing Speak channel I created for this purpose! 

My next step is to figure out how to make this data more meaningful, and how I might use it (or some other type of data from my device) to talk with a wearable or book that I make.  I also need to figure out how to use some of the other features of Thing Speak, because I don't yet understand how to use MATLAB code or apply most of the Thing Speak apps.

No comments:

Post a Comment

Thanks for commenting.