Coder Social home page Coder Social logo

pimoroni / piglow Goto Github PK

View Code? Open in Web Editor NEW
134.0 29.0 27.0 626 KB

Python library & examples for the Pimoroni PiGlow

Home Page: https://shop.pimoroni.com/products/piglow

License: MIT License

Python 71.25% Makefile 0.98% Shell 21.43% CSS 2.99% HTML 3.35%

piglow's Introduction

Piglow

The PiGlow is a small add on board for the Raspberry Pi that provides 18 individually controllable LEDs.

Learn more: https://shop.pimoroni.com/products/piglow

This repository contains the library and examples for the PiGlow board.

Installation

Full install ( recommended ):

We've created a super-easy installation script that will install all pre-requisites and get your Piglow up and running in a jiffy. To run it fire up Terminal which you'll find in Menu -> Accessories -> Terminal on your Raspberry Pi desktop like so:

Finding the terminal

In the new terminal window, run our easy installer by typing:

curl -sS https://get.pimoroni.com/piglow | bash

If you choose to download examples you'll find them in /home/pi/Pimoroni/piglow/.

Library install for Python 3:

on Raspbian:

sudo apt-get install python3-piglow

other environments:

sudo pip3 install piglow

Library install for Python 2:

on Raspbian:

sudo apt-get install python-piglow

other environments:

sudo pip2 install piglow

In all cases you will have to enable the i2c bus.

Documentation & Support

Backwards Compatibility

The PiGlow Python library is designed to support examples written for Jason's PiGlow library found here: https://github.com/Boeeerb/PiGlow

It's compatible with the examples, and we've ported some over to show you how it's done.

Using PiGlow

To use the piglow library, you'll probably want to start by importing it:

import piglow

Now, you can turn some LEDs on:

piglow.red(64)

Nothing will happen yet, you've got to update PiGlow with your changes. Why? Because it's quicker! If you're setting up a pattern it costs time and resources to redraw every step of that setup to the PiGlow, so we don't do that. Instead you need to call show like so:

piglow.show()

A bug is a feature you can't turn off, however, so if you want to change that behaviour you can set it after importing piglow:

piglow.auto_update = True

This will turn on auto update, refreshing the PiGlow after each change so you don't have to.

Function Reference

Settings

  • piglow.auto_update - Set to True or False, determines if the PiGlow should automatically update after each LED change
  • piglow.clear_on_exit - Set to True or False, determines if the PiGlow should be cleared on exit

Colours

  • piglow.white( value from 0 to 255 )
  • piglow.blue( value from 0 to 255 )
  • piglow.green( value from 0 to 255 )
  • piglow.yellow( value from 0 to 255 )
  • piglow.orange( value from 0 to 255 )
  • piglow.red( value from 0 to 255 )

Arm, Spoke, Leg, they're all the same thing!

piglow.arm( index from 0 to 2, value from 0 to 255 )

Multiple LEDs in various different ways

The set method accepts a list of LEDs, a list of values, or a single LED or value, or any permutation therein:

piglow.set(0, 255) - sets LED 0 to full brightness

piglow.set([1,3,5,7,9,11,13,15,17],255) - sets all odd LEDs to full brightness

piglow.set(0,[50,50,50]) - let the 3 LEDs starting at index 0 to 50 brightness

Other support for PiGlow

Gordon Henderson (@drogon on Twitter) has very kindly added support for PiGlow into his very popular wiringPi library and even includes a basic command line tool that you can use to control your PiGlow! http://wiringpi.com/dev-lib/piglow/

Simon Walters (@cymplecy) has added awesome PiGlow support to his Raspberry Pi GPIO Scratch library: http://cymplecy.wordpress.com/2013/08/12/scratch-gpio-piglow-support/

Jason Barnett has put together a great Python class and a load of samples: https://github.com/Boeeerb/PiGlow

