micropython-tm1638 icon indicating copy to clipboard operation
micropython-tm1638 copied to clipboard

ESP32-WROOM-32

Open VladimirAstrelin opened this issue 2 years ago • 8 comments

Dear Sirs, thanks a lot for your great libraries for TM1637 & TM1638. Everything works just fine except keys(buttons) in your library for TM1638.

while True:
    pressed = tm.keys()
    for i in range(8):
        tm.led(i, (pressed >> i) & 1)
    sleep_ms(10)

This piece of code doesn't turn on LEDs on the board. Please let me know what might go wrong. Many thanks in advance, Vlad, Ukraine.

VladimirAstrelin avatar Jul 16 '23 13:07 VladimirAstrelin

Hi @VladimirAstrelin which board are you using the library with?

mcauser avatar Jul 17 '23 04:07 mcauser

Dear Sir, I use ESP32-WROOM-32 as I mentioned in the subject to my message. Here's a little more detailed description: ESP32 Type-C CH340 2.4GH Dual Mode WiFi+Bluetooth Dual Core ESP32-WROOM-32 Dev Board Thanks for answering my message. I hope my reply will help. Thanks again for your libraries ! I would like to understand better how they work. Warmest regards, Vlad, Ukraine.

VladimirAstrelin avatar Jul 17 '23 06:07 VladimirAstrelin

Hi, I meant, which TM16xx board were you trying to use this library with. Not the microcontroller using it.

mcauser avatar Jul 17 '23 07:07 mcauser

I use this one:

https://www.aliexpress.com/i/32893633739.html

TM1638 Key Module 8-Bit Digital LED Display Tube Module Board 7 Segment 8 Bits RED TM1638 KEY LED Display Panel

Thanks for your support.

VladimirAstrelin avatar Jul 17 '23 08:07 VladimirAstrelin

I am using the same board. I just tried your code on mine and it works as expected.

  • Press S1 and LED 1 lights up.
  • Press S2 and LED 2 lights up.

Hopefully they haven't changed any wiring on newer boards. Mine is a few years old now.

You could try power cycling the board:

tm.power(0)
tm.power(1)
tm.led(0,1)

You can try calling tm.write() to see if it turns the correct LEDs on. It expects a byte array of up to 16 bytes.

byte0 - 1st 7 segment (below LED1)
byte1 - LED1
byte2 - 2nd 7 segment
byte3 - LED2
byte4 - 3rd 7 segment
byte5 - LED3
...
byte14 - 8th 7 segment (right most)
byte15 - LED8

Turn all segments and LEDs on:

tm.write(bytearray([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]))

Turn all segments on, all LEDs off:

tm.write(bytearray([255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0]))

Turn all LEDs on, all segments off:

tm.write(bytearray([0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]))
# only the LSB is used, so effectively the same as:
tm.write(bytearray([0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1]))

If you press and hold S1 and call tm.keys() does it give you 1? Hold both S1 and S2 and you should get 3.

mcauser avatar Jul 17 '23 12:07 mcauser

  1. If you press and hold S1 and call tm.keys() does it give you 1? --- No, it doesn't. It gives zero. What pins on ESP32 do you use for STB, CLK and DIO ? What's the role of STB ? Maybe the problem with keys is about wrong wiring of STB ?
  2. LEDs ( LED1...LED8) work fine, Seven-segmen LEDs work fine...but keys do not react...nothing happens when I press them..

VladimirAstrelin avatar Jul 17 '23 13:07 VladimirAstrelin

Here is the photo on My ESP32 with TM1638 board, as you can see ALL LEDs and 7-segments are working just fine. But keys do not react at all. Here is the link to the photo: https://drive.google.com/drive/folders/11qr3VCV6V0n5WOEQ1qmSY4h-VdYr-_5w?usp=sharing Here is my code:

from time import sleep_ms from machine import Pin import tm1638

tm = tm1638.TM1638(stb=Pin(13), clk=Pin(22), dio=Pin(21))

turn them on, one by one

for i in range(8): tm.led(i, 1) sleep_ms(200)

turn them off, one by one

for i in range(8): tm.led(i, 0) sleep_ms(200)

toggle 1st LED

tm.led(0, 1) tm.led(0, 0)

toggle the 2nd LED

tm.led(1, True) tm.led(1, False)

turn on only the 4th LED

tm.leds(8)

turn on only the first 3 LEDs

tm.leds(7)

every 2nd led on

for i in range(10): tm.leds(0b01010101) sleep_ms(100) tm.leds(0b10101010) sleep_ms(100)

leds off

tm.leds(0)

THIS PART BELOW DOESN'T WORK:

while True: pressed = tm.keys() for i in range(8): tm.led(i, (pressed >> i) & 1) sleep_ms(10)

VladimirAstrelin avatar Jul 17 '23 13:07 VladimirAstrelin

STB is strobe, DIO is data in/out, CLK is clock.

I'm using a TinyPICO ESP32 with pins:

tm = tm1638.TM1638(stb=Pin(5), clk=Pin(18), dio=Pin(23))

So it looks like it's mostly working. I think it might be trying to loop too fast. Try increasing the sleep_ms(10) to 500 and see if that works. 10ms works fine on mine. Just trying to rule that out.

Little test I put together, which prints whats happening inside tm.keys()

def test():
	tm.stb(0)
	tm._byte(66)
	for i in range(4):
		print(tm._scan_keys())
	tm.stb(1)

Press = 4x printed values
S1 = 1 0 0 0
S2 = 0 1 0 0
S3 = 0 0 1 0
S4 = 0 0 0 1
S5 = 16 0 0 0
S6 = 0 16 0 0
S7 = 0 0 16 0
S8 = 0 0 0 16

mcauser avatar Jul 17 '23 14:07 mcauser