• Guest
HabraHabr
  • Main
  • Users

  • Development
    • Programming
    • Information Security
    • Website development
    • JavaScript
    • Game development
    • Open source
    • Developed for Android
    • Machine learning
    • Abnormal programming
    • Java
    • Python
    • Development of mobile applications
    • Analysis and design of systems
    • .NET
    • Mathematics
    • Algorithms
    • C#
    • System Programming
    • C++
    • C
    • Go
    • PHP
    • Reverse engineering
    • Assembler
    • Development under Linux
    • Big Data
    • Rust
    • Cryptography
    • Entertaining problems
    • Testing of IT systems
    • Testing Web Services
    • HTML
    • Programming microcontrollers
    • API
    • High performance
    • Developed for iOS
    • CSS
    • Industrial Programming
    • Development under Windows
    • Image processing
    • Compilers
    • FPGA
    • Professional literature
    • OpenStreetMap
    • Google Chrome
    • Data Mining
    • PostgreSQL
    • Development of robotics
    • Visualization of data
    • Angular
    • ReactJS
    • Search technologies
    • Debugging
    • Test mobile applications
    • Browsers
    • Designing and refactoring
    • IT Standards
    • Solidity
    • Node.JS
    • Git
    • LaTeX
    • SQL
    • Haskell
    • Unreal Engine
    • Unity3D
    • Development for the Internet of things
    • Functional Programming
    • Amazon Web Services
    • Google Cloud Platform
    • Development under AR and VR
    • Assembly systems
    • Version control systems
    • Kotlin
    • R
    • CAD/CAM
    • Customer Optimization
    • Development of communication systems
    • Microsoft Azure
    • Perfect code
    • Atlassian
    • Visual Studio
    • NoSQL
    • Yii
    • Mono и Moonlight
    • Parallel Programming
    • Asterisk
    • Yandex API
    • WordPress
    • Sports programming
    • Lua
    • Microsoft SQL Server
    • Payment systems
    • TypeScript
    • Scala
    • Google API
    • Development of data transmission systems
    • XML
    • Regular expressions
    • Development under Tizen
    • Swift
    • MySQL
    • Geoinformation services
    • Global Positioning Systems
    • Qt
    • Dart
    • Django
    • Development for Office 365
    • Erlang/OTP
    • GPGPU
    • Eclipse
    • Maps API
    • Testing games
    • Browser Extensions
    • 1C-Bitrix
    • Development under e-commerce
    • Xamarin
    • Xcode
    • Development under Windows Phone
    • Semantics
    • CMS
    • VueJS
    • GitHub
    • Open data
    • Sphinx
    • Ruby on Rails
    • Ruby
    • Symfony
    • Drupal
    • Messaging Systems
    • CTF
    • SaaS / S+S
    • SharePoint
    • jQuery
    • Puppet
    • Firefox
    • Elm
    • MODX
    • Billing systems
    • Graphical shells
    • Kodobred
    • MongoDB
    • SCADA
    • Hadoop
    • Gradle
    • Clojure
    • F#
    • CoffeeScript
    • Matlab
    • Phalcon
    • Development under Sailfish OS
    • Magento
    • Elixir/Phoenix
    • Microsoft Edge
    • Layout of letters
    • Development for OS X
    • Forth
    • Smalltalk
    • Julia
    • Laravel
    • WebGL
    • Meteor.JS
    • Firebird/Interbase
    • SQLite
    • D
    • Mesh-networks
    • I2P
    • Derby.js
    • Emacs
    • Development under Bada
    • Mercurial
    • UML Design
    • Objective C
    • Fortran
    • Cocoa
    • Cobol
    • Apache Flex
    • Action Script
    • Joomla
    • IIS
    • Twitter API
    • Vkontakte API
    • Facebook API
    • Microsoft Access
    • PDF
    • Prolog
    • GTK+
    • LabVIEW
    • Brainfuck
    • Cubrid
    • Canvas
    • Doctrine ORM
    • Google App Engine
    • Twisted
    • XSLT
    • TDD
    • Small Basic
    • Kohana
    • Development for Java ME
    • LiveStreet
    • MooTools
    • Adobe Flash
    • GreaseMonkey
    • INFOLUST
    • Groovy & Grails
    • Lisp
    • Delphi
    • Zend Framework
    • ExtJS / Sencha Library
    • Internet Explorer
    • CodeIgniter
    • Silverlight
    • Google Web Toolkit
    • CakePHP
    • Safari
    • Opera
    • Microformats
    • Ajax
    • VIM
  • Administration
    • System administration
    • IT Infrastructure
    • *nix
    • Network technologies
    • DevOps
    • Server Administration
    • Cloud computing
    • Configuring Linux
    • Wireless technologies
    • Virtualization
    • Hosting
    • Data storage
    • Decentralized networks
    • Database Administration
    • Data Warehousing
    • Communication standards
    • PowerShell
    • Backup
    • Cisco
    • Nginx
    • Antivirus protection
    • DNS
    • Server Optimization
    • Data recovery
    • Apache
    • Spam and antispam
    • Data Compression
    • SAN
    • IPv6
    • Fidonet
    • IPTV
    • Shells
    • Administering domain names
  • Design
    • Interfaces
    • Web design
    • Working with sound
    • Usability
    • Graphic design
    • Design Games
    • Mobile App Design
    • Working with 3D-graphics
    • Typography
    • Working with video
    • Work with vector graphics
    • Accessibility
    • Prototyping
    • CGI (graphics)
    • Computer Animation
    • Working with icons
  • Control
    • Careers in the IT industry
    • Project management
    • Development Management
    • Personnel Management
    • Product Management
    • Start-up development
    • Managing the community
    • Service Desk
    • GTD
    • IT Terminology
    • Agile
    • Business Models
    • Legislation and IT-business
    • Sales management
    • CRM-systems
    • Product localization
    • ECM / EDS
    • Freelance
    • Venture investments
    • ERP-systems
    • Help Desk Software
    • Media management
    • Patenting
    • E-commerce management
    • Creative Commons
  • Marketing
    • Conferences
    • Promotion of games
    • Internet Marketing
    • Search Engine Optimization
    • Web Analytics
    • Monetize Web services
    • Content marketing
    • Monetization of IT systems
    • Monetize mobile apps
    • Mobile App Analytics
    • Growth Hacking
    • Branding
    • Monetize Games
    • Display ads
    • Contextual advertising
    • Increase Conversion Rate
  • Sundry
    • Reading room
    • Educational process in IT
    • Research and forecasts in IT
    • Finance in IT
    • Hakatonas
    • IT emigration
    • Education abroad
    • Lumber room
    • I'm on my way

Recognition of gestures with the help of APDS-9960

Recognition of gestures with the help of APDS-9960

 
Reading the comments to my previous article about APDS-996? where it was about color recognition and lighting level for me, two things became obvious: 1) the topic of gesture recognition is interesting and 2) this topic is not disclosed.
 
 
Indeed, if I took up the description of APDS-996? then without a description of the gestures, this description looks somewhat unfinished. So I found free time to explore this topic too.
 
 
In this article, I bring to your attention an overview of the gesture recognition capabilities that the APDS-9960 sensor provides.
 
last time , we will use STM32VLDISCOVERY. The connection also did not change.
 
 
Setting up APDS-9960
 
 
We make the initial adjustment of the sensor.
 
 
Here and so:
 
 
APDS9960_init [/b]
void APDS9960_init (void) {
i2c1_write (APDS9960_CONTROL, DEFAULT_PGAIN);
i2c1_write (APDS9960_GPENTH, DEFAULT_GPENTH);
i2c1_write (APDS9960_GEXTH, DEFAULT_GEXTH);
i2c1_write (APDS9960_GCONF? DEFAULT_GGAIN);
i2c1_write (APDS9960_GPULSE, DEFAULT_PULSE_LENGTH);
i2c1_write (APDS9960_PPULSE, DEFAULT_PULSE_LENGTH);
}

 
What is happening here? Let's understand.
 
 
i2c1_write (APDS9960_CONTROL, DEFAULT_PGAIN);
 
PGAIN (Proximity Gain Control) is a parameter that controls the gain of the approach sensitivity. Assign it a value of ? which corresponds to a fourfold increase.
 
 
i2c1_write (APDS9960_GPENTH, DEFAULT_GPENTH);
i2c1_write (APDS9960_GEXTH, DEFAULT_GEXTH);

 
GPENTH (Gesture Proximity Enter Threshold Register) - this parameter sets the proximity threshold to determine the start of the gesture recognition.
 
 
GEXTH (Gesture Exit Threshold Register), respectively, sets a threshold for determining the end of the gesture recognition.
 
 
i2c1_write (APDS9960_GCONF? DEFAULT_GGAIN);
 
