Ich habe ein paar Touch-Sensormodule mit einem MPR121 (Freescale) in die Hände bekommen.
Das Modul hat 12 Sensorfelder und der Chip als Komunikationsweg I²C plus einen IRQ-Ausgang der aktiv(0) wird wenn sich an den Sensorfeldern etwas ändert.
nxp.com/docs/en/data-sheet/MPR121.pdf
Der MPR121 wird zwar nicht mehr produziert, aber die Module sind zu Hauf (noch) beim freundlichen Chinesen u. a. zu bekommen. Leider war kein Bascom-Code zu finden.
Also diy:
Alles anzeigen
Die Software basiert auf der App. Note 3944 vom Hersteller:
nxp.com/docs/en/application-note/AN3944.pdf
Bei der Hardware ist zu beachten, das der MPR121 mit 3,3V läuft. Es gibt aber auch Module die den Pegelwandler schon integriert haben.
LG
Das Modul hat 12 Sensorfelder und der Chip als Komunikationsweg I²C plus einen IRQ-Ausgang der aktiv(0) wird wenn sich an den Sensorfeldern etwas ändert.
nxp.com/docs/en/data-sheet/MPR121.pdf
Der MPR121 wird zwar nicht mehr produziert, aber die Module sind zu Hauf (noch) beim freundlichen Chinesen u. a. zu bekommen. Leider war kein Bascom-Code zu finden.
Also diy:
BASCOM-Quellcode
- '-------------------------------------------------------------------------------
- '
- 'Touch Sensor
- 'MPR121 (freescale) A C H T U N G ! VCC=3,3V >>>> Pegelwandler verwenden!
- '.............................................oder 3V3 µC-Board
- 'Arduino NANO / UNO ........o.ä.
- '
- 'Nov.2018 by Mandarin15
- '
- 'Demo mit Minimal-Konfiguration
- '
- '-------------------------------------------------------------------------------
- $regfile = "m328pdef.dat"
- $crystal = 16000000
- $hwstack = 64
- $swstack = 32
- $framesize = 64
- Config Portb.5 = Output
- Led Alias Portb.5
- '________________________________________________________________________________Register lt. Datenblatt / AN3944
- Mhd_rising Alias &H2B
- Nhd_amount_rising Alias &H2C
- Ncl_rising Alias &H2D
- Fdl_rising Alias &H2E
- Mhd_falling Alias &H2F
- Nhd_amount_falling Alias &H30
- Ncl_falling Alias &H31
- Fdl_falling Alias &H32
- Ele0_touch_threshold Alias &H41
- Ele0_release_threshold Alias &H42
- Ele1_touch_threshold Alias &H43
- Ele1_release_threshold Alias &H44
- Ele2_touch_threshold Alias &H45
- Ele2_release_threshold Alias &H46
- Ele3_touch_threshold Alias &H47
- Ele3_release_threshold Alias &H48
- Ele4_touch_threshold Alias &H49
- Ele4_release_threshold Alias &H4A
- Ele5_touch_threshold Alias &H4B
- Ele5_release_threshold Alias &H4C
- Ele6_touch_threshold Alias &H4D
- Ele6_release_threshold Alias &H4E
- Ele7_touch_threshold Alias &H4F
- Ele7_release_threshold Alias &H50
- Ele8_touch_threshold Alias &H51
- Ele8_release_threshold Alias &H52
- Ele9_touch_threshold Alias &H53
- Ele9_release_threshold Alias &H54
- Ele10_touch_threshold Alias &H55
- Ele10_release_threshold Alias &H56
- Ele11_touch_threshold Alias &H57
- Ele11_release_threshold Alias &H58
- Filter_cfg Alias &H5D
- Electrode_cfg Alias &H5E
- Gpio_ctrl_reg_0 Alias &H73 'GPIO auf meinem Board nicht verfügbar
- Gpio_ctrl_reg_1 Alias &H74
- Gpio_data_reg Alias &H75
- Gpio_dir_ctrl_reg Alias &H76
- Gpio_enable_reg Alias &H77
- Gpio_data_set_reg Alias &H78
- Gpio_data_clear_reg Alias &H79
- Gpio_data_toggle_reg Alias &H7A
- Auto_cfg_control_0 Alias &H7B
- Auto_cfg_usl Alias &H7D
- Auto_cfg_lsl Alias &H7E
- Auto_cfg_target_level Alias &H7F
- Touch_threshold Alias &H0F
- Release_threshold Alias &H0A
- Mpr121_read_adr Alias &HB5
- Mpr121_write_adr Alias &HB4
- '_______________________________________________________________________________
- Dim Touch As Boolean 'Neue Daten von MPR121
- Dim Touchstatus As Word
- Dim Touchstatus_l As Byte At Touchstatus Overlay
- Dim Touchstatus_h As Byte At Touchstatus + 1 Overlay
- Config Pind.2 = Input 'IRQ! von MPR121 (Active Low Open-drain Interrupt Output)
- Portd.2 = 1 'Pullup
- Config Int0 = Falling 'PIND.2
- Enable Int0
- On Int0 Int0_irq
- $lib "i2c_TWI.lib"
- Config Scl = Portc.5 'Ports fuer IIC-Bus
- Config Sda = Portc.4
- Config Twi = 400000
- Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'USB_debug
- Declare Sub Mpr121write(byval Reg_address As Byte , Byval Daten As Byte)
- Declare Function Mpr121read(byval Read_register As Byte ) As Byte
- '-------------------------------------------------------------------------------
- I2cinit
- Gosub Mpr121config
- Enable Interrupts
- Print "START MPR121 Demo"
- '###############################################################################
- '###############################################################################
- Do
- If Touch = 1 Then
- Print Bin(touchstatus)
- Touch = 0
- Led = 0
- End If
- Loop
- '###############################################################################
- '###############################################################################
- '_______________________________________________________________________________
- Int0_irq:
- 'MPR121 Irq
- Touchstatus_l = Mpr121read(&H00)
- Touchstatus_h = Mpr121read(&H01)
- Touch = 1 'neue Daten
- Led = 1
- Return
- '_______________________________________________________________________________
- Mpr121config:
- 'Section A
- 'This group of setting controls the filtering of the system when the data is greater than the baseline
- Call Mpr121write(mhd_rising , &H01)
- Call Mpr121write(nhd_amount_rising , &H01)
- Call Mpr121write(ncl_rising , &H00)
- Call Mpr121write(fdl_rising , &H00)
- 'Section B
- 'This group of setting controls the filtering of the system, when the data is less than the baseline
- Call Mpr121write(mhd_falling , &H01)
- Call Mpr121write(nhd_amount_falling , &H01)
- Call Mpr121write(ncl_falling , &HFF)
- Call Mpr121write(fdl_falling , &H02)
- 'Section C
- 'The touch threshold registers set the minimum delta from the baseline when a touch is detected
- Call Mpr121write(ele0_touch_threshold , Touch_threshold)
- Call Mpr121write(ele0_release_threshold , Release_threshold)
- Call Mpr121write(ele1_touch_threshold , Touch_threshold)
- Call Mpr121write(ele1_release_threshold , Release_threshold)
- Call Mpr121write(ele2_touch_threshold , Touch_threshold)
- Call Mpr121write(ele2_release_threshold , Release_threshold)
- Call Mpr121write(ele3_touch_threshold , Touch_threshold)
- Call Mpr121write(ele3_release_threshold , Release_threshold)
- Call Mpr121write(ele4_touch_threshold , Touch_threshold)
- Call Mpr121write(ele4_release_threshold , Release_threshold)
- Call Mpr121write(ele5_touch_threshold , Touch_threshold)
- Call Mpr121write(ele5_release_threshold , Release_threshold)
- Call Mpr121write(ele6_touch_threshold , Touch_threshold)
- Call Mpr121write(ele6_release_threshold , Release_threshold)
- Call Mpr121write(ele7_touch_threshold , Touch_threshold)
- Call Mpr121write(ele7_release_threshold , Release_threshold)
- Call Mpr121write(ele8_touch_threshold , Touch_threshold)
- Call Mpr121write(ele8_release_threshold , Release_threshold)
- Call Mpr121write(ele9_touch_threshold , Touch_threshold)
- Call Mpr121write(ele9_release_threshold , Release_threshold)
- Call Mpr121write(ele10_touch_threshold , Touch_threshold)
- Call Mpr121write(ele10_release_threshold , Release_threshold)
- Call Mpr121write(ele11_touch_threshold , Touch_threshold)
- Call Mpr121write(ele11_release_threshold , Release_threshold)
- 'Section D
- 'There are three settings embedded in this register so it is only necessary to pay attention to one
- Call Mpr121write(filter_cfg , &H04)
- 'Section E
- 'Electrode Configuration
- Call Mpr121write(electrode_cfg , &H0C) 'Enable 12 Electrodes
- 'Section F
- 'Enable Auto Config and auto Reconfig
- 'call mpr121Write(Auto_cfg_control_0, &H0B)
- 'call Mpr121write(Auto_cfg_usl , &H9C)
- 'call Mpr121write(Auto_cfg_lsl , &H65)
- 'call Mpr121write(Auto_cfg_target_level , &H8C)
- Return
- '_______________________________________________________________________________
- Sub Mpr121write(byval Reg_address As Byte , Byval Daten As Byte)
- I2cstart
- I2cwbyte Mpr121_write_adr 'write 0xB4
- I2cwbyte Reg_address 'write register reg_Address
- I2cwbyte Daten
- I2cstop
- End Sub
- '_______________________________________________________________________________
- Function Mpr121read(byval Read_register As Byte ) As Byte
- Local Read_data As Byte
- I2cstart
- I2cwbyte Mpr121_write_adr
- I2cwbyte Read_register
- I2crepstart
- I2cwbyte Mpr121_read_adr
- I2crbyte Read_data , Nack
- I2cstop
- Mpr121read = Read_data
- End Function
- '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- End
Die Software basiert auf der App. Note 3944 vom Hersteller:
nxp.com/docs/en/application-note/AN3944.pdf
Bei der Hardware ist zu beachten, das der MPR121 mit 3,3V läuft. Es gibt aber auch Module die den Pegelwandler schon integriert haben.
LG