// API callback
showrecentposts({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$blogger":"http://schemas.google.com/blogger/2008","xmlns$georss":"http://www.georss.org/georss","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$thr":"http://purl.org/syndication/thread/1.0","id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016"},"updated":{"$t":"2024-09-02T09:20:05.354+01:00"},"category":[{"term":"raspberry pi"},{"term":"Python"},{"term":"minecraft"},{"term":"games"},{"term":"gpio"},{"term":"social networking"},{"term":"camera"},{"term":"microbit"},{"term":"Adventures in Minecraft"},{"term":"c"},{"term":"get_iplayer"},{"term":".net"},{"term":"Car"},{"term":"RSS"},{"term":"c#"},{"term":"gps"},{"term":"raspbmc \/ xbmc"},{"term":"robot"},{"term":"asp"},{"term":"html"},{"term":"xml"},{"term":"scratch"}],"title":{"type":"text","$t":"\u0026lt;Stuff about=\u0026quot;code\u0026quot; \/\u0026gt;"},"subtitle":{"type":"html","$t":"about = (stuff == 'code')"},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/posts\/default"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default?alt=json-in-script\u0026orderby=published"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"},{"rel":"next","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default?alt=json-in-script\u0026start-index=26\u0026max-results=25\u0026orderby=published"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"generator":{"version":"7.00","uri":"http://www.blogger.com","$t":"Blogger"},"openSearch$totalResults":{"$t":"136"},"openSearch$startIndex":{"$t":"1"},"openSearch$itemsPerPage":{"$t":"25"},"entry":[{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-7757665876450438932"},"published":{"$t":"2018-06-17T21:23:00.000+01:00"},"updated":{"$t":"2018-06-17T21:23:44.003+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Pi Camera stop motion animation"},"content":{"type":"html","$t":"In preparation for a Raspberry Pi event I decided to create a simple GUI for creating stop motion animations using the Pi camera module to use for a demo.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjhfzhfHlf8scEeU0JsqINJYxqzJOxQeHFy8EA0GovaTvPL70GBRJ4GuVLEYXD14NQpqeCW4Jy7udCA3kWsFZFSaSp6sN1SDwZFK7l2itvQdiRHsZR890VbFeu8JXZRc1ZD39Is9H-8EoBV\/s1600\/picamera_setup.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"1578\" data-original-width=\"1600\" height=\"315\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjhfzhfHlf8scEeU0JsqINJYxqzJOxQeHFy8EA0GovaTvPL70GBRJ4GuVLEYXD14NQpqeCW4Jy7udCA3kWsFZFSaSp6sN1SDwZFK7l2itvQdiRHsZR890VbFeu8JXZRc1ZD39Is9H-8EoBV\/s320\/picamera_setup.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nIts a really simple application, you start it up, you click \"take image\", you re-position the scene, you click \"take image\" and so on until you are happy with your animation and you click \"save\" to store it as an animated gif.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiEQjSUPWAIWUd3fLfwWAlRQf1GWjQ-LagPJaxJOIM6LRCB2GtempGvadF8xZgBnmzAnGNxxCUhMx8SkI0VLa1jQzrapBF0qYtibOK_ts58n_t1fDaJ_STHLHmu8JvHX7y3e3fY2paHsTVd\/s1600\/Df5PZAGXUAA3IM7.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"493\" data-original-width=\"468\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiEQjSUPWAIWUd3fLfwWAlRQf1GWjQ-LagPJaxJOIM6LRCB2GtempGvadF8xZgBnmzAnGNxxCUhMx8SkI0VLa1jQzrapBF0qYtibOK_ts58n_t1fDaJ_STHLHmu8JvHX7y3e3fY2paHsTVd\/s320\/Df5PZAGXUAA3IM7.jpg\" width=\"303\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cspan id=\"goog_1990565738\"\u003E\u003C\/span\u003E\u003Cspan id=\"goog_1990565739\"\u003E\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgViL82p7JehkXOh31vEIRqgjS603s6BWTutt7MbSzac5DEgsVEciQ1JC3blZRlyMenVWGP3mTKDAxo6qrT3NfnD8LEoA9A-TmTwFYN8zgNebIvJkcdZqienLEekOU48qpKpYv4hUoPkch0\/s1600\/animation1529238449.919678.gif\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"480\" data-original-width=\"640\" height=\"240\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgViL82p7JehkXOh31vEIRqgjS603s6BWTutt7MbSzac5DEgsVEciQ1JC3blZRlyMenVWGP3mTKDAxo6qrT3NfnD8LEoA9A-TmTwFYN8zgNebIvJkcdZqienLEekOU48qpKpYv4hUoPkch0\/s320\/animation1529238449.919678.gif\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nYou can find the source code at\u0026nbsp;\u003Ca href=\"https:\/\/goo.gl\/4Xvu7b\"\u003Egoo.gl\/4Xvu7b\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstall\u003C\/b\u003E\n\u003Cbr \/\u003E\n1. Connect a camera module\u003Cbr \/\u003E\n2. Enable the camera (Menu \u0026gt; Preferences \u0026gt; Raspberry Pi Configuration, Interfaces, Camera)\u003Cbr \/\u003E\n3. Open a terminal (Menu \u0026gt; Accessories \u0026gt; Terminal), install the modules and download the code:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo pip3 install guizero\nsudo pip3 install imageio\nwget -O guizero_stopmotion.py https:\/\/goo.gl\/zMTjas\u003C\/pre\u003E\n4. Run the program:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Epython3 guizero_stopmotion.py\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EA couple of \"interesting\" things about this project\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\nThe gui was created using \u003Ca href=\"https:\/\/lawsie.github.io\/guizero\/\"\u003Eguizero\u003C\/a\u003E\u0026nbsp;which is a super simple to use library for creating GUI's, definitely have a look.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nMost of the work was finding a way to create animated gifs in Python and working with images in memory rather than stored on disk\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nWhen the image is captured from the camera it isn't stored to a file, it is stored in a numpy array, this means each frame is only stored in memory making it faster:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E# create the camera\ncamera = PiCamera(resolution=\"640x480\")\ncamera_output = PiRGBArray(camera)\n...\n# capture the image\ncamera.capture(camera_output, \"rgb\")\n# append the camera image to the list as a numpy array\nanimation.images.append(camera_output.array)\u003C\/pre\u003E\nThe python module imageio is used to create the gif by passing the frames as a list, but again rather than being written to disk each time it is created as an in memory BytesIO stream:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Egif_output = BytesIO()\nimageio.mimsave(gif_output, animation.images, format=\"gif\")\u003C\/pre\u003E\nWhen the animated gif is displayed in guizero the BytesIO stream has to be open into a PIL Image.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Eanimation.image = Image.open(gif_output)\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/7757665876450438932\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2018\/06\/pi-camera-stop-motion-animation.html#comment-form","title":"2 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7757665876450438932"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7757665876450438932"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2018\/06\/pi-camera-stop-motion-animation.html","title":"Pi Camera stop motion animation"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjhfzhfHlf8scEeU0JsqINJYxqzJOxQeHFy8EA0GovaTvPL70GBRJ4GuVLEYXD14NQpqeCW4Jy7udCA3kWsFZFSaSp6sN1SDwZFK7l2itvQdiRHsZR890VbFeu8JXZRc1ZD39Is9H-8EoBV\/s72-c\/picamera_setup.jpg","height":"72","width":"72"},"thr$total":{"$t":"2"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-2395741164252085477"},"published":{"$t":"2018-06-09T21:58:00.000+01:00"},"updated":{"$t":"2018-06-17T21:24:00.086+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"}],"title":{"type":"text","$t":"Get the weather using Python"},"content":{"type":"html","$t":"I recently spent a hour or so hacking a lucky cat so that it would only wave when it was sunny.\u003Cbr \/\u003E\n\u003Cblockquote class=\"twitter-tweet\" data-lang=\"en\"\u003E\n\u003Cdiv dir=\"ltr\" lang=\"en\"\u003E\nAt \u003Ca href=\"https:\/\/twitter.com\/Raspberry_Pi?ref_src=twsrc%5Etfw\"\u003E@Raspberry_Pi\u003C\/a\u003E 's MakerDay I hacked a lucky cat so it only waves when it's sunny. \u003Ca href=\"https:\/\/t.co\/JUED5nYadt\"\u003Epic.twitter.com\/JUED5nYadt\u003C\/a\u003E\u003C\/div\u003E\n— Martin O'Hanlon (@martinohanlon) \u003Ca href=\"https:\/\/twitter.com\/martinohanlon\/status\/1005342439874486273?ref_src=twsrc%5Etfw\"\u003EJune 9, 2018\u003C\/a\u003E\u003C\/blockquote\u003E\n\u003Cscript async=\"\" charset=\"utf-8\" src=\"https:\/\/platform.twitter.com\/widgets.js\"\u003E\u003C\/script\u003E\n\nIt did this by pulling the weather data from \u003Ca href=\"https:\/\/openweathermap.org\/\"\u003EOpen Weather Map\u003C\/a\u003E using the Python module \u003Ca href=\"https:\/\/github.com\/csparpa\/pyowm\"\u003Epyowm\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E1.\u003C\/b\u003E\u0026nbsp;\u003Ca href=\"https:\/\/home.openweathermap.org\/users\/sign_up\"\u003ESign up for a free API key in Open Weather Map\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E2.\u003C\/b\u003E Install the pyown Python module, open a \u003Cb\u003ETerminal\u003C\/b\u003E or \u003Cb\u003ECommand Prompt\u003C\/b\u003E and run:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ci\u003EWindows\u003C\/i\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Epip install pyown\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Ci\u003ERaspberry Pi \/ Linux\u003C\/i\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo pip3 install pyown\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Ci\u003EMacOS\u003C\/i\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Epip3 install pyown\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E3.\u003C\/b\u003E Create a Python program using the following code, inserting your API key:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Eimport pyowm\n\nowm = pyowm.OWM('put api key here')\n\nobservation = owm.weather_at_place('Cambridge,GB')\nw = observation.get_weather()\n\nclouds = w.get_clouds()\nwind = w.get_wind()\nhumidity = w.get_humidity()\ntemp = w.get_temperature('celsius')\n\nprint(\"{}, {}, {}, {}\".format(clouds, wind, humidity, temp)\n\u003C\/pre\u003E\n\u003Cbr \/\u003E\nNote - it can take up to 60 minutes for your API key to be activated.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThere is a lot more information which can be pulled back - have a look at the \u003Ca href=\"https:\/\/pyowm.readthedocs.io\/en\/latest\/pyowm.webapi25.html#module-pyowm.webapi25.weather\"\u003Eweather module documentation\u003C\/a\u003E\u0026nbsp;for more details.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/2395741164252085477\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2018\/06\/get-weather-using-python.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/2395741164252085477"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/2395741164252085477"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2018\/06\/get-weather-using-python.html","title":"Get the weather using Python"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-6513597663825924441"},"published":{"$t":"2018-03-04T08:20:00.001+00:00"},"updated":{"$t":"2018-06-17T21:24:00.117+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"}],"title":{"type":"text","$t":"Python - Creating shortcuts"},"content":{"type":"html","$t":"I was recently working on the \u003Ca href=\"https:\/\/mu.readthedocs.io\/\"\u003Emu\u003C\/a\u003E project (a Python IDE for beginners), which is super easy to install using pip, but there is no way to automate the creation of desktop and menu shortcuts.\u003Cbr \/\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nThis seemed like a really big miss, shortcuts are the usual way for people (and certainly beginners to launch applications).\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nSo I set to creating a really simple way of creating shortcuts for Python applications.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nEnter \u003Ca href=\"http:\/\/shortcut.readthedocs.io\/en\/latest\/\"\u003Eshortcut\u003C\/a\u003E, a X platform (Windows, MacOS, Linux, Raspberry Pi) Python module for automatically creating shortcuts.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nIts really simple to \u003Ca href=\"http:\/\/shortcut.readthedocs.io\/en\/latest\/#install\"\u003Einstall\u003C\/a\u003E and \u003Ca href=\"http:\/\/shortcut.readthedocs.io\/en\/latest\/app.html\"\u003Euse\u003C\/a\u003E:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Epip3 install shortcut\nshortcut name_of_app\u003C\/pre\u003E\n\u003Cdiv\u003E\nIt will find the location of the app and create desktop and menu shortcuts for it.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\nThere is also a \u003Ca href=\"http:\/\/shortcut.readthedocs.io\/en\/latest\/api.html\"\u003EPython API\u003C\/a\u003E\u0026nbsp;which can be used to do the same:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom shortcut import ShortCutter\ns = ShortCutter()\ns.create_desktop_shortcut(\"python\")\ns.create_menu_shortcut(\"python\")\n\u003C\/pre\u003E\n\u003Cdiv\u003E\nYou will find documentation at\u0026nbsp;\u003Ca href=\"http:\/\/shortcut.readthedocs.io\/en\/latest\"\u003Eshortcut.readthedocs.io\u003C\/a\u003E\u0026nbsp;and code at\u0026nbsp;\u003Ca href=\"https:\/\/github.com\/martinohanlon\/shortcut\"\u003Egithub.com\/martinohanlon\/shortcut\u003C\/a\u003E.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/6513597663825924441\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2018\/03\/python-creating-shortcuts.html#comment-form","title":"1 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6513597663825924441"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6513597663825924441"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2018\/03\/python-creating-shortcuts.html","title":"Python - Creating shortcuts"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"1"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-3333313331509564526"},"published":{"$t":"2017-12-29T22:47:00.001+00:00"},"updated":{"$t":"2018-06-03T08:06:25.375+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Setup Raspberry Pi Samba share"},"content":{"type":"html","$t":"I almost always setup a samba share on every Raspberry Pi I install, it allows me to easily share files and work on my projects - so I thought I had better write down how I do it.\n\u003Cbr \/\u003E\nInstall samba:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install samba\u003C\/pre\u003E\nModify the Samba config file to add a share called pihome which points to the \/home\/pi directory:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo nano \/etc\/samba\/smb.conf\u003C\/pre\u003E\nScroll to the bottom and add the following:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Eprotocol = SMB2\n\n[pihome]\n   comment= Pi Home\n   path=\/home\/pi\n   browseable=Yes\n   writeable=Yes\n   only guest=no\n   create mask=0644\n   directory mask=0755\n   public=no\u003C\/pre\u003E\n\u003Cbr \/\u003E\nSetup a samba password for the Pi user:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo smbpasswd -a pi\u003C\/pre\u003E\nRestart the samba service:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo service smbd restart\u003C\/pre\u003E\nYou should now be able to connect to your Pi using the address:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E\/\/ip_address_of_pi\/pihome\u003C\/pre\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/3333313331509564526\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/12\/setup-raspberry-pi-samba-share.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/3333313331509564526"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/3333313331509564526"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/12\/setup-raspberry-pi-samba-share.html","title":"Setup Raspberry Pi Samba share"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-6503279979279620242"},"published":{"$t":"2017-11-15T20:56:00.001+00:00"},"updated":{"$t":"2017-11-15T20:57:28.569+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"},{"scheme":"http://www.blogger.com/atom/ns#","term":"social networking"}],"title":{"type":"text","$t":"Slack command line stream"},"content":{"type":"html","$t":"I thought a Slack console might be useful, a very simple client I could display on an always on screen, so I did some experimenting with the \u003Ca href=\"https:\/\/slackapi.github.io\/python-slackclient\/\"\u003ESlack Developer Kit for Python\u003C\/a\u003E and made a super simple command line program which streams messages.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIt is most definitely a starting point rather than a finished solution, but someone might find it useful.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi0r77ohRBN5ePbD3epllpKzjFIIHARp_IkYWOgGynqsnM5ribSXaVho3oaLSJJxaEfvQO8NoZCsfIGSTOQeDVYY7THlezDSh-vPAquAlj1oGKiTyVj8r__bftAyTAkO3086Gun4KCVTu-8\/s1600\/commandlineslack2.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"371\" data-original-width=\"640\" height=\"185\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi0r77ohRBN5ePbD3epllpKzjFIIHARp_IkYWOgGynqsnM5ribSXaVho3oaLSJJxaEfvQO8NoZCsfIGSTOQeDVYY7THlezDSh-vPAquAlj1oGKiTyVj8r__bftAyTAkO3086Gun4KCVTu-8\/s320\/commandlineslack2.png\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003ESetup\u003C\/b\u003E (assuming you are using a Raspberry Pi \/ Linux computer, although it will work on Windows as well).\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n1. Generate a \u003Ca href=\"https:\/\/api.slack.com\/custom-integrations\/legacy-tokens\"\u003Esecurity token\u003C\/a\u003E\u0026nbsp;for the slack group you want to stream.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv\u003E\n2. Create an environment variable SLACK_API_TOKEN and put your security token in it.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nEdit \/etc\/profile adding the export to the bottom:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo nano \/etc\/profile\nexport SLACK_API_TOKEN=[my super long token]\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n3. Install slackclient and colorama using pip:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo pip3 install colorama\nsudo pip3 install slackclient\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n4. Download the \u003Ca href=\"https:\/\/gist.github.com\/martinohanlon\/477b6ea4c3bdc679ddff92dfc3bff4a7\"\u003Eslack_stream.py from gist\u003C\/a\u003E:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ewget https:\/\/gist.githubusercontent.com\/martinohanlon\/477b6ea4c3bdc679ddff92dfc3bff4a7\/raw\/8ec39d08a9501b25d381ac3b008e9cf7be92377a\/slack_streamer.py\n\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n5. Run it:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Epython3 slack_streamer.py\u003C\/pre\u003E\n\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/6503279979279620242\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/11\/slack-command-line-stream.html#comment-form","title":"2 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6503279979279620242"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6503279979279620242"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/11\/slack-command-line-stream.html","title":"Slack command line stream"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi0r77ohRBN5ePbD3epllpKzjFIIHARp_IkYWOgGynqsnM5ribSXaVho3oaLSJJxaEfvQO8NoZCsfIGSTOQeDVYY7THlezDSh-vPAquAlj1oGKiTyVj8r__bftAyTAkO3086Gun4KCVTu-8\/s72-c\/commandlineslack2.png","height":"72","width":"72"},"thr$total":{"$t":"2"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-6014865720845294542"},"published":{"$t":"2017-07-07T15:37:00.002+01:00"},"updated":{"$t":"2017-07-07T16:55:17.492+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Python Bluetooth RFCOMM Client Server"},"content":{"type":"html","$t":"As part of the \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2017\/04\/bluedot-bluetooth-remote-for-raspberry.html\"\u003EBlue Dot\u003C\/a\u003E\u0026nbsp;project I needed to create a simple Bluetooth client \/ server\u0026nbsp;library so that the communication\u0026nbsp;could be managed. This library, \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/btcommapi.html\"\u003Ebtcomm\u003C\/a\u003E,\u0026nbsp;is part of\u0026nbsp;bluedot but its not exclusive and\u0026nbsp;can be used for Bluetooth communication in Python.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIt uses a 2 way RFCOMM communication - you can send messages to and from 2 devices, 1 being the server which waits for connections, 1 being the client which makes a connection.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstall the library\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install python3-dbus\nsudo pip3 install bluedot\n\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EPairing\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThe 2 devices you which want to communicate between will need to be paired, the Blue Dot documentation describes \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/pairpipi.html\"\u003Ehow to pair 2 raspberry pi's\u003C\/a\u003E which might be useful.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003ESimple Client \/ Server Example\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv\u003E\n\u003Cspan class=\"n\"\u003ELets create a simple example, a server which waits for connections and when it receives data it echo's it back to the\u0026nbsp;client.\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cspan class=\"n\"\u003E\u003C\/span\u003E\u003Cspan class=\"n\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan class=\"n\"\u003ECreate a new Python program and save it as btserver.py:\u003C\/span\u003E\u003Cspan class=\"n\"\u003E\u003Cbr \/\u003E\n\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E\u003Cspan class=\"n\"\u003Efrom bluedot.btcomm import BluetoothServer\nfrom signal import pause\n\ndef data_received(data):\n    print(data)\n    s.send(data)\n\ns = BluetoothServer(data_received)\npause()\u003C\/span\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cspan class=\"n\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\n\u003Cspan class=\"n\"\u003ECreate a 2nd program and save it as btclient.py:\u003C\/span\u003E\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom bluedot.btcomm import BluetoothClient\nfrom signal import pause\n\ndef data_received(data):\n    print(data)\n\nc = BluetoothClient(\"nameofyourserver\", data_received)\nc.send(\"helloworld\")\n\npause()\n\u003C\/pre\u003E\n\u003Cdiv\u003E\n\u003Cspan class=\"n\"\u003E\u003Cbr \/\u003E\u003C\/span\u003E\u003C\/div\u003E\nRun the server and then run the client, the client should connect and \"Hello World\" will be sent to the server and displayed on the screen, the server will then send the same \"Hello World\" message back to the client, which will print it to the screen.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EAdapter\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThere is also a useful API for accessing the Bluetooth adapter allowing you to get its current status, power it on\/off, make it discoverable or find the devices its paired with.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom bluedot.btcomm import BluetoothAdapter\n\na = BluetoothAdapter()\n\nprint(\"Powered = {}\".format(a.powered))\nprint(a.paired_devices)\na.allow_pairing()\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EDocumentation\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cb\u003E\u003C\/b\u003E\u003Cbr \/\u003E\nThere is comprehensive documentation for the \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/btcommapi.html\"\u003Ebtcomm library\u003C\/a\u003E, which describes the API and how to use it.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/6014865720845294542\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/07\/python-bluetooth-rfcomm-client-server.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6014865720845294542"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6014865720845294542"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/07\/python-bluetooth-rfcomm-client-server.html","title":"Python Bluetooth RFCOMM Client Server"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-5054924099828289705"},"published":{"$t":"2017-07-04T21:53:00.001+01:00"},"updated":{"$t":"2017-07-04T21:53:49.849+01:00"},"title":{"type":"text","$t":"Mac OS - Check Java version before running script"},"content":{"type":"html","$t":"I needed to check what version of Java was installed on a Mac before running my program, so with the help of \u003Ca href=\"https:\/\/stackoverflow.com\/questions\/7334754\/correct-way-to-check-java-version-from-bash-script\"\u003Estackoverflow\u003C\/a\u003E and a few other resources I pulled together the following bash script which checks to see if the version of Java is greater than 1.8 before continuing.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E\n# Work out the JAVA version we are working with:\nJAVA_VER_MAJOR=\"\"\nJAVA_VER_MINOR=\"\"\nJAVA_VER_BUILD=\"\"\n\n# Based on: http:\/\/stackoverflow.com\/a\/32026447\nfor token in $(java -version 2\u003E\u00261 | grep -i version)\ndo\n    if [[ $token =~ \\\"([[:digit:]])\\.([[:digit:]])\\.(.*)\\\" ]]\n    then\n        JAVA_VER_MAJOR=${BASH_REMATCH[1]}\n        JAVA_VER_MINOR=${BASH_REMATCH[2]}\n        JAVA_VER_BUILD=${BASH_REMATCH[3]}\n        break\n    fi\ndone\n\n#check version is greater than 1.7 (i.e. at least 1.8)\nif [ \"$JAVA_VER_MAJOR\" -gt \"1\" ]; then\n    echo start your program\nelif [ \"$JAVA_VER_MINOR\" -gt \"7\" ]; then\n    echo start your program\nelse\n    echo ERROR - Java needs to be updated.\n    echo Currently installed version is $JAVA_VER_MAJOR.$JAVA_VER_MINOR - 1.8 is required\nfi\n\u003C\/pre\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/5054924099828289705\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/07\/mac-os-check-java-version-before.html#comment-form","title":"2 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/5054924099828289705"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/5054924099828289705"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/07\/mac-os-check-java-version-before.html","title":"Mac OS - Check Java version before running script"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"2"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-3694958622208814974"},"published":{"$t":"2017-05-05T18:07:00.000+01:00"},"updated":{"$t":"2017-05-05T18:08:14.555+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi Touchscreen Portrait"},"content":{"type":"html","$t":"I recently wanted to turn my Raspberry Pi Official Touchscreen portrait (i.e. sideways!), which turns out is a bit of pain. \u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhQPJjZJJuVP7hQFYt7FZcQHpcIz__tae9gx0AX7XtyTsLaJ9DrezSBUccQsHhfcprTyoOTVEXpkqWebb2tRZ25GwiZi06B80LRSCH3RLcGR5V8Fss3Fu_u60LKZsqKmqp1vSVW9FUtAxL9\/s1600\/IMG_20170501_174954646_HDR.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhQPJjZJJuVP7hQFYt7FZcQHpcIz__tae9gx0AX7XtyTsLaJ9DrezSBUccQsHhfcprTyoOTVEXpkqWebb2tRZ25GwiZi06B80LRSCH3RLcGR5V8Fss3Fu_u60LKZsqKmqp1vSVW9FUtAxL9\/s320\/IMG_20170501_174954646_HDR.jpg\" width=\"180\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\nTurning the display is relatively easy but making the touch work is more difficult - there was a \u003Ca href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?p=1084567#p1084567\"\u003Eset of instructions on the Raspberry Pi forum\u003C\/a\u003E, but a \u003Ca href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?f=28\u0026amp;t=172025\"\u003Erecent update to Jessie meant they no longer worked\u003C\/a\u003E, so I pulled this set of instructions together:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstall xinput:\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install xinput\u003C\/pre\u003E\n\u003Cb\u003ERotate the display by editing config.txt:\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo nano \/boot\/config.txt\u003C\/pre\u003E\n\u0026nbsp;.. add this to the buttom of the file:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Edisplay_rotate=1\u003C\/pre\u003E\nUse Ctrl X, Yes to Save\u003Cbr \/\u003E\n\u003Cb\u003ECreate a script to rotate the touchscreen:\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Enano \/home\/pi\/touch_rotate.sh\u003C\/pre\u003E\n\u0026nbsp;.. add the following command\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Exinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix'  0 1 0 -1 0 1 0 0 1\u003C\/pre\u003E\n\u003Cb\u003EMake the script executable:\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Echmod +x touch_rotate.sh\u003C\/pre\u003E\n\u003Cb\u003EMake the script run when the GUI starts by editing autostart:\n\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo nano ~\/.config\/lxsession\/LXDE-pi\/autostart\u003C\/pre\u003E\n\u0026nbsp;.. add this to the bottom to run your script\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E@\/home\/pi\/touch_rotate.sh\u003C\/pre\u003E\n\u003Cb\u003EReboot:\n\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo reboot\u003C\/pre\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/3694958622208814974\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/05\/raspberry-pi-touchscreen-portrait.html#comment-form","title":"10 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/3694958622208814974"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/3694958622208814974"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/05\/raspberry-pi-touchscreen-portrait.html","title":"Raspberry Pi Touchscreen Portrait"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhQPJjZJJuVP7hQFYt7FZcQHpcIz__tae9gx0AX7XtyTsLaJ9DrezSBUccQsHhfcprTyoOTVEXpkqWebb2tRZ25GwiZi06B80LRSCH3RLcGR5V8Fss3Fu_u60LKZsqKmqp1vSVW9FUtAxL9\/s72-c\/IMG_20170501_174954646_HDR.jpg","height":"72","width":"72"},"thr$total":{"$t":"10"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-6467936860477264703"},"published":{"$t":"2017-04-24T22:09:00.000+01:00"},"updated":{"$t":"2017-04-25T09:26:16.154+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"gpio"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"},{"scheme":"http://www.blogger.com/atom/ns#","term":"robot"}],"title":{"type":"text","$t":"Blue Dot - a bluetooth remote for Raspberry Pi"},"content":{"type":"html","$t":"\u003Ca href=\"http:\/\/bluedot.readthedocs.io\/\"\u003EBlue Dot\u003C\/a\u003E is a really simple way to add Bluetooth remote control to your Raspberry Pi projects.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjI8fdvPv07GNB-2t0rh5RXudgPQV-ykQFkxnkbT-hrPieXzz963u0XNSCo0o2RwGJNZ2BZPxxNYy7KHj4rvvWym7q-q81KbXP6jHy9w_tQ_jpfR5KjXmXHj-a5OcyVhKo9_9v7PoHd2jw4\/s1600\/blue_dot_feature.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"156\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjI8fdvPv07GNB-2t0rh5RXudgPQV-ykQFkxnkbT-hrPieXzz963u0XNSCo0o2RwGJNZ2BZPxxNYy7KHj4rvvWym7q-q81KbXP6jHy9w_tQ_jpfR5KjXmXHj-a5OcyVhKo9_9v7PoHd2jw4\/s320\/blue_dot_feature.png\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nI created Blue Dot after being asked many times at \u003Ca href=\"https:\/\/www.raspberrypi.org\/picademy\/\"\u003EPicademy\u003C\/a\u003E “how can I get rid of all these wires?”.\u0026nbsp;\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nBlue dot is an \u003Ca href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.stuffaboutcode.bluedot\"\u003Eandroid app\u003C\/a\u003E (client) and really easy to use \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/\"\u003EPython library\u003C\/a\u003E which allows you to wirelessly control your Python projects, whether that is a \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/recipes.html#flash-an-led\"\u003Elight switch\u003C\/a\u003E, \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/recipes.html#remote-camera\"\u003Eremote camera\u003C\/a\u003E, \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/recipes.html#robot\"\u003Erobot\u003C\/a\u003E or anything else you can think of!\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/eW9oEPySF58\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/eW9oEPySF58?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nSee the \u003Ca href=\"http:\/\/bluedot.readthedocs.io\/en\/latest\/gettingstarted.html\"\u003Egetting started guide\u003C\/a\u003E for more info on 'getting started', or follow the tutorial below.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstallation \u0026amp; Use\u003C\/b\u003E\u003Cbr \/\u003E\nThese instructions assume your Raspberry Pi is running the latest version of \u003Ca href=\"https:\/\/www.raspberrypi.org\/downloads\/raspbian\/\"\u003ERaspbian with Pixel\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nYou will need a Raspberry Pi with built-in Bluetooth (such as the Pi 3 or Pi Zero W) or a Raspberry Pi and a USB Bluetooth dongle.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EGet the app\u003C\/b\u003E\u003Cbr \/\u003E\nDownload and install the \u003Ca href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.stuffaboutcode.bluedot\"\u003EBlue Dot app\u003C\/a\u003E from the google play store.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhZMUnUdymcbdQDdktSRoSpBvQup0V83yUHEMTDzW6WfdP9Du8OLxv9jkax088PKrb_5xSx6D-8kBylsGvfAlXiUgqm91hTaQmbwO64RxkakRyJ2DF0y2HZYgg1k9LqHN1Ddiw8TDXM4jKQ\/s1600\/bluedotandroid.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhZMUnUdymcbdQDdktSRoSpBvQup0V83yUHEMTDzW6WfdP9Du8OLxv9jkax088PKrb_5xSx6D-8kBylsGvfAlXiUgqm91hTaQmbwO64RxkakRyJ2DF0y2HZYgg1k9LqHN1Ddiw8TDXM4jKQ\/s320\/bluedotandroid.png\" width=\"186\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nIf you are wondering why there is no iOS app? Its because iOS doesn't support Bluetooth serial comms; you can only really talk to 'standard devices' (cars, speakers, fitness trackers, etc).\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\nPython library\u003C\/b\u003E\u003Cbr \/\u003E\nOpen a terminal (Menu \u0026gt; Accessories \u0026gt; Terminal) and type:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install python3-dbus\nsudo pip3 install bluedot\u003C\/pre\u003E\nOr if you need to use Python 2 (please dont tho!):\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install python-dbus\nsudo pip install bluedot\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\nPairing\u003C\/b\u003E\u003Cbr \/\u003E\nIn order to communicate over Bluetooth securely you need to pair your phone to your Raspberry Pi.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nOn your Android phone:\u003Cbr \/\u003E\n\u003Col\u003E\n\u003Cli\u003EOpen Settings\u003C\/li\u003E\n\u003Cli\u003ESelect Bluetooth\u003C\/li\u003E\n\u003Cli\u003EThis will make your phone Discoverable\u003C\/li\u003E\n\u003C\/ol\u003E\nUsing your Raspberry Pi\u003Cbr \/\u003E\n\u003Col\u003E\n\u003Cli\u003EClick the bluetooth icon on the taskbar\u003C\/li\u003E\n\u003Cli\u003ETurn on Bluetooth (if its off)\u003C\/li\u003E\n\u003Cli\u003EClick Make Discoverable\u003C\/li\u003E\n\u003Cli\u003EClick Add Device\u003C\/li\u003E\n\u003Cli\u003EYour phone will appear in the list, select it and click Pair\u003C\/li\u003E\n\u003Cli\u003EEnter a PIN code\u003C\/li\u003E\n\u003C\/ol\u003E\nOn your Android phone\u003Cbr \/\u003E\n\u003Col\u003E\n\u003Cli\u003EEnter the same PIN code when prompted\u003C\/li\u003E\n\u003Cli\u003EClick Ok\u003C\/li\u003E\n\u003C\/ol\u003E\n\u003Cb\u003ECode\u003C\/b\u003E\u003Cbr \/\u003E\nThe simplest way to use the Blue Dot is as a button:\u003Cbr \/\u003E\n\u003Col\u003E\n\u003Cli\u003EOpen Python 3 (Menu \u0026gt; Programming \u0026gt; Python 3)\u003C\/li\u003E\n\u003Cli\u003ECreate a new file (File \u0026gt; New File)\u003C\/li\u003E\n\u003Cli\u003EThe following code, will start up the Blue Dot, and wait for it to be pressed:\u003C\/li\u003E\n\u003Cdiv\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom bluedot import BlueDot\nbd = BlueDot()\nbd.wait_for_press()\nprint(\"You pressed the blue dot!\")\u003C\/pre\u003E\n\u003C\/div\u003E\n\u003Cli\u003ESave your program (File \u0026gt; Save) as mydot.py\u003C\/li\u003E\n\u003Cli\u003ERun your program (Run \u0026gt; Run Module)\u003C\/li\u003E\n\u003Cli\u003EOpen the Blue Dot app\u003C\/li\u003E\n\u003Cli\u003EConnect to your Raspberry Pi\u003C\/li\u003E\n\u003Cli\u003EPress the Blue Dot\u003C\/li\u003E\n\u003C\/ol\u003E\nAs well as waiting for something to happen you can also call functions when the button is pressed, released or the position its pressed moves.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom bluedot import BlueDot\nfrom signal import pause\n\ndef say_hello():\n    print(\"Hello World\")\n\ndef say_goodbye():\n    print(\"goodbye\")\n\nbd = BlueDot()\nbd.when_pressed = say_hello\nbd.when_released = say_goodbye\n\npause()\u003C\/pre\u003E\nBy using the position of where the button is pressed you can use the Blue Dot like a joystick:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom bluedot import BlueDot\nfrom signal import pause\n\ndef dpad(pos):\n    if pos.top:\n        print(\"up\")\n    elif pos.bottom:\n        print(\"down\")\n    elif pos.left:\n        print(\"left\")\n    elif pos.right:\n        print(\"right\")\n    elif pos.middle:\n        print(\"fire\")\n\nbd = BlueDot()\nbd.when_pressed = dpad\n\npause()\u003C\/pre\u003E\nAdd to this \u003Ca href=\"http:\/\/gpiozero.readthedocs.io\/en\/stable\/api_boards.html#robot\"\u003Egpiozero's Robot\u003C\/a\u003E\u0026nbsp;functions, you can create a Bluetooth\u0026nbsp;controlled robot with very little code.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom bluedot import BlueDot\nfrom gpiozero import Robot\nfrom signal import pause\n\nbd = BlueDot()\nrobot = Robot(left=(lfpin, lbpin), right=(rfpin, rbpin))\n\ndef move(pos):\n    if pos.top:\n        robot.forward()\n    elif pos.bottom:\n        robot.backward()\n    elif pos.left:\n        robot.left()\n    elif pos.right:\n        robot.right()\n\ndef stop():\n    robot.stop()\n\nbd.when_pressed = move\nbd.when_moved = move\nbd.when_released = stop\n\npause()\u003C\/pre\u003E\nCheck out the\u0026nbsp;\u003Ca href=\"http:\/\/bluedot.readthedocs.io\/\"\u003EBlue Dot documentation\u003C\/a\u003E\u0026nbsp;for more information and ideas\u0026nbsp;- you really can do a lot with a simple circle :)"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/6467936860477264703\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/04\/bluedot-bluetooth-remote-for-raspberry.html#comment-form","title":"19 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6467936860477264703"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6467936860477264703"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/04\/bluedot-bluetooth-remote-for-raspberry.html","title":"Blue Dot - a bluetooth remote for Raspberry Pi"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjI8fdvPv07GNB-2t0rh5RXudgPQV-ykQFkxnkbT-hrPieXzz963u0XNSCo0o2RwGJNZ2BZPxxNYy7KHj4rvvWym7q-q81KbXP6jHy9w_tQ_jpfR5KjXmXHj-a5OcyVhKo9_9v7PoHd2jw4\/s72-c\/blue_dot_feature.png","height":"72","width":"72"},"thr$total":{"$t":"19"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-7088190184008843036"},"published":{"$t":"2017-01-05T21:44:00.000+00:00"},"updated":{"$t":"2017-03-07T10:41:29.967+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"gpio"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi - 4 digit 7 Segment display, gpiozero"},"content":{"type":"html","$t":"I recently picked up some '\u003Ca href=\"https:\/\/shop.pimoroni.com\/products\/retro-4-digit-led-display\"\u003Eretro 4 digit LED displays\u003C\/a\u003E' from \u003Ca href=\"https:\/\/www.pimoroni.com\/\"\u003Epimoroni\u003C\/a\u003E, noticing there was no support in \u003Ca href=\"http:\/\/gpiozero.readthedocs.io\/\"\u003Egpiozero\u003C\/a\u003E for 7 segment displays (either \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/10\/raspberry-pi-7-segment-display-gpiozero.html\"\u003Esingle\u003C\/a\u003E or multi digit) I decided to add them and create a \u003Ca href=\"https:\/\/github.com\/RPi-Distro\/python-gpiozero\/pull\/488\"\u003Epull request\u003C\/a\u003E. \u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThis builds on the code I created for driving \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/10\/raspberry-pi-7-segment-display-gpiozero.html\"\u003Esingle 7 segment displays\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEglXu-uBYLu3J_9wYXXLwoXxZmRd1-rSKnq4lbIshD14B6xy7nGNahsaKWwEZ7J7afvSIAx49AxUs16BiNyvppHSOf-cqz-zBoojYsoR6TeHq7upmYL0-TwjdvXCdNGJCzL2wEa7L33qmkJ\/s1600\/7seg_leds.PNG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"162\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEglXu-uBYLu3J_9wYXXLwoXxZmRd1-rSKnq4lbIshD14B6xy7nGNahsaKWwEZ7J7afvSIAx49AxUs16BiNyvppHSOf-cqz-zBoojYsoR6TeHq7upmYL0-TwjdvXCdNGJCzL2wEa7L33qmkJ\/s320\/7seg_leds.PNG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nHopefully the PR will get added into a gpiozero release soon, but until then add this\u0026nbsp;\u003Ca href=\"https:\/\/gist.github.com\/martinohanlon\/23a8a67bc3c68988fbb492b3d5d42ca5\"\u003Ecode\u003C\/a\u003E\u0026nbsp;to your project and use the following to drive your display.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E#setup the pins\n\n#these are the pins the LED are connected too\n# (in the order A, B, C, D, E, F, G, decimal point)\nLED_PINS = (7, 22, 25, 17, 8, 27, 4, 24)\n#these are the pins the digits are connected too\nDIGIT_PINS = (23, 18, 15, 14)\n\n#create the multi seven segment display\n# use active_high=True when digit pins are cathode (ground)\nmulti_sev = MultiSevenSegmentDisplay(LED_PINS, DIGIT_PINS,\n                                     active_high=True)\n\n#display your message\nmulti_sev.display(\"LEDS\")\n\n#turn off the display using\nmulti_sev.off()\u003C\/pre\u003E\nThe display function works by plexing the display, turning the LEDs on one at a time, so quickly it tricks the eye into thinking the display is showing 1 message.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/jeg5sjdHCYM\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/jeg5sjdHCYM?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/7088190184008843036\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/01\/raspberry-pi-4-digit-7-segment-display.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7088190184008843036"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7088190184008843036"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2017\/01\/raspberry-pi-4-digit-7-segment-display.html","title":"Raspberry Pi - 4 digit 7 Segment display, gpiozero"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEglXu-uBYLu3J_9wYXXLwoXxZmRd1-rSKnq4lbIshD14B6xy7nGNahsaKWwEZ7J7afvSIAx49AxUs16BiNyvppHSOf-cqz-zBoojYsoR6TeHq7upmYL0-TwjdvXCdNGJCzL2wEa7L33qmkJ\/s72-c\/7seg_leds.PNG","height":"72","width":"72"},"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-934532202965093203"},"published":{"$t":"2016-12-08T22:43:00.001+00:00"},"updated":{"$t":"2017-01-10T16:11:46.712+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi - bash memory split check"},"content":{"type":"html","$t":"I needed a bash script which would only launch a program on a Raspberry Pi if there was enough memory dedicated to the GPU.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nI pulled this script together which checks to see if there is at least 128 MB dedicated to the GPU before starting the program.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E#!\/bin\/bash\n\n#check there is enough gpu memory to start\n#get the gpu memory and output to a file called gpu_mem\nvcgencmd get_mem gpu \u0026gt; gpu_mem\nsource gpu_mem\n#strip last char from the output (i.e. 64M)\ngpu=${gpu%?}\nif (( $gpu \u0026gt;= 128 )); then\n    .\/launch_program\nelse\n    echo \"The program needs at least 128MB of memory allocated to the GPU\"\n    echo \"Use sudo raspi-config (Advanced Options \u0026gt; Memory Split) to change\"\nfi\n#remove the gpu_mem file\nrm gpu_mem\u003C\/pre\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/934532202965093203\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/12\/raspberry-pi-bash-memory-split-check.html#comment-form","title":"1 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/934532202965093203"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/934532202965093203"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/12\/raspberry-pi-bash-memory-split-check.html","title":"Raspberry Pi - bash memory split check"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"1"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-7197400687200821627"},"published":{"$t":"2016-11-29T18:12:00.000+00:00"},"updated":{"$t":"2017-01-10T16:15:32.604+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"games"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Compile Allegro 5.x for Raspberry Pi"},"content":{"type":"html","$t":"I am in the process of porting \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/06\/mayhem-2-open-source-cave-shooter.html\"\u003EMayhem 2\u003C\/a\u003E to Allegro 5 (with the help of \u003Ca href=\"https:\/\/github.com\/karjonas\"\u003EJonas Karlsson\u003C\/a\u003E), and wanted to compile the latest version of Allegro on the Pi, as only an older version is available through apt.\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003EInstall the dependencies\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install build-essential git cmake cmake-curses-gui xorg-dev libgl1-mesa-dev libglu-dev libpng-dev libcurl4-nss-dev libfreetype6-dev libjpeg-dev libvorbis-dev libopenal-dev libphysfs-dev libgtk2.0-dev libpulse-dev libflac-dev libdumb1-dev\u003C\/pre\u003E\n\u003Cb\u003EGet the Code\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Egit clone https:\/\/github.com\/liballeg\/allegro5.git\ncd allegro5\u003C\/pre\u003E\n\u003Cb\u003ECheck out the version you want\u003C\/b\u003E - see \u003Ca href=\"https:\/\/github.com\/liballeg\/allegro5\/branches\/all\"\u003Ehere\u003C\/a\u003E for a list of versions\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Egit checkout 5.2.1\u003C\/pre\u003E\n\u003Cb\u003EBuild it\n\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E\nmkdir build\ncd build\ncmake .. -DCMAKE_TOOLCHAIN_FILE=..\/cmake\/Toolchain-raspberrypi.cmake\nmake\u003C\/pre\u003E\n\u003Cb\u003EInstall it\n\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo make install\nexport PKG_CONFIG_PATH=\/home\/pi\/allegro5\/build\/lib\/pkgconfig\nsudo ldconfig\u003C\/pre\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/7197400687200821627\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/11\/compile-allegro-5x-for-raspberry-pi.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7197400687200821627"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7197400687200821627"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/11\/compile-allegro-5x-for-raspberry-pi.html","title":"Compile Allegro 5.x for Raspberry Pi"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-1426184457101715442"},"published":{"$t":"2016-10-24T22:13:00.000+01:00"},"updated":{"$t":"2017-03-07T10:40:56.703+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"gpio"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi, 7 Segment Display, gpiozero"},"content":{"type":"html","$t":"I've been working on an \u003Ca href=\"https:\/\/github.com\/RPi-Distro\/python-gpiozero\/pull\/488\"\u003Eupdate\u003C\/a\u003E to \u003Ca href=\"http:\/\/gpiozero.readthedocs.io\/en\/v1.3.1\/\"\u003Egpiozero\u003C\/a\u003E to add a 7 segment display - hopefully this will make it into gpiozero soon, but until then if you want to use a 7 segment display with your Raspberry Pi you can follow the details below.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ci\u003EUpdate - I have updated this to support single and \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2017\/01\/raspberry-pi-4-digit-7-segment-display.html\"\u003Emultiple digit 7 segment displays\u003C\/a\u003E.\u003C\/i\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhmLxG6GPXSQyzFFH666ThImQR5ntxzwzw4e4xkJ2nWArg8ovpYD8wYjeCsp1DitPKcZRirxJCdkItELfPs5Cs-4nJE1Zp0zIGmFjfXG-wIOpRGPjZah33BimsqvCzAPnLR765D2Q2X_g_6\/s1600\/7segment.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhmLxG6GPXSQyzFFH666ThImQR5ntxzwzw4e4xkJ2nWArg8ovpYD8wYjeCsp1DitPKcZRirxJCdkItELfPs5Cs-4nJE1Zp0zIGmFjfXG-wIOpRGPjZah33BimsqvCzAPnLR765D2Q2X_g_6\/s320\/7segment.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003EWire it up\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nThe seven segment display will have 7 pins to connect the digit's LEDs, 1 pin to connect the decimal point LED and 1 pin which is the common pin.\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nThe LED pins should connect to 8 GPIO pins depending on whether your 7 segment display is a common-anode or a common-cathode the common pin should connect to either a 3.3v pin or the ground. Your also going to need a suitable resistor (probably a 330) between your GPIO and LED pins.\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Ctable align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto; margin-right: auto; text-align: center;\"\u003E\u003Ctbody\u003E\n\u003Ctr\u003E\u003Ctd style=\"text-align: center;\"\u003E\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgmzef35o60aEis6v3_u1ex0DXeimX4MaL5qa-VTlv8fdAljvL1QoX_PE3MNDGL-2dplZ8GIdJoLWpEXtuZlmrCnpDfHsBZmFTZ0gwie3lmLl17Sy_f1eG8f3OEXfINavPzC1OSAr_54E8x\/s1600\/7segment_bb.png\" imageanchor=\"1\" style=\"margin-left: auto; margin-right: auto;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgmzef35o60aEis6v3_u1ex0DXeimX4MaL5qa-VTlv8fdAljvL1QoX_PE3MNDGL-2dplZ8GIdJoLWpEXtuZlmrCnpDfHsBZmFTZ0gwie3lmLl17Sy_f1eG8f3OEXfINavPzC1OSAr_54E8x\/s320\/7segment_bb.png\" width=\"229\" \/\u003E\u003C\/a\u003E\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd class=\"tr-caption\" style=\"text-align: center;\"\u003EWired up as a common-anode\u003C\/td\u003E\u003C\/tr\u003E\n\u003C\/tbody\u003E\u003C\/table\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003ECode\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nCreate a new program and add the following to the top of the your program (this is the class which will allow you to control the display).\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom gpiozero import LEDBoard, OutputDeviceError, LEDCollection\n\nclass SevenSegmentDisplay(LEDBoard):\n    \"\"\"\n    Extends :class:`LEDBoard` for a 7 segment LED display \n\n    7 segment displays have either 7 or 8 pins, 7 pins for the digit display \n    and an optional 8th pin for a decimal point. 7 segment displays \n    typically have either a common anode or common cathode pin, when\n    using a common anode display 'active_high' should be set to False.\n    Instances of this class can be used to display characters or control \n    individual leds on the display. For example::\n\n        from gpiozero import SevenSegmentDisplay\n\n        seven = SevenSegmentDisplay(1,2,3,4,5,6,7,8,active_high=False)\n        seven.display(\"7\")\n    \n    :param int \\*pins:\n        Specify the GPIO pins that the 7 segment display is attached to.\n        Pins should be in the LED segment order A,B,C,D,E,F,G,decimal_point \n        (the decimal_point is optional).\n\n    :param bool pwm:\n        If ``True``, construct :class:`PWMLED` instances for each pin. If\n        ``False`` (the default), construct regular :class:`LED` instances. This\n        parameter can only be specified as a keyword parameter.\n\n    :param bool active_high:\n        If ``True`` (the default), the :meth:`on` method will set all the\n        associated pins to HIGH. If ``False``, the :meth:`on` method will set\n        all pins to LOW (the :meth:`off` method always does the opposite). This\n        parameter can only be specified as a keyword parameter.\n\n    :param bool initial_value:\n        If ``False`` (the default), all LEDs will be off initially. If\n        ``None``, each device will be left in whatever state the pin is found\n        in when configured for output (warning: this can be on). If ``True``,\n        the device will be switched on initially. This parameter can only be\n        specified as a keyword parameter.    \n    \n    \"\"\"\n    def __init__(self, *pins, **kwargs):\n        # 7 segment displays must have 7 or 8 pins\n        if len(pins) \u0026lt; 7 or len(pins) \u0026gt; 8:\n            raise ValueError('SevenSegmentDisplay must have 7 or 8 pins')\n        # Don't allow 7 segments to contain collections\n        for pin in pins:\n            assert not isinstance(pin, LEDCollection)\n        pwm = kwargs.pop('pwm', False)\n        active_high = kwargs.pop('active_high', True)\n        initial_value = kwargs.pop('initial_value', False)\n        if kwargs:\n            raise TypeError('unexpected keyword argument: %s' % kwargs.popitem()[0])\n            \n        self._layouts = {\n            '1': (False, True, True, False, False, False, False),\n            '2': (True, True, False, True, True, False, True),\n            '3': (True, True, True, True, False, False, True),\n            '4': (False, True, True, False, False, True, True),\n            '5': (True, False, True, True, False, True, True),\n            '6': (True, False, True, True, True, True, True),\n            '7': (True, True, True, False, False, False, False),\n            '8': (True, True, True, True, True, True, True),\n            '9': (True, True, True, True, False, True, True),\n            '0': (True, True, True, True, True, True, False),\n            'A': (True, True, True, False, True, True, True),\n            'B': (False, False, True, True, True, True, True),\n            'C': (True, False, False, True, True, True, False),\n            'D': (False, True, True, True, True, False, True),\n            'E': (True, False, False, True, True, True, True),\n            'F': (True, False, False, False, True, True, True),\n            'G': (True, False, True, True, True, True, False),\n            'H': (False, True, True, False, True, True, True),\n            'I': (False, False, False, False, True, True, False),\n            'J': (False, True, True, True, True, False, False),\n            'K': (True, False, True, False, True, True, True),\n            'L': (False, False, False, True, True, True, False),\n            'M': (True, False, True, False, True, False, False),\n            'N': (True, True, True, False, True, True, False),\n            'O': (True, True, True, True, True, True, False),\n            'P': (True, True, False, False, True, True, True),\n            'Q': (True, True, False, True, False, True, True),\n            'R': (True, True, False, False, True, True, False),\n            'S': (True, False, True, True, False, True, True),\n            'T': (False, False, False, True, True, True, True),\n            'U': (False, False, True, True, True, False, False),\n            'V': (False, True, True, True, True, True, False),\n            'W': (False, True, False, True, False, True, False),\n            'X': (False, True, True, False, True, True, True),\n            'Y': (False, True, True, True, False, True, True),\n            'Z': (True, True, False, True, True, False, True),\n            '-': (False, False, False, False, False, False, True),\n            ' ': (False, False, False, False, False, False, False),\n            '=': (False, False, False, True, False, False, True)\n        }\n        \n        super(SevenSegmentDisplay, self).__init__(*pins, pwm=pwm, active_high=active_high, initial_value=initial_value)\n    \n    def display(self, char):\n        \"\"\"\n        Display a character on the 7 segment display\n\n        :param string char:\n            A single character to be displayed \n        \"\"\"\n        char = str(char).upper()\n        if len(char) \u0026gt; 1:\n            raise ValueError('only a single character can be displayed')\n        if char not in self._layouts:\n            raise ValueError('there is no layout for character - %s' % char)\n        layout = self._layouts[char]\n        for led in range(7):\n            self[led].value = layout[led]\n            \n    def display_hex(self, hexnumber):\n        \"\"\"\n        Display a hex number (0-F) on the 7 segment display\n\n        :param int hexnumber:\n            The number to be displayed in hex \n        \"\"\"\n        self.display(hex(hexnumber)[2:])\n\n    @property\n    def decimal_point(self):\n        \"\"\"\n        Represents the status of the decimal point led\n        \"\"\"\n        # does the 7seg display have a decimal point (i.e pin 8)\n        if len(self) \u0026gt; 7:\n            return self[7].value \n        else:\n            raise OutputDeviceError('there is no 8th pin for the decimal point')\n    \n    @decimal_point.setter\n    def decimal_point(self, value):\n        \"\"\"\n        Sets the status of the decimal point led\n        \"\"\"\n        if len(self) \u0026gt; 7:\n            self[7].value = value\n        else:\n            raise OutputDeviceError('there is no 8th pin for the decimal point')    \n    \n    def set_char_layout(self, char, layout):\n        \"\"\"\n        Create or update a custom character layout, which can be used with the \n        `display` method.\n\n        :param string char:\n            A single character to be displayed \n            \n        :param tuple layout:\n            A 7 bool tuple of LED values in the segment order A, B, C, D, E, F, G\n        \"\"\"\n        char = str(char).upper()\n        if len(char) != 1:\n            raise ValueError('only a single character can be used in a layout')\n        if len(layout) != 7:\n            raise ValueError('a character layout must have 7 segments')\n        self._layouts[char] = layout\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003ECreate the display\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nCreate an instance on the 7 segment display object, you need to pass the pins in the order, A,B,C,D,E,F,G,Decimal Point.\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgtRY8kijxPpDU3vzcQ7AuLrFfaAhSxOfYNYcC0y-vcLyi8UYZOhunQGqqpHbbNykQGHWzTAfO3FrJJfVU8fX0wLGEW9Xv2B1G4FLc7IsFlVuot-Ivz4FfNm1jhNkCz4crwmwnSPeD-7nDj\/s1600\/7seg_pinouts.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgtRY8kijxPpDU3vzcQ7AuLrFfaAhSxOfYNYcC0y-vcLyi8UYZOhunQGqqpHbbNykQGHWzTAfO3FrJJfVU8fX0wLGEW9Xv2B1G4FLc7IsFlVuot-Ivz4FfNm1jhNkCz4crwmwnSPeD-7nDj\/s320\/7seg_pinouts.png\" width=\"217\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Eseven_seg = SevenSegmentDisplay(20, 21, 6, 22, 27, 18, 15, 13)\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nIf you have a common-anode display you will also need to set the active_high parameter to False:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Eseven_seg = SevenSegmentDisplay(20, 21, 6, 22, 27, 18, 15, 13, \n                                active_high=False)\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003EDisplay a character\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nYou can show a character on the display using the .display() method.\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Eseven_seg.display(\"8\")\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003EAdd a new character\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nYou can add your own characters to the display, using the .set_char_layout() method passing the character and a tuple of 7 booleans for each of the LEDs in order A,B,C,D,E,F,G.\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Eseven_seg.set_char_layout(\"_\", (False, False, False, True, False, False, False))\nseven_seg.display(\"_\")\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003EDecimal point\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\nYou can turn the decimal point on by setting the .decimal_point property.\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Eseven_seg.decimal_point = True\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/1426184457101715442\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/10\/raspberry-pi-7-segment-display-gpiozero.html#comment-form","title":"5 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/1426184457101715442"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/1426184457101715442"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/10\/raspberry-pi-7-segment-display-gpiozero.html","title":"Raspberry Pi, 7 Segment Display, gpiozero"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhmLxG6GPXSQyzFFH666ThImQR5ntxzwzw4e4xkJ2nWArg8ovpYD8wYjeCsp1DitPKcZRirxJCdkItELfPs5Cs-4nJE1Zp0zIGmFjfXG-wIOpRGPjZah33BimsqvCzAPnLR765D2Q2X_g_6\/s72-c\/7segment.jpg","height":"72","width":"72"},"thr$total":{"$t":"5"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-7438934064274327565"},"published":{"$t":"2016-09-20T20:03:00.000+01:00"},"updated":{"$t":"2016-09-20T20:33:39.524+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"microbit"},{"scheme":"http://www.blogger.com/atom/ns#","term":"minecraft"}],"title":{"type":"text","$t":"Microbit making Minecraft Earthquakes"},"content":{"type":"html","$t":"In this tutorial you are going to connect your Microbit up to your Raspberry Pi and program them so that when your Microbit is shaken it creates an earthquake in Minecraft.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEilvnIhttEMW9hP5PUCPiCpLQCsfMWkzl-qu9tv_JRBE8P3l_vUeVe08nXFF-_hej1ZZ8KrYd8VV22BxRe7r4H_oNYidNOlls-zAkmsUN0OQB7cFTCMQ8HnZC1Jv248oYZ0Md_C-qTrZDws\/s1600\/ezgif.com-optimize.gif\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"222\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEilvnIhttEMW9hP5PUCPiCpLQCsfMWkzl-qu9tv_JRBE8P3l_vUeVe08nXFF-_hej1ZZ8KrYd8VV22BxRe7r4H_oNYidNOlls-zAkmsUN0OQB7cFTCMQ8HnZC1Jv248oYZ0Md_C-qTrZDws\/s400\/ezgif.com-optimize.gif\" width=\"400\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nThis is part of a workshop I delivered at \u003Ca href=\"http:\/\/2016.pyconuk.org\/\"\u003EPyConUK 2016\u003C\/a\u003E\u0026nbsp;-\u0026nbsp;\u003Ca href=\"https:\/\/drive.google.com\/open?id=1VElMfrxKNG5qnwfQ0mx5o8-IeuYRfRatxlRqzInn6GE\"\u003Edownload the complete worksheet\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nYou are going to connect your micro:bit’s pins to the Raspberry Pi gpio pins using some cables and crocodile clips; programs on the micro@bit and Raspberry Pi will make Steve shake in Minecraft.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstall mu\u003C\/b\u003E\u003Cbr \/\u003E\nTo put you python program on your Micro:bit you will need the editor \u003Ca href=\"https:\/\/github.com\/mu-editor\/mu\"\u003Emu\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nOpen a Terminal (Menu \u0026gt; Accessories \u0026gt; Terminal) and type:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get update\nsudo apt-get install mu\n\u003C\/pre\u003E\n\u003Cb\u003EAngry micro:bit\u003C\/b\u003E\u003Cbr \/\u003E\nThe first task is to program your micro:bit so it gets angry when it's shaken.\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003EConnect your micro:bit to the Raspberry Pi using the USB cable.\u003C\/li\u003E\n\u003Cli\u003EOpen mu to create a new Python program for your micro:bit by clicking on Menu \u0026gt; Programming \u0026gt; mu.\u003C\/li\u003E\n\u003Cli\u003EClick New and type the following code into the editor.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom microbit import *\nwhile True:\n    if accelerometer.current_gesture() == \"shake\":\n        display.show(Image.ANGRY)\n    else:\n        display.show(Image.HAPPY)\u003C\/pre\u003E\n\u003Cul\u003E\n\u003Cli\u003EClick Flash to put your program on your micro:bit.\u003C\/li\u003E\n\u003C\/ul\u003E\nWhen the yellow light on the back of your micro:bit stops flashing your program will run.\u003Cbr \/\u003E\nYou should see a happy face on your micro:bit - until it’s shaken!\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiKvt05qD3CTmGkHEwF6agy2kCV19dN4GG_N-3bDM2gaA-ad_cHhoNr3Okn_Xn-q8nJzUEmOH5Pi3p9_4Wi9KTk5u84WfHv-47yo2DgrJM5hAtmoFjMy6m-hkt7Zzdii1KhvcvUw5aecbHz\/s1600\/mbhappy.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"163\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiKvt05qD3CTmGkHEwF6agy2kCV19dN4GG_N-3bDM2gaA-ad_cHhoNr3Okn_Xn-q8nJzUEmOH5Pi3p9_4Wi9KTk5u84WfHv-47yo2DgrJM5hAtmoFjMy6m-hkt7Zzdii1KhvcvUw5aecbHz\/s200\/mbhappy.png\" width=\"200\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both;\"\u003E\n\u003Cspan style=\"color: red;\"\u003EAny errors will be scrolled on your micro:bit’s leds; if you get an error check your code carefully.\u003C\/span\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cb\u003EPins\u003C\/b\u003E\u003C\/div\u003E\nNow you need to finish your micro:bit program so that it turns pin 0 on and off when it's shaken\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003EGo back to Mu and modify your program so that it turns pins 0 on (1) and off (0) when shaken.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom microbit import *\nwhile True:\n    if accelerometer.current_gesture() == \"shake\":\n        display.show(Image.ANGRY)\n        \u003Cb\u003Epin0.write_digital(1)\u003C\/b\u003E\n    else:\n        display.show(Image.HAPPY)\n        \u003Cb\u003Epin0.write_digital(0)\u003C\/b\u003E\u003C\/pre\u003E\n\u003Cul\u003E\n\u003Cli\u003EClick Flash to put your program on your micro:bit.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cb\u003EConnect it up\u003C\/b\u003E\u003Cbr \/\u003E\nNext you will use a jumper cable and a crocodile clip to connect your micro:bit to the Raspberry Pi.\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003EConnect the jumper cable to GPIO17 on the Raspberry Pi\u003C\/li\u003E\n\u003Cli\u003EClip the crocodile clip to the end of the jumper cable\u003C\/li\u003E\n\u003Cli\u003EClip the other end of the crocodile clip to pin0 on the micro:bit\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEggrJ2QN4D6AUzxvUDdrDnVQrvkmj3hNnzcpZkpskxcPuhVi2nLD01T1I6F2RsuZmFFJejaV3yAfx5PXI_UDhBfgC_vgbIbySAzCfOhxxFxOJ7by6LkRjtrYthI0ft-dy1Mceb0Lrh8OA7V\/s1600\/IMGP6235_crop.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"250\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEggrJ2QN4D6AUzxvUDdrDnVQrvkmj3hNnzcpZkpskxcPuhVi2nLD01T1I6F2RsuZmFFJejaV3yAfx5PXI_UDhBfgC_vgbIbySAzCfOhxxFxOJ7by6LkRjtrYthI0ft-dy1Mceb0Lrh8OA7V\/s400\/IMGP6235_crop.JPG\" width=\"400\" \/\u003E\u003C\/a\u003E\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjdPdazaA1lemGV5v0r3IJC3QtaDINJgdZRYTabvxSYUdxtbLKjRUjpKhzMremP1ZcaT3VT-dhD9Irm5mH5E9-QExnVelT4g-rEYacuwiVBhsL5f2kOiQfsED1oQ38bdXW_B-QCrtHyNwMI\/s1600\/Raspberry-Pi-GPIO-Layout-Model-B-Plus-rotated-2700x900.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"106\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjdPdazaA1lemGV5v0r3IJC3QtaDINJgdZRYTabvxSYUdxtbLKjRUjpKhzMremP1ZcaT3VT-dhD9Irm5mH5E9-QExnVelT4g-rEYacuwiVBhsL5f2kOiQfsED1oQ38bdXW_B-QCrtHyNwMI\/s320\/Raspberry-Pi-GPIO-Layout-Model-B-Plus-rotated-2700x900.png\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cb\u003EShake Steve\u003C\/b\u003E\u003Cbr \/\u003E\nYou now need to create your Minecraft program to shake Steve when the micro:bit is shaken and pin0 is set to 1.\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003EClick Menu \u0026gt; Games \u0026gt; Minecraft: Pi Edition to run the game.\u003C\/li\u003E\n\u003Cli\u003EClick Start Game, then click Create New (or choose an existing one) to enter a world:\u003C\/li\u003E\n\u003Cli\u003EPress ESC to go back to the Minecraft menu but leave the game playing.\u003C\/li\u003E\n\u003Cli\u003EOpen Python IDLE by clicking Menu \u0026gt; Programming \u0026gt; Python 3.\u003C\/li\u003E\n\u003Cli\u003EUse File \u0026gt; New Window to create a new program and save it as ‘mc_micro.py’.\u003C\/li\u003E\n\u003Cli\u003EType the following code into the program to import the modules you will need\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom mcpi.minecraft import Minecraft\nfrom gpiozero import DigitalInputDevice\nfrom time import sleep\u003C\/pre\u003E\n\u003Cul\u003E\n\u003Cli\u003ECreate a connection to Minecraft using the code.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cpre class=\"prettyprint\"\u003Emc = Minecraft.create()\u003C\/pre\u003E\n\u003Cul\u003E\n\u003Cli\u003EPost a message to the chat window.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cpre class=\"prettyprint\"\u003Emc.postToChat(\"Micromine bitcraft earthquake\")\u003C\/pre\u003E\n\u003Cul\u003E\n\u003Cli\u003ERun your program by clicking Run \u0026gt; Run Module.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cdiv\u003E\nYou should see your message appear in the Minecraft chat window.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cdiv\u003E\n\u003Cspan style=\"color: red;\"\u003EAny errors will be displayed in the Python Shell in red.\u003C\/span\u003E\u003C\/div\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cdiv\u003E\nUpdate your program to shake Steve, by adding the following code at the bottom of your program.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cul\u003E\n\u003Cli\u003ECreate a pin which is connected to Pi GPIO 17 and micro:bit pin 0.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Epin0 = DigitalInputDevice(17)\u003C\/pre\u003E\n\u003Cdiv\u003E\n\u003Cul\u003E\n\u003Cli\u003ECreate a loop which constants gets Steve’s position.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Ewhile True:\n    sleep(0.1)\n    pos = mc.player.getPos()\u003C\/pre\u003E\n\u003Cdiv\u003E\n\u003Cul\u003E\n\u003Cli\u003EIf pin0 is on (1) it adds 0.5 to Steve’s height (y).\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003E    if pin0.value == 1:\n        pos.y = pos.y + 0.5\n        mc.player.setPos(pos)\u003C\/pre\u003E\n\u003Cdiv\u003E\n\u003Cul\u003E\n\u003Cli\u003ERun your program by clicking Run \u0026gt; Run Module.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\nShake your micro:bit and Steve will be shaken in Minecraft.\u003C\/div\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cb\u003EChallenges\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nCan you change the program so that it creates a more realistic earthquake by adding random values to the x, y, z values.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nComplete the\u0026nbsp;\u003Ca href=\"https:\/\/drive.google.com\/open?id=1VElMfrxKNG5qnwfQ0mx5o8-IeuYRfRatxlRqzInn6GE\"\u003Eworksheet\u003C\/a\u003E\u0026nbsp;from \u003Ca href=\"http:\/\/2016.pyconuk.org\/\"\u003EPyConUK 2016\u003C\/a\u003E\u0026nbsp;which includes using the micro:bit buttons to makes blocks disappear and appear.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/7438934064274327565\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/09\/microbit-making-minecraft-earthquakes.html#comment-form","title":"3 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7438934064274327565"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7438934064274327565"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/09\/microbit-making-minecraft-earthquakes.html","title":"Microbit making Minecraft Earthquakes"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEilvnIhttEMW9hP5PUCPiCpLQCsfMWkzl-qu9tv_JRBE8P3l_vUeVe08nXFF-_hej1ZZ8KrYd8VV22BxRe7r4H_oNYidNOlls-zAkmsUN0OQB7cFTCMQ8HnZC1Jv248oYZ0Md_C-qTrZDws\/s72-c\/ezgif.com-optimize.gif","height":"72","width":"72"},"thr$total":{"$t":"3"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-7457420126039383438"},"published":{"$t":"2016-06-17T20:00:00.000+01:00"},"updated":{"$t":"2016-06-17T20:00:23.852+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"games"}],"title":{"type":"text","$t":"Mayhem 2 - an open source cave shooter"},"content":{"type":"html","$t":"I recently \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/04\/mayhem-classic-amiga-game-ported-to.html\"\u003Eported an abandoned\u0026nbsp;version the classic amiga game, Mayhem, to the Raspberry Pi\u003C\/a\u003E - I did this exclusively so I could play the game with my friend, Lee, using \u003Ca href=\"http:\/\/retropie.org\/\"\u003ERetroPie\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nSince then myself and Lee, an artist for sumo digital, have been modding the game, adding new levels, features and controls - it now really is Mayhem \u003Cb\u003E2\u003C\/b\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiaufHWCGzwr6W5YA8mF5bU8fuL7TgWTukq6qirACfpjy4OileqQUJwgL1mdYK0fDKPnUgeKkM6hq01sprPudBFae3qC7gVxZjll4chObXR5g_cPNQ9GUTaFR4nIonMB7zFfB-C0Xq-mQ8R\/s1600\/Mayhem2pg.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"240\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiaufHWCGzwr6W5YA8mF5bU8fuL7TgWTukq6qirACfpjy4OileqQUJwgL1mdYK0fDKPnUgeKkM6hq01sprPudBFae3qC7gVxZjll4chObXR5g_cPNQ9GUTaFR4nIonMB7zFfB-C0Xq-mQ8R\/s320\/Mayhem2pg.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nMayhem 2 is available for \u003Ca href=\"https:\/\/github.com\/martinohanlon\/mayhem\"\u003EWindows\u003C\/a\u003E and \u003Ca href=\"https:\/\/github.com\/martinohanlon\/mayhem-pi\"\u003ERaspberry Pi\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nI'm hoping there will\u0026nbsp;be lots more features and changes to the game over the coming months, if anyone has any idea's or would like to contribute it would be great to hear from you.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EGameplay\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nMayhem 2\u0026nbsp;is a multiplayer (2 - 4) flight shooter with a really simple objective - destroy your opponents before they destroy you.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nYour ship has limited fuel which will run down when you boost, if you run out you will be unable to control your ship, to refuel, land on any flat surface.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nYou can protect yourself from attack using your shields which will stop all bullets, be careful though your shields run down quickly and you wont be able to boost while your shields are on. \u003Cbr \/\u003E\n\u003Cbr \/\u003E\nPower -ups are dropped (sometimes) when a player is destroyed (by either crashing or being shot) and when collected will give you a temporary boost such as a triple-shot weapon, better shields or more thrust.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/oxAzUuwuleM\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/oxAzUuwuleM?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nNew levels have been added including new ones with no edges, where you can seamlessly fly across the edge of the map.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/E3mho6J6OG8\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/E3mho6J6OG8?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EOptions\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nLevels 1-3 are the original game levels, all other levels are new to Mayhem 2.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nDCA are anti spaceship guns which will fire at the player if they get too close.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nWall collision can be turned off for new players to get used to the controls and playing the game.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EControls\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nMayhem 2 supports\u0026nbsp; joystick and keyboard control, joystick controls can be\u0026nbsp;configured via the main menu.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nDefault joystick controls, assume an \"xbox \/ ps like\" joystick:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ctable\u003E\u003Cthead\u003E\n\u003Ctr\u003E\u003Cth\u003EControl\u003C\/th\u003E\u003Cth\u003EAction\u003C\/th\u003E\u003C\/tr\u003E\n\u003C\/thead\u003E\u003Ctbody\u003E\n\u003Ctr\u003E\u003Ctd\u003EStick 1\u003C\/td\u003E\u003Ctd\u003ELeft \/ Right\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd\u003EButton 1 (A)\u003C\/td\u003E\u003Ctd\u003EThrust\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd\u003EButton 2 (B)\u003C\/td\u003E\u003Ctd\u003EShield\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd\u003EButton 6 (RB)\u003C\/td\u003E\u003Ctd\u003EFire\u003C\/td\u003E\u003C\/tr\u003E\n\u003C\/tbody\u003E\u003C\/table\u003E\n\u003Cbr \/\u003E\nIf joysticks are connected, they are used as the players controls, if there are less than 4 joysticks connected, keys are used for the rest of the players in order:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ctable\u003E\u003Cthead\u003E\n\u003Ctr\u003E\u003Cth\u003EKey\u003C\/th\u003E\u003Cth\u003ELeft\u003C\/th\u003E\u003Cth\u003ERight\u003C\/th\u003E\u003Cth\u003EShield\u003C\/th\u003E\u003Cth\u003EThrust\u003C\/th\u003E\u003Cth\u003EFire\u003C\/th\u003E\u003C\/tr\u003E\n\u003C\/thead\u003E\u003Ctbody\u003E\n\u003Ctr\u003E\u003Ctd\u003E1\u003C\/td\u003E\u003Ctd\u003Ez\u003C\/td\u003E\u003Ctd\u003Ex\u003C\/td\u003E\u003Ctd\u003Ec\u003C\/td\u003E\u003Ctd\u003Ev\u003C\/td\u003E\u003Ctd\u003Eg\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd\u003E2\u003C\/td\u003E\u003Ctd\u003Eleft\u003C\/td\u003E\u003Ctd\u003Eright\u003C\/td\u003E\u003Ctd\u003Epad del\u003C\/td\u003E\u003Ctd\u003Epad 0\u003C\/td\u003E\u003Ctd\u003Epad enter\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd\u003E3\u003C\/td\u003E\u003Ctd\u003Eb\u003C\/td\u003E\u003Ctd\u003En\u003C\/td\u003E\u003Ctd\u003E,\u003C\/td\u003E\u003Ctd\u003Em\u003C\/td\u003E\u003Ctd\u003El\u003C\/td\u003E\u003C\/tr\u003E\n\u003Ctr\u003E\u003Ctd\u003E4\u003C\/td\u003E\u003Ctd\u003Ey\u003C\/td\u003E\u003Ctd\u003Eu\u003C\/td\u003E\u003Ctd\u003Eo\u003C\/td\u003E\u003Ctd\u003Ei\u003C\/td\u003E\u003Ctd\u003E0\u003C\/td\u003E\u003C\/tr\u003E\n\u003C\/tbody\u003E\u003C\/table\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstall\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u003Ci\u003EFor windows:\u003C\/i\u003E\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nDownload the zip file from \u003Ca href=\"https:\/\/github.com\/martinohanlon\/mayhem\/archive\/master.zip\"\u003Ehttps:\/\/github.com\/martinohanlon\/mayhem\/archive\/master.zip\u003C\/a\u003E, open and copy mayhem-master to a folder. \u003Cbr \/\u003E\n\u003Cbr \/\u003E\nDouble click Mayhem2.exe in the mayhem-master folder. \u003Cbr \/\u003E\n\u003Cbr \/\u003E\nNote - You maybe presented with message saying that the application was stopped from starting as it is unrecognised, click 'more info' and and choose 'run anyway'. \u003Cbr \/\u003E\n\u003Cdiv\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\u003C\/div\u003E\n\u003Cb\u003E\u003Ci\u003EFor Raspberry Pi:\u003C\/i\u003E\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nOpen a terminal and type:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install liballegro4.4 liballegro4-dev\ngit clone https:\/\/github.com\/martinohanlon\/mayhem-pi\u003C\/pre\u003E\nRun using:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecd mayhem-pi\n.\/start\u003C\/pre\u003E\n\u003Cb\u003ECode\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThe full source code is available on GitHub for \u003Ca href=\"https:\/\/github.com\/martinohanlon\/mayhem\"\u003EWindows\u003C\/a\u003E and \u003Ca href=\"https:\/\/github.com\/martinohanlon\/mayhem-pi\"\u003ERaspberry Pi\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/7457420126039383438\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/06\/mayhem-2-open-source-cave-shooter.html#comment-form","title":"4 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7457420126039383438"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7457420126039383438"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/06\/mayhem-2-open-source-cave-shooter.html","title":"Mayhem 2 - an open source cave shooter"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiaufHWCGzwr6W5YA8mF5bU8fuL7TgWTukq6qirACfpjy4OileqQUJwgL1mdYK0fDKPnUgeKkM6hq01sprPudBFae3qC7gVxZjll4chObXR5g_cPNQ9GUTaFR4nIonMB7zFfB-C0Xq-mQ8R\/s72-c\/Mayhem2pg.jpg","height":"72","width":"72"},"thr$total":{"$t":"4"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-9015538987632472401"},"published":{"$t":"2016-05-19T12:40:00.000+01:00"},"updated":{"$t":"2016-05-19T23:05:04.425+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi - Playing a Sound File with Python"},"content":{"type":"html","$t":"A question I get asked a lot in Picademy is how to I play a sound file using Python.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nUsing just whats on the standard Raspbian image the easiest way, IMO, is to use Pygame.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThis small code snippet below shows you how. Just put the wav file in the same place as your program.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Eimport pygame\nfrom time import sleep\n\n#Initialise pygame and the mixer\npygame.init()\npygame.mixer.init()\n\n#load the sound file\nmysound = pygame.mixer.Sound(\"mysound.wav\")\n\n#play the sound file for 10 seconds and then stop it\nmysound.play()\ntime.sleep(10)\nmysound.stop()\u003C\/pre\u003E\n\u003Cbr \/\u003E\nYou will have to use wav files, as opposed to other sounds files such as mp3, ogg, etc - use\u0026nbsp;\u003Ca href=\"http:\/\/media.io\/\"\u003Emedia.io\u003C\/a\u003E\u0026nbsp;to convert them."},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/9015538987632472401\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/05\/raspberry-pi-playing-sound-file-with.html#comment-form","title":"5 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/9015538987632472401"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/9015538987632472401"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/05\/raspberry-pi-playing-sound-file-with.html","title":"Raspberry Pi - Playing a Sound File with Python"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"5"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-7003510159468627685"},"published":{"$t":"2016-04-12T21:53:00.002+01:00"},"updated":{"$t":"2016-07-12T12:44:06.123+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"c"},{"scheme":"http://www.blogger.com/atom/ns#","term":"games"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Mayhem, Amiga game, ported to Raspberry Pi"},"content":{"type":"html","$t":"\u003Ci\u003EUpdate - I've taken Mayhem forward to create \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/06\/mayhem-2-open-source-cave-shooter.html\"\u003EMayhem 2\u003C\/a\u003E.\u003C\/i\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nI had a\u0026nbsp;\u003Ca href=\"https:\/\/en.wikipedia.org\/wiki\/Amiga\"\u003ECommodore Amiga\u003C\/a\u003E\u0026nbsp;and a game I played, a lot, was \u003Ca href=\"http:\/\/www.lemonamiga.com\/games\/details.php?id=2972\"\u003EMayhem\u003C\/a\u003E, its a multiplayer (2-4) shooter - imagine multiplayer asteroids, with gravity, fuel and shields!\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIt was ported to the PC in 2002 by\u0026nbsp;\u003Ca href=\"https:\/\/github.com\/devpack\"\u003Edevpack\u003C\/a\u003E\u0026nbsp;who released the code in 2011 on\u0026nbsp;\u003Ca href=\"https:\/\/github.com\/devpack\/mayhem\"\u003Egithub\u003C\/a\u003E\u0026nbsp;and\u0026nbsp;\u003Ca href=\"https:\/\/code.google.com\/archive\/p\/mayhem\/\"\u003Egoogle code\u003C\/a\u003E\u0026nbsp;which is where I picked it up and ported it to the Raspberry Pi.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/Vxozz0Ijdr0\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/Vxozz0Ijdr0?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: center;\"\u003E\nThis is the port, but check out the \u003Ca href=\"https:\/\/www.youtube.com\/watch?v=fs30DLGxqhs\"\u003Eoriginal Amiga game\u003C\/a\u003E.\u003C\/div\u003E\n\u003Cbr \/\u003E\nI got some help from the \u003Ca href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?f=33\u0026amp;t=142284\u0026amp;\"\u003ERaspberry Pi forums in getting it to compile\u003C\/a\u003E\u0026nbsp;then it was case of sorting out a few case sensitive filename bugs (it was original written for Windows!) and tracking down a bug in the original code which was causing a memory access error and segmentation fault.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThe code is on \u003Ca href=\"http:\/\/github.com\/martinohanlon\/mayhem-pi\"\u003Egithub.com\/martinohanlon\/mayhem-pi\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EInstall\n\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo apt-get install liballegro4.4 liballegro4-dev\ngit clone https:\/\/github.com\/martinohanlon\/mayhem-pi\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003ERun\n\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecd mayhem-pi\n.\/start\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EKeys\u003C\/b\u003E\u003Cbr \/\u003E\nPlayer 1 - z, x, c, v, g\u003Cbr \/\u003E\nPlayer 2 - left, right, pad del, pad 0, pad enter\u003Cbr \/\u003E\nPlayer 3 - b, n, 'comma', m, l\u003Cbr \/\u003E\nPlayer 4 - y, u, o, i, 0\u003Cbr \/\u003E\nChange level - 1, 2, 3\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003ECompile\u003C\/b\u003E\u003Cbr \/\u003E\nIf you want to modify the game, I've got a couple of things on my \u003Ca href=\"https:\/\/github.com\/martinohanlon\/mayhem-pi\/issues\"\u003Elist\u003C\/a\u003E, you can recompile it with.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecd mayhem-pi\nmake\n\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgOQPkTpOxUSFF_z9ttjiblZFDePyVneJ-3-J2h1GE8HIIf0-MPD77VhaZotg3OBn3ODRMkgkPyQD2ZbszEeyK4Z9n3M2ZVTRVWJfX6EJeloxv2yn_1unQqWlpxCnN40-IplC5_c-tDGIwl\/s1600\/mayhem.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"243\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgOQPkTpOxUSFF_z9ttjiblZFDePyVneJ-3-J2h1GE8HIIf0-MPD77VhaZotg3OBn3ODRMkgkPyQD2ZbszEeyK4Z9n3M2ZVTRVWJfX6EJeloxv2yn_1unQqWlpxCnN40-IplC5_c-tDGIwl\/s320\/mayhem.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/7003510159468627685\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/04\/mayhem-classic-amiga-game-ported-to.html#comment-form","title":"2 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7003510159468627685"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/7003510159468627685"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/04\/mayhem-classic-amiga-game-ported-to.html","title":"Mayhem, Amiga game, ported to Raspberry Pi"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/img.youtube.com\/vi\/Vxozz0Ijdr0\/default.jpg","height":"72","width":"72"},"thr$total":{"$t":"2"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-9153734231388865972"},"published":{"$t":"2016-03-27T14:58:00.000+01:00"},"updated":{"$t":"2016-04-04T12:04:44.845+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"minecraft"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi - Take screenshots of Minecraft"},"content":{"type":"html","$t":"If you going to take a screenshot of Minecraft: Pi edition (or anything else for that matter), I really like a command line utility called \u003Ca href=\"https:\/\/github.com\/AndrewFromMelbourne\/raspi2png\"\u003Eraspi2png\u003C\/a\u003E,\u0026nbsp;its simple and screenshots images which have been created using the GPU (like games) as well.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjMcpKQbhvTTUllEgSCQPaLwgEPGHec5_FVcKs-A00vtZrdyTiSR150Sr0k06V9IGsKGqryn9CYUUuTLWlVFHSVyvlUplRIqa4Hev8dOPNQKQvwjfEytBYoy7AivFcFI4_RLOR1EzdeKyxA\/s1600\/myscreenshot.png\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"180\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjMcpKQbhvTTUllEgSCQPaLwgEPGHec5_FVcKs-A00vtZrdyTiSR150Sr0k06V9IGsKGqryn9CYUUuTLWlVFHSVyvlUplRIqa4Hev8dOPNQKQvwjfEytBYoy7AivFcFI4_RLOR1EzdeKyxA\/s320\/myscreenshot.png\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EDownload\u003C\/b\u003E\u003Cbr \/\u003E\nOpen a terminal and clone the repository from github:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecd ~\ngit clone https:\/\/github.com\/AndrewFromMelbourne\/raspi2png\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EUse\u003C\/b\u003E\u003Cbr \/\u003E\nChange directory to raspi2png and run the program's help to show all the options:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecd ~\/raspi2png\n.\/raspi2png --help\n\u003C\/pre\u003E\n\u003Cpre class=\"prettyprint\"\u003E\nUsage: raspi2png [--pngname name] [--width \u003Cwidth\u003E] [--height \u003Cheight\u003E] [--compression \u003Clevel\u003E] \n[--delay \u003Cdelay\u003E] [--display \u003Cnumber\u003E] [--stdout] [--help]\n\n    --pngname,-p - name of png file to create (default is snapshot.png)\n    --height,-h - image height (default is screen height)\n    --width,-w - image width (default is screen width)\n    --compression,-c - PNG compression level (0 - 9)\n    --delay,-d - delay in seconds (default 0)\n    --display,-D - Raspberry Pi display number (default 0)\n    --stdout,-s - write file to stdout\n    --help,-H - print this usage information\u003C\/number\u003E\u003C\/delay\u003E\u003C\/level\u003E\u003C\/height\u003E\u003C\/width\u003E\u003C\/pre\u003E\n\u003Cbr \/\u003E\nTo take screenshot you have to use the -p option and pass an image filename:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E.\/raspi2png -p myscreenshot.png\u003C\/pre\u003E\nAnother really useful option is -d to delay when to take the picture, this enables you to get the screen ready for a shot - to take a picture delayed by 10 seconds:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E.\/raspi2png -p mydelayedshot.png -d 10\u003C\/pre\u003E\nThe image files will be created in the ~\/raspi2png directory - if you want them in a different directory use a full path:\n\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E.\/raspi2png -p \/home\/pi\/mydir\/myscreenshot.png\u003C\/pre\u003E\nIf you use a filename which already exists raspi2png will overwrite the file without warning and the old image will be lost.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ci\u003EFyi - I wrote this blog post using a Raspberry Pi 3... \u0026nbsp;First time I've used a Pi to write about a Pi - thats progress!\u003C\/i\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/9153734231388865972\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/03\/raspberry-pi-take-screenshot-of.html#comment-form","title":"6 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/9153734231388865972"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/9153734231388865972"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/03\/raspberry-pi-take-screenshot-of.html","title":"Raspberry Pi - Take screenshots of Minecraft"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjMcpKQbhvTTUllEgSCQPaLwgEPGHec5_FVcKs-A00vtZrdyTiSR150Sr0k06V9IGsKGqryn9CYUUuTLWlVFHSVyvlUplRIqa4Hev8dOPNQKQvwjfEytBYoy7AivFcFI4_RLOR1EzdeKyxA\/s72-c\/myscreenshot.png","height":"72","width":"72"},"thr$total":{"$t":"6"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-8481785880871740046"},"published":{"$t":"2016-03-25T18:15:00.001+00:00"},"updated":{"$t":"2016-04-04T12:53:33.609+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"microbit"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"}],"title":{"type":"text","$t":"Microbit - get data from USB"},"content":{"type":"html","$t":"As part of my \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2015\/12\/minecraft-microbit-and-x-wing.html\"\u003EMinecraft, a Microbit and an X-Wing\u003C\/a\u003E project, I used the USB to read data from the Microbit's accelerometer and buttons to make the X-Wing move.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ca href=\"https:\/\/www.blogger.com\/\"\u003E@NCSComputing\u003C\/a\u003E on twitter has started re-using the code to make other things happen, so thought it would be a good idea to write up how it works, so others can do the same.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi9Vh60ArS8AhuEfI2fkKoeGeMRF-aOmztHdb33OT9uEQ9TpgSsZwyOZvIVhtiEVADxFhjHqpmSfFtv6izLZG-2krnyMwZUYn9CwVanXQa40yuFtCxfYf0CJE80H7A5x05uz_f9SFNPOqv0\/s1600\/CeLdEExWoAAkUWQ.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"178\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi9Vh60ArS8AhuEfI2fkKoeGeMRF-aOmztHdb33OT9uEQ9TpgSsZwyOZvIVhtiEVADxFhjHqpmSfFtv6izLZG-2krnyMwZUYn9CwVanXQa40yuFtCxfYf0CJE80H7A5x05uz_f9SFNPOqv0\/s320\/CeLdEExWoAAkUWQ.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nTo make this work you need one program which runs on the Microbit and prints data and a second runs on your computer (a Raspberry Pi, PC, Mac, anything with a USB port) which reads the data via a serial connection.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi6Rc70Dvq-t3g-cc6ExTEAqx9T2T71ZJ-4_Qg2xjZ94W8TNF1oHpFvFY4stvb-b8UX01Fzu8TVqNjUtxhDey1fixdp6kab4dJIp317zb929pUb1qzCwGc_4rDILP5lGcNBxHJNfH_js9mY\/s1600\/IMG_20160325_175730786_HDR.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"179\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi6Rc70Dvq-t3g-cc6ExTEAqx9T2T71ZJ-4_Qg2xjZ94W8TNF1oHpFvFY4stvb-b8UX01Fzu8TVqNjUtxhDey1fixdp6kab4dJIp317zb929pUb1qzCwGc_4rDILP5lGcNBxHJNfH_js9mY\/s320\/IMG_20160325_175730786_HDR.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nSee \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-serial\"\u003Egithub.com\/martinohanlon\/microbit-serial\u003C\/a\u003E for the code for both of these programs.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EThe Microbit\u003C\/b\u003E\u003Cbr \/\u003E\nThe \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-serial\/blob\/master\/microbitreaddata.py\"\u003Emicrobitreaddata.py\u003C\/a\u003E python program runs on the Microbit, gets the data and prints it to the output, which in this case is the USB serial connection, and should be flashed to your computer using the \u003Ca href=\"https:\/\/www.microbit.co.uk\/create-code\"\u003EPython editor\u003C\/a\u003E:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom microbit import *\n\nREFRESH = 500\n\ndef get_data():\n    x, y, z = accelerometer.get_x(), accelerometer.get_y(), accelerometer.get_z()\n    a, b = button_a.was_pressed(), button_b.was_pressed()\n    print(x, y, z, a, b)\n\ndef run():\n while True:\n  sleep(REFRESH)\n  get_data()\n\ndisplay.show('M')\nrun()\n\u003C\/pre\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EYour Computer\u003C\/b\u003E\u003Cbr \/\u003E\nThe \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-serial\/blob\/master\/clientreaddata.py\"\u003Eclientreaddata.py\u003C\/a\u003E python program runs on the computer and reads the data using \u003Ca href=\"http:\/\/pyserial.readthedocs.org\/en\/latest\/pyserial.html#installation\"\u003Epyserial\u003C\/a\u003E:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Eimport serial\n\n#the port will depend on your computer\n#for a raspberry pi it will probably be \/dev\/ttyACM0\n#PORT = \"\/dev\/ttyACM0\"\n#for windows it will be COM(something)\nPORT = \"COM3\"\n\nBAUD = 115200\n\ns = serial.Serial(PORT)\ns.baudrate = BAUD\ns.parity   = serial.PARITY_NONE\ns.databits = serial.EIGHTBITS\ns.stopbits = serial.STOPBITS_ONE\n\ntry:\n    while True:\n        #read a line from the microbit, decode it and\n        # strip the whitespace at the end\n        data = s.readline().rstrip()\n\n        #split the accelerometer data into x, y, z\n        data_s = data.split(\" \")\n        x, y, z = data_s[0], data_s[1], data_s[2]\n        a, b = data_s[3], data_s[4]\n        print(x,y,z)\n        print(a,b)\n\nfinally:\n    s.close()\n\u003C\/pre\u003E\nThe values of the accelerometer will be put into the variables x, y, z and the buttons in a \u0026amp; b.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003ESetting the PORT\u003C\/b\u003E\u003Cbr \/\u003E\nYou will have to change the \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-serial\/blob\/master\/clientreaddata.py#L5\"\u003EPORT variable in the clientreaddata.py program\u003C\/a\u003E to the comm port that the Microbit is connected to on your computer.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nFor a Raspberry Pi it is probably\u0026nbsp;\"\/dev\/ttyACM0\", in the event it isn't, unplug the Microbit and run:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Els \/dev\/tty*\u003C\/pre\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi17gmYrCCDacwPzpH85bwvm9FPPORdbbw8g4wT9no1-VSHk_5js6CxyrGSEKJQSdTZ7ZYUG7JzthUSy3yTMcQh-giHfJqNBnobuqFBecVNHnWa5_tCxtFnlpcrNK6zC8bpTR16nYmrNgNN\/s1600\/microbitpiport.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"192\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi17gmYrCCDacwPzpH85bwvm9FPPORdbbw8g4wT9no1-VSHk_5js6CxyrGSEKJQSdTZ7ZYUG7JzthUSy3yTMcQh-giHfJqNBnobuqFBecVNHnWa5_tCxtFnlpcrNK6zC8bpTR16nYmrNgNN\/s320\/microbitpiport.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nThen plug the Microbit and run the command again, the new device which appears will be the port of your Microbit.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nFor Windows it will be \"COM#\", the # being a number, the easiest way is to look in \u003Ca href=\"http:\/\/lmgtfy.com\/?q=open+windows+device+manager\"\u003EDevice Manager\u003C\/a\u003E for the \"mBed Serial Port (COM#)\"\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjd95AIFc6L6esujBum_oZUyI1Msl_nAPT8WUJngqK9eBt2sbtmziYn9e4LtyZ4Vtoa1d-vmhMvVYuW-9xTrBSxfpxrwMJvJwTjffrcBcepyvj7Zqi8VTTcwpCmLVx8DNYz91bpAth18tzc\/s1600\/microbit-windowscommport.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"265\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjd95AIFc6L6esujBum_oZUyI1Msl_nAPT8WUJngqK9eBt2sbtmziYn9e4LtyZ4Vtoa1d-vmhMvVYuW-9xTrBSxfpxrwMJvJwTjffrcBcepyvj7Zqi8VTTcwpCmLVx8DNYz91bpAth18tzc\/s320\/microbit-windowscommport.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/8481785880871740046\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/03\/microbit-get-data-from-usb.html#comment-form","title":"3 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/8481785880871740046"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/8481785880871740046"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/03\/microbit-get-data-from-usb.html","title":"Microbit - get data from USB"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi9Vh60ArS8AhuEfI2fkKoeGeMRF-aOmztHdb33OT9uEQ9TpgSsZwyOZvIVhtiEVADxFhjHqpmSfFtv6izLZG-2krnyMwZUYn9CwVanXQa40yuFtCxfYf0CJE80H7A5x05uz_f9SFNPOqv0\/s72-c\/CeLdEExWoAAkUWQ.jpg","height":"72","width":"72"},"thr$total":{"$t":"3"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-885971677212587197"},"published":{"$t":"2016-03-25T08:03:00.000+00:00"},"updated":{"$t":"2016-03-29T10:25:01.692+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"gpio"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Raspberry Pi gpiozero holdable button"},"content":{"type":"html","$t":"The current release of \u003Ca href=\"https:\/\/gpiozero.readthedocs.org\/\"\u003Egpiozero\u003C\/a\u003E\u0026nbsp;doesn't have the support to hold a button down e.g. when a button is pressed and then held down for 1 second something happens.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThis is really useful when building hardware projects and you want 1 button to do 2 things, say turn something on when pressed, and turn off when held down.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nI needed this for a project so I thought I would create a new HoldableButton class using gpiozero. Hopefully this will be \u003Ca href=\"https:\/\/github.com\/RPi-Distro\/python-gpiozero\/issues\/115\"\u003Eincorporated into gpiozero\u003C\/a\u003E, but until then you can use the class below.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThe code is also available \u003Ca href=\"https:\/\/gist.github.com\/martinohanlon\/20cee570d6ea4ca0b7ad\"\u003Ehere\u003C\/a\u003E as a gist.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nYou will need to add the HoldableButton class to your Python program:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom gpiozero import Button\nfrom threading import Timer\n\nclass HoldableButton(Button):\n    def __init__(self, pin=None, pull_up=True, bounce_time=None, \n                 hold_time=1, repeat=False): \n\n        super(HoldableButton, self).__init__(pin, pull_up, bounce_time)\n\n        # Set Button when_pressed and when_released to call local functions\n        # cant use super() as it doesn't support setters\n        Button.when_pressed.fset(self, self._when_button_pressed)\n        Button.when_released.fset(self, self._when_button_released)\n\n        self._when_held = None\n        self._when_pressed = None\n        self._when_released = None\n        self._is_held = False\n\n        self.hold_time = hold_time\n        self.repeat = repeat\n        self._held_timer = None\n\n    #override button when_pressed and when_released\n    @property\n    def when_pressed(self):\n        return self._when_pressed\n\n    @when_pressed.setter\n    def when_pressed(self, value):\n        self._when_pressed = value\n\n    @property\n    def when_released(self):\n        return self._when_released\n\n    @when_released.setter\n    def when_released(self, value):\n        self._when_released = value\n\n    @property\n    def when_held(self):\n        return self._when_held\n\n    @when_held.setter\n    def when_held(self, value):\n        self._when_held = value\n\n    @property\n    def is_held(self):\n        return self._is_held\n\n    def _when_button_pressed(self):\n        self._start_hold()\n        if self._when_pressed != None:\n            self._when_pressed()\n\n    def _when_button_released(self):\n        self._is_held = False\n        self._stop_hold()\n        if self._when_released != None:\n            self.when_released()\n\n    def _start_hold(self):\n        self._held_timer = Timer(self.hold_time, self._button_held)\n        self._held_timer.start()\n\n    def _stop_hold(self):\n        if self._held_timer != None:\n            self._held_timer.cancel()\n\n    def _button_held(self):\n        self._is_held = True\n        if self._when_held != None:\n            if self.repeat and self.is_pressed:\n                self._start_hold()\n            self._when_held()\u003C\/pre\u003E\nUsing the HoldableButton class is pretty simple, similar to the gpiozero \u003Ca href=\"https:\/\/gpiozero.readthedocs.org\/en\/v1.1.0\/api_input.html#button\"\u003EButton\u003C\/a\u003E class and can be swapped for the Button class with no other changes.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Eholdbutton = HoldableButton(pin, hold_time = 1, repeat = False)\u003C\/pre\u003E\nYou have to pass a \u003Cb\u003Epin\u003C\/b\u003E number and optional hold_time and repeat values:\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003Ehold_time - is the number of seconds after the button is pressed before the button is consider 'held'\u003C\/li\u003E\n\u003Cli\u003Erepeat - is a boolean and if set to True will occur 'button held' events to be repeated after each hold_time\u003C\/li\u003E\n\u003C\/ul\u003E\nYou can use all the same methods and properties of the \u003Ca href=\"https:\/\/gpiozero.readthedocs.org\/en\/v1.1.0\/api_input.html#button\"\u003EButton\u003C\/a\u003E class, when_pressed, when_released, is_pressed, etc.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThere are 2 additional properties \u003Cb\u003Eis_held\u003C\/b\u003E, which will return a boolean stating whether the button has been held down for the 'hold_time' and\u0026nbsp;\u003Cb\u003Ewhen_held\u003C\/b\u003E\u0026nbsp;which when assigned a function will cause the function to be called when the button is held down.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Edef myheldfunction():\n    print(\"button held\")\n\nholdbutton.when_held = myheldfunction\u003C\/pre\u003E\nNow when a button is held down, the function will be called and \"button held\" printed."},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/885971677212587197\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/03\/raspberry-pi-gpiozero-holdable-button.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/885971677212587197"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/885971677212587197"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/03\/raspberry-pi-gpiozero-holdable-button.html","title":"Raspberry Pi gpiozero holdable button"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-3038311526989947612"},"published":{"$t":"2016-02-02T21:08:00.000+00:00"},"updated":{"$t":"2016-08-14T22:04:14.686+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"microbit"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"}],"title":{"type":"text","$t":"Microbit - a Bop-it game in Python"},"content":{"type":"html","$t":"I wanted to create a simple game for the Microbit and after bring brought an \u003Ca href=\"http:\/\/amzn.to\/1PPYkzw\"\u003ER2D2 Bop-it game\u003C\/a\u003E\u0026nbsp;I thought I would make one whereby you have to press the A and B buttons in time.\u003Cbr \/\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nLets start by importing the microbit and random libraries:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Efrom microbit import *\nimport random\u003C\/pre\u003E\n\u003Cdiv\u003E\nCreate some constants, one for the SPEED which is the amount of time in between each bop for each level, and one for the LEVELUP's which is the amount of points at each level:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003ESPEED = {0: 1000, 1: 750, 2: 650, 3: 600, 4: 550, 5: 500}\nLEVELUP = (5, 10, 15, 20, 25, 30)\u003C\/pre\u003E\n\u003Cdiv\u003E\nCreate 4 functions which when caused will show A, B, a tick and a cross:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Edef show_a():\n    display.clear()\n    display.show(\"A\")\n\ndef show_b():\n    display.clear()\n    display.show(\"B\")\n\ndef show_tick():\n    display.clear()\n    display.set_pixel(0, 3, 9)\n    display.set_pixel(1, 4, 9)\n    display.set_pixel(2, 3, 9)\n    display.set_pixel(3, 2, 9)\n    display.set_pixel(4, 1, 9)\n    \ndef show_cross():\n    display.clear()\n    display.show(\"X\")\u003C\/pre\u003E\n\u003Cdiv\u003E\nCreate a function which will wait for the button to be pressed, returning True if it is and False if it isn't:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Edef wait_for_button(rightbutton, wrongbutton):\n    rightpressed = False\n    wrongpressed = False\n    \n    started = running_time()\n    now = running_time()\n    \n    while now - started \u0026lt; SPEED[level]:\n        if rightbutton.is_pressed():\n            rightpressed = True\n        if wrongbutton.is_pressed():\n            wrongpressed = True\n        now = running_time()\n        \n    if rightpressed == True and wrongpressed == False:\n        return True\n    else:\n        return False\u003C\/pre\u003E\n\u003Cdiv\u003E\nSet 3 variables for the level, the score and one which will be set to True when the game is over:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Elevel = 0\nscore = 0\ngameover = False\u003C\/pre\u003E\n\u003Cdiv\u003E\nScroll \"BopBit\" on the screen to show its the start of the game:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Edisplay.scroll(\"BopBit\")\u003C\/pre\u003E\n\u003Cdiv\u003E\nLoop until the game is over:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Ewhile gameover == False:\u003C\/pre\u003E\n\u003Cdiv\u003E\nRandomly pick an action (either A or B), show it on the screen and wait for a button to be pressed:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003E    success = False\n    \n    #randomly pick an A or B button\n    action = random.randint(0, 1)\n    \n    #wait for the button to be pressed\n    if action == 0:\n        show_a()\n        success = wait_for_button(button_a, button_b)\n    elif action == 1:\n        show_b()\n        success = wait_for_button(button_b, button_a)\n\u003C\/pre\u003E\n\u003Cdiv\u003E\nIf the player pressed the right button in time show a tick and increase the score or show a cross:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003E    if success:\n        show_tick()\n        score = score + 1\n        #if the score is a levelup score increase the level \n        if score in LEVELUP:\n            level = level + 1\n    else:\n        show_cross()\n        gameover = True\u003C\/pre\u003E\n\u003Cdiv\u003E\nWait for a small amount of time (half the current speed):\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003E    sleep(int(SPEED[level] \/ 2))\u003C\/pre\u003E\n\u003Cdiv\u003E\nAfter the game is over, sleep for 1 second, and display the players score on a loop:\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Esleep(1000)\nwhile True:\n    display.scroll(\"{} points\".format(score))\u003C\/pre\u003E\n\u003Cdiv\u003E\nYou can view the \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\/blob\/master\/examples\/bopbit.py\"\u003Ecomplete code\u003C\/a\u003E in my \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\"\u003EMicrobit MicroPython examples repository\u003C\/a\u003E on github.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\nHow about taking it further by adding new actions such as shaking or a connecting up a speaker and adding a sound track,\u003Cbr \/\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/3038311526989947612\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/02\/microbit-bop-it-game-in-python.html#comment-form","title":"3 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/3038311526989947612"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/3038311526989947612"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/02\/microbit-bop-it-game-in-python.html","title":"Microbit - a Bop-it game in Python"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"3"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-961458907318401267"},"published":{"$t":"2016-01-18T00:19:00.000+00:00"},"updated":{"$t":"2016-12-05T13:32:32.796+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"c"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Pocket PiGRRL - Battery Monitor"},"content":{"type":"html","$t":"I recently made myself an \u003Ca href=\"https:\/\/learn.adafruit.com\/pocket-pigrrl\/overview\"\u003EAdafruit Pocket PiGRRL\u003C\/a\u003E\u0026nbsp;and I wanted to modify it so it would warn me when the battery was running low - there is a\u0026nbsp;small red LED but its hidden inside the case!\u003Cbr \/\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjK4K32m-NHpUQtZxWwh-Syq1TRNk04YBxcHG92lTNzKYSUwkC37HkXKcZztZjmQqRucA0uTfnNcTDxRd0F7-udv7-e8TPu4CCLtLrjAPireNqGDr52B1yv1T4zsSo8RvzY1Gzu3jXfw1PM\/s1600\/IMG_20160106_213746797.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjK4K32m-NHpUQtZxWwh-Syq1TRNk04YBxcHG92lTNzKYSUwkC37HkXKcZztZjmQqRucA0uTfnNcTDxRd0F7-udv7-e8TPu4CCLtLrjAPireNqGDr52B1yv1T4zsSo8RvzY1Gzu3jXfw1PM\/s320\/IMG_20160106_213746797.jpg\" width=\"227\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nThe plan was to create a program which would sense the battery getting low and put a warning icon on the top left of screen giving me time to shutdown the Pi properly or plug it in.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi1GzNiMoCNBXlnH81w-AaEVCl4_F4GIX6SvmlI9RInRRFuv-vZBFKuq3gQa6LCI7ibEDCmUyPMoOvHzwCpXXS34VxWv5JrM9mpgJVwzV4vsdKWBEBknfEBmEunL171VPEOX5jhgy72dwY0\/s1600\/IMGP4581.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"236\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi1GzNiMoCNBXlnH81w-AaEVCl4_F4GIX6SvmlI9RInRRFuv-vZBFKuq3gQa6LCI7ibEDCmUyPMoOvHzwCpXXS34VxWv5JrM9mpgJVwzV4vsdKWBEBknfEBmEunL171VPEOX5jhgy72dwY0\/s320\/IMGP4581.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjglPQ00C79ekosFvhGerqTsoNDPYe2P0UZN3CxXlsU6bJFmvQCI5KvCcwdFqkonIv1TcXo3Lw8TnrhxAzjXlLNyZAbTecF7P_t_YUiW5sdPmmT50qOO-zwak_mVAq2JrtF3A7BnPPDcwtJ\/s1600\/lowbatticon.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjglPQ00C79ekosFvhGerqTsoNDPYe2P0UZN3CxXlsU6bJFmvQCI5KvCcwdFqkonIv1TcXo3Lw8TnrhxAzjXlLNyZAbTecF7P_t_YUiW5sdPmmT50qOO-zwak_mVAq2JrtF3A7BnPPDcwtJ\/s1600\/lowbatticon.jpg\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nTLDR - just scroll down to install Grrl Battery Monitor.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nI started with the software as I, foolishly, thought this would be the hardest part, the problem with creating an icon is that is has to go over the top of everything regardless of what is on the screen (command prompt, emulators, emulation station, everything) or what hardware was rendering it.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nMy first plan was that I could use \u003Ca href=\"http:\/\/picamera.readthedocs.org\/en\/release-1.10\/\"\u003EPicamera\u003C\/a\u003E's overlay function which I knew used the GPU to output directly to the screen, and with a bit of help from \u003Ca href=\"https:\/\/twitter.com\/waveform80\"\u003EDave Jones\u003C\/a\u003E\u0026nbsp;who put together a \u003Ca href=\"https:\/\/gist.github.com\/waveform80\/b13f7d78e6671c133984\"\u003Eprototype\u003C\/a\u003E, it was looking good, but while the icon appeared on top of emulators and the command prompt, it didnt write over emulation station.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nI came across \u003Ca href=\"http:\/\/raspberrycompote.blogspot.co.uk\/2012\/12\/low-level-graphics-on-raspberry-pi-part_9509.html\"\u003ELow Level Graphics on Raspberry Pi\u003C\/a\u003E\u0026nbsp;which walks you through writing graphics directly to the \u003Ca href=\"https:\/\/en.wikipedia.org\/wiki\/Linux_framebuffer\"\u003ELinux framebuffer\u003C\/a\u003E\u0026nbsp;using C, this was a lot lower level than I hoped to get into but it would definitely write my icon over anything that was on the screen - using this I wrote a \u003Ca href=\"https:\/\/github.com\/martinohanlon\/grrl-bat-monitor\/blob\/master\/grrl_bat_mon.c\"\u003Eprogram\u003C\/a\u003E to create an icon on the screen when a GPIO pin was triggered.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nNext I needed to be able to read from the \u003Ca href=\"https:\/\/learn.adafruit.com\/adafruit-powerboost-1000c-load-share-usb-charge-boost\/overview\"\u003Epower booster\u003C\/a\u003E when the battery was running low, my original plan was to use the LBO (low battery output) pin, but this proved to be way more difficult than I expected, read this\u0026nbsp;\u003Ca href=\"http:\/\/forums.adafruit.com\/viewtopic.php?f=19\u0026amp;t=87713\"\u003Epost on Adafruit's forum\u003C\/a\u003E if your really interested.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nI ended up connecting a wire to the low battery warning led (red) on the power booster and using this to switch a transistor which connected a GPIO to ground.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgrT980PXKt9EDC_bqgqnveclsiAMuROX-n4ae3HtWl4R3ov_t4PTj6gG00zdz0_PeV0D2S3aTvqY7ABabikH7JQ1qttPywc4gn7q7WQTg1nHMHHw49zAgmGupvUyKLtOJklpuwOTSiVWGG\/s1600\/IMGP4584.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"313\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgrT980PXKt9EDC_bqgqnveclsiAMuROX-n4ae3HtWl4R3ov_t4PTj6gG00zdz0_PeV0D2S3aTvqY7ABabikH7JQ1qttPywc4gn7q7WQTg1nHMHHw49zAgmGupvUyKLtOJklpuwOTSiVWGG\/s320\/IMGP4584.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nIts been frustrating but I am really pleased with how it worked out - if you want to add the batter monitor to your own Pocket PiGRRL follow the instructions below.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cb\u003EInstall Grrl Battery Monitor\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nYou will need a few parts:\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cul\u003E\n\u003Cli\u003ESome wire\u003C\/li\u003E\n\u003Cli\u003E2N3904 NPN transistor\u003C\/li\u003E\n\u003Cli\u003E47k resistor\u003C\/li\u003E\n\u003Cli\u003EStrip board\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cdiv\u003E\n\u003Ci\u003ENote - if you are doing this on a PiGRRL 2 with a Pi 3, be sure to check out Christian's comments about the \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-battery-monitor.html?showComment=1473048626905#c1441985850678463142\"\u003Epin to use\u003C\/a\u003E and \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-battery-monitor.html?showComment=1472960188243#c2350592785972375454\"\u003Ewiring-pi install\u003C\/a\u003E before starting.\u003C\/i\u003E\u003C\/div\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n1. Open up your Pi GRRL and connect a small length of wire to the red (low power) led on the power booster.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiPr34yaLp8BynYyg915kcfG4048idtoiZ1hgMItYfZgoNIg5NoqltJAJ8_pKUZQm34VGG9pjjddhxhbhjEoTSr7l4kZKGAxpPV-4nyg3XRLeI02aU002OjLzyc7SzSwKQoWSJsaTB51hFx\/s1600\/redledsolderpoint.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"290\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEiPr34yaLp8BynYyg915kcfG4048idtoiZ1hgMItYfZgoNIg5NoqltJAJ8_pKUZQm34VGG9pjjddhxhbhjEoTSr7l4kZKGAxpPV-4nyg3XRLeI02aU002OjLzyc7SzSwKQoWSJsaTB51hFx\/s320\/redledsolderpoint.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEizMY1duHqkPAzrNiO-iF8koagk0SQ2rP0tYcStU6RAQnEKHb2-edU4q6e84sUipIEMj6-I7tlWJSQU_2QZWYGCyxwFJwoxPU1FAuDlT-cxyvskTAH00ud8H1dEXeQQAoIKsq5iKR7a9kvW\/s1600\/redledwire.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"258\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEizMY1duHqkPAzrNiO-iF8koagk0SQ2rP0tYcStU6RAQnEKHb2-edU4q6e84sUipIEMj6-I7tlWJSQU_2QZWYGCyxwFJwoxPU1FAuDlT-cxyvskTAH00ud8H1dEXeQQAoIKsq5iKR7a9kvW\/s320\/redledwire.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n2. Solder the components to the strip board. including 2 lengths of wire which will connect to GPIO 19 and GND.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgFqwrG2-KLh35_DulJlDn8_2-Y_l3ZB93YZ5wcShQlj1LuO0IX7auSCrGhPqGJf-CWI8CpxPRfIuiGB0cDTg_CH4ChktlckkkD-G1cB7l2GOeAi8M6XtDDghuDpi4paSnUo6UaIqupY_Q6\/s1600\/stripboard2.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"293\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgFqwrG2-KLh35_DulJlDn8_2-Y_l3ZB93YZ5wcShQlj1LuO0IX7auSCrGhPqGJf-CWI8CpxPRfIuiGB0cDTg_CH4ChktlckkkD-G1cB7l2GOeAi8M6XtDDghuDpi4paSnUo6UaIqupY_Q6\/s320\/stripboard2.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjRE3vCJlVXhLtu360KoUrd7s2xQ719FMdaEn1b3uq_C6I2u4zKeZxv_hpIFLgEfV44kU9rGqDgnzLhXEuQCyqMO_Gld2PTxq-JPmirEiclYTDZ4ibG6lioDuaqDY2x21aVxH_5IUY1yZPR\/s1600\/stripboard.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"274\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjRE3vCJlVXhLtu360KoUrd7s2xQ719FMdaEn1b3uq_C6I2u4zKeZxv_hpIFLgEfV44kU9rGqDgnzLhXEuQCyqMO_Gld2PTxq-JPmirEiclYTDZ4ibG6lioDuaqDY2x21aVxH_5IUY1yZPR\/s320\/stripboard.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgHHvFn3GOgghH_3aI-XoVUWZxfcKT1_lGwUo4NfzMFkuCeX3XHxVNWIPYTNT3v0r4648ne49b7czVh2v6hGjB3CWCisKRFpsc6Ju3gfUHjG8_XwR5rVn81ckruy-HHMjZFM2kynkBJHUwX\/s1600\/stripboard3.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"143\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgHHvFn3GOgghH_3aI-XoVUWZxfcKT1_lGwUo4NfzMFkuCeX3XHxVNWIPYTNT3v0r4648ne49b7czVh2v6hGjB3CWCisKRFpsc6Ju3gfUHjG8_XwR5rVn81ckruy-HHMjZFM2kynkBJHUwX\/s320\/stripboard3.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: left;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n3. Flip over your Pi and solder the GPIO and GND wires to the underside of the Pi's GPIO header.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi3g3t8mTunHz8E7KDTs1SCyBsmLAYq-81ArPmRAkxgU30unjqrFpClvk3UTj4zs4W_u4-IkiVAOSSM9PUhSZLhL62mwQxD7D6lub_aWd4SomMgApludPT73Le82i9RXc7lzaBrgirV_xPQ\/s1600\/soldertopi.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"299\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEi3g3t8mTunHz8E7KDTs1SCyBsmLAYq-81ArPmRAkxgU30unjqrFpClvk3UTj4zs4W_u4-IkiVAOSSM9PUhSZLhL62mwQxD7D6lub_aWd4SomMgApludPT73Le82i9RXc7lzaBrgirV_xPQ\/s320\/soldertopi.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhr6Fv89Hs-K4zsNFCUxZoCA_T3iCsAGr1OfD9Xus_cluz4tuOatKJ74iwP_wN-v4hz6cppNGJ1wNQNe4HG-rH-LYbT072s88yqlNILlzoNVWR5koJPLagg8Y5tApkJwQxPAgJ5mPAGJCEV\/s1600\/soldertopi2.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"288\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhr6Fv89Hs-K4zsNFCUxZoCA_T3iCsAGr1OfD9Xus_cluz4tuOatKJ74iwP_wN-v4hz6cppNGJ1wNQNe4HG-rH-LYbT072s88yqlNILlzoNVWR5koJPLagg8Y5tApkJwQxPAgJ5mPAGJCEV\/s320\/soldertopi2.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: center;\"\u003E\n\u003Ci\u003EThe yellow wire is for my \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-adding-mute.html\"\u003Emute \/ un-mute amp function\u003C\/a\u003E.\u003C\/i\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n4, Solder the wire from the low power (red) led to the strip board.\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgXMBgF783WYcMrnHSG8KvEmWwxdniyUZRZ69CMIM7p1usZ1459Et1slshLOV_OeQ-e3ieBSaL038f2OKxibeabqNBTBmN-BAuhyLJuxueBogSKKEROi-h6eIlLzy2lO1S7MXbOnRmHlHgq\/s1600\/redledsolder.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"245\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgXMBgF783WYcMrnHSG8KvEmWwxdniyUZRZ69CMIM7p1usZ1459Et1slshLOV_OeQ-e3ieBSaL038f2OKxibeabqNBTBmN-BAuhyLJuxueBogSKKEROi-h6eIlLzy2lO1S7MXbOnRmHlHgq\/s320\/redledsolder.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n5. Stick the strip board to the case in-between the power booster and the amp with a bit of glue and put your PiGRRL back together.\u003C\/div\u003E\n\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n6. Download the program from \u003Ca href=\"https:\/\/github.com\/martinohanlon\/grrl-bat-monitor\"\u003Egithub.com\/martinohanlon\/grrl-bat-monitor\u003C\/a\u003E\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecd ~\ngit clone https:\/\/github.com\/martinohanlon\/grrl-bat-monitor\u003C\/pre\u003E\n\u003Cdiv\u003E\n7. Make the program run at boot by editing \/etc\/rc.local\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo nano \/etc\/rc.local\u003C\/pre\u003E\n\u003Cdiv\u003E\nScroll down and add the command under '\/usr\/local\/bin\/retrogame \u0026amp;' but before 'exit 0':\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003E\/home\/pi\/grrl-bat-monitor\/grrl_bat_mon \u0026amp;\u003C\/pre\u003E\n\u003Cdiv\u003E\n8. Reboot and test!\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/961458907318401267\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-battery-monitor.html#comment-form","title":"19 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/961458907318401267"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/961458907318401267"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-battery-monitor.html","title":"Pocket PiGRRL - Battery Monitor"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjK4K32m-NHpUQtZxWwh-Syq1TRNk04YBxcHG92lTNzKYSUwkC37HkXKcZztZjmQqRucA0uTfnNcTDxRd0F7-udv7-e8TPu4CCLtLrjAPireNqGDr52B1yv1T4zsSo8RvzY1Gzu3jXfw1PM\/s72-c\/IMG_20160106_213746797.jpg","height":"72","width":"72"},"thr$total":{"$t":"19"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-6539045085930367286"},"published":{"$t":"2016-01-10T16:47:00.001+00:00"},"updated":{"$t":"2017-04-24T09:11:24.656+01:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"games"},{"scheme":"http://www.blogger.com/atom/ns#","term":"raspberry pi"}],"title":{"type":"text","$t":"Pocket PiGRRL - adding a mute"},"content":{"type":"html","$t":"I recently made myself a \u003Ca href=\"https:\/\/learn.adafruit.com\/pocket-pigrrl\/overview\"\u003EPocket PiGRRL\u003C\/a\u003E based on Adafruit's tutorial - it really is a great machine and a brilliant learning experience.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjhyphenhyphenYsTsgVOXd2MryaQDtKPwzqJ9-qe-60EQPN_125rnO60F-2sTq2sX8NfE-qY2TET5VIOXWBs2EvwC1ZwjURZsYMXldZS6otMej8z1SqWKqfZF-tc1VyxqeUztBStw9OauW7KZOn91Cqp\/s1600\/IMG_20160106_213808996.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"320\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjhyphenhyphenYsTsgVOXd2MryaQDtKPwzqJ9-qe-60EQPN_125rnO60F-2sTq2sX8NfE-qY2TET5VIOXWBs2EvwC1ZwjURZsYMXldZS6otMej8z1SqWKqfZF-tc1VyxqeUztBStw9OauW7KZOn91Cqp\/s320\/IMG_20160106_213808996.jpg\" width=\"222\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nThere was one aspect though that I didn't like, the speaker hisses, not particularly loud and when your playing a game its not that noticeable but if you have got the volume down it is really annoying. Its all down the Raspberry Pi's noisy analogue audio out so there isn't a great deal you can do to clean it up.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nMy solution was to add the ability to shutdown the amp, effectively muting it when I didn't want any sound.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nThe PAM8302A amp breakout board has a shutdown (SD) pin which when a ground (logic zero) is connected it puts the amp into idle mode, muting the amp and reducing power consumption.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhtEYw-XuoH1UROiSCo0vF1fK7K_uhlVKlzSlJ5IsJpK8d5buVfu7y5ddRL7ku_BzY-kGHlJlh6N_eZyWO933GryHqG0pZYjaqVVHwSqcfe3rfwLjFiVZTA7lEhQSbLtIumCWng7HTGfiVz\/s1600\/gaming_secure_pam8302.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"262\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhtEYw-XuoH1UROiSCo0vF1fK7K_uhlVKlzSlJ5IsJpK8d5buVfu7y5ddRL7ku_BzY-kGHlJlh6N_eZyWO933GryHqG0pZYjaqVVHwSqcfe3rfwLjFiVZTA7lEhQSbLtIumCWng7HTGfiVz\/s320\/gaming_secure_pam8302.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nI soldered a piece of wire between GPIO 26 on the bottom of the A+ and the shutdown pin on the PAM8302A ampl.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Ci\u003ENote - a few people have noted in the comments that on other models of PiGrrl (such as the Pi Grrl 2) GPIO 26 is already used and have suggested changing this to GPIO 7.\u003C\/i\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjEqzTci2SVmJJ1Yv3ih7qX8eqz4Fy1KE1FX-R5IiGfQBAzNeR-t_luEy5CKviHu3IZd7pGO7gMkr96SrkhmkAdwZfFzrICMtlatpcICbV-71dPr0MWamLVvoJ4Sqa8125T0rK7CNwiVHVI\/s1600\/IMG_20160108_204432090.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"194\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjEqzTci2SVmJJ1Yv3ih7qX8eqz4Fy1KE1FX-R5IiGfQBAzNeR-t_luEy5CKviHu3IZd7pGO7gMkr96SrkhmkAdwZfFzrICMtlatpcICbV-71dPr0MWamLVvoJ4Sqa8125T0rK7CNwiVHVI\/s320\/IMG_20160108_204432090.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhcSStbgebj8CkqY1VJgE6dw6ysvjVxe18I7bdWTYr2xiJWzrbIq_xNVEV6_iKp3OuYVYtID9zf0EnEbTvH-Qjh_ehLB6MvInJcewLEASWyKu_svBNgIu9pcMy8t9alwn-fY4EG2WEuK0BP\/s1600\/IMG_20160108_204531426.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"183\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhcSStbgebj8CkqY1VJgE6dw6ysvjVxe18I7bdWTYr2xiJWzrbIq_xNVEV6_iKp3OuYVYtID9zf0EnEbTvH-Qjh_ehLB6MvInJcewLEASWyKu_svBNgIu9pcMy8t9alwn-fY4EG2WEuK0BP\/s320\/IMG_20160108_204531426.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nThis gave me a way of triggering the shutdown pin next I needed some software and a way of running it.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nUsing this \u003Ca href=\"https:\/\/weekendengineer.wordpress.com\/2014\/09\/15\/adding-an-apps-tab-in-emulationstation\/\"\u003Etutorial\u003C\/a\u003E as the basis I added an 'Apps' tab to emulation station where I could run 2 scripts to mute and unmute the amp.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIf you want to configure your Pocket PiGRRL to do the same, you can follow the instructions below.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EDownload and install wiring pi\u003C\/b\u003E\u003Cbr \/\u003E\nThe software uses wiringpi's gpio command line utility, so \u003Ca href=\"http:\/\/wiringpi.com\/download-and-install\/\"\u003Edownload and install\u003C\/a\u003E it.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EConfigure emulation station\u003C\/b\u003E\u003Cbr \/\u003E\nCopy the emulation station default settings file to the pi user's emulation station configuration:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Ecp \/etc\/emulationstation\/es_systems.cfg ~\/.emulationstation\/\u003C\/pre\u003E\nAdd the 'apps' tab to the settings file:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Enano ~\/.emulationstation\/es_systems.cfg\u003C\/pre\u003E\nScroll down to the bottom and add the following before the \u0026lt;\/systemList\u0026gt; text:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E  \u0026lt;system\u0026gt;\n    \u0026lt;fullname\u0026gt;Applications\u0026lt;\/fullname\u0026gt;\n    \u0026lt;name\u0026gt;Apps\u0026lt;\/name\u0026gt;\n    \u0026lt;path\u0026gt;~\/RetroPie\/roms\/apps\u0026lt;\/path\u0026gt;\n    \u0026lt;extension\u0026gt;.sh .SH .py .PY\u0026lt;\/extension\u0026gt;\n    \u0026lt;command\u0026gt;%ROM%\u0026lt;\/command\u0026gt;\n    \u0026lt;platform\u0026gt;apps\u0026lt;\/platform\u0026gt;\n    \u0026lt;theme\u0026gt;esconfig\u0026lt;\/theme\u0026gt;\n  \u0026lt;\/system\u0026gt;\u003C\/pre\u003E\nSave and exit using Ctrl X.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nMake a directory in roms to hold the scripts:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Emkdir ~\/RetroPie\/roms\/apps\u003C\/pre\u003E\nCreate a script to mute the amp by setting GPIO 26 to low (0):\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Enano ~\/RetroPie\/roms\/apps\/mute_amp.sh\n\ngpio -g mode 26 out\ngpio -g write 26 0\u003C\/pre\u003E\nAnd an unmute script:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Enano ~\/RetroPie\/roms\/apps\/unmute_amp.sh\n\ngpio -g mode 26 out\ngpio -g write 26 1\u003C\/pre\u003E\nMake the scripts executable:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Echmod +x ~\/RetroPie\/roms\/apps\/mute_amp.sh\nchmod +x ~\/RetroPie\/roms\/apps\/unmute_amp.sh\u003C\/pre\u003E\nYou can now test the scripts by running them:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E~\/RetroPie\/roms\/apps\/mute_amp.sh\n~\/RetroPie\/roms\/apps\/unmute_amp.sh\u003C\/pre\u003E\nReboot and the Apps tab will appear in emulation station with 2 options to mute and unmute the amp.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nI wanted the amp to be muted by default, so I added the script to be run at boot by editing \/etc\/rc.local:\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003Esudo nano \/etc\/rc.local\u003C\/pre\u003E\nScroll down and add the unmute command under '\/usr\/local\/bin\/retrogame \u0026amp;' but before 'exit 0':\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003E\/home\/pi\/RetroPie\/roms\/apps\/mute_amp.sh \u0026amp;\u003C\/pre\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/6539045085930367286\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-adding-mute.html#comment-form","title":"21 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6539045085930367286"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/6539045085930367286"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2016\/01\/pocket-pigrrl-adding-mute.html","title":"Pocket PiGRRL - adding a mute"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjhyphenhyphenYsTsgVOXd2MryaQDtKPwzqJ9-qe-60EQPN_125rnO60F-2sTq2sX8NfE-qY2TET5VIOXWBs2EvwC1ZwjURZsYMXldZS6otMej8z1SqWKqfZF-tc1VyxqeUztBStw9OauW7KZOn91Cqp\/s72-c\/IMG_20160106_213808996.jpg","height":"72","width":"72"},"thr$total":{"$t":"21"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-2401981052522948903"},"published":{"$t":"2015-12-18T13:52:00.000+00:00"},"updated":{"$t":"2016-02-02T21:09:13.207+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Adventures in Minecraft"},{"scheme":"http://www.blogger.com/atom/ns#","term":"microbit"},{"scheme":"http://www.blogger.com/atom/ns#","term":"minecraft"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"}],"title":{"type":"text","$t":"Minecraft, a Microbit and an X-Wing"},"content":{"type":"html","$t":"I was having a chat with \u003Ca href=\"https:\/\/twitter.com\/whaleygeek\"\u003EDavid Whale\u003C\/a\u003E, my co-author of \u003Ca href=\"http:\/\/eu.wiley.com\/WileyCDA\/WileyTitle\/productCd-111894691X.html\"\u003EAdventures in Minecraft\u003C\/a\u003E\u0026nbsp;and he remarked that wouldn't it be cool if you could control something in Minecraft using the Microbit. (Btw - you should definitely check out David's virtual\u0026nbsp;\u003Ca href=\"https:\/\/github.com\/whaleygeek\/mc_microbit\"\u003EMinecraft Microbit\u003C\/a\u003E.)\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nI settled on the idea of using the Microbit's accelerometer to control an object flying through Minecraft. What object, well it had to be the X-Wing, from my previous \u003Ca href=\"http:\/\/www.stuffaboutcode.com\/2015\/03\/minecraft-star-wars.html\"\u003EMinecraft - Star Wars\u003C\/a\u003E project.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjTT6N7wHhnbR9TJgShpHaztW4t8T3ReNTLRaeKtUIdZ8Ehf23i5bl45DW8FZtJ1OeLtsn2IQmz7vWUUjTX0DWjpIU4GR11lNYMhIaieIRlULc7K9Wswksa9QRnVEU8sTBIwzH78sQxaoPj\/s1600\/minecraft_microbit.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"180\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjTT6N7wHhnbR9TJgShpHaztW4t8T3ReNTLRaeKtUIdZ8Ehf23i5bl45DW8FZtJ1OeLtsn2IQmz7vWUUjTX0DWjpIU4GR11lNYMhIaieIRlULc7K9Wswksa9QRnVEU8sTBIwzH78sQxaoPj\/s320\/minecraft_microbit.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nThe A button starts and stops the X-Wing, by tilting the Microbit left and right you can turn and the B button drops blocks of TNT which create craters where they land.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/59KqWVwj_Cc\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/59KqWVwj_Cc?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\nThere are 2 python programs:\u003Cbr \/\u003E\n\u003Col\u003E\n\u003Cli\u003E\u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\/blob\/master\/examples\/mcfly\/microbitreaddata.py\"\u003Emicrobitreaddata.py\u003C\/a\u003E - this runs on the Microbit and reads the status of the buttons and accelerometer\u0026nbsp;\u003C\/li\u003E\n\u003Cli\u003E\u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\/blob\/master\/examples\/mcfly\/mcfly.py\"\u003Emcfly.py\u003C\/a\u003E - this runs on your computer (I used a Windows PC running Raspberry Juice and full Minecraft, but it would work on a Raspberry Pi as well) which reads the data from the Microbit and makes all the calls to move the X-Wing in Minecraft.\u003C\/li\u003E\n\u003C\/ol\u003E\nYou will find the full code and my other Microbit MicroPython examples at \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\"\u003Egithub.com\/martinohanlon\/microbit-micropython\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/2401981052522948903\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2015\/12\/minecraft-microbit-and-x-wing.html#comment-form","title":"6 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/2401981052522948903"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/2401981052522948903"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2015\/12\/minecraft-microbit-and-x-wing.html","title":"Minecraft, a Microbit and an X-Wing"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjTT6N7wHhnbR9TJgShpHaztW4t8T3ReNTLRaeKtUIdZ8Ehf23i5bl45DW8FZtJ1OeLtsn2IQmz7vWUUjTX0DWjpIU4GR11lNYMhIaieIRlULc7K9Wswksa9QRnVEU8sTBIwzH78sQxaoPj\/s72-c\/minecraft_microbit.JPG","height":"72","width":"72"},"thr$total":{"$t":"6"}},{"id":{"$t":"tag:blogger.com,1999:blog-9007601562606157016.post-4484906708426493818"},"published":{"$t":"2015-11-30T18:41:00.001+00:00"},"updated":{"$t":"2016-02-02T21:09:13.215+00:00"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"microbit"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Python"}],"title":{"type":"text","$t":"MicroBit Magic 8 Ball with MicroPython"},"content":{"type":"html","$t":"I wanted to create something with the MicroBit which used the on-board accelerometer and I settled on a \u003Ca href=\"https:\/\/en.wikipedia.org\/wiki\/Magic_8-Ball\"\u003EMagic 8 Ball\u003C\/a\u003E, the fortune-telling pool ball which when shaken and asked a question it provides, a, often cryptic, response.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ciframe allowfullscreen=\"\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https:\/\/i.ytimg.com\/vi\/b-8cRJiEKbo\/0.jpg\" frameborder=\"0\" height=\"266\" src=\"https:\/\/www.youtube.com\/embed\/b-8cRJiEKbo?feature=player_embedded\" width=\"320\"\u003E\u003C\/iframe\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv\u003E\nThe program works out whether the MicroBit has been shaken by:\u003C\/div\u003E\n\u003Cdiv\u003E\n\u003Cul\u003E\n\u003Cli\u003EReading the x, y, z values from the accelerometer in a loop and adding them together to get a total force exposed\u003C\/li\u003E\n\u003Cli\u003EGetting the difference between the last reading and the current reading\u003C\/li\u003E\n\u003Cli\u003EIf the difference is greater than a threshold, you assume the MicroBit has been shaken\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cdiv\u003E\nI wrapped this into a function wait_for_shake, which perhaps not unsurprisingly blocks until the MicroBit is shaken!\u003C\/div\u003E\n\u003Cpre class=\"prettyprint\"\u003Eimport microbit\n\nTOLERANCE = 3000\n\ndef get_accel_total():\n    x = microbit.accelerometer.get_x()\n    y = microbit.accelerometer.get_y()\n    z = microbit.accelerometer.get_z()\n    return x + y + z\n\ndef wait_for_shake():\n    shaken = False\n    last = get_accel_total()\n    while not shaken:\n        this = get_accel_total()\n        diff = last - this\n        if diff \u0026lt; 0: diff = diff * -1\n        if diff \u0026gt; TOLERANCE:\n            shaken = True\n        last = this\n        microbit.sleep(50)\u003C\/pre\u003E\n\u003Cdiv\u003E\nIts not 'very' sophisticated but it works.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nOnce I had this working it pretty simple to add a loop which waited for the MicroBit to be shaken and scrolled a random message on the LED screen.\u003Cbr \/\u003E\n\u003Cpre class=\"prettyprint\"\u003EMESSAGES = [\"It is certain\", \"Dont count on it\", \"Ask again\"]\nwhile True:\n    microbit.display.print(\"8\")\n    wait_for_shake()\n    microbit.display.clear()\n    microbit.sleep(2000)\n    message = microbit.random(len(MESSAGES))\n    microbit.display.scroll(MESSAGES[message])\u003C\/pre\u003E\nIf you want to add your own messages, just add them to the MESSAGES list.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nYou can find the code \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\/blob\/master\/examples\/8ball.py\"\u003Ehere\u003C\/a\u003E and other examples in my \u003Ca href=\"https:\/\/github.com\/martinohanlon\/microbit-micropython\"\u003Emicrobit-micropython GitHub repository\u003C\/a\u003E.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgtF74zSKhW3DuvXp_HElUiCMxuOr6Ne2lAnymogpqgdAJUkRS_8zTsbWhHbYAnASsh_ZowYbM4UiitgrpYemXSdfCS25PcL0xOjINdGXdVB41x-lhkjdbG8YCnGE6jqEizfIM2ggrFQyLS\/s1600\/8ballmicrobit.JPG\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" height=\"242\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEgtF74zSKhW3DuvXp_HElUiCMxuOr6Ne2lAnymogpqgdAJUkRS_8zTsbWhHbYAnASsh_ZowYbM4UiitgrpYemXSdfCS25PcL0xOjINdGXdVB41x-lhkjdbG8YCnGE6jqEizfIM2ggrFQyLS\/s320\/8ballmicrobit.JPG\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.stuffaboutcode.com\/feeds\/4484906708426493818\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2015\/11\/microbit-magic-8-ball-with-micropython.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/4484906708426493818"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/9007601562606157016\/posts\/default\/4484906708426493818"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.stuffaboutcode.com\/2015\/11\/microbit-magic-8-ball-with-micropython.html","title":"MicroBit Magic 8 Ball with MicroPython"}],"author":[{"name":{"$t":"Martin O'Hanlon"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03047799173301971515"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/img.youtube.com\/vi\/b-8cRJiEKbo\/default.jpg","height":"72","width":"72"},"thr$total":{"$t":"0"}}]}});