Project tutorial
Stranger Blinks: Send Messages from the Upside-Down

Stranger Blinks: Send Messages from the Upside-Down © CC BY-NC-ND

A wall of LED where you can spell out messages from the Upside-Down is the best way to impress your friends and to cheat the Demogorgon.

  • 3,511 views
  • 1 comment
  • 10 respects

Components and supplies

Apps and online services

About this project

Halloween is coming up soon and probably you need something quick and easy to make. This is the project for you!

We think having a wall of LED on your shoulders, where you can spell out messages from the Upside-Down is the best way to impress your friends and to cheat the Demogorgon.

The design is very simple, as most of the dirty job is done for you by Zerynth, the programming tool used to make this project. Zerynth allows makers and professional designers to develop IoT and Embedded solutions using Python for Microcontrollers.

Step 1: Stranger Things you need

The project requires few elements:

  • Zerynth App: the Zerynth mobile interface for smart objects and IoT systems. Any mobile will become the objects display and remote controller.
  • Zerynth Shield: A ready to use multi-sensors board that adds smart functions to your everyday life objects. In alternative, you can use a simple buzzer, from which you can play the Stranger Things theme song in RTTTL!
  • Arduino DUE or ST Nucleo or Particle Photon or UDOO or NodeMCU(ESP8266) or Flip&Clip by Mikroelektronika. Zerynth is multi-board compatible! You can find all the supported boards here.
  • If you not use Particle Photon or NodeMCU (which have a wifi module onboard), you need an element that connects the board to the Zerynth App, such as a wi-fi shield (with the CC3000 wifi chip by Texas Instruments) for Arduino DUE or the WiFi Plus Click (with the MCW1001A wifi chip by Microchip ) for the Flip&Click.
  • 2 Addressable RGB 30-LED (WS2812B) Strip, 5V, 1m by Adafruit or Pololu
  • a cardboard large enough where to write an alphabet.
  • A portable power bank and a USB cable long enough to let you put it in your pocket.

In our case, we have chosen to make the project using a Particle Photon and a Zerynth Shield.

Step 2: Assembling

  • Connect the input connector of one Neopixel strip to the output connector of the other one.
  • Place the new 2m NeoPixel strip on the cardboard to and mark the points where the holes will be made. We have chosen to put a letter every 2 leds.
  • Paste the strip on the cardboard being careful to match the holes with the LEDs. Attention, take note of the matching between the letters and the position of the LEDs on the strip because this relation will be hard coded during the programming step.
  • turns the cardboard and draw the letters.
  • Paste a little box where to put the board and the Zerynth Shield (or a simple buzzer)
  • Connect the input connector of the first NeoPixel strip to the related port on the Zerynth Shield. Port pins are: GND; Vin; LED.
  • Connect the board to the PC to program it

Step 3: Programming

Using Zerynth is very easy! All the following steps are explained in details in this getting started:

  • Create a Zerynth account.
  • Connect and "virtualize" your board.
  • Install the necessary modules (e.g. you need RTTTL and NeoPixel modules) using the Zerynth Package Manager.
  • create a new project. Attention: you need to create 3 files: main.py, template.html and project.md
  • copy the attached code. You can also find it on github
  • uplink the code on your board and you're done!

After turning on the board, this will automatically connect to the preset network. Then just open the Zerynth App, which will go in search of Zerynth objects connected to the network, select the object of interest, in this case that one called "Stranger Blinks", and you can interact with it! In this case, the Zerynth App shows a textarea form where to digit the message, a button to send the message and a flip-switch to enable and disable the buzzer.

The code is very simple and has a lot of comments. For any questions or suggestions please feel free to post on the Zerynth community forum.

Step 4: Run!

Alright, you are ready to run and ask for trick or treat! Don't forget to take some Eggo Waffles for Eleven!

Luigi F. Cerfeda ( @L_F_Cerfeda) - Zerynth team

Code

main.pyPython
################################################################################
# Stranger Blinks
#
# Created by Zerynth Team - 2016
# Author: Luigi F. Cerfeda
#
################################################################################

#### Import modules

