{"action":"created","issue":{"url":"https://api.github.com/repos/MrYsLab/pymata-aio/issues/22","labels_url":"https://api.github.com/repos/MrYsLab/pymata-aio/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/MrYsLab/pymata-aio/issues/22/comments","events_url":"https://api.github.com/repos/MrYsLab/pymata-aio/issues/22/events","html_url":"https://github.com/MrYsLab/pymata-aio/issues/22","id":102426912,"number":22,"title":"Commands not sent when using a tkinter GUI","user":{"login":"fisherds","id":295078,"avatar_url":"https://avatars.githubusercontent.com/u/295078?v=3","gravatar_id":"","url":"https://api.github.com/users/fisherds","html_url":"https://github.com/fisherds","followers_url":"https://api.github.com/users/fisherds/followers","following_url":"https://api.github.com/users/fisherds/following{/other_user}","gists_url":"https://api.github.com/users/fisherds/gists{/gist_id}","starred_url":"https://api.github.com/users/fisherds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fisherds/subscriptions","organizations_url":"https://api.github.com/users/fisherds/orgs","repos_url":"https://api.github.com/users/fisherds/repos","events_url":"https://api.github.com/users/fisherds/events{/privacy}","received_events_url":"https://api.github.com/users/fisherds/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-21T17:26:12Z","updated_at":"2015-08-21T20:42:46Z","closed_at":"2015-08-21T20:42:46Z","body":"We're now working with simple GUIs to drive the RedBot.  In this example we're using tkinter to make a simple button grid.  Each button drives the Redbot wheels in a different direction.  If you run the example below the command sent last (right PWM in this case) is not sent unless you press the button a second time.  Same issue with using the arrow keys.  All buttons and keys need to be pressed twice to work right.  I'm guessing it's a related issues to some other things we've filed???  Any chance you can fix this one too. :)  Thanks\r\n\r\n        \"\"\"\r\n        Uses the tkinter/ttk graphics library that comes with Python to drive a RedBot.\r\n        \"\"\"\r\n        \r\n        import tkinter\r\n        from tkinter import ttk\r\n        from pymata_aio.pymata3 import PyMata3\r\n        from pymata_aio.constants import Constants\r\n        \r\n        # RedBot motor pins from RedBot.h\r\n        L_CTRL_1 = 2\r\n        L_CTRL_2 = 4\r\n        PWM_L = 5\r\n        \r\n        R_CTRL_1 = 7\r\n        R_CTRL_2 = 8\r\n        PWM_R = 6\r\n        \r\n        board = PyMata3()\r\n        \r\n        \r\n        def main():\r\n            print(\"tkinter GUI drive\")\r\n            board.set_pin_mode(L_CTRL_1, Constants.OUTPUT)\r\n            board.set_pin_mode(L_CTRL_2, Constants.OUTPUT)\r\n            board.set_pin_mode(PWM_L, Constants.PWM)\r\n            board.set_pin_mode(R_CTRL_1, Constants.OUTPUT)\r\n            board.set_pin_mode(R_CTRL_2, Constants.OUTPUT)\r\n            board.set_pin_mode(PWM_R, Constants.PWM)\r\n        \r\n            root = tkinter.Tk()\r\n            root.title(\"RedBot simple drive\")\r\n        \r\n            main_frame = ttk.Frame(root, padding=30, relief=\"raised\")\r\n            main_frame.grid()\r\n        \r\n            button = ttk.Button(main_frame, text=\"Forward\")\r\n            button.grid(column=1, row=0)\r\n            button[\"command\"] = driveForward\r\n        \r\n            button = ttk.Button(main_frame, text=\"CCW Spin\")\r\n            button.grid(column=0, row=1)\r\n            button[\"command\"] = ccwSpin\r\n        \r\n            button = ttk.Button(main_frame, text=\"Stop\")\r\n            button.grid(column=1, row=1)\r\n            button[\"command\"] = stop\r\n        \r\n            button = ttk.Button(main_frame, text=\"CW Spin\")\r\n            button.grid(column=2, row=1)\r\n            button[\"command\"] = cwSpin\r\n        \r\n            button = ttk.Button(main_frame, text=\"Reverse\")\r\n            button.grid(column=1, row=2)\r\n            button[\"command\"] = driveReverse\r\n        \r\n            root.bind(\"<Up>\", driveForward)\r\n            root.bind(\"<Left>\", cwSpin)\r\n            root.bind(\"<space>\", stop)\r\n            root.bind(\"<Right>\", ccwSpin)\r\n            root.bind(\"<Down>\", driveReverse)\r\n        \r\n            root.mainloop()\r\n        \r\n        \r\n        def driveForward(event=None):\r\n            print(\"Go forward\")\r\n            board.digital_write(L_CTRL_1, 1)\r\n            board.digital_write(L_CTRL_2, 0)\r\n            board.analog_write(PWM_L, 255)\r\n            board.digital_write(R_CTRL_1, 1)\r\n            board.digital_write(R_CTRL_2, 0)\r\n            board.analog_write(PWM_R, 255)\r\n        \r\n        \r\n        def ccwSpin(event=None):\r\n            print(\"Spin counter clockwise\")\r\n            board.digital_write(L_CTRL_1, 0)\r\n            board.digital_write(L_CTRL_2, 1)\r\n            board.analog_write(PWM_L, 255)\r\n            board.digital_write(R_CTRL_1, 1)\r\n            board.digital_write(R_CTRL_2, 0)\r\n            board.analog_write(PWM_R, 255)\r\n        \r\n        \r\n        def stop(event=None):\r\n            print(\"Stop\")\r\n            board.digital_write(L_CTRL_1, 1)\r\n            board.digital_write(L_CTRL_2, 1)\r\n            board.analog_write(PWM_L, 0)\r\n            board.digital_write(R_CTRL_1, 1)\r\n            board.digital_write(R_CTRL_2, 1)\r\n            board.analog_write(PWM_R, 0)\r\n        \r\n        \r\n        def cwSpin(event=None):\r\n            print(\"Clockwise spin\")\r\n            board.digital_write(L_CTRL_1, 1)\r\n            board.digital_write(L_CTRL_2, 0)\r\n            board.analog_write(PWM_L, 255)\r\n            board.digital_write(R_CTRL_1, 0)\r\n            board.digital_write(R_CTRL_2, 1)\r\n            board.analog_write(PWM_R, 255)\r\n        \r\n        \r\n        def driveReverse(event=None):\r\n            print(\"Go forward\")\r\n            board.digital_write(L_CTRL_1, 0)\r\n            board.digital_write(L_CTRL_2, 1)\r\n            board.analog_write(PWM_L, 255)\r\n            board.digital_write(R_CTRL_1, 0)\r\n            board.digital_write(R_CTRL_2, 1)\r\n            board.analog_write(PWM_R, 255)\r\n        \r\n        \r\n        main()\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/MrYsLab/pymata-aio/issues/comments/133556441","html_url":"https://github.com/MrYsLab/pymata-aio/issues/22#issuecomment-133556441","issue_url":"https://api.github.com/repos/MrYsLab/pymata-aio/issues/22","id":133556441,"user":{"login":"MrYsLab","id":5189838,"avatar_url":"https://avatars.githubusercontent.com/u/5189838?v=3","gravatar_id":"","url":"https://api.github.com/users/MrYsLab","html_url":"https://github.com/MrYsLab","followers_url":"https://api.github.com/users/MrYsLab/followers","following_url":"https://api.github.com/users/MrYsLab/following{/other_user}","gists_url":"https://api.github.com/users/MrYsLab/gists{/gist_id}","starred_url":"https://api.github.com/users/MrYsLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrYsLab/subscriptions","organizations_url":"https://api.github.com/users/MrYsLab/orgs","repos_url":"https://api.github.com/users/MrYsLab/repos","events_url":"https://api.github.com/users/MrYsLab/events{/privacy}","received_events_url":"https://api.github.com/users/MrYsLab/received_events","type":"User","site_admin":false},"created_at":"2015-08-21T20:42:46Z","updated_at":"2015-08-21T20:42:46Z","body":"Repaired in version 1.8"}}