Solutions to exercise 13: Seven Segment display and Keypad

The Seven Segment Display and the TM1637 controller chip

Exercise 1:

Writing a bit banging driver is a non-trivial task. Not only must you correctly set the signal levels but you also must get the timing of the signals right. All this must be done by programming GPIO pins. But how can you make sure the signals have the shape they should have as described in the chip's data sheet? The best way of course is to observe the signals on an oscilloscope. If you don't have a scope at hand then you can try to log the signals and their timing To files.

This is the strategy I opted for: Each time I set a signal to either the dio or the clk pin I write this event into a log file. as long as I wait, I copy the current signals levels onto the log file.

Before starting to write the actual driver I only try to transfer a byte, making sure the chip answers with the expected acknowledge signal, and plot the log file for control.

tm1637_timing.png

You can clearly the see sequence:

  • first the start sequence: dio going from high to low while clk is high
  • then the 8 data bits (here I send the value 0x55)
  • reading the acknowledge signal on the nineth clock cycle
  • and finally the stop sequence: dio going from low to high while clk is high
Please compare this plot with the timing diagrams from the TM1637 data sheet.

The driver tm1637.py has the following methods:

  • start_transfer: implements the start sequence of the protocol
  • write_bit(bit): write a single bit, cannot be called separately but is used by write_byte
  • write byte(data): write the bit data and check for the acknowledge from the tm1637 chip
  • stop_transfer: implement the stop sequence
The above three methods are foreseen for internal use.
  • display_on: switch the display on. To be call once at the beginning off your code
  • clear_digits(colon): blank the display. If colon is True, the colon is switched on
  • write_digit(digit_num,digit,colon): write the value digit to digit number digit_num. If digit_num is the second digit (digits are counted from zero) and color is true then the colon is also switched on
  • write_hex(number,colon): write the 16 bit hex number number to the display. If colon is true then the colon will also be switched on
  • write_dec(number,colon): same as write_hex but for decimal numbers.
In addition to the driver itself, which must be uploaded to the ESP32 before use

ampy put tm1637.py /lib/tm1637.py

the test program itestTM1637.py s provided showing how to use the driver.

If you want to see the timing diagram you should set tm1637.debug to true. Like this each setting of the dio or clk line is recorded. At the end of the program you can write these data to files on the ESP32 file system and transfer them with ampy:

ampy get /data/dio.txt > dio.txt

ampy get /data/clk.txt > clk.txt

Have a look at testTM1637_debug.py to find out how to write these files. The /data directory must be prepared on the ESP32 before.

The Keypad

Exercise 1:

-- Uli Raich - 2021-01-22

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng tm1637_timing.png r1 manage 34.6 K 2021-01-22 - 13:49 UliRaich  
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r2 - 2021-01-22 - UliRaich
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback