Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more.
0

TPIC6B595 with CircuitPython?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

TPIC6B595 with CircuitPython?

by sixpence668 on Sun Mar 08, 2020 11:01 am

I'm just dipping my toe into transitioning from Arduino to CircuitPython, and I'm trying to get a sense of some specific capabilities. Namely, is it possible to use TPIC6B595 shift registers with CircuitPython code (via the Feather M4 Express)?

I'm going to be addressing 50 individual segments of one color LED strip, to create a randomized flicker effect. Each section pulls 100mA at 12v, which is why I was looking at the TPIC6B595.

I'm familiar with the Arduino ShiftOut function, but for the life of me, I can't find any information on a similar function for CircuitPython. Am I just not looking in the right place? Alternatively, is there a more efficient way to approach this project?

sixpence668
 
Posts: 32
Joined: Tue Apr 29, 2014 11:23 am

Re: TPIC6B595 with CircuitPython?

by mikeysklar on Sun Mar 08, 2020 12:10 pm

Hi sixpence668,

I'm pretty sure the TPIC6B595 will be compatible with our CircuitPython adafruit_74hc595 library since the chip is just a higher current version of the same underlying architecture. You can see the example code here:

https://circuitpython.readthedocs.io/pr ... en/latest/

This project seems easier to do with neopixels, but maybe there is some limitation to them (speed?) that you need to individually address so many segments.

mikeysklar
 
Posts: 846
Joined: Mon Aug 01, 2016 8:10 pm

Re: TPIC6B595 with CircuitPython?

by sixpence668 on Sun Mar 08, 2020 1:18 pm

Thanks for the information!

The reasoning behind not using neopixels is largely cost. Also, the segments are going to be distributed throughout a garment, and the individual LED's don't need to be addressed, just the groups. (I'm creating a randomized 'lightning' effect)

sixpence668
 
Posts: 32
Joined: Tue Apr 29, 2014 11:23 am

Re: TPIC6B595 with CircuitPython?

by tannewt on Mon Mar 09, 2020 6:32 pm

We do also have a `simpleio` library that is primarily Python functions that act like Arduino functions. It has a `shift_out`. You can see the source here: https://github.com/adafruit/Adafruit_Ci ... io.py#L133

And the docs are here: https://circuitpython.readthedocs.io/pr ... .shift_out

tannewt
 
Posts: 1536
Joined: Thu Oct 06, 2016 8:48 pm

Re: TPIC6B595 with CircuitPython?

by sixpence668 on Sun Mar 15, 2020 4:50 pm

Thanks for the replies! I've started to work through converting my old Arduino code, and I think I've got it mostly figured out.

What the code should do is call a random pin on the shift register, randomly flicker the leds at two different brightnesses, and then repeat on a different random pin. Am I at all on the right track here?

Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
import adafruit_74hc595
import busio
import time
import random
import pulseio

spi = busio.SPI(board.SCK, MOSI=board.MOSI)

latch_pin = digitalio.DigitalInOut(board.D5)
sr = adafruit_74hc595.ShiftRegister74HC595(spi, latch_pin)

random.seed(seed)

led = sr.get_pin(random.randint(1, 16))

def howBright1():
    pulseio.PWMOut(board.A1)
    howBright1.duty_cycle = random.randomint(100, 32767)

def howBright2():
    pulseio.PWMOut(board.A1)
    howBright2.duty_cycle = random.randomint(32767, 65535)

while True:
    setBrightness = howBright1
    led.value = True
    time.sleep(random.uniform(.02, .3))
    setBrightness = howBright2
    time.sleep(random.uniform(.1, .7))
    led.value = False

sixpence668
 
Posts: 32
Joined: Tue Apr 29, 2014 11:23 am

Re: TPIC6B595 with CircuitPython?

by mikeysklar on Wed Mar 18, 2020 5:20 pm

The code looks good. Have you been able to run with the TPIC6B595?

mikeysklar
 
Posts: 846
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.