技术专栏
基于SD3403手势传感器的应用
PAJ7620U2手势传感器应用
一 PAJ7620传感器简介
ATK-PAJ7620是一款高性能手势识别传感器模块。该模块采用原相科技(Pixart)公司的 PAJ7620U2
芯片,芯片内部集成了光学数组式传感器,以使复杂的手势和光标模式输出,自带九种手势
识别,支持上、下、左、右、前、后、顺时针旋转、逆时针旋转和挥动的手势动作识别,以
及支持物体接近检测等功能
该传感器需要注意的几点是:
1 该传感器模块需要进行唤醒才能使用
2 需要进行模块初始化(手势识别初始化,接近检测初始化等)
3 该传感器功耗很低,因此明面上的功耗是无法直接看出来的(无法知道是否正常工作)
二 重要寄存器简介
1 bank寄存器:
0xef
2 手势识别寄存器
0x43
三 代码详情
直接上代码,我这边使用的是/dev/i2c-3节点,有需要的朋友可以自取
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include<stdint.h>
#define I2C_DEVICE "/dev/i2c-3" // I2C设备文件路径
#define DEVICE_ADDR 0x73 // 目标设备的I2C地址
#define REG_BANK_SEL 0xEF // 寄存器地址:Bank选择寄存器
#define REG_BANK0 0x00 // Bank0
#define REG_BANK1 0x01 // Bank1
#define REG_SUSPEND_CMD 0x3B // 寄存器地址:命令寄存器
#define SUSPEND_NORMAL 0x00 // 常规模式
#define SUSPEND_SUSPEND 0x01 // 挂起模式
#define REG_OPERATION_MODE 0x47 // 寄存器地址:操作模式寄存器
#define ENABLE_WAKEUP 0x20 // 启用唤醒功能
const unsigned char Init_Gesture_Array[][2] = {
{0xEF,0x00},
{0x41,0x00},
{0x42,0x00},
{0xEF,0x00},
{0x48,0x3C},
{0x49,0x00},
{0x51,0x10},
{0x83,0x20},
{0x9F,0xF9},
{0xEF,0x01},
{0x01,0x1E},
{0x02,0x0F},
{0x03,0x10},
{0x04,0x02},
{0x41,0x40},
{0x43,0x30},
{0x65,0x96},
{0x66,0x00},
{0x67,0x97},
{0x68,0x01},
{0x69,0xCD},
{0x6A,0x01},
{0x6B,0xB0},
{0x6C,0x04},
{0x6D,0x2C},
{0x6E,0x01},
{0x74,0x00},
{0xEF,0x00},
{0x41,0xFF},
{0x42,0x01},
};
const unsigned char Init_Register_Array[][2] = {
{0xEF,0x00},
{0x37,0x07},
{0x38,0x17},
{0x39,0x06},
{0x41,0x00},
{0x42,0x00},
{0x46,0x2D},
{0x47,0x0F},
{0x48,0x3C},
{0x49,0x00},
{0x4A,0x1E},
{0x4C,0x20},
{0x51,0x10},
{0x5E,0x10},
{0x60,0x27},
{0x80,0x42},
{0x81,0x44},
{0x82,0x04},
{0x8B,0x01},
{0x90,0x06},
{0x95,0x0A},
{0x96,0x0C},
{0x97,0x05},
{0x9A,0x14},
{0x9C,0x3F},
{0xA5,0x19},
{0xCC,0x19},
{0xCD,0x0B},
{0xCE,0x13},
{0xCF,0x64},
{0xD0,0x21},
{0xEF,0x01},
{0x02,0x0F},
{0x03,0x10},
{0x04,0x02},
{0x25,0x01},
{0x27,0x39},
{0x28,0x7F},
{0x29,0x08},
{0x3E,0xFF},
{0x5E,0x3D},
{0x65,0x96},
{0x67,0x97},
{0x69,0xCD},
{0x6A,0x01},
{0x6D,0x2C},
{0x6E,0x01},
{0x72,0x01},
{0x73,0x35},
{0x74,0x00},
{0x77,0x01},
};
unsigned char PAJ7620U2_init(int i2c_fd)
{
unsigned char i,State;
int k=0;
unsigned char data[2] = {0xef, 0x00}; // 要发送的数据
write(i2c_fd, data, 2) ;
k= sizeof(Init_Register_Array)/2;
for(int j =0; j<k;j++)
{
write(i2c_fd,Init_Register_Array[j],2);
usleep(400);
}
return 1;
}
int wakeup(int i2c_fd)
{
int ret;
uint8_t data = 0x0a;
//wake up
unsigned char buffer[1];
buffer[0] = 0x00;
ret=write(i2c_fd, buffer, 1) ;
if(ret != 1)
{
printf("write fail is wake up1\n");
}
usleep(500);
ret=write(i2c_fd, buffer, 1) ;
if(ret != 1)
{
printf("write fail is wake up1\n");
}
usleep(500);
//select bank0
unsigned char buffer3[2];
buffer3[0] = REG_BANK_SEL;
buffer3[1] = REG_BANK0;
ret=write(i2c_fd, buffer3, sizeof(buffer3));
if ( ret < 2) {
perror("Failed to select Bank1");
printf("ret is %d\n ",ret);
close(i2c_fd);
return 1;
}
}
void gs_wakeup(int i2c_fd)
{
}
int main() {
int i2c_fd;
unsigned short Gesture_Data;
int len = sizeof(Init_Gesture_Array)/sizeof(Init_Gesture_Array[0]);
// 打开I2C设备
if ((i2c_fd = open(I2C_DEVICE, O_RDWR)) < 0) {
perror("Failed to open I2C device");
return -1;
}
// 设置目标设备的I2C地址
if (ioctl(i2c_fd, I2C_SLAVE, DEVICE_ADDR) < 0) {
perror("Failed to set I2C slave address");
close(i2c_fd);
return -1;
}
wakeup(i2c_fd);
PAJ7620U2_init(i2c_fd);
printf("\nGesture Sensor OK\r\n");
// select bank 0
unsigned char data[2] = {0xEF, 0x00};
write(i2c_fd, data, 2) ;
for (int i =0; i< len;i++)
{
write(i2c_fd,Init_Gesture_Array[i],2);
usleep(400);
}
while (1)
{ // read have problem,no read reg_addr
unsigned char data8[1] = {0x43};
write(i2c_fd,data8,1);
read(i2c_fd,&Gesture_Data,sizeof(Gesture_Data));
printf("data is 0x%x\n",Gesture_Data);
if (Gesture_Data)
{
switch (Gesture_Data)
{
case 0x01: printf("Up\r\n"); break;
case 0x02: printf("Down\r\n"); break;
case 0x04: printf("Left\r\n"); break;
case 0x08: printf("Right\r\n"); break;
case 0x10: printf("Forward\r\n"); break;
case 0x20: printf("Backward\r\n"); break;
case 0x40: printf("Clockwise\r\n"); break;
case 0x80: printf("AntiClockwise\r\n"); break;
case 0x100: printf("Wave\r\n"); break;
default: break;
}
Gesture_Data=0;
}
usleep(500000);
}
// 关闭I2C设备
close(i2c_fd);
return 0;
}
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
2
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包
暂无数据
相关专栏
-
浏览量:750次2024-08-22 17:27:55
-
浏览量:10129次2022-11-10 18:07:40
-
浏览量:1128次2023-12-22 14:53:36
-
浏览量:1294次2023-03-20 10:56:09
-
浏览量:7987次2020-12-07 21:44:22
-
浏览量:8963次2020-12-07 17:31:38
-
浏览量:2060次2022-03-30 17:15:07
-
浏览量:1394次2024-02-23 17:41:04
-
浏览量:623次2023-04-21 12:59:31
-
浏览量:699次2023-11-18 15:07:05
-
浏览量:1717次2019-12-25 15:37:50
-
浏览量:1679次2020-08-31 10:00:46
-
浏览量:1745次2019-11-07 15:20:16
-
浏览量:1998次2018-04-13 09:41:02
-
浏览量:1586次2023-06-30 10:33:51
-
浏览量:1912次2019-07-01 10:40:05
-
浏览量:2950次2019-09-17 14:36:22
-
浏览量:2639次2018-04-04 10:11:56
-
浏览量:1966次2019-06-28 11:14:01
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者
易百纳用户53690
您的支持将鼓励我继续创作!
打赏金额:
¥1
¥5
¥10
¥50
¥100
支付方式:
微信支付
打赏成功!
感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注