{"id":16,"date":"2022-11-12T21:53:56","date_gmt":"2022-11-12T21:53:56","guid":{"rendered":"https:\/\/pocketmoneytronics.co.uk\/?page_id=16"},"modified":"2022-11-12T22:31:06","modified_gmt":"2022-11-12T22:31:06","slug":"gpio-xmas-tree","status":"publish","type":"page","link":"https:\/\/pocketmoneytronics.co.uk\/?page_id=16","title":{"rendered":"GPIO Xmas Tree"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13 aligncenter\" src=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree1-205x300.jpg\" alt=\"\" width=\"205\" height=\"300\" srcset=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree1-205x300.jpg 205w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree1.jpg 624w\" sizes=\"auto, (max-width: 205px) 100vw, 205px\" \/><\/p>\n<p>The GPIO Xmas tree for the Raspberry Pi includes 5 LEDs that can be controlled from a simple Scratch or Python program. You can buy one from <a href=\"https:\/\/thepihut.com\/\">The Pi Hut<\/a> or the Raspberry Pi Store in Cambridge.<\/p>\n<p>The tree should be connected to the six GPIO pins as shown here. Ensure the LEDs are facing outwards:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-17 aligncenter\" src=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/connect-to-GPIO-300x224.png\" alt=\"\" width=\"300\" height=\"224\" srcset=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/connect-to-GPIO-300x224.png 300w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/connect-to-GPIO-1024x765.png 1024w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/connect-to-GPIO-768x574.png 768w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/connect-to-GPIO.png 1055w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>When programming your tree, you need to know the GPIO pin number associated with each LED. Setting a GPIO to output <b>high <\/b>will turn the LED on whilst setting it <b>low <\/b>will turn it off.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-18 aligncenter\" src=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/GPIO-connections-257x300.jpg\" alt=\"\" width=\"257\" height=\"300\" srcset=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/GPIO-connections-257x300.jpg 257w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/GPIO-connections.jpg 616w\" sizes=\"auto, (max-width: 257px) 100vw, 257px\" \/><\/p>\n<p>Do you want to use Scratch 3 to control the LEDs on your tree? If so, click the <b>Add an Extension <\/b>icon, find <b>Raspberry Pi GPIO<\/b> and click on it. You can then drag blocks to construct either of the sample programs shown on this page (and click the green flag to run them).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-19 aligncenter\" src=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/blink-top-300x268.png\" alt=\"\" width=\"300\" height=\"268\" srcset=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/blink-top-300x268.png 300w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/blink-top.png 501w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>To control the tree using Python, open Thonny and enter this example code:<\/p>\n<pre>    from gpiozero import LEDBoard\r\n    from time import sleep\r\n\r\n    tree = LEDBoard(26, 13, 6, 19, 5)\r\n\r\n    while True:\r\n        # illuminate the top and bottom LEDs\r\n        tree.value = (1, 0, 1, 0, 1)\r\n        sleep(0.5)\r\n        # illuminate the middle row of LEDs\r\n        tree.value = (0, 1, 0, 1, 0)\r\n        sleep(0.5)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Here is the circuit diagram for the tree:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-22 aligncenter\" src=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree-schematic-small-PNG-284x300.png\" alt=\"\" width=\"284\" height=\"300\" srcset=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree-schematic-small-PNG-284x300.png 284w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree-schematic-small-PNG-969x1024.png 969w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree-schematic-small-PNG-768x812.png 768w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/tree-schematic-small-PNG.png 1049w\" sizes=\"auto, (max-width: 284px) 100vw, 284px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Here is another piece of Scratch code for you to try:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20\" src=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/cascade.png\" alt=\"\" width=\"501\" height=\"817\" srcset=\"https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/cascade.png 501w, https:\/\/pocketmoneytronics.co.uk\/wp-content\/uploads\/2022\/11\/cascade-184x300.png 184w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The GPIO Xmas tree for the Raspberry Pi includes 5 LEDs that can be controlled from a simple Scratch or Python program. You can buy one from The Pi Hut or the Raspberry Pi Store in Cambridge. The tree should be connected to the six GPIO pins as shown here. Ensure the LEDs are facing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-16","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=\/wp\/v2\/pages\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":6,"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=\/wp\/v2\/pages\/16\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=\/wp\/v2\/pages\/16\/revisions\/31"}],"wp:attachment":[{"href":"https:\/\/pocketmoneytronics.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}