Ben Lebherz has forked Jasons project and tidied up the code a bit while adding gamma correction: https://github.com/benleb/PyGlow

Manuel Ernst has created a Node.js library: https://github.com/zaphod1984/node-piglow

More information

For more information the datasheet for the SN3218 IC is included in this repository which outlines the complete communication protocol for the chip.

For those wanting to wire up their PiGlow in other ways these are the GPIO pins used by the module:

  • P1 & P17 (3V3)
  • P2 (5V)
  • P14 (GND)
  • P3 (SDA)
  • P5 (SCL)

Special Thanks

A special thanks for Jason Barnett for carrying the PiGlow torch with his original library.

piglow's People

Contributors

benscarb avatar gadgetoid avatar lowfatcode avatar matt-deacalion avatar roguem avatar rowlap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

piglow's Issues

Installation with pip issue

I had these errors while trying to install using pip install

"" ERROR: Command errored out with exit status 1:""

Error: No SMBus

Hi,
I have an up-to-date RPi3 and have plugged my PiGlow into it. I ran the install script, which didn't throw any errors, but the example scripts all fail to run. Looks like maybe an incompatibility between Python 2/3?

$ ./cycle.py 
0
Traceback (most recent call last):
  File "/home/pi/Pimoroni/piglow/examples/cycle.py", line 14, in <module>
    piglow.show()
  File "/usr/lib/python3/dist-packages/piglow.py", line 126, in show
    setup()
  File "/usr/lib/python3/dist-packages/piglow.py", line 323, in setup
    import sn3218
  File "/usr/lib/python3/dist-packages/sn3218.py", line 108, in <module>
    i2c = SMBus(i2c_bus_id())
FileNotFoundError: [Errno 2] No such file or directory

pip won't install piglow

pi@raspberrypi ~/piglow $ sudo pip install piglow
Downloading/unpacking piglow
Could not find a version that satisfies the requirement piglow (from versions: 1.1dev, 1.2dev)
Cleaning up...
No distributions matching the version for piglow
Storing debug log for failure in /root/.pip/pip.log

pi@raspberrypi ~/piglow $ sudo cat /root/.pip/pip.log
/usr/bin/pip run on Fri Jul 24 01:44:44 2015
Downloading/unpacking piglow
Getting page https://pypi.python.org/simple/piglow/
URLs to search for versions for piglow:
https://pypi.python.org/simple/piglow/
Analyzing links from page https://pypi.python.org/simple/piglow/
Found link https://pypi.python.org/packages/source/p/piglow/piglow-1.1dev.tar.gz#md5=cb9e06c76fd623f9f2d48809773cf458 (from https://pypi.python.org/simple/piglow/), version: 1.1dev
Found link https://pypi.python.org/packages/source/p/piglow/piglow-1.2dev.tar.gz#md5=42ea0e3ae95a2af341d72c38857b1baa (from https://pypi.python.org/simple/piglow/), version: 1.2dev
Ignoring link https://pypi.python.org/packages/source/p/piglow/piglow-1.1dev.tar.gz#md5=cb9e06c76fd623f9f2d48809773cf458 (from https://pypi.python.org/simple/piglow/), version 1.1dev is a pre-release (use --pre to allow).
Ignoring link https://pypi.python.org/packages/source/p/piglow/piglow-1.2dev.tar.gz#md5=42ea0e3ae95a2af341d72c38857b1baa (from https://pypi.python.org/simple/piglow/), version 1.2dev is a pre-release (use --pre to allow).
Could not find a version that satisfies the requirement piglow (from versions: 1.1dev, 1.2dev)
Cleaning up...
No distributions matching the version for piglow
Exception information:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 290, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1178, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 322, in find_requirement
raise DistributionNotFound('No distributions matching the version for %s' % req)
DistributionNotFound: No distributions matching the version for piglow

pi@raspberrypi ~/piglow $ pip --version
pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)

