Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Elecrow Meteor IPS Touchscreen with RGB LEDs
    • Pi Pico Pinout Display on the Command Line
    • How to Add a Raspberry Pi Pico Reset Button
    • Pi Pico Onboard LED
    • Pi Pico W Pinout and Power Pins
    • CrowPi L Raspberry Pi Laptop and Learning Platform
    • Pi Pico W Launched
    • Add Kodi to RetroPie Menu
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        December 23, 2022

        How to Add a Raspberry Pi Pico Reset Button

        November 20, 2022

        Pi Pico Onboard LED

        May 6, 2022

        Add Kodi to RetroPie Menu

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Add-ons»Happy Halloween With A Raspberry Pi And Pi-Lite
      Pi-Lite Happy Halloween Example

      Happy Halloween With A Raspberry Pi And Pi-Lite

      1
      By Matt on October 10, 2013 Add-ons, Tutorials & Help

      It’s that time of year when mad inventors start creating Halloween themed electronics projects. I’ve never managed to be organised to do a seasonal project but this year I decided to give it a try.

      So this year I decided to take what I’ve learnt about the Pi-Lite and create a simple Halloween project I can stick in the window along side our more traditional carved pumpkins.

      This post follows on from my previous Pi-Lite articles :

      • How To Setup The Pi-Lite LED Matrix Board
      • Pi-Lite LED Matrix Board Python ‘Hello World’ Example
      • Pi-Lite LED Matrix Board Custom Sprites Example

      TPi-Lite Happy Halloween Exampleo re-create this project you’ll need :

      • Raspberry Pi
      • Pi-Lite
      • SD card (I used the latest Raspbian image)
      • Power supply
      • My Python script

      Python Script

      The following script will display an animated object and then scroll “Happy Halloween !” across the screen. It repeats until CTRL-C is pressed.

      #!/usr/bin/env python
      
      import sys
      import serial
      import time
      
      # Define lists which contain frames of animations
      face   = ['000000000000000000010011000011000100011000110000010110000110110000110110000010110011000110011000100010011000000000000000000000',
                '000000000000000000010000011011000110011000110000010110000110110000110110000010110011000110011000110010000011000000000000000000']
      bat    = ['010000000011000000001100000000110000110110000011111011001111100001111100011111011110110000000110000001100000011000000010000000',
                '000000100000001100000011000000110000110110001011111010001111100001111100011111010110110001000110000000011000000001100000000100']
      ghost  = ['000000000000000000000011111001100001010000010100100010100000001100100001100000010010000010001100001000011111000000000000000000',
                '000000000000000000000011111001100010010000010100000001100100001100000010100100010010000001001100001000011111000000000000000000']
      spider = ['001001000010010010100100101010101000001011110000111001000111000000111000000111001001011110010101000100100101010010010001001000',
                '010010010100100101101001000100101010011011101000111000000111000000111000000111000011011101100101010101001000100100101010010010']
      
      # Combine into dictionary object
      objects = {'face':face,'bat':bat,'ghost':ghost,'spider':spider}
      
      # Define text message to scroll
      message = "Happy Halloween !\r"
      
      # Configure Pi serial port
      s = serial.Serial()
      s.baudrate = 9600
      s.timeout = 0
      s.port = "/dev/ttyAMA0"
      
      def showObject(name,count,delay):
        # Function to display frames from a specified object
        # name  - object to display
        # count - number of times to display object
        # delay - ms to wait between frames
        object = objects[name]for x in range(count):
          for frame in range(len(object)):
            command = "$$$F" + object[frame]+ "\r"
            s.write(command)
            time.sleep(delay)
        # Clear display
        s.write("$$$ALL,OFF\r")
      
      try:
          # Open serial port
          s.open()
      except serial.SerialException, e:
          sys.stderr.write("could not open port %r: %s\n" % (port, e))
          sys.exit(1)
      
      # Turn off all LEDs
      s.write("$$$ALL,OFF\r")
      time.sleep(0.5)
      
      try:
      
        while True:
          # Get list of object names from dictionary
          mykeys = objects.keys()
      
          # Loop through each object
          for x in range(len(mykeys)):
            showObject(mykeys[x],5,0.5)
            time.sleep(1)
            s.write(message)
            # Wait for scrolling message
            time.sleep(8)
      
      except KeyboardInterrupt:
        print("Quit")
      

      Here is a video of the script in action :

      Script Downloads

      Rather than cutting-n-pasting the above script you can also download it directly to your Pi using :

      wget https://bitbucket.org/MattHawkinsUK/rpispy-pi-lite/raw/master/pi_lite_happy_halloween.py

      Or if you use Git on your Pi grab all my Pi-Lite example scripts by cloning my Pi-Lite repository on BitBucket :

      git clone https://bitbucket.org/MattHawkinsUK/rpispy-pi-lite.git

      Modifications

      There are lots of ways you could modify and improve this script. You can change the scrolling message but make sure you adjust the “time.sleep” delay to match. There are more details about how I estimate this time in my hello world scrolling text post. As a rough estimate it is 0.5 seconds per character in your message.

      You could also add other objects by defining new lists and adding them to the dictionary. To generate the 126 character string for each frame you can use my 14×9 LED Matrix Sprite Generator (opens in new window/tab).

      Happy Halloween!

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticlePi-Lite LED Matrix Board Custom Sprites Example
      Next Article Adventures In Raspberry Pi

      Related Posts

      How to Add a Raspberry Pi Pico Reset Button

      Pi Pico Onboard LED

      Add Kodi to RetroPie Menu

      1 Comment

      1. Mike on December 5, 2013 3:37 pm

        Many thanks for this, just what I needed to get Xmas going…

        and for those who need, here’s my animated snow fall:


        snow = ['000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
        '000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
        '000000000000000000100000000010000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
        '001000000000000000000000000010000000101000000010000000000000000100000000000000000000000000000000000000000000000000000000000000',
        '001010000000100000000000000000000000001000000010100000001000000100000000010000000100000000000000000000000000000000000000000000',
        '000010000000101000000010000000000000100000000000100000001010000000100000010000000101000000010000000000000000000000000000000000',
        '010000000000001000000010100000001000100000000010000000100010000000101000000010000001000000010100000001000000000000000000000000',
        '010100000001000000100000100000001010000000100010000000101000000010001000000010100000001000000100000001010000000100000000000000',
        '000100000001010000100100000010000010100000101000000010001000000010100000001000100000001010000000100000010000000101000000010000',
        '000000000000010000000101000010010000101000001010000010000000001000100000001010000000100010000000101000000010000001000000010100',
        '000000000000000000000001000000010100001001000010100000001000001000000000000010000000101000000010001000000010000000001000000100',
        '000000000000000000000000000000000100000001010000100100001010000000100000000000000000001000000010100000001000000000001000000000',
        '000000000000000000000000000000000000000000010000000101000010010000101000000010000000000000000000100000001010000000100000000000',
        '000000000000000000000000000000000000000000000000000001000000010000001001000010100000001000000000000000000010000000101000000010',
        '000000000000000000000000000000000000000000000000000000000000000000000001000000100000001010000000100000000000000000001000000010',
        '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000101000000010000000000000000000',
        '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000010000000001000000000',
        '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000',
        '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000']

        Reply

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      March 13, 2023

      Elecrow Meteor IPS Touchscreen with RGB LEDs

      December 26, 2022

      Pi Pico Pinout Display on the Command Line

      December 23, 2022

      How to Add a Raspberry Pi Pico Reset Button

      November 20, 2022

      Pi Pico Onboard LED

      November 14, 2022

      Pi Pico W Pinout and Power Pins

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Pico
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter Kodi LCD LED Linux media Minecraft Model A motionEyeOS PCB photography photos Pi-Lite Pi Pico power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI SSH temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      March 13, 2023

      Elecrow Meteor IPS Touchscreen with RGB LEDs

      December 26, 2022

      Pi Pico Pinout Display on the Command Line

      December 23, 2022

      How to Add a Raspberry Pi Pico Reset Button

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      mastodon.social@RPiSpy

      Type above and press Enter to search. Press Esc to cancel.