# import modules for rtttl
from community.floyd.rtttl import rtttl

# import modules for neopixel
from neopixel import ledstrips as neo

# import the streams module, it is needed to send data around
import streams

# import modules for wifi connection and communication
from wireless import wifi
from broadcom.bcm43362 import bcm43362 as wifi_driver
from zerynthapp import zerynthapp

# open the default serial port, the output will be visible in the serial console
s=streams.serial()

#### Define parameters and variables

# define a RTTTL melody to be played by passing it the RTTTL string.
# find more songs at http://ez4mobile.com/nokiatone/rtttf.htm and many other websites
stranger_sounds = rtttl.tune("StrangerThings:d=4,o=5,b=170:8c4,8p,8c4,8g,8b,8p,8c4,8p,8c4,8g,8e,8p,8c4,8p,8c4,8g,8b,8p,8c4,8p,8c4,8g,8e,8p,8c4,8p,8c4,8g,8b,8p,8c4,8p,8c4,8g,8e,8p,8c4,8p,8c4,8g,8b,8p,8c4,8p,8c4,8g,8e,8p,8p,8e4,8e,8g,8b,8p,8c4,8p,8c4,8g,8e,8p")


num_leds = 60                     # adjust this to match the number of LEDs on your strip
led_pin = D6                      # this should match the data pin of the LED strip

# define the letters printed on your wall and a set of colors
alphabet = "ABCDEFGHIYKLMNOPQRSTUVWXYZ"
colors = [(255,0,0), (0,255,0),(0,0,255),(255, 255, 0),(0,255,255), (255,0,255),(255,255,255)]

# associate letters to colors
alphabet_colors = {}
for i in alphabet:
    alphabet_colors[i] = colors[random(0, len(colors)-1)]

# positions = [i for i in range(num_leds)]

# alphabet_positions = {}
# for i,item in enumerate(alphabet):
#     alphabet_positions[item] = positions[i]

# hard coding to associate letters to positions
alphabet_positions = {'A':0, 'B':2, 'C':4, 'D':6, 'E':8, 'F':10, 'G':12, 'H':14,
                       'I':36, 'J':34, 'K':32, 'L':30, 'M':29, 'N':27, 'O':25, 'P':23, 'Q':21,
                       'R': 41, 'S':43, 'T':45, 'U':47, 'V':49, 'W': 51, 'X':53, 'Y': 55, 'Z':57}

# define the default message to be blinked and set sound to off
running_message = ""
sound_enabled = 0

# create a new Neopixel strip composed of <num_leds> LEDs and connected to pin led_pin
leds = neo.LedStrip(led_pin, num_leds) 

# set how long leds are on and off
time_on=1250
time_off=500

# associate colors to letter through positions and blink the leds
for i in alphabet:
    leds[alphabet_positions[i]] = alphabet_colors[i]
leds.on()

# save the template.html in the board flash with new_resource
new_resource("template.html")


#### WIFI CONNECTION

# init the wifi driver!
# The driver automatically registers itself to the wifi interface
# with the correct configuration for the selected board
wifi_driver.auto_init()

# use the wifi interface to link to the Access Point
# change network name, security and password as needed
# connect to a wifi network
for i in range(3):
    try:
        print("Establishing Link...")
        wifi.link("Zerynth",wifi.WIFI_WPA2,"zerynthwifi")
        print("Ok!")
        break # cool, we are connected
    except Exception as e:
        print(e)
        continue  # try again
else:
    print("Failed") # sorry can't connect

#### Define the functions

def clean_message(msg):
    msg = msg.upper()
    for i in msg:
        if i not in alphabet and i != ' ': # blank spaces are allowed
            clean_msg = msg.replace(i,'')
            msg = clean_msg
    return msg

def random_blink():
    leds.setall(random(0,255),random(0,255),random(0,255))
    leds.on()
    sleep(time_on)
    leds.clear()
    leds.on()
    

# To be continuously executed by a thread a function requires an infinite loop

