adafruit_tlc5947

CircuitPython module for the TLC5947 12-bit 24 channel LED PWM driver. See examples/simpletest.py for a demo of the usage.

  • Author(s): Tony DiCola, Walter Haschka

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_tlc5947.TLC5947(spi, latch, *, auto_write=True, num_drivers=1)[source]

TLC5947 12-bit 24 channel LED PWM driver. Create an instance of this by passing in at least the following parameters:

Parameters:
  • spi – The SPI bus connected to the chip (only the SCK and MOSI lines are used, there is no MISO/input).
  • latch – A DigitalInOut instance connected to the chip’s latch line.

Optionally you can specify:

Parameters:
  • auto_write – This is a boolean that defaults to True and will automatically write out all the channel values to the chip as soon as a single one is updated. If you set to False to disable then you MUST call write after every channel update or when you deem necessary to update the chip state.
  • num_drivers – This is an integer that defaults to 1. It stands for the number of chained LED driver boards (DOUT of one board has to be connected to DIN of the next). For each board added, 36 bytes of RAM memory will be taken. The channel numbers on the driver directly connected to the controller are 0 to 23, and for each driver add 24 to the port number printed. The more drivers are chained, the more viable it is to set auto_write=False, and call write explicitly after updating all the channels.
class PWMOut(tlc5947, channel)[source]

Internal PWMOut class that mimics the behavior of CircuitPython’s PWMOut class but is associated with a channel on the TLC5947. You can get and set the instance’s duty_cycle property as a 16-bit PWM value (note there will be quantization errors as the TLC5947 is a 12-bit PWM chip, instead use the TLC5947 class item accessor notation for direct 12-bit raw PWM channel access). Note you cannot change the frequency as it is fixed by the TLC5947 to ~2.4-5.6 mhz.

duty_cycle

Get and set the 16-bit PWM duty cycle value for this channel.

frequency

Frequency of the PWM channel, note you cannot change this and cannot read its exact value (it varies from 2.4-5.6 mhz, see the TLC5947 datasheet).

create_pwm_out(channel)[source]

Create an instance of a PWMOut-like class that mimics the built-in CircuitPython PWMOut class but is associated with the TLC5947 channel that is specified. This PWMOut class has a duty_cycle property which you can read and write with a 16-bit value to control the channel. Note there will be quantization error as the chip only supports 12-bit PWM, if this is problematic use the item accessor approach to update the raw 12-bit channel values.

write()[source]

Write out the current channel PWM values to the chip. This is only necessary to call if you disabled auto_write in the initializer, otherwise write is automatically called on any channel update.