solderparty / arduino_tsc2004 Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Running on my Adafruit Feather M0, my loop() was always blocking on readData(). I believe the problem is that touched() was returning 'true' even when no touch was detected (and thus no data for readData()).
If I am reading the datasheet correctly, I believe a "touch detected" is signalled by bit15 being set in CRF0. The current touched() code returns true whenever CRF0 is non-zero, which happens frequently even when no touch was detected.
I believe touched() should be something like:
return readRegister16(_REG_CFR0) & (CFR0_PENMODE | CFR0_STATUS) >>15;
I was able to workaround the problem in my test code, by adding a TOUCHED_DETECTED macro that tests bit15 only
#define _REG_CFR0 (0xC << 3)
#define CFR0_STATUS (1 << 14)
#define CFR0_PENMODE (1 << 15)
#define TOUCH_DETECTED(t) (bool) (((t).readRegister16(_REG_CFR0) & (CFR0_PENMODE | CFR0_STATUS) ) >> 15)
Lines 138 & 139 in TSC2004.cpp should read:
*z = *x * (z2/z1 - 1); // per page 15 of the datasheet
*z = *z * _RESISTOR_VAL / 4096;
Yeah, I know that *z *= should work but the compiler optimizes out the first line if the 2nd line isn't changed, and you still get only zero.
Make these 2 changes and it returns non-zero values. Note that it returns lower values for lighter touches, contrary to what I expected, but this is reasonable since resistance will decrease with higher pressure.
This version includes my touched() fix, referenced in the other issue, as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.