python模块,用于通过i2c与cypress capsense cy8c201xx电容式触摸传感器通信
CypressCapsense_I2C的Python项目详细描述
cypress capsense c8yc201xx over i2c的python库
GitHub:https://github.com/voidptr/CypressCapsense/tree/master/BeagleBone
此库需要smbus linux i2c库。它已经在 beaglebone,但是它应该可以在任何支持i2c的linux系统上工作。
例如:
import CypressCapsense_I2C ####### INITIAL SETUP - Only Do Once Per Device # sensorInit = CypressCapsense_I2C.CypressCapsense_I2C(0x00, debug=True) # sensorInit.setupDevice() # sensorInit.changeDeviceAddress(0x5D) # or whatever address you want ######################################################################## ## this device has already been set up to use 0x5D as its address sensor = CypressCapsense_I2C.CypressCapsense_I2C(0x5D, debug=False) while(True): print "0x%02X" % sensor.fetchTouchStatus()
外部文件
柏树冠层cy8c201xx
CY8C201xx寄存器参考指南
http://www.cypress.com/?rID=14664http://www.cypress.com/?docID=41921
特质
I2C地址
应使用地址初始化CypressCapSense芯片。每 http://www.cypress.com/?id=4&rID=29387,默认地址是0x00。如果你是 与多个Cypress Capsense设备通信时,必须重置 使用此库中的changeDeviceAddress函数的默认地址
要确认设备地址的值,可以断开所有其他 除了capsense之外的未知设备,然后运行:
$ i2cdetect -y -r 1
设置地址只需要一次
设置地址可以在Arduino设备上工作,也可以在Beaglebone上工作。 基于pic的设备(如芯片组)不能用于重新设置地址 但是,因为它们保留地址0x00用于某些内部用途。
合理的默认值
此库包含一个函数,用于在Capsense上设置合理的默认值 芯片(setupdevice)。默认情况下,它禁用每个GPIO,打开每个 触摸传感器,并将电容感测阈值设置为合理值。
尽管如此,这些设置对你来说可能并不明智。GPIO和 可以通过设置设备设置CapSense设置,但要设置不同的感应 阈值,您必须自己应用这些设置,使用write 原始的。
要设置这些值,必须将设备置于安装操作模式,应用 设置,然后保存并重新启动:
sensor.write(CSE_COMMAND_REG, SETUP_OPERATION_MODE); sensor.write(CypressCapsense_I2C.CSE_CS_OTH_SET, (CypressCapsense_I2C.CSE_OTH_SET_DISABLE_EXT_CAP | CypressCapsense_I2C.CSE_OTH_SET_SENSOR_RESET | CypressCapsense_I2C.CSE_OTH_SET_CLOCK_IMO)) sensor.write(CypressCapsense_I2C.CSE_COMMAND_REG, CypressCapsense_I2C.STORE_CURRENT_CONFIGURATION_TO_NVM) sensor.write(CypressCapsense_I2C.CSE_COMMAND_REG, CypressCapsense_I2C.RECONFIGURE_DEVICE) sensor.write(CypressCapsense_I2C.CSE_COMMAND_REG, CypressCapsense_I2C.NORMAL_OPERATION_MODE)
设备安装只需要一次设置存储在 跨重新启动的非易失性内存。
感应复位
根据制造商的要求,Capsense芯片具有调整到 环境随着时间的推移保持传感器的灵敏度和准确性
然而,在我的董事会设计中,我发现无论他们使用什么方法 可笑的无效。因此,重新设置板传感器是谨慎的 定期地。这可以通过reset函数来完成:
sensor.reset()
缓冲读取
出于某种原因,capsense设备不喜欢响应缓冲区- 读取SMBus库中的功能SMBus读取字节(addr) 原始人应该做的,但它只是挂。所以,这意味着我们不能 尽可能读取设备配置和版本号的I2C缓冲区 在Arduino驾驶室
最终,这会删除设备上的一些调试功能,但对于 设置和读取触摸状态的基本目的,此库执行 诡计。YMMV公司。
待办事项
滑块
一些capsense芯片能够提供硬件中介的滑块。
此库的用户可以设置适当的设置来使用这些
使用write原语的功能,但在安装设备期间易于支持
尚不可用敬请期待。
CypressCapsense的PyDoc输出
关于模块CypressCapsense\u I2C的帮助:
NAME CypressCapsense_I2C FILE /home/rosiec/CypressCapsense/BeagleBone/CypressCapsense_I2C.py CLASSES CypressCapsense_I2C class CypressCapsense_I2C | Methods defined here: | | __init__(self, address, busnum=-1, debug=False) | | changeDeviceAddress(self, new_address) | Parameters: | new_address - 7 Bit new device address to set | | Return Value: | none | | Errors: | none | | Description: | Sends command to device to unlock the address register, change the address | value, and re-lock the register. | | errMsg(self) | | fetchRawCounts(self, port, sensor) | Parameters: | port - Which port to query (0 or 1) | sensor - Which sensor to query (0-4) | | Return Value: | uint16_t - The raw count of the sensor. | | Errors: | If port > 1, or sensor > 4, return 0 | | Description: | Fetches the raw count values from the sensor | | fetchTouchStatus(self) | Parameters: | | Return Value: | uint16_t - The status of the sensors. Each bit being on/off | | Errors: | none | | Description: | Fetches the touch true/false status from the sensors | | read(self, register_address) | Parameters: | register_address - 8 Bit register address designating where to read | | Return Value: | byte | | Errors: | none | | Description: | reads from the Capsense device | to get the data at that location and returns a byte | | readString(self, register_address, size) | Parameters: | register_address - 8 Bit register_address designating where to read | size - number of bytes to be read | | Return Value: | results | | Errors: | none | | Description: | reads consecutive bytes starting | from the given register_address | | reboot(self) | Reboot the board. | | reset(self) | Reset the touch sensors baseline value. | | setupDevice(self, gpio, capsense) | Parameters: | gpio - 16 bits to turn on as GPIO xxxBBBBBxxxBBBBB | (LSB 8 bits (LSB 5 bits) for GPIO0, MSB 8 bits (LSB 5 bits) GPIO1) | capsense - 16 bits to turn on as Capsense xxxBBBBBxxxBBBBB | (LSB 8 bits (LSB 5 bits) for GPIO0, MSB 8 bits (LSB 5 bits) GPIO1) | | Return Value: | none | | Errors: | If the pin settings conflict, return false | | Description: | Sets the pins to be used as capsense or GPIO on ports 0 and 1. A pin may not be | both capsense and gpio at the same time. | | write(self, register_address, data) | Parameters: | register_address - 8 Bit register_address designating were to write | data - Data to be written | | Return Value: | | Errors: | | Description: | writes a byte to specified register_address | | writeString(self, register_address, data) | Parameters: | register_address - 8 Bit register_address designating were to write | data - Data to be written | | Return Value: | none | | Errors: | none | | Description: | Writes a string of bytes to | specified register_address. If amount of bytes is above 64 the data | will automaticly be truncated. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | CSE_COMMAND_REG = 160 | | CSE_CS_ENABLE0 = 6 | | CSE_CS_ENABLE1 = 7 | | CSE_CS_FILTERING = 86 | | CSE_CS_FINGER_TH_00 = 97 | | CSE_CS_FINGER_TH_01 = 98 | | CSE_CS_FINGER_TH_02 = 99 | | CSE_CS_FINGER_TH_03 = 100 | | CSE_CS_FINGER_TH_04 = 101 | | CSE_CS_FINGER_TH_10 = 102 | | CSE_CS_FINGER_TH_11 = 103 | | CSE_CS_FINGER_TH_12 = 104 | | CSE_CS_FINGER_TH_13 = 105 | | CSE_CS_FINGER_TH_14 = 106 | | CSE_CS_IDAC_00 = 107 | | CSE_CS_IDAC_01 = 108 | | CSE_CS_IDAC_02 = 109 | | CSE_CS_IDAC_03 = 110 | | CSE_CS_IDAC_04 = 111 | | CSE_CS_IDAC_10 = 112 | | CSE_CS_IDAC_11 = 113 | | CSE_CS_IDAC_12 = 114 | | CSE_CS_IDAC_13 = 115 | | CSE_CS_IDAC_14 = 116 | | CSE_CS_OTH_SET = 81 | | CSE_CS_READ_BUTTON = 129 | | CSE_CS_READ_RAWL = 135 | | CSE_CS_READ_RAWM = 134 | | CSE_CS_READ_STATUS0 = 136 | | CSE_CS_READ_STATUS1 = 137 | | CSE_CS_SCAN_POS_00 = 87 | | CSE_CS_SCAN_POS_01 = 88 | | CSE_CS_SCAN_POS_02 = 89 | | CSE_CS_SCAN_POS_03 = 90 | | CSE_CS_SCAN_POS_04 = 91 | | CSE_CS_SCAN_POS_10 = 92 | | CSE_CS_SCAN_POS_11 = 93 | | CSE_CS_SCAN_POS_12 = 94 | | CSE_CS_SCAN_POS_13 = 95 | | CSE_CS_SCAN_POS_14 = 96 | | CSE_GPIO_ENABLE0 = 8 | | CSE_GPIO_ENABLE1 = 9 | | CSE_I2C_ADDR_DM = 124 | | CSE_I2C_DEV_LOCK = 121 | | CSE_OTH_SET_CLOCK_IMO = 0 | | CSE_OTH_SET_CLOCK_IMO2 = 32 | | CSE_OTH_SET_CLOCK_IMO4 = 64 | | CSE_OTH_SET_CLOCK_IMO8 = 96 | | CSE_OTH_SET_DISABLE_EXT_CAP = 2 | | CSE_OTH_SET_ENABLE_EXT_CAP = 2 | | CSE_OTH_SET_NO_SENSOR_RESET = 0 | | CSE_OTH_SET_SENSOR_RESET = 8 | | CS_FILTERING_TOUCH_BASELINE_RESET = 64 | | GET_FIRMWARE_REVISION = 0 | | NORMAL_OPERATION_MODE = 7 | | READ_DEVICE_CONFIGURATION = 5 | | RECONFIGURE_DEVICE = 6 | | SETUP_OPERATION_MODE = 8 | | STORE_CURRENT_CONFIGURATION_TO_NVM = 1 | | lock = [150, 90, 195] | | unlock = [60, 165, 105]