S5D9 HowTo: Cloud-driven Blinky

s5d9

#1

Project Goals

  • external LED blinks by using power from Grove connector
  • number of blinks is controlled by Renesas IoT Sandbox Data Intelligence

Learning Objectives

  • Modify Data Intelligence workflows to receive an event and publish an event with MQTT
  • Create basic Python functions
  • Use standard Python library time for delay
  • Get integer from dashboard event and use in workflow (number of blinks)

Prerequisites

Open Data Intelligence Workflow Studio

Go to the Cloud GPIO workflow you created in the previous tutorial.

Open the blue box for Python code.

Python Code

Insert the code below.

'''
Renesas Data Intelligence GPIO
'''

def turnOff():
    MQTT.publish_event_to_client('s5d9', 'G4:11:0;G1:1:0') # sets pin 4_11 low and pin 1_01 low 
    log("LED turned off")
    return 0

def turnOn():
    MQTT.publish_event_to_client('s5d9', 'G4:11:1;G1:1:1') # sets pin 4_11 high and pin 1_01 high
    log("Grove connector on")
    return 1
    
import MQTT
import time

ledState = 0

#Toggle 
if IONode.is_trigger('in1'):
    toggle = IONode.get_input('in1')['event_data']['value']
    if toggle == 1:
        ledState = turnOn()
    elif toggle == 0:
        ledState = turnOff()

#     else:
#         log("LED toggled")
#Blink
elif IONode.is_trigger('in2'):
    blinkNum = IONode.get_input('in2')['event_data']['value']
    # modify code to blink external LED
    for blink in range(0, blinkNum * 2):
        if ledState:
            turnOn()
            ledState = 0
        else:
            turnOff()
            ledState = 1
        time.sleep(.7)
        log("it blinked")
    log("LED blinked " + str(blinkNum) + " times")

Click on Save and Activate

Test

Input 10 Blinks.

You will see the event and the LED will blink.


$20 Discount Coupon on Renesas S5D9 IoT Fast Prototyping Kit


S5D9 IoT Fast Prototyping Kit Tutorials
Cloud-Driven Blinky Video Demo Overview
S5D9 HowTo: Variable Blinky from IoT Cloud Event
HowTo: Control Fan with S5D9 and IoT Sandbox Dashboard