Difference: SolutionsToSevenSegmentDisplayAndKeyPad (2 vs. 3)

Revision 32021-01-23 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Solutions"

Solutions to exercise 13: Seven Segment display and Keypad

The Seven Segment Display and the TM1637 controller chip

Changed:
<
<

Exercise 1:

>
>

Exercise 1: The driver and its test program

  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.
Line: 43 to 43
 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.

Added:
>
>

Exercise 2: A clock program

Once the driver is working it is easy to write programs using the seven segment display. As an example we implement a clock program. First we connect to WiFi using the wifi_connect module which also sets the ESP32 real time clock with the current date and time.

Then we create a TM1637 instance, switch the display on and set it with the current time. The cetTime method of wifi_connect gets the current CET time (use gmtTime if you are in the GMT time zone).

Then we provide a callback function for timer interrupts which is triggered every second. The callback function again gets the current time and calls the write_dec method in the tm1637 driver to display the current time. The colon is toggled every second.

 

The Keypad

Changed:
<
<

Exercise 1:

>
>

Exercise 1 and 2:

In order to scan the keypad I set all column pins to input with pull-up. In order to scan I set one of the row pins to output (keeping the other input with pull-up) and I pull this pin to ground. If a button in this row is pressed then a zero will be read on one of the column pins, if not, all column pins will read a high value.

Now cycle all row pins, switching only one of them to output with value zero and read every column pin.

Exercise 1 is implemented in keypad_V1, exercise 2 in keypad_V2.

Exercise 3:

A circular buffer is a data structure found very frequently in embedded systems. In addition to a fixed size buffer it has 2 pointers, one containing the index where the next element is to be written and one containing the index of the next character to be read. When reaching the end of the buffer the pointer cycle back to its start.

This exercises can be developed and tested on the Python version of your PC.

Exercise 4:

In this exercise I set again all columns pins to input but all row pins are set to output with value 0. I attach a GPIO interrupt on the falling edge to each of the column pins.

If any key is pressed, the interrupt is generated. In the interrupt service routine (key_change) I scan the keypad and insert the key value into the circular buffer. The circular buffer methods are used to check if data is available or to read out the key presses that have occurred.

  -- Uli Raich - 2021-01-22
 
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