{"id":938,"date":"2016-07-29T01:45:22","date_gmt":"2016-07-29T00:45:22","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=938"},"modified":"2016-07-29T01:45:22","modified_gmt":"2016-07-29T00:45:22","slug":"running-ev3dev-on-a-raspberry-pi-3","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2016\/running-ev3dev-on-a-raspberry-pi-3","title":{"rendered":"Running ev3dev on a Raspberry Pi 3"},"content":{"rendered":"<p>A few days ago the ev3dev project launched a great feature: <a href=\"http:\/\/www.ev3dev.org\/news\/2016\/07\/11\/nightly-image-builds\/\">nightly image builds<\/a>. Right after that I got a received a notice that they included in the image for Raspberry Pi 2\/3 support for onboard the Bluetooth and needed to test it.<\/p>\n<p>So I did test it. And found out that onboard Bluetooth indeed works&#8230; as also onboard Wi-Fi&#8230; as also the Brick Pi, no need to disable BT. Yeah, no more USB dongles!<\/p>\n<p>The procedure is very simple &#8211; the really important step is freeing the hardware serial port for the BrickPi (both the onboard Bluetooth and the BrickPi need a UART so a soft UART (&#8220;miniuart&#8221;) is used for BT instead of the default one.<\/p>\n<ul>\n<li>get the <a href=\"https:\/\/bintray.com\/ev3dev\/nightly\/ev3dev-jessie\/_latestVersion\">latest nightly image build<\/a> for the Pi2\/Pi3 (mine was 26 July 2016) and restore it to a microSD card<\/li>\n<li>insert the card in the Pi3<\/li>\n<li>connect an USB keyboard and a HDMI display to the Pi3<\/li>\n<li>power up the Pi<\/li>\n<li>login (robot + maker) &#8211; if you cannot see the login prompt change to the proper console with Alt+F1 or Alt+F2 or Alt+F[n]<\/li>\n<li>run &#8216;sudo connmanctl&#8217; to configure BT and Wi-Fi (see <a href=\"http:\/\/www.ev3dev.org\/docs\/tutorials\/setting-up-wifi-using-the-command-line\/\">this tutorial<\/a> on how to configure Wi-Fi from command line; for BT just run &#8216;sudo connmanctl enable bluetooth&#8217;)<\/li>\n<li>edit the &#8216;\/boot\/flash\/config.txt&#8217; and uncomment these 4 lines:\n<ul>\n<li>dtoverlay=brickpi<\/li>\n<li>init_uart_clock=32000000<\/li>\n<li>dtoverlay=pi3-miniuart-bt<\/li>\n<li>core_freq=250<\/li>\n<\/ul>\n<\/li>\n<li>sudo reboot<\/li>\n<li>remove the display and the keyboard and from now on just connect through Wi-Fi<\/li>\n<\/ul>\n<p>To test that both Bluetooth and the BrickPi work properly I used a python script to read the NXT ultrasonic sensor (in the first input port) and change the color of my WeDo 2.0 Smart Hub from green to red:<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"BrickPi + WeDo 2.0\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/JQ-WHxK2R0M?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<pre>#!\/usr\/bin\/python\r\n\r\n# run with sudo\r\n# assumes NXT Ultrasonic at INPUT #1\r\n\r\nfrom ev3dev.auto import *\r\nfrom gattlib import GATTRequester\r\nfrom time import sleep\r\n\r\nBTdevice = \"hci0\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # BlueTooth 4.0 BLE capable device\r\n\r\nWeDo2HubAddress\u00a0 = \"A0:E6:F8:1E:58:57\"\r\n\r\nInputCommand_hnd = 0x3a\r\nOutputCommand_hnd\u00a0 = 0x3d\r\n\r\nRGBAbsoluteMode_cmd = str(bytearray([01,02,06,17,01,01,00,00,00,02,01]))\r\nRGBAbsoluteOutput_cmd = str(bytearray([06,04,03]))\u00a0 # or \"\\x06\\x04\\x03\"\r\n\r\nDELAY\u00a0\u00a0\u00a0\u00a0\u00a0 = 0.3\r\n\r\n# DO NOT FORGET TO CONFIG FOR US sensor:\r\n# sudo echo nxt-i2c &gt; \/sys\/class\/lego-port\/port0\/mode\r\n# sudo echo \"lego-nxt-us 0x01\" &gt; \/sys\/class\/lego-port\/port0\/set_device\r\n#\r\nus = UltrasonicSensor('ttyAMA0:S1:i2c1')\r\nassert us.connected\r\n\r\nreq = GATTRequester(WeDo2HubAddress,True,BTdevice)\r\nsleep(DELAY)\r\n\r\n# configure RBG LED to Absolute Mode (accepts 3 bytes for RGB instead of default Index Mode)\r\nreq.write_by_handle(InputCommand_hnd,RGBAbsoluteMode_cmd)\r\n\r\nwhile(True):\r\n\u00a0 if (us.value() &lt; 10):\r\n\u00a0\u00a0\u00a0 print(\"!\")\r\n\u00a0\u00a0\u00a0 req.write_by_handle(OutputCommand_hnd, RGBAbsoluteOutput_cmd+chr(255)+chr(0)+chr(0))\r\n\u00a0\u00a0\u00a0 sleep(DELAY)\r\n\u00a0 else:\r\n\u00a0\u00a0\u00a0 print(\"-\")\r\n\u00a0\u00a0\u00a0 req.write_by_handle(OutputCommand_hnd, RGBAbsoluteOutput_cmd+chr(0)+chr(255)+chr(0))\r\n\u00a0\u00a0\u00a0 sleep(DELAY)<\/pre>\n<p>My script need the <a href=\"https:\/\/bitbucket.org\/OscarAcena\/pygattlib\">gattlib<\/a> library to talk with Bluetooth Low Energy devices. You can install this library with &#8216;pip&#8217; but first need to install some dependencies:<\/p>\n<pre>sudo apt-get install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev<\/pre>\n<p>then<\/p>\n<pre>sudo pip install gattlib<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago the ev3dev project launched a great feature: nightly image builds. Right after that I got a received a notice that they included in the image for Raspberry Pi 2\/3 support for onboard the Bluetooth and needed to test it. So I did test it. And found out that onboard Bluetooth indeed &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2016\/running-ev3dev-on-a-raspberry-pi-3\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Running ev3dev on a Raspberry Pi 3&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[38,233,39,13,157,154,18,158,19,148,20,98,271],"tags":[273],"series":[],"class_list":["post-938","post","type-post","status-publish","format-standard","hentry","category-ble","category-bluetooth-pt","category-bluetooth","category-ev3dev","category-ev3dev-en","category-lego-en","category-lego","category-lego-mindstorms-en","category-lego-mindstorms","category-linux-en","category-linux","category-python","category-wedo-2-0","tag-brickpi"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-f8","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=938"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/938\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=938"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}