Introduction: Spark Core IoT Controller
Since I got my Spark Core a long while back, I’ve been fiddling without really knowing what I wanted to do with it. Lately, I’ve also been playing with my Rapiro again, and that’s when I got the idea to build a physical controller for the robot, with at its heart a Spark Core (now replaced by Particle Photon).
The controller would be used to send different MQTT messages depending on which button was pressed. Rapiro (or any other IoT device, really) would be configured with a MQTT client and would be able trigger certain actions based on the received messages.
This instructable is about building the controller and performing some initial tests.
PS: This is my first instructable, so any feedback is welcome ;) Hope you like it!
Step 1: Prototype
The list of required components was the following:
- Spark Core / Particle Photon
- prototyping board
- pushbuttons (14)
- 1×12 female header (2)
- 4xAA battery pack
- optionally, a on/off button
Once you found everything you need, proceeded by laying out the different components on the prototyping board. With a bit of luck, everything should fit and you can move on to soldering all the buttons and making the connections: once side of each button goes to GND, the other side to one of I/Os.
The layout I used is pretty basic:
- centrally, the Spark Core (or Particle Photon) with the RGB LED used to display status information
- on the left, five buttons which can be used for movement actions
- on the right, nine buttons which can be used for various functions
You can use the same layout or pick a custom one, as you prefer.
To make the connections, I used stripped solid core wire, which I bent into shape using a pair of pliers.
Step 2: Code
For the code, I used Chris Howard‘s port of Nick O’Leary‘s PubSubClient for Arduino, combined with my attached sketch. I’ve added comments in the code, so it should be clear what I’m trying to achieve, but to summarise:
- every pin is set as an input which is HIGH by default, using an internal pull-up resistor
- pressing a button will pull the pin down to ground, setting it LOW
- the onboard RGB LED is used to display status information:
- red: not connected to MQTT broker
- green: connected to MQTT broker
- blue: button is being pressed
- check if connected to broker, if not: reconnect
- check if button is pressed, if yes: publish MQTT message
The code is attached and needs to be pasted entirely in Particle's online IDE, available at https://build.particle.io
Don't forget to load the library!
Step 3: Demo
Here’s a short video with a brief explanation of the controller, followed by a demo.
Participated in the