I don't know if this might be related: https://stackoverflow.com/a/18319230

Installer error

When running the curl get.pimoroni.com/piglow | bash command as instructed, it says

sh: line 274: dt_check: command not found

But it then carries on as normal, so I guess it's not quite a fatal error?

Using set method

Great starting material. Although relatively simple, the piglow is making me very enthusiast and it's a nice first experience with addons on the Pi.

The readme suggests the following command: set(0, 255) - sets LED 0 to full brightness
Perhaps this is implied since the sentence above states 'The set method ...' but I guess many people will first find out that set(0, 255) is not what they expect (makes sense) and instead piglow.set(0, 255) should be used. I would suggest to clarify this.

Ring modulo crash

Although the ring() and single() library functions allow any integer value for ring_index, the code crashes when passed certain values due to modulo 7, which should be modulo 6 to correspond with the size of the lists in _legs.

Steps to reproduce, creating a wormhole-in-space effect:

$ cat piglow-ring-modulo-bug.py
import piglow

for x in range(20):
    piglow.ring(x, 100)
    piglow.ring(x+1, 0)
    piglow.show()

$ python3 piglow-ring-modulo-bug.py
Traceback (most recent call last):
  File "/home/pi/piglow-ring-modulo-bug.py", line 5, in <module>
    piglow.ring(x+1, 0)
  File "/home/pi/piglow-pristine/piglow/library/piglow.py", line 181, in ring
    _set([_legs[0][ring_index], _legs[1][ring_index], _legs[2][ring_index]], value)
IndexError: list index out of range

legs.py not working in python3

pi@raspberrypi:~/Pimoroni/piglow$ python3 legs.py
Traceback (most recent call last):
File "legs.py", line 13, in
piglow.set(0, map(lambda x: x - 1 if x > 1 else 0, piglow.get()))
File "/usr/local/lib/python3.4/dist-packages/piglow.py", line 81, in set
_set(leds, value)
File "/usr/local/lib/python3.4/dist-packages/piglow.py", line 110, in _set
_values[leds] = (value % 256)
TypeError: unsupported operand type(s) for %: 'map' and 'int'

Not Compatible After Updating to Debian Bullseye repositories

Hi,

I'm having the following messages if I try to install Piglow
` curl https://get.pimoroni.com/piglow | bash ~
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 38667 100 38667 0 0 16468 0 0:00:02 0:00:02 --:--:-- 16482

This script will install everything needed to use
Piglow

Always be careful when running scripts and commands copied
from the internet. Ensure they are from a trusted source.

If you want to see what this script does before running it,
you should run: 'curl https://get.pimoroni.com/piglow'

--- Warning ---

The Piglow installer
does not work on this version of Raspbian.
Check https://github.com/pimoroni/piglow
for additional information and support
`
and

` sudo apt-get install python3-piglow ~
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libc6-dev : Breaks: libgcc-8-dev (< 8.4.0-2~) but 8.3.0-6+rpi1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
`

The problem occurs if you try to install Piglow after these chaanges:
edit the file /etc/apt/sources.list changing buster to bullseye; edit the file /etc/apt/sources.list.d/raspi.list changing buster to bullseye; sudo apt update; sudo apt upgrade -y

Thanks

tween() without start parameter non-linear fade

start is an optional parameter to tween(), with the documented default of "the current state".

The problem is the implementation literally assigns a reference to the _values list, without taking a copy. As such, when _values changes during the loop, so does start as they refer to the same list.

Link to code at time of writing.

Steps to reproduce:

from piglow import tween

for _ in range(3):
    tween(2.0, [255] * 18)
    tween(2.0, [0] * 18)

for _ in range(3):
    tween(2.0, start=[0]*18, end=[255]*18)
    tween(2.0, start=[255]*18, end=[0]*18)

What happened:
In the first loop, LEDs fade in/out much faster than the second loop.

What's expected:
Both loops give the same result.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.