mmk8283
Posts: 4
Joined: Thu Oct 18, 2018 11:31 am

Communication device -- Help with touch sensor mpr121 Please!

Thu Oct 18, 2018 11:40 am

I'm developing a communication device for my son who has cerebral palsy and is non-verbal, I am a novice at writing code, but I have followed an instructable to make a voice recording playback device. The trouble I have is that the code is set up to use GPIO pins to be hooked to physical buttons. My son has limited capabilities for pressing buttons, and I would like to use touch sensors with the adafruit MPR121 board. I have managed to get the MPR121 installed and recognized, but I cannot figure out how to change the code I have from using the GPIO pins to the I2C input from the MPR121 board.

Please please help]

Below is a link to the instructable with the code I used to make a playback device (uses GPIO pins)
https://www.instructables.com/id/Playba ... pberry-Pi/

Code: Select all

import RPi.GPIO as GPIO
import time
import os
#variables:
butPressed = [True, True, True, True, True, True, True]#if button i is pressed, then butPressed[i] is False
pin = [26, 19, 13, 6, 5, 21, 20]#GPIO pins of each button
recordBool = False#True if a record is in progress
GPIO.setmode(GPIO.BCM)
for i in range(0, 7):
    GPIO.setup(pin[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)#sets Pi's internal resistors to pull-up
while True:
    for i in range(0, 7):
        butPressed[i] = GPIO.input(pin[i])#checks if a button is pressed
        if butPressed[i] == False:#if a button is pressed
            previousTime = time.time()
            while butPressed[i] == False and recordBool == False:
                butPressed[i] = GPIO.input(pin[i])
                if time.time() - previousTime > 1.0:#if the button is pressed for more than a second, then recordBool is True
                    recordBool = True
            if recordBool == True:#if recordBool is True, it plays a beep sound and then records
                os.system("aplay -D plughw:CARD=Device_1,DEV=0 beep.wav")
                os.system("arecord %d.wav -D sysdefault:CARD=1 -f cd -d 20 &" %i)#records for maximum 20 seconds in file i.wav, with cd quality
                while butPressed[i] == False:
                    butPressed[i] = GPIO.input(pin[i])
                os.system("pkill -9 arecord")#the record is stopped when the button is let go, or after 20 seconds
                recordBool = False
            else:#if recordBool is False, it plays sound i.wav
                os.system("aplay -D plughw:CARD=Device_1,DEV=0 %d.wav" %i)
    time.sleep(0.1)

scotty101
Posts: 3182
Joined: Fri Jun 08, 2012 6:03 pm

Re: Communication device -- Help with touch sensor mpr121 Please!

Thu Oct 18, 2018 1:30 pm

Have you read the Adafruit tutorial for the touch sensor
https://learn.adafruit.com/mpr121-capac ... lack/usage

There is a section of code roughly half way down that page that give an example of how to read from the different buttons. I'd create a function to read the buttons, and return "stop", "play", "record", "pause", etc or None depending on whether a button is pressed (but wasn't before) and use that returned value to control the recording/playing.

I don't have the sensor to be able to write something for you but can help debug if you share code and enough information.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

mmk8283
Posts: 4
Joined: Thu Oct 18, 2018 11:31 am

Re: Communication device -- Help with touch sensor mpr121 Please!

Thu Oct 18, 2018 1:35 pm

I've spent many hours trying different things... Trouble is, I'm a complete novice to writing code, I will keep looking at examples and trying to modify/merge things together to get something close. Thanks for sharing the info!

scotty101
Posts: 3182
Joined: Fri Jun 08, 2012 6:03 pm

Re: Communication device -- Help with touch sensor mpr121 Please!

Thu Oct 18, 2018 4:03 pm

mmk8283 wrote:
Thu Oct 18, 2018 1:35 pm
I've spent many hours trying different things... Trouble is, I'm a complete novice to writing code, I will keep looking at examples and trying to modify/merge things together to get something close. Thanks for sharing the info!
Once you have something close, share it and the error messages that you get and the forum will be here to help.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

mmk8283
Posts: 4
Joined: Thu Oct 18, 2018 11:31 am

Re: Communication device -- Help with touch sensor mpr121 Please!

Wed Oct 31, 2018 1:32 pm

I abandoned the mpr121 chip and used the adafruit AT42QT1070 instead. the device works great now! My son now has a 4 section touch sensitive "see-n-say" that can be used to teach symbols for PECS communication!
Attachments
IMG_20181101_055807132.jpg
IMG_20181101_055807132.jpg (191.88 KiB) Viewed 298 times
IMG_20181101_055821114.jpg
IMG_20181101_055821114.jpg (209.68 KiB) Viewed 298 times
touch2.jpg
touch2.jpg (47.48 KiB) Viewed 327 times

Return to “Assistive technology and accessibility”