{"id":3251,"date":"2020-04-09T00:45:36","date_gmt":"2020-04-08T15:45:36","guid":{"rendered":"https:\/\/programresource.net\/?p=3251"},"modified":"2020-04-09T00:45:38","modified_gmt":"2020-04-08T15:45:38","slug":"use-m5stack-as-bluetooth-keyboard-and-control-presentation","status":"publish","type":"post","link":"https:\/\/programresource.net\/en\/2020\/04\/09\/3251.html","title":{"rendered":"Use M5Stack as Bluetooth keyboard and control presentation"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718-1024x581.png\" alt=\"\" class=\"wp-image-3246\" srcset=\"https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718-1024x581.png 1024w, https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718-300x170.png 300w, https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718-768x436.png 768w, https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718-1536x872.png 1536w, https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>ESP32 devices can be used as Bluetooth device, such as mouse or keyboard. It was hard to write sketch while ago, but now, there&#8217;s handy library which you can easily make ESP32 to Bluetooth hid device.<\/p>\n\n\n\n<p>This time, I&#8217;ll be using M5Stack to work as simple PowerPoint controller.<\/p>\n\n\n\n<p>Download and install library from URL below for Bluetooth Keyboard.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/T-vK\/ESP32-BLE-Keyboard\">https:\/\/github.com\/T-vK\/ESP32-BLE-Keyboard<\/a><\/p>\n\n\n\n<p>After installing library is simple. Call begin, then press\/release function to send  key. Since M5Stack have 3 buttons, I&#8217;ve assigned Home, Page Up, and Page Down key to them. You can also do some more complicated control using long hold button, etc.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;M5Stack.h&gt;\n#include &lt;BleKeyboard.h&gt;\n\nBleKeyboard bleKeyboard(&quot;M5 Presenter&quot;);\nbool blestate = false;\n\nvoid showstate(char *txt) {\n\tM5.Lcd.setCursor(0, 120);\n\tM5.Lcd.fillRect(0, 120, 320, 20, BLACK);\n\tM5.Lcd.printf(txt);\n}\n\nvoid setup() {\n\tM5.begin();\n\tM5.Power.begin();\n\n\tbleKeyboard.begin();\n\n\tM5.Lcd.clear(BLACK);\n\tM5.Lcd.setTextSize(2);\n\tM5.Lcd.println(&quot;Presenter&quot;);\n\tM5.Lcd.println(&quot;A: Home&quot;);\n\tM5.Lcd.println(&quot;B: Page Up&quot;);\n\tM5.Lcd.println(&quot;C: Page Down&quot;);\n\tshowstate(&quot;Disconnected&quot;);\n}\n\nvoid loop() {\n\tM5.update();\n\n\tif (bleKeyboard.isConnected()) {\n\t\tif (!blestate) {\n\t\t\tblestate = true;\n\t\t\tshowstate(&quot;Connected&quot;);\n\t\t}\n\n\t\tif (M5.BtnA.wasPressed()) {\n\t\t\tbleKeyboard.press(KEY_HOME);\n\t\t\tbleKeyboard.release(KEY_HOME);\n\t\t} else if (M5.BtnB.wasPressed()) {\n\t\t\tbleKeyboard.press(KEY_PAGE_UP);\n\t\t\tbleKeyboard.release(KEY_PAGE_UP);\n\t\t} else if (M5.BtnC.wasPressed()) {\n\t\t\tbleKeyboard.press(KEY_PAGE_DOWN);\n\t\t\tbleKeyboard.release(KEY_PAGE_DOWN);\n\t\t}\n\t} else {\n\t\tif (blestate) {\n\t\t\tblestate = false;\n\t\t\tshowstate(&quot;Disconnected&quot;);\n\t\t}\n\t}\n}\n<\/pre><\/div>\n\n\n<p>After writing sketch to M5Stack and booting, you will find M5Stack as Bluetooth device with name &#8220;M5 Presenter&#8221;. Pair and you are ready.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/programresource.net\/images\/2020\/04\/bluetooth.png\"><img decoding=\"async\" src=\"https:\/\/programresource.net\/images\/2020\/04\/bluetooth.png\" alt=\"\" class=\"wp-image-3248\" srcset=\"https:\/\/programresource.net\/images\/2020\/04\/bluetooth.png 550w, https:\/\/programresource.net\/images\/2020\/04\/bluetooth-261x300.png 261w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/figure>\n\n\n\n<p>Press 3 buttons on M5Stack, and it will work as Home, Page UP, and Page Down key.<\/p>\n\n\n\n<p>See below for quick video. Amazingly simple.<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/ApHMJuPbrxI?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation\"><\/iframe><\/span>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>ESP32 devices can be used as Bluetooth device, such as mouse or keyboard. It was hard to write sketch while ago, but now, there&#8217;s handy library which you can easily make ESP32 to Bluetooth hid device. This time, I&#8217;ll be using M5Stack to work as simple PowerPoint controller. Download and install library from URL below for Bluetooth Keyboard. https:\/\/github.com\/T-vK\/ESP32-BLE-Keyboard After installing library is simple. Call begin, then press\/release function to send key. Since M5Stack have 3 buttons, I&#8217;ve assigned Home, Page Up, and Page Down key to them. You can also do some more complicated control using long hold button, etc. After writing sketch to M5Stack and booting, you will &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3247,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[866],"tags":[982,976,883,983],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/programresource.net\/images\/2020\/04\/vlcsnap-2020-04-09-00h08m21s718.png","jetpack_shortlink":"https:\/\/wp.me\/p3pJyQ-Qr","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3251"}],"collection":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/comments?post=3251"}],"version-history":[{"count":1,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3251\/revisions"}],"predecessor-version":[{"id":3252,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3251\/revisions\/3252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media\/3247"}],"wp:attachment":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media?parent=3251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/categories?post=3251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/tags?post=3251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}