项目作者: RatJuggler

项目描述 :
Display a variety of effects on the Raspberry Pi led-shim from Pimoroni.
高级语言: Python
项目地址: git://github.com/RatJuggler/led-shim-demo.git
创建时间: 2019-07-08T20:26:27Z
项目社区:https://github.com/RatJuggler/led-shim-demo

开源协议:MIT License

下载


led-shim-demo

Over-Engineered

Upload Python Package
PyPi Package

Test & QA
GitHub release (latest by date)

An application to display a variety of effects on the Raspberry Pi led-shim
from Pimoroni.

The effects are based on the examples given in the base library plus some
additions from my fork.

  • Binary Clock - Shows hours, minutes and seconds.
  • Candle - A flickering candle.
  • CheerLights - Synchronize with the CheerLights “Internet of Things” project.
  • Coloured Lights - Simple coloured lights like Xmas lights.
  • Digital Rain - Cut price Matrix effect.
  • Gradient Graph - A moving colour gradient determined by the height of a sine wave.
  • Rainbow - A slowly moving rainbow effect.
  • Random Blink - Some random blinking.
  • Solid Colours - A basic effect which just shows a sequence of solid colours.

If you have more than one Pi with an led-shim you can use the lead/follow commands to share options and perform a simple
synchronised start across them. Be sure to start the follow instances before the lead.

Installing

Install on Raspbian using:

  1. pip3 install ledshimdemo

Or update using:

  1. pip3 install -U ledshimdemo

Running

  1. $ ledshimdemo --help
  2. Usage: ledshimdemo [OPTIONS] COMMAND [ARGS]...
  3. Show various effects on one or more Raspberry Pi's with Pimoroni LED
  4. shim's.
  5. Use the 'display' command for a single Pi. For multiple Pi's one must use
  6. the 'lead' command and the others the 'follow' command. Ensure you start
  7. the followers before starting the lead.
  8. To limit the effects shown use the effect-list option to list the effects
  9. available then add them to the command line as required. Otherwise all
  10. effects will be shown.
  11. Options:
  12. --version Show the version and exit.
  13. -e, --effect-list List the effects available and exit.
  14. -l, --log-level [DEBUG|VERBOSE|INFO|WARNING]
  15. Show additional logging information.
  16. [default: INFO]
  17. --help Show this message and exit.
  18. Commands:
  19. display Display the effects on a single Pi
  20. follow Follow a lead instance.
  21. lead Act as a lead for other instances to follow.
  22. $ ledshimdemo display --help
  23. Usage: ledshimdemo display [OPTIONS] [EFFECTS]...
  24. Display the effects on a single Pi
  25. Options:
  26. -p, --parade [CYCLE|RANDOM] How the effects are displayed. [default:
  27. CYCLE]
  28. -d, --duration INTEGER RANGE How long to display each effect for, in
  29. seconds (1-180). [default: 10]
  30. -r, --repeat INTEGER RANGE How many times to run the effects before
  31. stopping (1-240). [default: 1]
  32. -b, --brightness INTEGER RANGE How bright the effects will be (1-10).
  33. [default: 8]
  34. -i, --invert Change the display orientation.
  35. --help Show this message and exit.
  36. $ ledshimdmeo follow --help
  37. Usage: ledshimdemo follow [OPTIONS] IP_ADDRESS
  38. Follow a lead instance.
  39. Options:
  40. -o, --port INTEGER RANGE Set the port number used for syncing. [default:
  41. 5556]
  42. --help Show this message and exit.
  43. $ ledshimdemo lead --help
  44. Usage: ledshimdemo lead [OPTIONS] IP_ADDRESS [EFFECTS]...
  45. Act as a lead for other instances to follow.
  46. Options:
  47. -p, --parade [CYCLE|RANDOM] How the effects are displayed. [default:
  48. CYCLE]
  49. -d, --duration INTEGER RANGE How long to display each effect for, in
  50. seconds (1-180). [default: 10]
  51. -r, --repeat INTEGER RANGE How many times to run the effects before
  52. stopping (1-240). [default: 1]
  53. -b, --brightness INTEGER RANGE How bright the effects will be (1-10).
  54. [default: 8]
  55. -i, --invert Change the display orientation.
  56. -o, --port INTEGER RANGE Set the port number used for syncing.
  57. [default: 5556]
  58. --help Show this message and exit.

