I'm new to electronics and have been having fun with an esp8266 and Micropython. I'm trying to get a couple of chained shift registers (sn74hc595) working to control 16 leds and am struggling to understand the results I'm getting.
My script is as follows:
from machine import Pin
import time
def sixteen_bit(sleep_time=100):
while True:
for value in [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535]:
bits = [value >> i & 1 for i in range(15, -1, -1)]
for i in range(15, -1, -1):
data.value(bits[i])
clock.value(1)
clock.value(0)
latch.value(1)
latch.value(0)
time.sleep_ms(sleep_time)
It's a bit hard to tell in my video but each led lights up individually before it all repeats. Google Drive Video Example
Based on my code and a rudimentary understanding of shift registers I would expect all leds to light up when [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] is shifted in.
So my first question is why isn't my script lighting up each led with the previous leds still lit? Let me know if you need me to clarify further! Thanks!
I modified your code to print
valuefollowed by the sequence ofbits[i]values you generate, and got:So you're generating the right bit patterns, but you're not clocking the data into the shift register correctly.
Assuming that
data,clockandlatchare actually driving the output pins you think they are, then this is an electronics question rather than a MicroPython question. But I would start by adding a time delay after you take each pin high or low.