MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    MMM-Navigate, Navigation inside MagicMirror with Rotary Encoder

    Scheduled Pinned Locked Moved System
    45 Posts 6 Posters 25.2k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      AxLed Module Developer
      last edited by

      @Eisblume
      I found the line in node_helper.js, its line 35

      const C = new Gpio(self.config.GPIOPins[2], 'in', 'both',{debounceTimeout : 20 }); //BCM Pin 19
      

      Here you can try to increase/reduce the debounceTimeout between 10 and 50 (in steps of 10) and see if there is a difference for your “pressed” problem.

      AxLED

      1 Reply Last reply Reply Quote 0
      • E Offline
        Eisblume
        last edited by Eisblume

        @AxLed
        I tried every very with different press speed. It doesn’t work. No press Signal will be sent :-(

        I don´t understand why cw and cww works fine, but not the press - Button?

        Edit:
        I test the Rotary with this: https://github.com/martinohanlon/KY040
        Here the press button works fine.

        pi@raspberrypi:~/EncoderTest/KY040/examples $ python python3.py
        turned - 0
        turned - 0
        turned - 1
        turned - 1
        button pressed
        button pressed
        button pressed
        button pressed
        button pressed
        button pressed

        1 Reply Last reply Reply Quote 0
        • A Offline
          AxLed Module Developer
          last edited by

          @Eisblume
          Please post your config and make sure your private keys are x-ed. So i can try to copy your setup to my test pi and maybe find out whats the reason. That your rotary encoder generally works is good to know.
          AxLED

          1 Reply Last reply Reply Quote 0
          • E Offline
            Eisblume
            last edited by Eisblume

            Ok, thanks @AxLed !!

            config.js:

            /* Magic Mirror Config Sample
             *
             * By Michael Teeuw http://michaelteeuw.nl
             * MIT Licensed.
             *
             * For more information how you can configurate this file
             * See https://github.com/MichMich/MagicMirror#configuration
             *
             */
            
            var config = {
            	address: "0.0.0.0", // Address to listen on, can be:
            	                      // - "localhost", "127.0.0.1", "::1" to listen on loopback interface
            	                      // - another specific IPv4/6 to listen on a specific interface
            	                      // - "", "0.0.0.0", "::" to listen on any interface
            	                      // Default, when address config is left out, is "localhost"
            	port: 8080,
            	ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.1/120", "192.168.1.1/24"], // Set [] to allow all IP addresses
            	                                                       // or add a specific IPv4 of 192.168.1.5 :
            	                                                       // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
            	                                                       // or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
            	                                                       // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],
            
            	language: "de",
            	timeFormat: 24,
            	units: "metric",
            
            	modules: [
            		{
            			module: "alert",
            		},
            		{
            			module: "clock",
            			position: "top_left"
            		},
            		{
            			module: "MMM-Navigate",
            			header: "Navigation",
            			position: "top_left",
            			config: {
            					Alias: [
            						'Seiten blättern',
            						'News (mehr/weniger Details)',
            						'Test notification',
            						'News - mehr Details',
            						'News - weniger Details',
            						'Neustart MagicMirror (PM2)',
            						'Neustart',
            						'Herunterfahren'
            					],
            					Action: [
            						[{notification:'PAGE_INCREMENT',payload:''},{notification:'PAGE_DECREMENT',payload:''}],//action array, first press locks menu, after this rotation CW/CCW executes, second press release lock mode
            						[{notification:'ARTICLE_MORE_DETAILS',payload:''},{notification:'ARTICLE_LESS_DETAILS',payload:''}],
            						{notification: "SHOW_ALERT", payload: {type:"notification",message:"Dies ist eine Testnachricht"}},//single action, execute on press
            						{notification:'ARTICLE_MORE_DETAILS',payload:''},
            						{notification:'ARTICLE_LESS_DETAILS',payload:''},
            						{notification: "REMOTE_ACTION", payload: {action: "RESTART"}},
            						{notification: "REMOTE_ACTION", payload: {action: "REBOOT"}},
            						{notification: "REMOTE_ACTION", payload: {action: "SHUTDOWN"}}
            					],
            					GPIOPins: [26,20,19]//rotary cw, rotary ccw, rotary press (BCM Numbering)
            					},
            },
            		{
                		module: 'MMM-Remote-Control',
                		// uncomment the following line to show the URL of the remote control on the mirror
                		// , position: 'bottom_left'
                		// you can hide this module afterwards from the remote control itself
                		config: {
                    		customCommand: {},  // Optional, See "Using Custom Commands" below
                    		customMenu: "custom_menu.json", // Optional, See "Custom Menu Items" below
                    		showModuleApiMenu: true, // Optional, Enable the Module Controls menu
                    		apiKey: ""         // Optional, See API/README.md for details
                		}
            		},
            		{
            			module: "updatenotification",
            			position: "top_bar"
            		},
            		{
            			module: "calendar",
            			header: "Familie Reetz",
            			position: "top_left",
            			config: {
            				calendars: [
            					{
            						symbol: "calendar-check",
            						url: "webcal://pxxxxxxm/xxxxxxxKSw_tdQ8WGeTZVjgr6Vwn1HDxxxxxxx5OuupPnKOIExxxx"
            					}
            				]
            			}
            		},
            //		{
            //			module: "compliments",
            //			position: "lower_third"
            //		},
            {
            			module: "currentweather",
            			position: "top_right",
            			config: {
            				location: "xxxx",
            				locationID: "xxx",  //ID from http://bulk.openweathermap.org/sample/; unzip the gz file and find your city
            				appid: "xxxxx"
            			}
            		},
            		{
            			module: "weatherforecast",
            			position: "top_right",
            			header: "Wettervorhersage",
            			config: {
            				location: "xxxx",
            				locationID: "xxxx",  //ID from https://openweathermap.org/city
            				appid: "xxxxx"
            			}
            		},
            		{
            			module: "newsfeed",
            			position: "bottom_bar",
            			config: {
            				feeds: [
            					{
            						title: "Tagesschau",
            						url: "http://www.tagesschau.de/xml/rss2"
            						//url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
            					}
            				],
            				showSourceTitle: true,
            				showPublishDate: true
            			}
            		},
            		{
                		module: "MMM-Fuel",
                		position: "bottom_left",
                		config: {
                    			api_key: "xxxxx",
                    			lat: 123456,
                    			lng: 654321,
                    			types: ["diesel"],
                    			radius: 15,
                    			max: 3     			
                				}
            		},
            		{
            	        module: 'MMM-Dreambox',
            			header: 'Vu+ Ultimo4K powered by VTi',
            			position: 'bottom_right',
            			config: {
            				apiBase: 'http://192.168.1.50:90',
            				//omxargs: ' --vol -6000 --win 0,625,590,957 --live ',
            				omxargs: ' --win 600,60,1490,940 -o both ',
            				refreshInterval: 1000 * 30, //refresh every 30 seconds
            				apibouquet: 0, //bouquet, if there is more than one under apiservices (/web/getallservices),
            				apiRecordingsID: 0, //which recording folder should be listed
            				listmax: 10,
            				apiabout: '/web/about',
            				apiservices: '/web/getallservices',
            				apiepgnow: '/web/epgnow?bRef=',
            				apizap: '/web/zap?sRef=',
            				apiTimerlist: '/web/timerlist',
            				apiServicelistplayable: '/web/servicelistplayable?sRef=',
            				apiLocations: '/web/getlocations', //where are the recording folders listed
            				apiMovielist: '/web/movielist?dirname=' //link for opening recording folder and list recordings
            				}
            		},
            	]
            
            };
            
            /*************** DO NOT EDIT THE LINE BELOW ***************/
            if (typeof module !== "undefined") {module.exports = config;}
            
            
            1 Reply Last reply Reply Quote 0
            • A Offline
              AxLed Module Developer
              last edited by

              @Eisblume
              I tested wih modules of your config.

              My testconfiguration:

              • Raspberry Pi 1
              • MagicMirror v2.7.1
              • npm v6.8.0
              • node v8.9.0
              • no electron (as i dont run/installable on Pi 1), i run node serveronly
              • display: Webbrowser

              My rotary encoder works as follows:

              • Seite blättern (press works and gives a red frame an a lock sign, cw an ccw dont work, as MMM-Pages isnt part of your config)
              • News (mehr/weniger Details) (press works and gives a red frame an a lock sign, cw an ccw works)
              • Test notification (press works, no cw or ccw functionality by design)
              • News - mehr Details (press works, no cw or ccw functionality by design)
              • News - weniger Details (press works, no cw or ccw functionality by design)
              • Neustart MagicMirror (PM2) (dont work in my testconfiguration, as i dont use PM on RPI1)
              • Neustart (press works, there is a pop up notification to press twice for reeboot, requires MMM-Remote-Control)
              • Herunterfahren (press works, there is a pop up notification to press twice for shutdown, requires MMM-Remote-Control)

              Two ideas:

              • wrong cabeling, here are the 3 pins for CW, CW and PRESS of your config.js (GPIOPins: [26,20,19])
                0_1558555492514_bmc.JPG
              • messed up setup, try to save your config and reinstall raspian an MM

              Greets

              AxLED

              1 Reply Last reply Reply Quote 0
              • E Offline
                Eisblume
                last edited by

                Thank you so much for your help. But It still doesn’t work.

                The cabeling is correct I checked it many times ;-)

                The crazy thing is, when I remove ground, the press button works, but not the cw and cww.

                I think, I will try a clean reinstall on my RPi3.

                1 Reply Last reply Reply Quote 0
                • E Offline
                  Eisblume
                  last edited by Eisblume

                  @AxLed
                  Also after clean install with nothing more, the default modules and MMM-Navigate and MMM-Remote-Controll it doesn’t work.

                  Here you can see: https://youtu.be/G2eRoPxRPjU

                  Only when I remove ground, the press action works. But then, the cw and cww doesn’t work…

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    AxLed Module Developer
                    last edited by

                    @Eisblume
                    Thanks for your reply, i tested at my pi with disconnected ground cable, but there is no press, cw or ccw working at all.
                    My last ideas:

                    • can you messure your 5 cables if maybe one is interrupted
                    • maybe there are two versions of KY-040 on the marked, i have this one Amazon
                    • is your second rotary encoder shows same symptoms?
                    • did you connect + of rotary encoder to 5V once (which would be wrong and maybe damaged your GPIO PINs/chip)?

                    AxLED

                    1 Reply Last reply Reply Quote 0
                    • E Offline
                      Eisblume
                      last edited by

                      @AxLed
                      Do not think that I am lying ;-), but it works fine, when I start MagicMirror and after that I start the python - script from here https://github.com/martinohanlon/KY040.

                      cw, cww and press works absolutely fine.

                      It is very strange.

                      1 Reply Last reply Reply Quote 0
                      • E Offline
                        Eisblume
                        last edited by Eisblume

                        @AxLed
                        Ok, i fix it now for me.

                        I know, it is a dirty code, but don’t found another solution :dizzy_face:

                        I attached the KY040 python script in the node_helper.js. Then everything works fine.

                        //node_helper.js
                        /* Magic Mirror
                         * Node Helper: {MMM-Navigate}
                         *
                         * By {AxLED}
                         * {MIT} Licensed.
                         */
                        
                         //Debugging
                         //tail -f ~/.pm2/logs/mm-out-0.log
                         //tail -f ~/.pm2/logs/mm-error-0.log 
                        
                        const Gpio = require('onoff').Gpio;
                        ...
                        const spawn = require("child_process").spawn;
                        //Variables
                        ...
                          start: function() {
                        		var self = this;
                        		this.loaded = false;
                        		var process = spawn("python", ["/home/pi/Downloads/KY040/examples/python3.py"]);
                        	},
                        	
                        ...
                        });
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          AxLed Module Developer
                          last edited by

                          @Eisblume
                          No Problem, i am glad it works for you now, so you also did your first coding experiance.

                          AxLED

                          1 Reply Last reply Reply Quote 0
                          • E Offline
                            Eisblume
                            last edited by

                            @AxLed
                            Yes very interesting experiences :-) !

                            Could you explain my how to start “Tagesschau in 100 Sekunden” in MMM-Navigate ??

                            1 Reply Last reply Reply Quote 0
                            • A Offline
                              AxLed Module Developer
                              last edited by

                              @Eisblume
                              You need two things:

                              • first: a modules which is able to stream 100Sec Tagesschau, i made a fork see MMM-Podcast2
                              • second: the right config (i posting only the relevant part)
                              ....
                              {
                              			module: 'MMM-Podcast2',
                              			config: {
                              				// See 'Configuration options' for more information.
                              				omxargs: ' --win 0,0,1920,1080  -o both '
                              			}
                              		},
                              {
                              			module: "MMM-Navigate",
                              			header: "Navigation",
                              			position: "top_right",
                              			config: {
                              					Alias: [
                              						'Tagesschau 100 Sekunden',
                              						'Herunterfahren'
                              					],
                              					Action: [
                              						{notification:'BUTTON_PRESSED',payload:''},
                              						{notification: "REMOTE_ACTION", payload: {action: "SHUTDOWN"}}
                              					],
                              					GPIOPins: [26,20,19]//rotary cw, rotary ccw, rotary press (BCM Numbering)
                              					},
                              		},
                              ...
                              

                              AxLED

                              E 1 Reply Last reply Reply Quote 0
                              • E Offline
                                Eisblume @AxLed
                                last edited by

                                @AxLed said in MMM-Navigate, Navigation inside MagicMirror with Rotary Encoder:

                                {notification:‘BUTTON_PRESSED’,payload:‘’},

                                Thanks. Works perfect !!!

                                1 Reply Last reply Reply Quote 0
                                • K Offline
                                  keineAhnung123
                                  last edited by

                                  Hello @AxLed ,

                                  Two things:

                                  First

                                  I have the same issue like @Eisblume :

                                  The click doesnt work.
                                  When i then start a sample code to test the rotary encoder (from like here), the click works in the sample code.
                                  If i start the Magic Mirror after that again, then the click works there too.

                                  Maybe there is a missing initialization of the rotary encoder in your code?

                                  Second

                                  Is there a possibility to get more config possibilities?
                                  Like starting the module hidden or shortening the time of the hiding process?

                                  Thanks in advance :)

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    AxLed Module Developer
                                    last edited by

                                    @keineAhnung123,

                                    to your first issue:

                                    • is only click not working or is rotation also not working?
                                      Because rotation and click (Button press) uses the same library (onOff).
                                    • on which pin is click connected, as the pi GPIO Pins have different features?
                                    • what versions you are using (pi, OS, MM-Version)?

                                    To your second issue.

                                    • MMM-Navigate uses the MM notification system, so you can do almost everything you want. What are you trying to to, maybe i can give you a sample for your config.js
                                    • for shortening time of hidding see MM Docs -> search for hide, there is a parameter for speed.

                                    Regards

                                    AxLED

                                    1 Reply Last reply Reply Quote 0
                                    • K Offline
                                      keineAhnung123
                                      last edited by

                                      Hello @AxLed , thanks for your reply

                                      first

                                      • rotation works fine but the button press does not
                                      • i use your standard configuration so it seems to be BCM 19
                                      • PI 3 B+, stretch, MM 2.14.0

                                      I tried MMM-Buttons too. Same problem there. I first have to run a sample script with python and after that the button works in MM too. It uses the onoff library too.

                                      I found a strange behaviour:
                                      I start MM -> button click doesnt work
                                      I start python test script and after that MM -> button click works
                                      When i restart the Raspberry PI and start MM (without the python test script) -> button click works
                                      When i shutdown the Raspberry PI and cut off the connection to an electricity source and restart the PI after that -> button click doesnt work

                                      Thats strange isnt it?

                                      second

                                      I changed the hiding time from 10000 to 2000 cause i prefer a shorter time.
                                      Is there a way to start the module hidden?
                                      I tried following:

                                          // Define start sequence.
                                      
                                          start: function() {
                                      
                                              Log.info("Starting module: " + this.name);
                                      
                                              this.sendConfig();//pass config to node_helper.js
                                      
                                              this.hide();
                                      
                                          },
                                      

                                      and this

                                          //Helper, to use module without Rotary Encoder and without GPIO Pins, like developing in Pixel VM
                                      
                                          notificationReceived: function(notification, payload) {
                                      
                                              if(notification === "CW" || notification === "CCW" || notification === "PRESSED"){
                                      
                                                  this.naviaction({inputtype: ""+ notification +""});
                                      
                                              }
                                      
                                              if(notification === "SHELLCOMMAND"){
                                      
                                                   this.sendSocketNotification(notification, payload);
                                      
                                              } 
                                      
                                              if(notification === "MODULE_DOM_CREATED"){
                                      
                                                   this.hide();
                                      
                                              }
                                      
                                          },
                                      

                                      but both didnt take effect :(

                                      third

                                      I found an reproducable error:
                                      When i start MM and first rotate counterclockwise there is an error in the MM console:

                                      [09.01.2021 09:11.07.337] [LOG]   MMM-Navigate, listen on GPIO PINs (BCM): 26,20,19
                                      
                                      [09.01.2021 09:11.18.306] [ERROR] Whoops! There was an uncaught exception...
                                      [09.01.2021 09:11.18.321] [ERROR] ReferenceError: lastdir is not defined
                                          at tick (/home/pi/MagicMirror/modules/MMM-Navigate/node_helper.js:92:39)
                                          at /home/pi/MagicMirror/modules/MMM-Navigate/node_helper.js:66:4
                                          at /home/pi/MagicMirror/modules/MMM-Navigate/node_modules/onoff/onoff.js:135:9
                                          at Array.forEach (<anonymous>)
                                          at pollerEventHandler (/home/pi/MagicMirror/modules/MMM-Navigate/node_modules/onoff/onoff.js:134:32)
                                      

                                      It doesnt effect the functionality but just wanted to mention it… ;)

                                      1 Reply Last reply Reply Quote 0
                                      • A Offline
                                        AxLed Module Developer
                                        last edited by

                                        @keineAhnung123,

                                        thanks for feedback.
                                        first:
                                        Idea A:

                                        • maybe the pin 19 is the problem, because it is not only a GPIO pin rather it has SPI features. Can you change to BCM16 (and change it in config.js as well) and try it?

                                        Idea B:

                                        • Do you use capacitors for debouncing? If not, you can change debouncing value of following line: https://github.com/Ax-LED/MMM-Navigate/blob/master/node_helper.js#L37

                                        second:

                                        • Which module should start hidden? MMM-Navigate?

                                        third:
                                        I tried to reproduce on my pi 3 and get no error, so i checked the code.
                                        You can add following line as new line 19 in node_helper.js
                                        var lastdir = '';

                                        AxLED

                                        1 Reply Last reply Reply Quote 0
                                        • K Offline
                                          keineAhnung123
                                          last edited by

                                          @AxLed
                                          I will try that later. Thanks
                                          And yes, i want to start MMM-Navigate hidden. Is that possible?

                                          1 Reply Last reply Reply Quote 0
                                          • A Offline
                                            AxLed Module Developer
                                            last edited by

                                            @keineAhnung123 ,

                                            informations to your second issue:
                                            Your request is not provided by MMM-Navigate, maybe it is possible with one of the following modules (untested):

                                            • MMM-ModuleScheduler
                                            • MMM-ModuleToggle

                                            AxLED

                                            1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy