The MMM-Swipe
program is a MagicMirror addon module.
This module uses 2 HC-SR04 ultrasonic sensors to determing hand position to produce a "Swipe Left", "Swipe Right", or "Press"
This is a fork of the original version here: https://github.com/mochman/MMM-Swipe. Thank you to mochman for the inital devlopment.
This fork includes a major refactoring of the node_helper
script and uses only the onoff
node module. This eliminates the need to run the MagicMirror with sudo to access the GPIO pins on a Raspberry Pi.
Refactoring has been completed, and this should be very close to a fully functional module, but it requires testing. As of now, no further development is planned by me at this time as the sensors make an audible sound that the dog doesn't like, which means I'll be taking a new direction.
- Uses
onoff
node module instead ofmmm-usonic
andmmm-gpio
- No SUDO required
- Sensors/detection can be started/stopped automatically with the
autoStart
configuration option, or can be started/stopped by sending a notification from another module: e.g.:this.sendNotification("SWIPE_CONTROL", "START")
. - Testing scripts included in the
usonic
folder if you want to play around with the sensors. Run them usingnode usonic/testingXXX.js
from the MMM-Swipe folder. Also includes a script to usepigpio
instead ofonoff
(still requires sudo). - Wiring difference Wiring is based off the
pigpio
sample on this site which adds a voltage divider to lower the input back to the RPi to 3.3VDC. It also uses a single trigger pin, simply connect the trigger pins for each sensor together and then connect one to the GPIO pin on the RPi.
- Navigate into your MagicMirror's
modules
folder and executegit clone https://github.com/mochman/MMM-Swipe.git
. A new folder labeledMMM-Swipe
will appear, cd into it. - Execute
npm install
to install the dependencies - You will need to run
sudo npm start
instead ofnpm start
in order to read/write to the GPIO pins.
To use this module, add it to the modules array in the config/config.js
file:
modules: [
{
module: 'MMM-Swipe',
position: 'bottom_left', // Doesn't matter after it's setup. It should be blank.
// Best results in one of the side regions like: bottom_left
config: {
// See 'Configuration options' for more information.
echoLeftPin: 24, //Left Sensor's BCM Numbered Echo pin - REQUIRED
triggerLeftPin: 23, //Left Sensor's BCM Numbered trigger pin - REQUIRED
echoRightPin: 26, //Right Sensor's BCM Numbered Echo pin - REQUIRED
triggerRightPin: 25, //Right Sensor's BCM Numbered trigger pin - REQUIRED
useAsButton: false, //Enable a GPIO output when you "press".
buttonPin: 8,
verbose: false,
calibrate: false
}
}
]
This module will use the sendNotification(notification, payload)
to send:
notification = 'MOVEMENT'
payload = 'Swipe Left'
, 'Swipe Right'
, or 'Press'
Please use as appropriate in your module using notificationReceived(notification, payload, sender)
Please wire the sensors using this diagram. ![Example: hcsr04.png] (https://raw.githubusercontent.com/clebert/r-pi-usonic/master/resources/hcsr04.png)
Remember to use the GPIO numbers, not actual pins. For example, if you want to use the defaults and you have a Raspberry Pi 2/3, echoLeftPin should be on GPIO24 (which is physical pin 18, etc...).
The following properties can be configured:
Option | Description |
---|---|
echoLeftPin |
Left Sensor's Echo pin. Example: 24
This value is REQUIRED |
echoRightPin |
Right Sensor's Echo pin. Example: 23
This value is REQUIRED |
triggerLeftPin |
Left Sensor's Trigger pin. Example: 26
This value is REQUIRED |
triggerRightPin |
Right Sensor's Echo pin. Example: 25
This value is REQUIRED |
useAsButton |
If you want to enable a GPIO output when you "press", change this to true Example: true
Default Value: false
|
triggerRightPin |
GPIO pin that will be activated when you "press" the sensors. Example: 8
This value is REQUIRED if you enable useAsButton |
leftDistance |
Distance in cm that will initiate the movement detection with the left sensor Example: 20
Default Value: 20
|
rightDistance |
Distance in cm that will initiate the movement detection with the right sensor Example: 20
Default Value: 20
|
verbose |
Will display swipe data to the screen for checking Example: true
Default Value: false
|
calibrate |
This will dispay the distances read by your sensors so you can use a leftDistance & rightDistance that works for you.Example: true
Default Value: true
|