{"id":259,"date":"2015-01-11T23:13:09","date_gmt":"2015-01-11T23:13:09","guid":{"rendered":"http:\/\/int03.co.uk\/blog\/?p=259"},"modified":"2015-12-29T15:58:33","modified_gmt":"2015-12-29T15:58:33","slug":"raspberry-pi-gpio-states-at-boot-time","status":"publish","type":"post","link":"https:\/\/int03.co.uk\/blog\/2015\/01\/11\/raspberry-pi-gpio-states-at-boot-time\/","title":{"rendered":"Raspberry Pi GPIO states at boot time"},"content":{"rendered":"<p>When external hardware is connected to the Raspberry Pi, it can be important to know the initial state of the GPIO pins at boot time. For example, if we have a motor connected to a GPIO pin, it could be a problem if the motor starts running as the system boots up. Ideally, we would want all the pins defined as inputs at start up, but that doesn&#8217;t seem to be the case with some of the Pi GPIO pins.<\/p>\n<p>Fortunately, there&#8217;s now a solution in the form of the <a title=\"Device Tree Pin Configuration\" href=\"http:\/\/www.raspberrypi.org\/documentation\/configuration\/pin-configuration.md\" target=\"_blank\">device tree pin configuration<\/a>. This involves creating a pin configuration source file, and compiling that to a binary &#8220;blob&#8221; which is loaded by the OS at start up. This source file can configure pins as inputs, outputs or in special function modes (UART serial port for example). It can also configure whether a pin has pull-up or pull-down enabled.<\/p>\n<p>This proved very useful for my <a title=\"Es(pi)resso: Raspberry Pi Espresso Machine\" href=\"http:\/\/int03.co.uk\/blog\/2014\/02\/26\/53\/\" target=\"_blank\">Espiresso project<\/a>, when I needed a pin to enable the pump at start up. Having run out of general GPIO pins, I was forced to use GPIO15 (RXD) which is configured as a pull-up UART pin by default. This would have resulted in the pump running as the system booted. However, by editing the device tree configuration, it was possible to set this pin as an input with pull-down mode, which prevents the external hardware being switched on during boot.\u00a0The GPIO pin can then be reconfigured as an output by the application, after the Pi has booted.<\/p>\n<p>As an update to this, there have been a couple of important developments with device-tree since I wrote this, which I&#8217;ll summarise briefly here:<\/p>\n<ul>\n<li>You can now create device tree overlays, to configure specific GPIO pins at boot. However, with NOOBS these do not take effect immediately (in which case the dt-blob.bin will still be needed).<\/li>\n<li>With NOOBS, the dt-blob.bin file needs to be placed on the recovery partition. Even then, I found the only way to ensure the pins stay in the desired state through the entire boot process is to have the dt-blob.bin on both recovery and \/boot partitions.<\/li>\n<li>In conclusion: avoid NOOBS for this application, and go with a vanilla Raspbian install<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When external hardware is connected to the Raspberry Pi, it can be important to know the initial state of the GPIO pins at boot time. For example, if we have a motor connected to a GPIO pin, it could be a problem if the motor starts running as the system boots up. Ideally, we would &hellip; <a href=\"https:\/\/int03.co.uk\/blog\/2015\/01\/11\/raspberry-pi-gpio-states-at-boot-time\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Raspberry Pi GPIO states at boot time<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/259"}],"collection":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=259"}],"version-history":[{"count":3,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions"}],"predecessor-version":[{"id":514,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions\/514"}],"wp:attachment":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}