Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    • Raspberry Pi 400 SSD Upgrade
    • Raspberry Pi Temperature Monitoring
    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
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Add-ons»Pi-Lite LED Matrix Board Python ‘Hello World’ Example
      Pi-Lite LED Matrix Board

      Pi-Lite LED Matrix Board Python ‘Hello World’ Example

      4
      By Matt on September 28, 2013 Add-ons, Tutorials & Help

      If you’ve followed the previous Pi-Lite setup article you should have a working Pi-Lite. The example Python scripts are great but I wanted to show a simple example of my own demonstrating the basics of sending scrolling text to the Pi-Lite.

      Scrolling text is something that the on-board microcontroller handles for you so it really doesn’t involve much effort to do using a short Python script.

      The following script scrolls two messages to demonstrate the technique.

      #!/usr/bin/env python
      
      import sys
      import serial
      import time
      
      # Define message complete with
      # carriage return at the end
      message1 = "Hello World!\r"
      message2 = "Pi-Lite messages are easy!\r"
      
      # Configure Pi serial port
      s = serial.Serial()
      s.baudrate = 9600
      s.timeout = 0
      s.port = "/dev/serial0"
      
      try:
          # Open serial port
          s.open()
      except serial.SerialException, e:
          # There was an error
          sys.stderr.write("could not open port %r: %s\n" % (port, e))
          sys.exit(1)
      
      print "Serial port ready"
      
      # Clear display
      s.write("$$$ALL,OFF\r")
      
      # Send message 1 to the Pi-Lite
      print message1
      s.write(message1)
      
      # Short delay to allow the
      # 12 character message to finish
      time.sleep(6)
      
      # Send message 2 to the Pi-Lite
      print message2
      s.write(message2)
      
      # Short delay to allow the
      # 26 character message to finish
      time.sleep(12)
      
      print "Good bye"
      

      You can create whatever messages you like and add more messages if required. The delays after each message give it time to finish scrolling before more data is sent to the Pi-Lite. If you don’t add the delay you risk sending data before the device has finished dealing with the previous set.

      I use the following quick calculation to estimate the delay required :

      delay = length x 5 x 0.08

      Pi-Lite LED Matrix BoardLength is the number of characters in the message. 5 is the average number of columns per character. 0.08 is the default scroll speed (80ms). The delay is then the time it takes the total number of columns to scroll across the display. You can then round up the value to the nearest whole number of seconds. It is only an approximation and you may need to tweak as appropriate.

      Sticking a message into a “while” loop would allow the message to repeat. For example you can replace the “Serial port ready” line in the above script with this code :

      print "Serial port ready"
      
      # Clear display
      s.write("$$$ALL,OFF\r")
      
      while True:
      
        # Send message 1 to the Pi-Lite
        print message1
        s.write(message1)
      
        # Short delay to allow the
        # 12 character message to finish
        time.sleep(6)
      
        # Send message 2 to the Pi-Lite
        print message2
        s.write(message2)
      
        # Short delay to allow the
        # 26 character message to finish
        time.sleep(12)
      

      Here is a short video of the Pi-Lite in action using the “while” loop above :

      This script is the basis by which you could start sending all sorts of information to the display e.g. time, temperature, web sourced data

      Here are the scripts which you can download directly rather than cutting and pasting the examples above :

      pi_lite_hello_world.py

      pi_lite_hello_world_repeat.py

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleHow To Setup The Pi-Lite LED Matrix Board
      Next Article Cambridge Raspberry Jam Goodies

      Related Posts

      Add Kodi to RetroPie Menu

      Disable Auto-login in Raspberry Pi OS

      Raspberry Pi Cloud Storage with MEGA

      4 Comments

      1. Pete on October 12, 2013 2:25 pm

        Hey when I try to run the code it says error on line 3 import serial

        no module named serial?

        sorry im quite new to all this

        Reply
        • Matt on October 12, 2013 3:25 pm

          Run through Part 1 of my Pi-Lite articles. One of the steps is the installation of the Python Serial module.

          Reply
      2. carlos hernandez on December 3, 2013 3:42 pm

        hello, it is a good blog, but i have a question, if i want to comunicate 2 raspberrys for the serial port, what i can do?

        Reply
      3. Tony Goodhew on December 19, 2013 10:56 am

        Your blogs are so much easier to follow than the ‘Official Documentation’.

        I had to add an extra line to get it to work:
        import sys
        at the top, after import time

        Reply

      Leave A Reply Cancel Reply

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

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      January 7, 2022

      RetroPie Temperature Monitor from Menu

      January 24, 2021

      Pi Pico 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 Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI 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
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      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

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