Skip to Content
Author's profile photo Former Member

Basic IoT scenario using HCP – Part 2 – Setup Particle Photon for receiving data

This blog is part of a series which is related to a end-to-end IoT scenario. This is the full scenario used for the mini CodeJam that was organised at the SAP Inside Track 2016 Belgium #sitBRU.

Basic IoT scenario using HCP and Particles and UI5 – the explanation

Part 2 – Photon receiving data

Welcome to part 2. Within this blog we use a second Photon with a relayboard and a 8 x 8 matrix display. The temperature and humidity data that was received from the SAPUI5 app will be posted towards the matrix display using the Particle Cloud API. The light treshold on the app in part 4 will toggle the led “on” and “off”.

You could combine the code from part 1 and 2 and put the scenario on one Photon. Another thing you cloud replace is the relayboard. Instead of using that, you could also use a led (onboard led D7 for instance).

Task Screenshot / Code

During this exercise we’ll use the following items:

  • Particle Photon on breadboard
  • USB cable
  • Some wires
  • 8 x 8 matrix display (max7219)
  • Relayboard
IMG_2870.JPG

Setup the relayboard with its pins connected in the following way:

  • VCC connected to 3V3 on the Photon
  • GND connected to GND on the Photon
  • Channel connected to D0 on the Photon
IMG_2871.JPG

Setup the matrix display with its pins connected in the following way:

  • VCC connected to 3V3 on the Photon
  • GND connected to GND on the Photon
  • DIN connected to A2 on the Photon
  • CS connected to A4 on the Photon
  • CLK connected to A3 on the Photon
IMG_2869.JPG
Powerup your Photon /wp-content/uploads/2016/06/image025_972412.png

Login into the particle cloud

Go to: http://build.particle.io

/wp-content/uploads/2016/06/image006_971851.png

Select the “Code” option at the bottom left of

the screen and create a new app. Just like we did in part 1 of the serie.

/wp-content/uploads/2016/06/image009_972400.jpg

Select the “Libraries” button on the bottom left and search for the “MAX7219”

/wp-content/uploads/2016/06/image054_971850.png
Include the library into your newly created application. /wp-content/uploads/2016/06/image022_971911.jpg
Copy/Enter the following code to your application.

// This #include statement was automatically added by the Particle IDE.

#include “LedControl-MAX7219-MAX7221/LedControl-MAX7219-MAX7221.h”

LedControl *led;

int led1 = D0; //or D7 if you don’t use the relayboard

int phase = 0;

char message[64];

char custMessage[64];

int messageLength = 0;

int myUptime = 0;

uint8_t data = A2;

uint8_t load = A4;

uint8_t myclock = A3;

void setup() {

led = new LedControl(data,myclock,load,1); //DIN,CLK,CS,HowManyDisplays

led->shutdown(0,false); //Turn it on

led->setIntensity(0,1);

Spark.function(“SetMessage”, setMessage);

Spark.variable(“Message”, custMessage, STRING);

pinMode(led1, OUTPUT);

Particle.function(“led”,ledToggle);

digitalWrite(led1, LOW);   

}

void loop() {

if(phase==0){ //Message-loop starts

        if(strlen(custMessage) == 0)

        {

            myUptime = (int)(millis()/1000);

            sprintf(message,”#SAPInsideTrack”); //update message

        }

        else

        {

            strcpy(message, custMessage); //update message

        }

        messageLength = strlen(message); // …and length

        led->tweenLetters(0,’ ‘,message[phase]); //scroll from empty to 1 letter

}

if(phase<messageLength-1){ //next characters except last one

led->tweenLetters(0,message[phase],message[phase+1]);

        phase++;

}else if(phase==messageLength-1){//last character scrolls to empty

        led->tweenLetters(0,message[phase],’ ‘);

        phase = 0; //restart message-loop

}

}

int setMessage(String _message)

{

_message.toCharArray(custMessage, 64);

return 0;

}

int ledToggle(String command) {

if (command==”on”) {

        digitalWrite(led1,HIGH);

        return 1;

}

else if (command==”off”) {

        digitalWrite(led1,LOW);

        return 0;

}

else {

        return -1;

}

  }

Verify and Flash your code to the photon. /wp-content/uploads/2016/06/image032_971918.jpg
The Photon is now setup to receive the data from the SAPUI5 app through the Particle Cloud API. Continue to Part 3 and setup the Webhook and monitor the data which is being pushed from first Photon towards the HCP IoT Services.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.