I know that this issue has been discussed in this forum, but I am a beginner in electronics and I was unable to come up with a solution to my problem by reading the related threads.
I am doing a 3x5 Led matrix (cathodes are connected row-wise):
I used a raspberry Pi B+ with an MCP23017 GPIO expander, 1000 Ohm resistors and 5mm LEDs (20mA, 3.2V). I used 1000 Ohm just because this is what I had. I turn ON one LED at a time (I believe this is called multiplexing). This is my code for displaying the digit 2:
import smbus
import time
bus = smbus.SMBus(1)
bus.write_byte_data(0x20, 0x00, 0x00)#setting GPIOs of bank A as outputs
bus.write_byte_data(0x20, 0x01, 0x00)#setting GPIOs of bank B to outputs
MATRIX = [[1, 1, 1], [0, 0, 1], [1, 1, 1], [1, 0, 0], [1, 1, 1]]
for k in range(100):
for irow, valr in enumerate(MATRIX):
for icol, valc in enumerate(valr):
A = [0, 0, 0, 0, 0, 0, 0, 0] #the 8 bits to send to bank A of MCP23017
A[7-icol] = 1 #anode of LED to light up set to HIGH
B = [1, 1, 1, 1, 1, 1, 1, 1] #the 8 bits to send to bank B of MCP23017
B[7-irow]=0 #cathode set to LOW
bus.write_byte_data(DEVICE, 0x12, append(int(''.join(str(e) for e in A), 2))) #bank A
bus.write_byte_data(DEVICE, 0x13, append(int(''.join(str(e) for e in B), 2))) #bankB
time.sleep(0.001)
Some LEDs lit despite not being 'told so'. From what I read online, this is due to current leakage. For instance, this is a two:
Where does the problem stem from ? :
- the code?
- The way I drive the LEDs (should I add transistors? (and why?), should I change the value of resistors? should I add pull-up/down resistors?)
I tried alternating between one LED ON then all LEDs OFF (I set all GPIOs to '0') but that didn't solve the problem.