Sample output with the default options:

  1. $ ledshimdemo display
  2. 2019-08-31 15:47:36,864 - INFO - Effect Options(parade=CYCLE, duration=10 secs, repeat=1, brightness=8, invert=False, effects=ALL)
  3. 2019-08-31 15:47:36,864 - INFO - Effect: BinaryClock - Shows hours, minutes and seconds. Update Frequency: 1 secs
  4. 2019-08-31 15:47:47,185 - INFO - Effect: Candle - A flickering candle. Update Frequency: 0.01 secs
  5. 2019-08-31 15:47:57,208 - INFO - Effect: CheerLights - Synchronize with the CheerLights "Internet of Things" project. Update Frequency: 5 secs
  6. 2019-08-31 15:48:07,745 - INFO - Effect: ColouredLights - Simple coloured lights like Xmas lights. Update Frequency: 0.5 secs
  7. 2019-08-31 15:48:17,817 - INFO - Effect: DigitalRain - Cut price Matrix effect. Update Frequency: 0.02 secs
  8. 2019-08-31 15:48:27,820 - INFO - Effect: GradientGraph - Sine wave colour gradient effect. Update Frequency: 0.01 secs
  9. 2019-08-31 15:48:37,826 - INFO - Effect: Rainbow - A slowly moving rainbow. Update Frequency: 0.01 secs
  10. 2019-08-31 15:48:47,861 - INFO - Effect: RandomBlink - Some random blinking. Update Frequency: 0.05 secs
  11. 2019-08-31 15:48:57,875 - INFO - Effect: SolidColours - A sequence of solid colours. Update Frequency: 0.5 secs

Troubleshooting

If you see the error ModuleNotFoundError: No module named 'smbus' you need to run the following install:

  1. sudo apt-get install python3-smbus

The led-shim also requires the I2C interface to be enabled so if you see a message Make sure you've enabled i2c in your Raspberry Pi configuration. you need to run the following command:

  1. sudo raspi-config

Then from the menu select 5. Interface Options and then P5 I2C. Select Yes to enable the interface and then restart you Pi.

However, if anything is going to cause a problem trying to run ledshimdemo it will be NumPy which is used by a couple of the
demos. The NumPy package is included in most builds of Raspbian, but installed with apt-get, this then causes problems if
anything tries to install a different version with pip3. For this reason ledshimdemo includes a dependency on an older version,
or later, hoping to pick up the global installed one. If you get an issue it’s worh trying to uninstalling any pip3 version and
then installing the apt-get version using:

  1. pip3 uninstall numpy
  2. sudo apt-get install python3-numpy

Development

Development is done in a branch and a pull request opened which will trigger the GitHub Actions Test & QA workflow. Once this is
passing the pull request can be used to merge the branch into master. Creating a release will then trigger a build and upload to
PyPi using the GitHub Actions Upload to PyPi workflow.

Addendum

This project is definitely over-engineered and somewhat laboured for what it actually does because it’s being used as a learning
exercise.

The application has a number of output logging levels built into it, including a custom VERBOSE level, to show some of the inner
workings. This is just because.

The effects are loaded dynamically using a mechanism loosely based on code from
this Python3 factory pattern example.

The code coverage for this project is a good example of why measuring unit test coverage can be a misleading indicator of quality.
Whilst it does have plenty of unit tests those for the effects are mostly simple smoke tests which show that the code will run.
They don’t actually confirm that the effects are producing the desired output.

The development work for this project was done using PyCharm on an Intel x64 machine, as the project was designed to be run on an
ARM based Raspberry Pi only a source distribution is uploaded to PyPi. However, when installing under Raspbian it should install
the ARM wheel from PiWheels making the installation much faster. See the
PiWheels FAQ for more information.

The synchronisation using the lead/follow commands is very basic, yes the effect options set for the lead are distributed to the
follow instances but there is only a primitive trigger to try and start the displays together and there is no heartbeat to try to
keep them in sync. If you run with more than about 10 repeat iterations you’ll soon see the displays go out of sync.