S5D9 HowTo: Cloud-Driven LEDs with On-Board LEDs

s5d9

#1

Preparation

  1. Update the board with the Data Intelligence Diagnostics binary from Medium One
  2. Go through the S5D9 Diagnostics Intelligence tutorial

Project Goal

On the Data Intelligence Diagnostics tutorial, there is a dashboard to toggle the LEDs. By default, it toggles the Yellow LED. We’re going to change the code so that it toggles any LED.

What You’ll Learn

By learning how to control LEDs on the board through the Renesas IoT Sandbox Data Intelligence, you will learn the following:

  1. Data Intelligence (Medium One) workflows in Python
  2. Cloud raw events
  3. Sending an event from the cloud to the S5D9 board
  4. Basic Python syntax

Overview of What You’ll Create

Sending 0 will turn off an LED. Sending 1 will turn on the LED.

When you toggle the Yellow LED, it will go back to the default state, which is green only.

With a small code modification, you can toggle all LEDs

Or, you can toggle the LEDs in any combination.

Steps

Log into the sandbox

You will see something similar to this:

Scroll down and toggle the default Yellow LED.

Workflow Studio

Open LED Toggle and Blink

Open Base Python

The comments have the description of the LED color combinations.

Set up led color as variable

The default is yellow or L2.

led = "L2"

#Toggle 
if IONode.is_trigger('in1'):
    toggle = IONode.get_input('in1')['event_data']['value']
    if toggle == 1:
        MQTT.publish_event_to_client('s5d9', led + ':1')
        log("LED turned on")
    elif toggle == 0:
        MQTT.publish_event_to_client('s5d9', led + ':0')
        log("LED turned off")
    else:
        MQTT.publish_event_to_client('s5d9', led)
        log("LED toggled")

Set up Python dictionary of color and state pairs

As it was difficult for me to refer back to what L1, L2, L3, L4, etc. meant, I created a dictionary. By changing the color variable to green, yellow, greenYellow, red, greenRed, yellowRed, or all, you can set up the toggle condition for any state.

led = "L2"
colorChoices = {"green":"1" , "yellow":"2", "greenYellow":"3", "red":"4",
                  "greenRed":"5", "yellowRed":"6", "all":"7"}
color = "yellowRed"

led = "L" + colorChoices[color]

#Toggle 
if IONode.is_trigger('in1'):
    toggle = IONode.get_input('in1')['event_data']['value']
    if toggle == 1:
        MQTT.publish_event_to_client('s5d9', led + ':1')
        log("LED turned on")
    elif toggle == 0:
        MQTT.publish_event_to_client('s5d9', led + ':0')
        log("LED turned off")
    else:
        MQTT.publish_event_to_client('s5d9', led)
        log("LED toggled")

Next Steps

  • Blink: You can apply this some system to the blink code.
  • GPIO: Using Dan Kane’s tutorial for the S3A7 you can set external LEDs to trigger using the Grove connectors
  • mobile: Dan’s tutorial also covers a mobile trigger

S5D9 IoT Fast Prototyping Kit Tutorials
HowTo: Control Fan with S5D9 and IoT Sandbox Dashboard