Newer
Older
This sketch has been designed to continually measure four sensors attached to pin 1,2 (reel) and 3,4 (arm) in a positioning device consisting of magnet based rotary encoders measuring angle and length of a string attached to a device.
It transforms the sensor measurements into angles. The reel rotations have to be tracked. The magnets used are no perfect round magnetic fields. While the missing accuracy on the reel is not problematic, the arm angle is corrected by an appropriate function that has to be deducted from measurements and varies by magnet.
To reduce noise, the sketch features an optimized queue and Low Pass filter. Each measurement and angle transformation takes 600 micro seconds. We found 30 measurements (changeable by defining queue_length and queue) a good comprimise between fluidity and accuracy (18 milli seconds per position). Only on position change the Bluetooth attribute getPos 19B10011-E8F2-537E-4F6C-D104768A1214 is updated, a notification is sent to reduce power consumption. Power consumption can further be reduced by changing POSITION_SMOOTH to only calculate and potentially update Bluetooth characteristic every X cycles.
The device can be used with hats providing additional functionality. This version is equipped with a PN532 NFC reader. The adafruit PN532 library is used.
In order to keep power use low, the NFC reader only is read every 200 cycles (changeable by defining NFC_CYCLES) which equates to a typical Smartphone NFC read rate. When a tag is read, page 7 to 9 is read and the attribute getNFC 19B10011-E8F2-537E-4F6C-D104768A1215 updated.
- [ ] Variable Names
- [ ] Initial NFC Tag imitation for pairing process
## Arduino environment
In order for this sketch to be transferred on a Seeed XIAO nrf52840, Arduino 1.8.19 is required (won't work on more recent versions). The bluetooth library ArduinoBLE should be version 1.3.4