In the GCONF2 register (Gesture configuration two), we explicitly set only the GGAIN (Gesture Gain Control) parameter to the gain value four times.
 
 
i2c1_write (APDS9960_GPULSE, DEFAULT_PULSE_LENGTH);
i2c1_write (APDS9960_PPULSE, DEFAULT_PULSE_LENGTH);

 
Backlight. By default, the value for the current source of the infrared LED of the backlight is set to ? which corresponds to a current of 100 mA, we are quite satisfied - we will not change it.
 
 
The IR illumination in APDS-9960 is a sequence of pulses and is characterized by the corresponding register parameters for GULL (Gesture pulse count and length) GPLEN (Gesture Pulse Length) and GPULSE (Number of Gesture Pulses) registers, as well as PPULSE approximations (Proximity Pulse Count Register ): PPLEN (Proximity Pulse Length) and PPULSE (Proximity Pulse Count) that specify the number of pulses and the period of each individual pulse.
 
 
Define that GPLEN and PPLEN will take the value 2 equal to 16 μs, and GPULSE and PPULSE to ? which corresponds to 10 pulses.
 
 
As you can see, the setting was not a bit more complicated than the one for recognizing colors and lighting from the previous review of APDS-9960.
 
 
Reading the data
 
 
Now we move to the main program cycle, in which we will start to record and interpret data from photodiodes, and also learn how to find the differences between one gesture and another.
 
 
First of all, start the APDS-9960 with the functions of work with gestures and approximation.
 
 
GesturesSet (GESTURES_START);
 
And immediately we begin to monitor the GVALID parameter. GVALID (Gesture FIFO Data) is a parameter of GSTATUS register (Gesture Status Register), which, being in a non-zero state, informs us that the sensor has usable data about gestures.
 
 
The documentation teaches us that the gesture information is in the buffer, in the RAM area, which in general is 32 x 4 bytes in size.
 
 
In practice, the actual size of this buffer can be learned by reading the value of the register GFLVL (Gesture FIFO level), i.e. by my purely empirical experimental observations, GFLVL * 4 is obtained. Something like this:
 
 

 
 
Well and as follows from the name of the buffer, the data in it are arranged in the order First In - First Out. That is, roughly speaking, than "before" received a signal from each of the photodiodes, the "higher" in GFLVL it is located.
 
 
Data from photodiodes (UDLR) can be read from the corresponding registers Gesture FIFO Register:
 
 
- GFIFO_U (Gesture FIFO Data, UP)
 
- GFIFO_D (Gesture FIFO Data, DOWN)
 
- GFIFO_L (Gesture FIFO Data, LEFT)
 
- GFIFO_R (Gesture FIFO Data, RIGHT)
 
 
After each reading of the values ​​from these registers, GFLVL is decremented; Thus, for good, it is necessary to read the entire buffer until GFLVL reaches zero.
 
 
To define gestures, we need only the first four bytes of this buffer, not more. Therefore, we will only read them.
 
 
GestureUp = i2c1_read (APDS9960_GFIFO_U);
GestureDown = i2c1_read (APDS9960_GFIFO_D);
GestureLeft = i2c1_read (APDS9960_GFIFO_L);
GestureRight = i2c1_read (APDS9960_GFIFO_R);

 
Recognition of gestures
 
 
To interpret what kind of gesture occurred, let's perform simple calculations:
 
 
GestUpDown = GestureUp-GestureDown;
GestLeftRight = GestureLeft-GestureRight;

 
To determine which exactly gesture at the given moment happened, it is not the values ​​of GestUpDown and GestLeftRight themselves that are important to us, but only a sign, so to speak, of a real number.
 
 
That is, in other words, taking negative and positive values ​​of the variables GestUpDown and GestLeftRight on the input determine which gesture is perfect.
 
 
The truth table for the variables GestUpDown and GestLeftRight is shown in the figure below
 
 

 
 
Now zero the GFLVL:
 
 
GesturesSet (GESTURES_STOP);
 
and return to the beginning of the main program cycle.
 
 
And now the whole code:
 
 
main.c [/b]

