AnsweredAssumed Answered

mpr121 raspberry pi help

Question asked by phil hall on Oct 2, 2018
Latest reply on Oct 4, 2018 by Tomas Vaverka

hi, 

I've bought a 12 key keypad which has an mpr121 chip built in.

How do i read registers 0x00 and 0x01?

How do i signal that the rq line has been read and can reset to high/floating?

i've got this far with the dummy method `keypad.rq_high

this is my python

 

import RPi.GPIO as GPIO
import posix
from fcntl import ioctl
import time

 

IOCTL_I2C_SLAVE = 0x0703

 

class KEYPAD:

  def __init__(self, i2c, rq_pin, address = 0x5a):
    self._fd = posix.open('/dev/i2c-%d' % i2c, posix.O_RDWR)
    ioctl(self._fd, IOCTL_I2C_SLAVE, address)

    self._rq_pin=rq_pin
    GPIO.setup(self._rq_pin, GPIO.IN, GPIO.PUD_UP)

    self.switch_on()

 

  def _del_(self):
    posix.close(self._fd)

 

  def switch_on(self):
    posix.write(self._fd, b'\x5e\x01')

 

  def rq_high(self):
    return GPIO.input(self._rq_pin) == GPIO.HIGH


GPIO.setmode(GPIO.BCM)

keypad=KEYPAD(1, 23)

try:

  while True:
    if keypad.rq_high():
      print("high", end = '\r')
    else:
      print("low ", end = '\r')

    time.sleep(0.01)

except KeyboardInterrupt:
    pass

 

print("")
GPIO.cleanup()

 

 

I only have switched on a few keys but realise i need to write something different to register 0x5e (probably 0x3f)

Attachments

Outcomes