Go Down

Topic: Does Capacitivesensor.h (capsense) work on ATSAMD21 and Arduino Zero? (Read 947 times) previous topic - next topic

rgoldman

Hi!
I am writing because I am unable to get "Capsense" (capactivesensor.h) to work on my ATSAMD21.  Capsense can measure gradations of capacitance (at lower resistance values).  This fits my application much better than of touch capacitance sensing which is either "on or off".  My search of the internet finds others have tried without success to use Capsense on the Arduino Zero and ATSAMD21 from Adafruit (Pro Trinket 3v).  I am using the Pro Trinket and ArduinoIDE verson 1.8.3.  I have the latest version of capacitivesensor.h (0.5.1).  I am using a 3 year old Macbook pro with OS 10.11.6 and USB 3.0.  The bootloader uploads successfully.   

I've researched several entries by Paul Stoffregen.  He of course maintains the capacitivesensor.h library.  He notes in several forums that capacitivesensor.h does not work well for the SAMD21G18A.  See his entry on https://communities.intel.com/message/387731#387731
In this forum entry he invites someone in the Arduino community to fix this. Has anyone made progress on this?  I am intrepid but have intermediate skill in Arduino library development and updating the capacitivesensor.h library appears a daunting task.  Any help here would be much appreciated, and thanks! 


From the actual library capacitvesensor.h:
(Note comment by Paul Stoffregen):

#elif defined(__SAMD21G18A__)
// runs extremely slow/unreliable on Arduino Zero - help wanted....
#define PIN_TO_BASEREG(pin)             portModeRegister(digitalPinToPort(pin))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*((base)+8)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*((base)+1)) = (mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*((base)+2)) = (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*((base)+5)) = (mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*((base)+6)) = (mask))

Go Up