Python

How Banana Pi M3+Adafruit Tlc59711+Led-stripe-->SPI-control-Programm

1 172
Edited by Blacksynonym at May 08, 2017 06:37

Hello,
i am new to the Single-computer-world and I have problems with the control over Spi of Tlc59711.

I have found this code so far:

#!/usr/bin/python

import sys
import spidev as spi# https://github.com/lthiery/SPI-Py
from bitstring import BitArray    # https://pypi.python.org/pypi/bitstring
#spi=spidev.SpiDev()
class Tlc59711:
    """Communicates with the TLC59711"""
    def __init__(self):
        self.outtmg = 1
        self.extgck = 0
        self.tmgrst = 1
        self.dsprpt = 1
        self.blank = 0
        self.brightness = tuple([0b1111111] * 3)  # (R, G, B) brightness
        self.pixels = [(0, 0, 0)] * 4             # (R, G, B) 0-3

    def command(self):
        """The bytes of the command that should update the data"""
        command = BitArray('0b100101') # magic WRITE code
        # make sure the values are single bits
        command += [BitArray(bool=bit) for bit in (
                self.outtmg, self.extgck, self.tmgrst,
                self.dsprpt, self.blank)]
        for b in self.brightness:
            command += BitArray(uint=b, length=7)
        for rgb in self.pixels:
            for color in rgb:
                command += BitArray(uint=color, length=16)
        assert len(command) == 224
        return tuple([ba.uint for ba in command.cut(8)]
    def sendCommand(self, spiMode=3):
        spi.open(mode=spiMode)
        spi.transfer(self.command())
        spi.close()

if __name__ == '__main__':
    tlc = Tlc59711()
    pixels = [min(65535, max(0, int(p))) for p in sys.argv[1:]]
    if len(pixels) == 1:
        tlc.pixels = [tuple(pixels) * 3] * 4
    elif len(pixels) == 3:
        tlc.pixels = [tuple(pixels)] * 4
    elif len(sys.argv) == 12:
        for i in range(4):
            tlc.pixels = tuple(pixels[i*3 : i*3+3])
    else:
        print ("please specify 1, 3, or 12 pixel values 0-65535")
        exit(1)
    #tlc.blank = 1
    print(" ").join(["%02x" % ba for ba in tlc.command()])
tlc.sendCommand()

This program is executed with python tlc59711.py 32768 (set value for channels). Unfortunately, I get this error back.

pi@bpi-iot-ros-ai:~$ python tlc59711.py 32768
96 df ff ff 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
Traceback (most recent call last):
  File "tlc59711.py", line 53, in <module>
    tlc.sendCommand()
  File "tlc59711.py", line 34, in sendCommand
    spi.openSpi(mode=spiMode)
AttributeError: 'module' object has no attribute 'openSpi'

What is wrong with this program (my programming skills are extremely bad)
Is there a simpler code to solve my problem?

I need a code that communicates and runs via Spi: Click Checkbutton1 (on) -> Led1 (Channel 1) on -> Click Checkbutton1 (off) - LED1 off
The circuit configuration is as indicated in the Tlc59711 data sheet. Use GioPins-2 (5V), 6 (ground), 19 (MISO) -> DI, 23 (S_Clk) -> CI


I need your help.
Blacky
This looks legit. Can you help me with my quick research paper? I kinda suck at my college projects

You have to log in before you can reply Login | Sign Up

Points Rules