Page 1 of 1

scratchClient mpr121, time from event till scratch2 reacts

Posted: Sat Jun 15, 2019 11:04 pm
by ghp
There was ticket on scratchClient on unacceptable long times from touch input on MPR121 till scratch reacts. The user "trying to make an interactive touch game but the delay between touch and register of events is delayed by a few second.. "

Good idea to measure reaction time. The approach was to add an automated 'touch' to a MPR121 input, in parallel switch a LED and take a video with both LED and scratch2 display. This repeated in 4 second intervals. With video cut software, the time of individual frames can be measured. 25 frames per sec, 40 ms resolution available.

The automated touch was created by connecting a 4.7 nF cap to the input. A microcontroller arduino zero connects this to gnd by switching input to 'output direction', level = low. Then wait 3 sec, switch pin to input, thus isolating the cap. Worked pretty good, the interrupt LED on mpr121 breakout pulses in parallel.

The arduino in parallel switches a LED on/off. The LED placed over the monitor and a video taken from this.

A small tweak in the config file for the mpr121, config_touch_mpr121.xml reduced polling time from 0.1 to 0.05.

With this, the reaction time trigger to event is 0,26 sec, 260 ms. Not very fast, but acceptable.
In a loop, the state of the input was copied to a variable in stage. This takes 40 ms longer, one frame in the video.