MagicMirror Module - detecting 3D gesture with GroveGesture Sensor(PAJ7620u2)
1.1.1
moduleExec
1.1.0
commandSet
is added.
commandSet
section.Unfortunately, due to it's short range and theory of electro-magnetic field, this sensor will not be used beneath Spymirror. But under the thin wooden, plastic or normal glass, it will work.
It works as 3D gesture sensor similar with Skywriter
or Flick!
, but definitely small, flat, and non-HAT. It could fit for bezel-frame of MagicMirror. Soldering is not needed.
sudo i2cdetect -y 1
or install it.
sudo apt-get update
sudo apt-get install i2c-tools
sudo i2cdetect -y 1
, if you can see 73
on the matrix of result, H/W is installed properly.cd ~/MagicMirror/modules
git clone https://github.com/eouia/MMM-GroveGestures
cd MMM-GroveGestures
npm install
cd scripts
chmod +x *.sh
You might need to modify /scripts/*.sh
files for your environment.
After installation of module,
cd ~/MagicMirror/modules/MMM-GroveGestures/py
cp grove_gesture_sensor.py.RPI grove_gesture_sensor.py
You can test your sensor with this;
cd ~/MagicMirror/modules/MMM-GroveGestures/py
python gesture_print.py
{
module: "MMM-GroveGestures",
position: "top_right",
config: {}
},
{
module: "MMM-GroveGestures",
position: "top_right",
config: {
autoStart: true, //When Mirror starts, recognition will start.
verbose:false, // If set as `true`, useful messages will be logged.
recognitionTimeout: 1000, //Gesture sequence will be ended after this time from last recognized gesture.
cancelGesture: "WAVE", //If set, You can cancel gesture sequence with this gesture.
visible: true, //Recognized gesture sequence will be displayed on position
idleTimer: 1000*60*30, // `0` for disable, After this time from last gesture, onIdle will be executed.
onIdle: { // See command section
moduleExec: {
module: [],
exec: (module, gestures) => {
module.hide(1000, null, {lockstring:"GESTURE"})
}
}
},
onDetected: {
notificationExec: {
notification: "GESTURE_DETECTED",
},
/* You can make Mirror to wake up the modules which were hidden by onIdle with any gestures.
moduleExec: {
module: [],
exec: (module) => {
module.show(1000, null, {lockstring:"GESTURE"})
}
}
*/
},
gestureMapFromTo: { //When your sensor is installed with rotated direction, you can calibrate with this.
"Up": "UP",
"Down": "DOWN",
"Left": "LEFT",
"Right": "RIGHT",
"Forward": "FORWARD",
"Backward": "BACKWARD",
"Clockwise": "CLOCKWISE",
"anti-clockwise": "ANTICLOCKWISE",
"wave": "WAVE"
},
defaultNotification: "GESTURE",
pythonPath: "/usr/bin/python", // your python path
defaultCommandSet: "default",
commandSet: {
"default": {
"FORWARD-BACKWARD": {
notificationExec: {
notification: "ASSISTANT_ACTIVATE",
payload: null
}
},
"LEFT-RIGHT": {
notificationExec: {
notification: "ASSISTANT_CLEAR",
payload:null,
}
},
"CLOCKWISE": {
moduleExec: {
module: [],
exec: (module, gestures) => {
module.hide(1000, null, {lockstring:"GESTURE"})
}
}
},
"ANTICLOCKWISE": {
moduleExec: {
module: [],
exec: (module, gestures) => {
module.show(1000, null, {lockstring:"GESTURE"})
}
}
},
"LEFT": {
notificationExec: {
notification: "ARTICLE_PREVIOUS",
payload: null,
}
},
"RIGHT": {
notificationExec: {
notification: "ARTICLE_NEXT",
payload: null,
}
},
},
},
}
},
You can modify, remove or create these gestures commands in config.js
newsfeed
newsfeed
MMM-AssistantMk2
instead HotwordMMM-AssistantMk2
) playing.command
in Configuration"GESTURE-SEQUENCE" : {
shellExec: "...",
notificationExec: { ... },
moduleExec: { ... }
}
shellExec
: You can execute this String
as shell command
shellExec: "sudo reboot now"
notificationExec
: You can send notification with this. If payload is not defined, gestures
Object will be used by default. If you want null value as payload, just set payload:null
.
notificationExec: {
notification: "SHOW_ALERT",
payload: {
message: "Hello, World",
timer: 5000
}
}
moduleExec
: You can control Module and it's method. exec
is function which has module
and gestures
objects as arguments.
moduleExec: {
module: ["clock", "newsfeed"], // `[]` will be all modules.
exec: (module, gestures) => {
module.hide()
}
}
gestures
Object
gestures: {
status: "FINISH", // "FINISH", "ONGOING", "CANCEL"
last: "LEFT", // Last detected gesture
sequence: "UP-DOWN-LEFT", // detected gesture sequence until now
}
You can define set of command for your purpose. The set would be changed by notification on runtime
defaultCommandSet: "DEFAULT_MODE",
commandSet: {
"DEFAULT_MODE": {
"LEFT": {
notificationExec: {
notification: "PAGE_INCREMENT",
payload: null
}
},
},
"NEWS_MODE": {
"LEFT": {
notificationExec: {
notification: "ARTICLE_NEXT",
payload: null
}
},
}
},
commandSetTrigger: {
"GG_CHANGE_COMMANDSET_NEWSMODE": "NEWS_MODE",
"GG_CHANGE_COMMANDSET_BY_PAYLOAD": (payload) => { // You can use callback function to change set with conditional payload values.
return payload.commandSetName
}
},
There are two sets of command - DEFAULT_MODE
and NEWS_MODE
. The "LEFT" command of each set could be defined differently.
You can change the set by notification GG_CHANGE_COMMANDSET_NEWSMODE
and GG_CHANGE_COMMANDSET
which are defined in commandSetTrigger
. If GG_CHANGE_COMMANDSET_NEWSMODE
notification is arrived, the current set of commands will be changed to NEWS_MODE
.
Of course, you can redefine the names of trigger notifications or commandSets.
[GESTURE] Python script is terminated. It will restart soon.
: If you too often meet this error, adjust your i2c bus speed. (Default would be 100000, try 10000 or 32000.)
https://www.raspberrypi-spy.co.uk/2018/02/change-raspberry-pi-i2c-bus-speed/