<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Micropython, CardComputer - issue reading Keyboard]]></title><description><![CDATA[<p dir="auto">Hi, I've sucessfully installed the most recent ESP32S3 build of Micropython on my M5Stack CardComputer. Due to it being a generic build, there are no specific device drivers included with the firmware; however, I've managed to get some integrated peripherals working, ie the LCD, sdCard.<br />
The keyboard (<a href="https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/products/core/Cardputer/Sch_M5Cardputer.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">schematic</a>) in giving me some problems, its a pretty standard key matrix, the rows are provides using a 74hc138 3-8 line decoder, and the columns are 7 GPIOs. The outputs from the decoder are active low (<a href="https://www.diodes.com/assets/Datasheets/74HC138.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">datasheet</a>), so I made the column pins inputs with pullups - doesnt work, needs pulldowns????<br />
Reading the column pins whilst iterating through the 8 rows should allow the individual key detection, but although key presses yield a pin change it doesn't work as expected and column 2 is always high???</p>
<pre><code>    from time import sleep_ms
    from machine import Pin

    '''
     M5Stack CardComputer Keyboard 
     74HC138 3 to 8 line decoder
    
     Decoder Pin   A2, A1, A0   ----\    Y6, Y5, Y4, Y3, Y2,  Y1,  Y0       
     GPIO Pin     G11, G9, G8   ----/    G7, G6, G5, G4, G3, G15, G13     
    '''
    
    class KeyBoard():
        def __init__(self):
            keyPins = [ ('C0', 13, Pin.IN, Pin.PULL_DOWN), ('C1', 15, Pin.IN, Pin.PULL_DOWN), ('C2', 3, Pin.IN, Pin.PULL_DOWN),
                        ('C3',  4, Pin.IN, Pin.PULL_DOWN), ('C4',  5, Pin.IN, Pin.PULL_DOWN), ('C5', 6, Pin.IN, Pin.PULL_DOWN),
                        ('C6',  7, Pin.IN, Pin.PULL_DOWN),
                        ('A0',  8, Pin.OUT, None), ('A1', 9, Pin.OUT, None), ('A2', 11, Pin.OUT, None) ]
    
            ap = dict()
            for (name, pin, direction, pull) in keyPins:
                self.pinMap[name] = Pin(pin, direction, pull) 

        def scan(self):
            for row in range(0,8):
                self.pinMap['A0'].value( row &amp; 0b001 )
                self.pinMap['A1'].value( row &amp; 0b010 &gt;&gt; 1 )
                self.pinMap['A2'].value( row &amp; 0b100 &gt;&gt; 2 )
                sleep_ms(250)
                print(f'{row:04b}\t',end='')
                for col in ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6']:
                    sleep_ms(0)
                    val = self.pinMap[col].value()
                    print(f'{val:01b} ', end='')
                print('')
            print('\n\n\n\n')
        
keyboard = KeyBoard()
while True:
    keyboard.scan()
    sleep_ms(500)
</code></pre>
<p dir="auto">Any ideas of where I'm going wrong??</p>
]]></description><link>https://community.m5stack.com/topic/5865/micropython-cardcomputer-issue-reading-keyboard</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 10:59:51 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/5865.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 03 Dec 2023 14:54:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Sat, 20 Jan 2024 18:41:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felipeparaizo" aria-label="Profile: felipeparaizo">@<bdi>felipeparaizo</bdi></a> said in <a href="/post/23415">Micropython, CardComputer - issue reading Keyboard</a>:</p>
<blockquote>
<p dir="auto">Não, qual seria esse driver ? como posso adicionar ?</p>
</blockquote>
<p dir="auto">Você precisa fazer upload do driver Micropython para a tela ST7789V2 no micropython usando thonny.</p>
]]></description><link>https://community.m5stack.com/post/23417</link><guid isPermaLink="true">https://community.m5stack.com/post/23417</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Sat, 20 Jan 2024 18:41:01 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Sat, 20 Jan 2024 16:29:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ajb2k3" aria-label="Profile: ajb2k3">@<bdi>ajb2k3</bdi></a> said in <a href="/post/23340">Micropython, CardComputer - issue reading Keyboard</a>:</p>
<blockquote>
<p dir="auto">Você adicionou um driver para controlar a tela?</p>
</blockquote>
<p dir="auto">Não, qual seria esse driver ? como posso adicionar ?</p>
]]></description><link>https://community.m5stack.com/post/23415</link><guid isPermaLink="true">https://community.m5stack.com/post/23415</guid><dc:creator><![CDATA[felipeparaizo]]></dc:creator><pubDate>Sat, 20 Jan 2024 16:29:46 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Sun, 14 Jan 2024 07:49:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felipeparaizo" aria-label="Profile: felipeparaizo">@<bdi>felipeparaizo</bdi></a> said in <a href="/post/23333">Micropython, CardComputer - issue reading Keyboard</a>:</p>
<blockquote>
<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/martynw" aria-label="Profile: martynw">@<bdi>martynw</bdi></a>, I've been trying for a while to get my CardComputer's screen to work with Micropython code. I want to display a simple "hello world," but I'm having trouble. Could you help me? Could you show your code for activating the screen and writing anything on it?</p>
</blockquote>
<p dir="auto">Have you added a driver to control the screen?</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thijsnl" aria-label="Profile: thijsnl">@<bdi>thijsnl</bdi></a> said in <a href="/post/23339">Micropython, CardComputer - issue reading Keyboard</a>:</p>
<blockquote>
<p dir="auto">Hello MartynW</p>
<p dir="auto">how do you use just the machine library. When I try this the m5stack gives an error.<br />
When I use the m5stack lib I don't have any problems with this</p>
</blockquote>
<p dir="auto">What's is the error?</p>
]]></description><link>https://community.m5stack.com/post/23340</link><guid isPermaLink="true">https://community.m5stack.com/post/23340</guid><dc:creator><![CDATA[ajb2k3]]></dc:creator><pubDate>Sun, 14 Jan 2024 07:49:01 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Sun, 14 Jan 2024 07:43:31 GMT]]></title><description><![CDATA[<p dir="auto">Hello MartynW</p>
<p dir="auto">how do you use just the machine library. When I try this the m5stack gives an error.<br />
When I use the m5stack lib I don't have any problems with this</p>
]]></description><link>https://community.m5stack.com/post/23339</link><guid isPermaLink="true">https://community.m5stack.com/post/23339</guid><dc:creator><![CDATA[thijsnl]]></dc:creator><pubDate>Sun, 14 Jan 2024 07:43:31 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Sat, 13 Jan 2024 15:44:34 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/martynw" aria-label="Profile: martynw">@<bdi>martynw</bdi></a>, I've been trying for a while to get my CardComputer's screen to work with Micropython code. I want to display a simple "hello world," but I'm having trouble. Could you help me? Could you show your code for activating the screen and writing anything on it?</p>
]]></description><link>https://community.m5stack.com/post/23333</link><guid isPermaLink="true">https://community.m5stack.com/post/23333</guid><dc:creator><![CDATA[felipeparaizo]]></dc:creator><pubDate>Sat, 13 Jan 2024 15:44:34 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Mon, 04 Dec 2023 15:05:07 GMT]]></title><description><![CDATA[<p dir="auto">Felix,</p>
<p dir="auto">Thank you for the extra pair of eyes much appreciated, I got so obsessed with the PULL_UP/PULL_DOWN issue, I didn't even consider the processing order of the bitwise logic!! Many thanks.</p>
<p dir="auto">Martyn</p>
]]></description><link>https://community.m5stack.com/post/22957</link><guid isPermaLink="true">https://community.m5stack.com/post/22957</guid><dc:creator><![CDATA[MartynW]]></dc:creator><pubDate>Mon, 04 Dec 2023 15:05:07 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython, CardComputer - issue reading Keyboard on Sun, 03 Dec 2023 19:29:29 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/martynw" aria-label="Profile: MartynW">@<bdi>MartynW</bdi></a></p>
<p dir="auto">I tried your code and changed two things to make it work:</p>
<ul>
<li>changed the inputs to pullups (as you already thought it should be) - the output matrix then is all 1s except for the button pressed.</li>
<li>used some additional brackets for A1 and A2 to force the AND operation to happen first</li>
</ul>
<pre><code>            self.pinMap['A0'].value( row &amp; 0b001 )
            self.pinMap['A1'].value( ( row &amp; 0b010 ) &gt;&gt; 1 )
            self.pinMap['A2'].value( ( row &amp; 0b100 ) &gt;&gt; 2 )

