TLC5947 + Beaglebone Black SPI

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
cbeauvois
 
Posts: 3
Joined: Mon Aug 05, 2013 4:51 pm

TLC5947 + Beaglebone Black SPI

Post by cbeauvois »

I got my TLC5947 breakout working on the BBB by looking at the Adafruit_TLC5947 Arduino library, and adapting the code to use Adafruit_BBIO.GPIO. This works great!
Now, I'd like to rewrite this to use the BBB's (2nd) SPI bus. Beyond setting up the bus/device, it seems like the 'write' method is where the magic happens, but I'm at a loss for how to port it to use Adafruit_BBIO.SPI; The TLC5947 page mentions using SPI, is there example code on how to do this that I just missed? Thanks for any help!

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: TLC5947 + Beaglebone Black SPI

Post by tdicola »

You'll want to check out the python spidev module, this is an interface for talking to SPI devices with the hardware's SPI ports. Unfortunately there isn't that much great documentation on using the module, but check out this PDF for some information and a few small examples: http://tightdev.net/SpiDev_Doc.pdf

You might want to skim the kernel's spidev module documentation too. You won't use these APIs directly, but it can help you undestand a little bit about what's happening at a lower level: https://www.kernel.org/doc/Documentation/spi/spidev

Finally it might help to check out some code that uses a SPI device. For example look at MAX31855's _read32 function to see how it calls the spidev read function to grab 4 bytes: https://github.com/adafruit/Adafruit_Py ... 55.py#L113

cbeauvois
 
Posts: 3
Joined: Mon Aug 05, 2013 4:51 pm

Re: TLC5947 + Beaglebone Black SPI

Post by cbeauvois »

Tony, thanks for this. Very helpful and the SpiDev doc was a good read.
It looks like all I need is to adapt 'write' to use SPI when sending out the 12bits per channel:

def write(self):
...
# for each_channel in range((24 * self.DRIVER_COUNT) - 1, 0, -1):
# 12 bits per channel, send MSB first
for each_bit in range(12, 0, -1):
GPIO.output(self.clock_pin, GPIO.LOW)
if (self.pwmbuffer[each_channel] & (1 << each_bit)):
GPIO.output(self.data_pin, GPIO.HIGH)
else:
GPIO.output(self.data_pin, GPIO.LOW)
GPIO.output(self.clock_pin, GPIO.HIGH)

Could it be as simple as:

from Adafruit_BBIO.SPI import SPI

spi = SPI(1,0) # acquire 2nd of BBB's 2 SPI ports, having loaded a proper overlay, etc.

if (self.pwmbuffer[each_channel] & (1 << each_bit)):
spi.write(1)
else:
spi.write(0)

Also, I'm curious about whether to use 'write' or 'xfer/xfer2'?

Thanks again! Hopefully I can put something together that saves someone else some time --

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: TLC5947 + Beaglebone Black SPI

Post by tdicola »

Yeah the write function will just write a list of bytes out the SPI bus, and the xfer/transfer function will both read and write bytes at the same time. The transfer function takes in an array of bytes like the write function does, but it also returns an array of bytes which were read during the write. If you don't care about what the device is sending back to you and just want to send it some data then you probably just need to use the write function.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”