Line Touch Sensor

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Line Touch Sensor

      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:

      BASCOM-Quellcode

      1. '-------------------------------------------------------------------------------
      2. '
      3. 'Touch Sensor
      4. 'MPR121 (freescale) A C H T U N G ! VCC=3,3V >>>> Pegelwandler verwenden!
      5. '.............................................oder 3V3 µC-Board
      6. 'Arduino NANO / UNO ........o.ä.
      7. '
      8. 'Nov.2018 by Mandarin15
      9. '
      10. 'Demo mit Minimal-Konfiguration
      11. '
      12. '-------------------------------------------------------------------------------
      13. $regfile = "m328pdef.dat"
      14. $crystal = 16000000
      15. $hwstack = 64
      16. $swstack = 32
      17. $framesize = 64
      18. Config Portb.5 = Output
      19. Led Alias Portb.5
      20. '________________________________________________________________________________Register lt. Datenblatt / AN3944
      21. Mhd_rising Alias &H2B
      22. Nhd_amount_rising Alias &H2C
      23. Ncl_rising Alias &H2D
      24. Fdl_rising Alias &H2E
      25. Mhd_falling Alias &H2F
      26. Nhd_amount_falling Alias &H30
      27. Ncl_falling Alias &H31
      28. Fdl_falling Alias &H32
      29. Ele0_touch_threshold Alias &H41
      30. Ele0_release_threshold Alias &H42
      31. Ele1_touch_threshold Alias &H43
      32. Ele1_release_threshold Alias &H44
      33. Ele2_touch_threshold Alias &H45
      34. Ele2_release_threshold Alias &H46
      35. Ele3_touch_threshold Alias &H47
      36. Ele3_release_threshold Alias &H48
      37. Ele4_touch_threshold Alias &H49
      38. Ele4_release_threshold Alias &H4A
      39. Ele5_touch_threshold Alias &H4B
      40. Ele5_release_threshold Alias &H4C
      41. Ele6_touch_threshold Alias &H4D
      42. Ele6_release_threshold Alias &H4E
      43. Ele7_touch_threshold Alias &H4F
      44. Ele7_release_threshold Alias &H50
      45. Ele8_touch_threshold Alias &H51
      46. Ele8_release_threshold Alias &H52
      47. Ele9_touch_threshold Alias &H53
      48. Ele9_release_threshold Alias &H54
      49. Ele10_touch_threshold Alias &H55
      50. Ele10_release_threshold Alias &H56
      51. Ele11_touch_threshold Alias &H57
      52. Ele11_release_threshold Alias &H58
      53. Filter_cfg Alias &H5D
      54. Electrode_cfg Alias &H5E
      55. Gpio_ctrl_reg_0 Alias &H73 'GPIO auf meinem Board nicht verfügbar
      56. Gpio_ctrl_reg_1 Alias &H74
      57. Gpio_data_reg Alias &H75
      58. Gpio_dir_ctrl_reg Alias &H76
      59. Gpio_enable_reg Alias &H77
      60. Gpio_data_set_reg Alias &H78
      61. Gpio_data_clear_reg Alias &H79
      62. Gpio_data_toggle_reg Alias &H7A
      63. Auto_cfg_control_0 Alias &H7B
      64. Auto_cfg_usl Alias &H7D
      65. Auto_cfg_lsl Alias &H7E
      66. Auto_cfg_target_level Alias &H7F
      67. Touch_threshold Alias &H0F
      68. Release_threshold Alias &H0A
      69. Mpr121_read_adr Alias &HB5
      70. Mpr121_write_adr Alias &HB4
      71. '_______________________________________________________________________________
      72. Dim Touch As Boolean 'Neue Daten von MPR121
      73. Dim Touchstatus As Word
      74. Dim Touchstatus_l As Byte At Touchstatus Overlay
      75. Dim Touchstatus_h As Byte At Touchstatus + 1 Overlay
      76. Config Pind.2 = Input 'IRQ! von MPR121 (Active Low Open-drain Interrupt Output)
      77. Portd.2 = 1 'Pullup
      78. Config Int0 = Falling 'PIND.2
      79. Enable Int0
      80. On Int0 Int0_irq
      81. $lib "i2c_TWI.lib"
      82. Config Scl = Portc.5 'Ports fuer IIC-Bus
      83. Config Sda = Portc.4
      84. Config Twi = 400000
      85. Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 'USB_debug
      86. Declare Sub Mpr121write(byval Reg_address As Byte , Byval Daten As Byte)
      87. Declare Function Mpr121read(byval Read_register As Byte ) As Byte
      88. '-------------------------------------------------------------------------------
      89. I2cinit
      90. Gosub Mpr121config
      91. Enable Interrupts
      92. Print "START MPR121 Demo"
      93. '###############################################################################
      94. '###############################################################################
      95. Do
      96. If Touch = 1 Then
      97. Print Bin(touchstatus)
      98. Touch = 0
      99. Led = 0
      100. End If
      101. Loop
      102. '###############################################################################
      103. '###############################################################################
      104. '_______________________________________________________________________________
      105. Int0_irq:
      106. 'MPR121 Irq
      107. Touchstatus_l = Mpr121read(&H00)
      108. Touchstatus_h = Mpr121read(&H01)
      109. Touch = 1 'neue Daten
      110. Led = 1
      111. Return
      112. '_______________________________________________________________________________
      113. Mpr121config:
      114. 'Section A
      115. 'This group of setting controls the filtering of the system when the data is greater than the baseline
      116. Call Mpr121write(mhd_rising , &H01)
      117. Call Mpr121write(nhd_amount_rising , &H01)
      118. Call Mpr121write(ncl_rising , &H00)
      119. Call Mpr121write(fdl_rising , &H00)
      120. 'Section B
      121. 'This group of setting controls the filtering of the system, when the data is less than the baseline
      122. Call Mpr121write(mhd_falling , &H01)
      123. Call Mpr121write(nhd_amount_falling , &H01)
      124. Call Mpr121write(ncl_falling , &HFF)
      125. Call Mpr121write(fdl_falling , &H02)
      126. 'Section C
      127. 'The touch threshold registers set the minimum delta from the baseline when a touch is detected
      128. Call Mpr121write(ele0_touch_threshold , Touch_threshold)
      129. Call Mpr121write(ele0_release_threshold , Release_threshold)
      130. Call Mpr121write(ele1_touch_threshold , Touch_threshold)
      131. Call Mpr121write(ele1_release_threshold , Release_threshold)
      132. Call Mpr121write(ele2_touch_threshold , Touch_threshold)
      133. Call Mpr121write(ele2_release_threshold , Release_threshold)
      134. Call Mpr121write(ele3_touch_threshold , Touch_threshold)
      135. Call Mpr121write(ele3_release_threshold , Release_threshold)
      136. Call Mpr121write(ele4_touch_threshold , Touch_threshold)
      137. Call Mpr121write(ele4_release_threshold , Release_threshold)
      138. Call Mpr121write(ele5_touch_threshold , Touch_threshold)
      139. Call Mpr121write(ele5_release_threshold , Release_threshold)
      140. Call Mpr121write(ele6_touch_threshold , Touch_threshold)
      141. Call Mpr121write(ele6_release_threshold , Release_threshold)
      142. Call Mpr121write(ele7_touch_threshold , Touch_threshold)
      143. Call Mpr121write(ele7_release_threshold , Release_threshold)
      144. Call Mpr121write(ele8_touch_threshold , Touch_threshold)
      145. Call Mpr121write(ele8_release_threshold , Release_threshold)
      146. Call Mpr121write(ele9_touch_threshold , Touch_threshold)
      147. Call Mpr121write(ele9_release_threshold , Release_threshold)
      148. Call Mpr121write(ele10_touch_threshold , Touch_threshold)
      149. Call Mpr121write(ele10_release_threshold , Release_threshold)
      150. Call Mpr121write(ele11_touch_threshold , Touch_threshold)
      151. Call Mpr121write(ele11_release_threshold , Release_threshold)
      152. 'Section D
      153. 'There are three settings embedded in this register so it is only necessary to pay attention to one
      154. Call Mpr121write(filter_cfg , &H04)
      155. 'Section E
      156. 'Electrode Configuration
      157. Call Mpr121write(electrode_cfg , &H0C) 'Enable 12 Electrodes
      158. 'Section F
      159. 'Enable Auto Config and auto Reconfig
      160. 'call mpr121Write(Auto_cfg_control_0, &H0B)
      161. 'call Mpr121write(Auto_cfg_usl , &H9C)
      162. 'call Mpr121write(Auto_cfg_lsl , &H65)
      163. 'call Mpr121write(Auto_cfg_target_level , &H8C)
      164. Return
      165. '_______________________________________________________________________________
      166. Sub Mpr121write(byval Reg_address As Byte , Byval Daten As Byte)
      167. I2cstart
      168. I2cwbyte Mpr121_write_adr 'write 0xB4
      169. I2cwbyte Reg_address 'write register reg_Address
      170. I2cwbyte Daten
      171. I2cstop
      172. End Sub
      173. '_______________________________________________________________________________
      174. Function Mpr121read(byval Read_register As Byte ) As Byte
      175. Local Read_data As Byte
      176. I2cstart
      177. I2cwbyte Mpr121_write_adr
      178. I2cwbyte Read_register
      179. I2crepstart
      180. I2cwbyte Mpr121_read_adr
      181. I2crbyte Read_data , Nack
      182. I2cstop
      183. Mpr121read = Read_data
      184. End Function
      185. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      186. End
      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