def play_sound():
    global sound_enabled
    while True:
        if sound_enabled:
            print("Start Melody")
            print("-"*30)
            print("STRANGER THINGS")
            print("-"*30)
            # play the melody actuating the PWM of pin D2
            stranger_sounds.play(D2.PWM)
            print("Finished")
            print()
            
def blink_message():
    global running_message
    running_message = clean_message(running_message)
    while True:
        leds.clear()
        leds.on()
        sleep(time_off)
        for i in running_message:
            if i == ' ':
                leds.clear()
                leds.on()
                sleep(time_on)
                leds.clear()
                leds.on()
                sleep(time_off)
            else:
                leds[alphabet_positions[i]]=alphabet_colors[i]
                leds.on()
                sleep(time_on)
                leds.clear()
                leds.on()
                sleep(time_off)
        random_blink()


#### ZerynthApp Setup

# the following functions will be called when the buttons on the Zerynth App are pressed
def change_message(message):
    global running_message
    running_message = message
    running_message = clean_message(running_message)

def enable_sound(flipswitch_status):
    global sound_enabled
    if flipswitch_status == 'on':
        sound_enabled = 1
        print(flipswitch_status)
        print(sound_enabled)
    elif flipswitch_status == 'off':
        sound_enabled = 0
        print(flipswitch_status)
        print(sound_enabled)

# configure the zerynth app with a name, a descripton and the template url
zp = zerynthapp.ZerynthApp("Stranger Blinks","Messages from the Upside Down","resource://template.html")

# everytime Javascript generates the event "change_message" the function change_message is called
zp.on("change_message",change_message)

# everytime Javascript generates the event "enable_sound" the function enable_sound is called
zp.on("enable_sound", enable_sound)

# run the ZerynthApp!
zp.run()

# since zp.run starts a new thread, you can do whatever else you want down here!

# define the threads that allow to blink the message and play the sound
thread(play_sound)
thread(blink_message)
template.htmlHTML
<html>

<head>
  <zerynth/>
  <zerynth-jquery/>
  <zerynth-jquery-mobile/>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>     
  <div data-role="page">
    <div data-role="header">

      <h1>Stranger Blinks</h1></div>

    <div role="main" class="ui-content" style="text-align:center">
      <p>
        <label>Write your stranger message:</label>
      </p>
      <p>
        <textarea id='txtData' rows='5'></textarea>
      </p>
      <p>
        <button type=button onclick="javascript:getValue();" id='btnGet'>Send!</button>
      </p>
      <div class="ui-field-contain" onclick="ZerynthApp.call('enable_sound', String($('#flip').val()))">
      <label for="flip">Play Stranger Sounds:</label>
      <select name="flip" id="flip" data-role="flipswitch" data-theme="b">
        <option value="off">Off</option>
        <option value="on">On</option>
      </select>
    </div>

    </div>
    <div data-role="footer">Powered by Zerynth</div>

  </div>
  <script>
    ZerynthApp.jquerymobile_scalecontent()

            function getValue() {
                var text = $("#txtData").val();
                ZerynthApp.call('change_message', text);
            }
  </script>
</body>

</html>
project.mdMarkdown
Stranger Blinks
===============

An interactive Halloween costume inspired by Stranger Things!

Schematics

Zerynth Shield
Find out more here http://www.zerynth.com/zerynth-shield/
In alternative, you can just a simple buzzer.

Comments

Similar projects you might like

IoT Thermometer Using Python

Project tutorial by Luigi Francesco Cerfeda

  • 7,717 views
  • 6 comments
  • 22 respects

IoT Ambient Light: Zerynth Lamp

Project tutorial by Luigi Francesco Cerfeda

  • 7,448 views
  • 6 comments
  • 31 respects

Smart Halloween Pumpkin Lamp

Project tutorial by Luigi Francesco Cerfeda

  • 2,212 views
  • 0 comments
  • 9 respects

Programmable Stranger Things Light Wall Costume

Project showcase by Michael Barretta

  • 3,527 views
  • 6 comments
  • 18 respects

Send and Receive Text Messages (SMS) with GSM SIM900 Shield

Project tutorial by Boian Mitov

  • 62,139 views
  • 5 comments
  • 31 respects
Add projectSign up / Login