#include "stm32f10x.h"
#define APDS9960_I2C_ADDR 0x39
#define APDS9960_ENABLE 0x80
#define APDS9960_GSTATUS 0xAF
#define APDS9960_GFLVL 0xAE
//Gesture FIFO Register (0xFC - 0xFF):
#define APDS9960_GFIFO_U 0xFC
#define APDS9960_GFIFO_D 0xFD
#define APDS9960_GFIFO_L 0xFE
#define APDS9960_GFIFO_R 0xFF
#define APDS9960_CONTROL 0x8F
#define APDS9960_GPENTH 0xA0
#define APDS9960_GEXTH 0xA1
#define APDS9960_GCONF2 0xA3
#define APDS9960_GPULSE 0xA6
#define APDS9960_PPULSE 0x8E
#define GESTURES_START 0x01
#define GESTURES_STOP 0x02
#define DEFAULT_GPENTH 40 //Threshold for gesture mode
#define DEFAULT_GEXTH 30 //Threshold for exiting gesture mode
#define DEFAULT_PGAIN 8 //Proximity Gain Control: 4X
#define DEFAULT_GGAIN 0x40 //Gesture Gain Control: 4X
#define DEFAULT_PULSE_LENGTH 0x89 //16us, 10 pulses
/* Bit fields * /
#define APDS9960_PON 0x01
#define APDS9960_AEN 0x02
#define APDS9960_PEN 0x04
#define APDS9960_WEN 0x08
#define APSD9960_AIEN 0x10
#define APDS9960_PIEN 0x20
#define APDS9960_GEN 0x40
#define APDS9960_GVALID 0x01
int GestUpDown = 0;
int GestLeftRight = 0;
//------------------------------------------------ -----------------------
uint8_t i2c1_read (uint8_t addr);
void i2c1_write (uint8_t addr, uint8_t data);
void I2C1_init (void)
{
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd (RCC_APB1Periph_I2C? ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_Init (GPIOB, & GPIO_InitStructure);
I2C_StructInit (& I2C_InitStructure);
I2C_InitStructure.I2C_ClockSpeed ​​= 100000;
I2C_InitStructure.I2C_OwnAddress1 = 0x01;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_Init (I2C? & I2C_InitStructure);
I2C_Cmd (I2C? ENABLE);
}
//------------------------------------------------ -----------------------
void APDS9960_init (void) {
i2c1_write (APDS9960_CONTROL, DEFAULT_PGAIN);
i2c1_write (APDS9960_GPENTH, DEFAULT_GPENTH);
i2c1_write (APDS9960_GEXTH, DEFAULT_GEXTH);
i2c1_write (APDS9960_GCONF? DEFAULT_GGAIN);
i2c1_write (APDS9960_GPULSE, DEFAULT_PULSE_LENGTH);
i2c1_write (APDS9960_PPULSE, DEFAULT_PULSE_LENGTH);
}
//------------------------------------------------ -----------------------
uint8_t i2c1_read (uint8_t addr)
{
uint8_t data;
while (I2C_GetFlagStatus (I2C? I2C_FLAG_BUSY));
I2C_GenerateSTART (I2C? ENABLE);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress (I2C? APDS9960_I2C_ADDR? I2C_Direction_Transmitter);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData (I2C? addr);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTART (I2C? ENABLE);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress (I2C? APDS9960_I2C_ADDR? I2C_Direction_Receiver);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_BYTE_RECEIVED));
data = I2C_ReceiveData (I2C1);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_BYTE_RECEIVED));
I2C_AcknowledgeConfig (I2C? DISABLE);
I2C_GenerateSTOP (I2C? ENABLE);
while (I2C_GetFlagStatus (I2C? I2C_FLAG_BUSY));
return data;
}
//------------------------------------------------ -----------------------
void i2c1_write (uint8_t addr, uint8_t data)
{
I2C_GenerateSTART (I2C? ENABLE);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress (I2C? APDS9960_I2C_ADDR? I2C_Direction_Transmitter);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData (I2C? addr);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData (I2C? data);
while (! I2C_CheckEvent (I2C? I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP (I2C? ENABLE);
while (I2C_GetFlagStatus (I2C? I2C_FLAG_BUSY)) {};
}
//------------------------------------------------ -----------------------
void GesturesSet (uint8_t GestSel) {
switch (GestSel)
{
case GESTURES_START:
i2c1_write (APDS9960_ENABLE, APDS9960_GEN | APDS9960_PEN | APDS9960_PON);
break;
case GESTURES_STOP:
i2c1_write (APDS9960_ENABLE, APDS9960_PEN | APDS9960_PON);
break;
default:
i2c1_write (APDS9960_ENABLE, APDS9960_GEN | APDS9960_PEN | APDS9960_PON);
}
}
//------------------------------------------------ -----------------------
int main ()
{
uint8_t GFLVL_buf = 0;
uint8_t GSTATUS_buf = 0;
uint8_t GestureUp = 0;
uint8_t GestureDown = 0;
uint8_t GestureLeft = 0;
uint8_t GestureRight = 0;
I2C1_init ();
APDS9960_init ();
while (1)
{
GFLVL_buf = 0;
GSTATUS_buf = 0;
GestureUp = 0;
GestureDown = 0;
GestureLeft = 0;
GestureRight = 0;
GestUpDown = 0;
GestLeftRight = 0;
GesturesSet (GESTURES_START);
GSTATUS_buf = i2c1_read (APDS9960_GSTATUS);
if (GSTATUS_buf & APDS9960_GVALID) {
GFLVL_buf = i2c1_read (APDS9960_GFLVL);
if (GFLVL_buf) {
GestureUp = i2c1_read (APDS9960_GFIFO_U);
GestureDown = i2c1_read (APDS9960_GFIFO_D);
GestureLeft = i2c1_read (APDS9960_GFIFO_L);
GestureRight = i2c1_read (APDS9960_GFIFO_R);
//Truth table:
//UP: GestUpDown (+) | GestLeftRight (+)
//DOWN: GestUpDown (-) | GestLeftRight (-)
//LEFT: GestUpDown (+) | GestLeftRight (-)
//RIGHT: GestUpDown (-) | GestLeftRight (+)
GestUpDown = GestureUp-GestureDown;
GestLeftRight = GestureLeft-GestureRight;
GesturesSet (GESTURES_STOP);
}
}
}
}

 
 
I want to note that the mechanism of gestures in APDS-9960 works very well. Recognition is stable, the built-in APDS-9960 UV and IR filters work well.
 
 
I hope this material will be useful to someone. Thank you for attention.

It may be interesting

  • Comments
  • About article
  • Similar news
This publication has no comments.

weber

Author

1-10-2018, 05:30

Publication Date

Development / Programming

Category
  • Comments: 0
  • Views: 377
Using optical character recognition in
Recognition of color and level of
The face recognition system installed
Machine vision for retail. How to read
Whiskers, paws and tail: how the neural
Modify the player Vanilla Music for
Write a comment
Name:*
E-Mail:


Comments
Global Dezigns is a Website Development Company in Karachi, Providing services of
website design in karachi
. We are delivering the best partnership across Pakistan. provides a complete range of web development services including web applications, website hosting and maintenance, domain registration, on-page search engine optimization, and website integration with social media platforms such as Facebook, Twitter, LinkedIn, Google Maps, and Google Local Directory. We believe we are well placed to take our knowledge and expertise to the logical next level with the latest web standards.  
  Show/hide text
https://www.globaldezigns.com/



Yesterday, 22:45

mike tomlin

This blog is really great. The information here will surely be of some help to me. Thanks!.mastering physics

Yesterday, 17:57

raymond weber

Coinyspace is the cryptocurrency community and trading forum where members can find any contributors of crypto ecosystem like currencies, exchanges & merchants. Check Out: Bitcoin Merchants
Yesterday, 16:57

noorseo

This is a great high resolution screen which you have shared for the users. Making a website is not an easy task but managing a good website is really a hard work. As far as this website is concerned, I am very happy.https://19216801.1
Yesterday, 16:01

nushra45

i'm satisfied to deem this make recognized Very beneficial for me, as it contains lot of advice. I usually favor to buttonhole The excellent and glad i found this count number in you assertion. thanks Subliminal Hypnosis
Yesterday, 14:56

jahangirkhatri

Adv
Website for web developers. New scripts, best ideas, programming tips. How to write a script for you here, we have a lot of information about various programming languages. You are a webmaster or a beginner programmer, it does not matter, useful articles will help to make your favorite business faster.

Login

Registration Forgot password