• A week with Phant

    I’ve written a bit over the last week about Phant, SparkFun’s data storage service.

    I just wanted to write a quick update on how it’s going.


    This is a screenshot of the ever reliable service taking data from my temperature and light sensor. Currently, the light sensor is between 444 and 447. That means the main lights are on (that’s how it’s set up at the moment).

    The temperature is supposed to be between 144 and 146. The 173 is a little odd. The Arduino does that from time to time, but I don’t know why.

    Random1 is the version of the code running.

    Random2 is currently reporting 1. That means the lights are on (according to simple code on the transmitter)

    if (LightReading < 650)
    	LightStatus = 1;
    	LightStatus = 0;

    Not very exciting or clever, but it’s creating useful enough test data.

    So far Phant has proved very, very reliable. Data is being submitted once every 11.5 seconds. There was a slight problem a day or so ago, but I think it’s with the Ethernet shield, because the problem was fixed as soon as I reset it.

    Next, I need to write a program (likely a web app) that takes the data from Phant and processes it into useful information.

    EDIT: SparkFun is having a sale until the end of the month, with 15% off sensors that could be used for with its Phant service! Cool.

  • Eagle and PCB design

    I’m currently trying to learn how to make little PCB boards in the computer via Eagle, so I can use OSH Park to print them (or via an interesting looking Aussie company Bread Board Killer)

    Anyway, these YouTube tutorials were really helpful.

    I’m yet to watch this one, but I’m sure it’ll be as helpful as the first two.

    (This page is really just here for my reference. I’ll likely need to come back to these soon, so why not just publish them on the blog?)


    I watched this last night too, and it was good. It goes through it a lot quicker, but it’s still useful.

  • Sensor Project - A small success

    I’ve been trying to create a bunch of little low-powered sensors for a month or so now, so I can use them to track various metrics around my house.

    I want to measure simple things like when the light is turned on/off, what the ambient temperature is, the times of doors opening and closing, etc. I also want to install a little sensor on my electricity meter so I can “count” the “pulses” (i.e., count the time it takes for the little wheel to go round - from this you can work out the amount of electricity usage across the day).

    Of course, having sensors measure things is one thing - getting the data is just as important.

    It was a very lucky coincidence, but the other day SparkFun released an awesome little service that is perfect for what I want. I’ve written a little bit about it here. Incidentally, I’ve also expanded my PHP class, PHPePhant, since then too.

    Anyway, on the sensor project, yesterday I had a very small win. I’ve not got a transmitter and a receiver - and amazingly, both are working!

    The transmitter sends data from two sensors - a light sensor and a temperature sensor - across the room to my receiver. That then pushes the data up to SparkFun. From there, I can plot the various changes in values.

    The links above will take you to the GitHub repositories where the code is. It takes two arduinos, one with an ethernet shield.

    There’s a lot more I need to do. Firstly, I need to introduce more sensors into the network. That way I can have multiple sensors around the house doing different things. Secondly, I want to investigate the use of a better radio transmitter. I’m using a very simple one at the moment that only sends data one way. It’d be nice if I could mesh them in some way, or at least have a two-way radio channel. Thirdly, I need to condense them down from a breadboard into a more permanent solution. I might start with a simple single-sided copper PCB prototype board, and once I’ve done that learn how to make a PCB board in Eagle and send it off to a manufacturing house for printing!

  • Arduino, an Ethernet shield and Phant - A quick howto

    Last night, my Arduino Uno Ethernet shield finally turned up.

    I’ve been waiting for it to arrive for a while, as it’s the key part of my little system to log and store sensor values from around the house.

    I was playing with the Ethernet Shield last night, and I found it a little hard to get the damn thing to send a simple POST request to the internet. It turned out the problem was that while I was assigning it an IP address, I didn’t tell it about the router’s gateway or DNS information - so it’s likely the requests weren’t getting though.

    In any case, it works perfectly now and every 10 seconds a request is being sent - and stored - by Phant over at data.sparkfun.com.

    It’s just random data at the moment, but it shouldn’t be too hard to connect up the sensors to the Ardunio and go from there.

    The reason I’m writing this post is really just to log and document an early version of my code. I have a bad habit with the Arduino of writing code and solving my problem, only to lose the code and have to start again. I reckon it’s down to the way that the IDE forces you to store the files in certain places.

    Here’s the receiver code, in a GitHub repo - you’ll need to include a public and private key of your own.

    Here’s a quick walk-through of the code in case you’re trying to get the Ethernet working with Phant in a really simple way.

    Include all the fun stuff, making sure to include your public and private keys.

    #include <SPI.h>
    #include <Ethernet.h>
    #include <Phant.h>
    char server[] = "data.sparkfun.com";
    Phant phant("data.sparkfun.com", "public_key", "private_key");

    Set your network details:

    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    // the dns server ip
    IPAddress dnServer(192, 168, 1, 254);
    // the router's gateway address:
    IPAddress gateway(192, 168, 1, 254);
    // the subnet:
    IPAddress subnet(255, 255, 255, 0);
    //the IP address is dependent on your network
    IPAddress ip(192, 168, 1, 23);

    Then, you need to create an instance of the ethernet class. The “client” bit, as you’ll see below, is what the code uses to send data out.

    EthernetClient client;

    In the setup loop, you should start it all up. The bottom line in will display the IP address. In my case, it is

    //initialize the ethernet device
    Ethernet.begin(mac, ip, dnServer, gateway, subnet);

    From here, I split the actual sending to data into another little function called “httppost”. I do this for the simple reason of keeping everything tidy.

    The loop is:

    void httppost()
      if (client.connect(server, 80))
        phant.add("light", "Random Numbers:");
        phant.add("random1", 1);
        phant.add("random2", 2);
        phant.add("room", 3);
        phant.add("temp", 4);
        Serial.println("Nothing happening...");

    What this is doing is using the Phant class (provided by SparkFun) to collect the data and then in phant.post() create a sting that the Phant service uses to store/log the data.

    In the example above, the fields are: light, random1, random2, room and temp. I’m just using random data at this point, but they could be anything - sensor values, strings, etc.

    Finally, the bit that gets it all working is in the loop() function:


    This will just display Starting... in the serial window, then it will call the httppost() function I talked about a little earlier.

    The key bit I needed to add to make the whole thing work though was: client.stop();

    That stopped the request, so after the 10 second delay and when the loop started running again, it would then start the client.connect(server, 80) process over again. In this case, the “server” part is defined at the top of the script - it’s data.sparkfun.com.

    It was all a bit confusing at the time, but it mostly makes sense now. This may not be the best way to go about it though, so if you can see any errors (there’ll be many) or want to suggest improvements - let me know in the comments below.

    Creating a network of sensors and transmitters

    Now that’s done, the next step it to program the receiver to parse the incoming strings from the transmitters. They include a string (of sorts) which will include the data.

    The radio payload looks a little like this: S:1#L:%i#T:%i#R:%i#C:%i

    There’s lots of hashes, %i, and things in there, so to break it up, S is sensor number, L is light value (from a photo resistor), T is temperature, R is random (likely replaced down the line), C is count (to try to work out if I am missing packets).

    In reality, the packet may look like this: S:2#L:555#T:234#R:123#C:232

    So I don’t lose it all, here’s the early transmitter code, in a GitHub repo.

  • Sparkfun - data storage


    SparkFun, everyone’s favourite electronics internet retailer, has released a really cool new service called Phant. Well, Phant is the engine behind https://data.sparkfun.com/, a website that allows the “Internet of Things” to store simple data online.

    For example, you’ve got a little thermometer connected to an ethernet enabled Arduino, once you’ve connected it up to the data service, you can send and store the sensor readings in Sparkfun’s cloud.

    As SparkFun says:

    What types of projects would benefit from this service?

    Almost anything. Your weather station in the backyard. A classroom of kids working on science experiments. A community concerned with pollution and crowdsourcing data collection. The weight of your pug’s food dish. You get the idea. If your project can send an http request, you can push data out to our servers.

    I have started writing a simple PHP class that connects to the Phant system.

    It’s called PHPePhant, and it’s hosted on GitHub. It’s still in its early days (it only POSTs data so far), but I hope to build it out soon. I haven’t written an open sourced PHP class before, so if you have any ideas or suggestions let me know. Better still, just dive right in and submit a pull request!

    I can already think of heaps of ways to use this lovely little (and really simple) service, so thanks SparkFun!

    Currently I’m collecting a few parts to create little sensors (which I’ll connect via a really simple cheap 433MHz radio system) that can detect the temperature in my house, if the light is on or not, when the door was opened, etc. All is fed back to the master Arduino, which will feed the data right into Phant. Perfect.