</code></pre>
<p dir="auto">Full code:</p>
<pre><code>from time import sleep_ms
from machine import Pin

    
class KeyBoard():
    def __init__(self):
      keyPins = [ ('C0', 13, Pin.IN, Pin.PULL_UP), ('C1', 15, Pin.IN, Pin.PULL_UP), ('C2', 3, Pin.IN, Pin.PULL_UP),
                  ('C3',  4, Pin.IN, Pin.PULL_UP), ('C4',  5, Pin.IN, Pin.PULL_UP), ('C5', 6, Pin.IN, Pin.PULL_UP),
                  ('C6',  7, Pin.IN, Pin.PULL_UP),
                  ('A0',  8, Pin.OUT, None), ('A1', 9, Pin.OUT, None), ('A2', 11, Pin.OUT, None) ]
    
      self.pinMap = dict()
      for (name, pin, direction, pull) in keyPins:
          self.pinMap[name] = Pin(pin, direction, pull) 

    def scan(self):
        for row in range(0,8):
            self.pinMap['A0'].value( row &amp; 0b001 )
            self.pinMap['A1'].value( ( row &amp; 0b010 ) &gt;&gt; 1 )
            self.pinMap['A2'].value( ( row &amp; 0b100 ) &gt;&gt; 2 )
            sleep_ms(250)
            print(f'{row:04b}\t',end='')
            for col in ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6']:
                sleep_ms(0)
                val = self.pinMap[col].value()
                print(f'{val:01b} ', end='')
            print('')
        print('\n\n\n\n')

    def scan2(self):
        for row in (7, 3, 6, 2, 5, 1, 4, 0):
            self.pinMap['A0'].value( row &amp; 0b001 )
            self.pinMap['A1'].value( ( row &amp; 0b010 ) &gt;&gt; 1 )
            self.pinMap['A2'].value( ( row &amp; 0b100 ) &gt;&gt; 2 )
            sleep_ms(250)
            print(f'{row:04b}\t',end='')
            for col in ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6']:
                sleep_ms(0)
                val = self.pinMap[col].value()
                print(f'{val:01b} ', end='')
            print('')
        print('\n\n\n\n')


keyboard = KeyBoard()
while True:
    keyboard.scan()
#    keyboard.scan2()
    sleep_ms(500)
</code></pre>
<p dir="auto">BTW: I like your coding style with the pinMap etc. (Note: I am not very familiar with Micropython.)</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/22953</link><guid isPermaLink="true">https://community.m5stack.com/post/22953</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Sun, 03 Dec 2023 19:29:29 GMT</pubDate></item></channel></rss>