Photon Maker Kit Feedback

A book has been written for the photon, and has quite a few easy projects in it to get you started, should you be interested.

Because it's really hard to do that for every item. The difficulty lies in the fact that there are so many different things you could do with them. Making a full project with each and every component would be extremely time consuming, and still wouldn't cover every possibility. Rather than doing that, some 'general' examples would be more appropriate.

  • Per component, show how it's supposed to be hooked up.
  • Per component, have some simple example code.
  • Have an example on how to communicate with any variable or any function.
  • Have an example on how to combine these.

Considering the API is accessible over a REST interface, it's not really true to say that:

A REST API can be accessed by pretty much any programming language. Javascript is one of the 'obvious' web languages, but most others should work just fine.

Would you mind telling us which ones, so we can have a look and see what could be improved on those? The tutorials by @bko in the tutorial section of the forum have always been of great help. Definitely worthwhile checking out :)!

That's kind of what being open source is about :wink: Input from the community is incredibly valuable, since there are limited resources available at any given time. Arduino, for example, has been around a lot longer, and have thus had more time to come up with more resources. Not to mention that they have a community of millions, and many of their contributions come from those members as well.

Much like I argued before, creating a project for every component might seem useful, but would still leave out a lot of possibilities, as well as be extremely time/resources consuming. Rather, giving you the building blocks for each of the required components, should allow you to build your own project. On the device side, you get some example code to get the basic functionality working. Then there are guides available on how to extract that data over the REST API. What you then choose do with that data is up to you, as is the programming language you'd like to use.
For each of these individual pieces, guides can be created, and I personally think that'd be more useful than 'complete' projects. Mind you, if you've got a project you're willing to share, then by all means do, much like a lot of people have already done in the "project share" category or the hackster page. Again, this is a community effort :smile:

So, all that aside, I can't but agree with you that more examples should be made available. I also think the components in the Maker kit should be officially supported by Particle. That's something that's been brought up before, and if I'm not mistaken, that's something they're looking into.


Now, as for your DS18B20, let me try to give you a mini-guide :smile:

Hooking it up

The sensor has three cables coming out of it, Ground (black), Power (red), and Data (yellow). Connect those in a breadboard to your Photon as shown in the image below. (The image shows the non-waterproof variant, so just match up the colors of the wires). We're using D2 since that's what's defined in the example later on, we'll get to that in a bit.


The resistor shown there is 4.7kΩ. That specific value isn't in the Maker kit, but you can use two 10kΩ resistors in parallel which are present. They have to be connected from Data (yellow) to Power (red).

That should be it as far as connecting it goes.

Code

For the code, we're going to use a (community made) library from the Web IDE. Once you're logged in there, go to the library section, and search for "ds18b20" and select the corresponding library:

Once that's opened, select "USE THIS EXAMPLE". A new project will be created with the example code ready to go. I'll put it here below with some additional comments. (Don't simply copy&paste this, since it will miss the necessary library)

#include "DS18B20/Particle-OneWire.h" // load the OneWire library
#include "DS18B20/DS18B20.h" // load the DS18B20 libarary

DS18B20 ds18b20 = DS18B20(D2); //Sets Pin D2 for Water Temp Sensor, why we used D2
int led = D7; // no obvious reason why that's here. Useful for testing as it's on-board.
char szInfo[64]; 
float pubTemp; 
double celsius; //
double fahrenheit;
unsigned int Metric_Publish_Rate = 30000;
unsigned int MetricnextPublishTime;
int DS18B20nextSampleTime;
int DS18B20_SAMPLE_INTERVAL = 2500;
int dsAttempts = 0;

void setup() {
    Time.zone(-5);
    Particle.syncTime();
    pinMode(D2, INPUT);
    // Exposes the fahrenheit variable to the cloud as tempHotWater.
    Particle.variable("tempHotWater", &fahrenheit, DOUBLE);
    Serial.begin(115200);
}

void loop() {

if (millis() > DS18B20nextSampleTime){
  getTemp();
  }

  if (millis() > MetricnextPublishTime){
    Serial.println("Publishing now.");
    publishData();
  }
}

// Function that will SSE publish to the cloud
void publishData(){
  if(!ds18b20.crcCheck()){
    return;
  }
  sprintf(szInfo, "%2.2f", fahrenheit);
  // publish a private event with name "dsTmp" and data "szInfo"
  Particle.publish("dsTmp", szInfo, PRIVATE); 
  MetricnextPublishTime = millis() + Metric_Publish_Rate;
}

// This is what gets the temperature from the sensor.
void getTemp(){
    if(!ds18b20.search()){
      ds18b20.resetsearch();
      celsius = ds18b20.getTemperature();
      Serial.println(celsius);
      while (!ds18b20.crcCheck() && dsAttempts < 4){
        Serial.println("Caught bad value.");
        dsAttempts++;
        Serial.print("Attempts to Read: ");
        Serial.println(dsAttempts);
        if (dsAttempts == 3){
          delay(1000);
        }
        ds18b20.resetsearch();
        celsius = ds18b20.getTemperature(); // gets temperature in Celcius
        continue;
      }
      dsAttempts = 0;
      fahrenheit = ds18b20.convertToFahrenheit(celsius); // converts to Fahrenheit
      DS18B20nextSampleTime = millis() + DS18B20_SAMPLE_INTERVAL;
      Serial.println(fahrenheit);
    }
}

Honestly, I don't know how the library works either. The great thing: I don't have to. The most important things are available in the example: getting the temperature. That's done by using the celsius = ds18b20.getTemperature(); function and fahrenheit = ds18b20.convertToFahrenheit(celsius); depending on what system you'd like to use.
Obviously, there are some other things going on in the getTemp() functions, but that function as a whole can be used in other code without having to know exactly what it does. There's a bit of error handling in there, which is nice.
I know this sounds bit vague, so let me know if further clarification is required.

Anyhow, the rest of the example consist of exposing variables to the cloud as well as publishing values using Server Sent Events, which you can subscribe to.
The loop() uses some rate limiting to make sure you're not reading the sensor non-stop, and more importantly, not crossing the publish rate-limit (1p/s, bursts of 4p/s allowed). It's using a non-blocking 'soft-delay' which doesn't block other processes.

Getting the data over the internet

Here's the part where it get difficult to create an example for since the data can be handled in A LOT of way. One of them is a web interface using JavaScript. For that, a great tutorial has already been made by @bko. With a few minor tweaks to his code, you should be able to get this running rather easily.
Should you want to use the SSEs, then you can use another one of his tutorials.
The exposed variable is also accessible if you use your browser to navigate to https://api.particle.io/v1/devices/[DeviceID_here]/temp?access_token=[Accesstoken_here].
The SSEs are available if you go to https://api.spark.io/v1/devices/events/?access_token=[Accesstoken_here]
Easy access to your functions/variables/events can be had on this page as well :smile:

Now, what you do with the data is up to you, and providing you with examples on how to do that is outside the scope of this community I think.


The above should help get you up and running with at least that sensor. Should anything be unclear, or require further explanation, then please do let us know, and we'll see what we can do.

Have a good one :smile:

6 Likes