Advertisement

Advertisement

Notice: This guide depicts a method of powering your Pi through the GPIO pins. This has proven to be safe and reliable, as long as you do it right! I can't take responsibility if you break your Pi.

The Raspberry Pi is an amazing piece of kit, especially for the price point. One of the worst aspects of the Raspberry Pi experience is the lack of reliability of most commonly available power supplies. When the Pi foundation made the decision to use the Micro USB connector, it sent a confusing statement to users. You can hardly blame someone who sees a Micro USB port and expects to be able to plug it in to their PC, mobile phone charger, or tablet charger. Unfortunately, this is almost always going to result in an unusable or unreliable Pi.

If you have a Model A or a Zero, your power requirements drop considerably, and you'll find that power supply selection is actually pretty easy, so long as you're not plugging in power hungry USB peripherals... But that won't get you very far. The official numbers suggest that even a hungry Pi should be able to operate in under 1.5A, but you'll commonly see threads on Reddit and elsewhere that simply finding a 1.5A capable adapter is usually not enough.

Most crashes on a Pi are caused by a brown out, which is what happens when the input voltage drops below what the Pi can tolerate. They specify 5v +/- 5%, which gives you a range of 4.75 to 5.25v before problems start to happen. Most USB power adapters are designed to charge batteries, not run a sophisticated device with narrow tolerances. Because of this, it is very common to specify your maximum power draw generously, even if you're dropping your voltage significantly. A battery will eventually level out as the amperage draw decreases and the voltage comes back up, so even having significantly lower voltage near your maximum power draw isn't really a problem for them. With the Pi, you'll find that you need to greatly over-spec your supply just to keep your voltage drop dropping too low under load.

I present you to an inexpensive solution to give you reliable and efficient power for your Pi. Assuming you already have soldering equipment, basic electronics tools, and a multimeter, this should be really inexpensive as well.

The piece you probably already have, or can get from a friend (or a dumpster if you know the right ones to look in) is a power brick style power supply for a laptop, cable modem, router, or other random electronic device. Damn near any of these will work, but the criteria you want is voltage higher than 7v but under 35v, and wattage higher than 12. Wattage is basically never listed, but if you multiple voltage x amperage, that's wattage. I'm not sure what mine came with, I'd bet I got it out of a dumpster, but it supplies 12v at 3.5A, giving us 42 watts of power to work with.

As you can see, I've already cut off the bullet connector. Nearly all of these will have the ground wire on the outside and the positive wire in an insulator, but use your multimeter to be sure before you go plugging things in.

Trim and strip your power brick's wires so they easily reach the lm2596's input pads, but without excess wire being exposed. I highly recommend you tin the wires and input pads before you connect to them, this makes it much easier to work with and much quicker to get that soldered connection. For the output side, I like to pre-tin the wires, push them through the holes in the pads, and solder them from the bottom. This will give you a nice strong connection.

When you are happy with your soldered connections, you need to adjust the regulator to provide you with 5v. From the factory, mine output the same voltage that comes in, so they start at 12v.

Input:

Initial output:

There is a very small flathead screw that adjusts your output voltage. It takes a lot of turning to start moving, but you can do it while monitoring your voltage if you use both hands. Keep turning it until you get to that 5.00v mark, or within a couple hundredths.

After tuning, we can connect to the Pi using the 5v and Ground pins on the GPIO header. If you had a poorly regulated power supply, this would be a bad idea. The Micro USB port has fuses to help keep you from letting the smoke out if you feed it too much voltage, but we've taken care of that.

If your Pi is situated upright with the HDMI port facing up, the top left pin is 5v,, then two pins to the right is a ground. If you use a servo lead like I did, it will look like this:

Note that the white wire is +5v, red is cut, and black is ground. The Pi does not provide voltage protection on the GPIO, so be sure to get this part right.

If you followed along, you should now have a reliable, efficient, and above all inexpensive power supply for your Pi. No more brown-outs, and if you're a cheap scrounger like me the whole thing cost under $3.

When people talk about Go executables being a single binary file without a bunch of dependencies, that's not necessarily true. The simplest of programs (hello world) will be linked static by default, but you don't have to get very complex to break away from that. Your Hello World app looks something like this:

package mainimport ( "fmt" )

func main() { fmt.Println("Hello, World!") }

And when you compile it with go build, running ldd on it will produce not a dynamic executable.

But that's not a very useful program, especially for a language like Go which has a sizable focus on networking. Let's write a slightly more complex example, a simple utility that uses icanhazip.com to determine your public IP address. It's still quite simple:

Suddenly, you're dependent on 4 external libraries! Now, most of this time this isn't a big deal. You're probably writing your code on a complete OS that has them, and chances are you're going to run them on something similar... But this is 2015, and the container revolution is upon us! So Docker has become one of those must-have technologies for giving you separation of concerns while still letting you consolidate hosts, and with a little effort you can make extremely small and efficient containers with almost no overhead. Docker will happily let you install a complete general purpose Linux userland (Try it! Install docker and run: docker run -it ubuntu:latest bash) but that's a lot of overhead for a simple process. On my system, that command creates a container with almost 190 megabytes of data, just to get you that bash shell. What if your single process container doesn't need all that?

Docker has helpfully created their 'scratch' image, basically an empty template to build on. If you have a static binary, that can literally be the only data in your container. But first, you need a static binary! For our Hello, World application, that's straightforward. A simple Dockerfile where your hello executable lies:

FROM scratch ADD hello / CMD [ "/hello" ]

Then, docker build -t hello . will create your container. docker images will show the size of any images you have created, this one is a measly 2.3 megabytes. To run it, just use "docker run hello".

Trying to do this with your whatsmyip executable will fail, as it needs those 4 libraries to be included. Now, you could add those libraries in your Dockerfile (with the ADD command), but wasn't part of the magic of Go that you didn't have to worry about those libraries? Fortunately, while it's not obvious, it is usually easy to get that static binary. For our sample program, just telling go to use it's own networking stack instead of leaning on the operating system is enough. Just add -a -tags netgo to your go build command! If you (or one of your imports) is using cgo, you may need to add some additional fields to your build command (many things will work by adding -ldflags '-extldflags "-static -lstdc++ -lm"')

And now you should have that wonderful statically linked binary, ready to roll put in a minimal Docker container. Just create a Dockerfile:

FROM scratch ADD whatsmyip / CMD [ "/whatsmyip" ]

and build with build -t whatsmyip . and run with docker run whatsmyip This new docker image is a measly 6.5 megabytes(use docker images to show the sizes of your images), with no overhead from shared libraries, shells, basic shell utilities, package managers, etc. Just your code, and nothing more.

SELECT `folder` AS `type`,`element` AS `name`,`params` AS `params`,`extension_id` AS `id`
FROMg5fsd_extensionsWHERE enabled = 1 AND type = 'plugin' AND state IN (0,1) AND access IN (1,1,5)
ORDERBY ordering

SELECT `id`,`name`,`rules`,`parent_id`
FROM `g5fsd_assets`
WHERE `name` IN ('root.1','com_admin','com_ajax','com_associations','com_banners','com_cache','com_categories','com_checkin','com_config','com_contact','com_content','com_contenthistory','com_cpanel','com_fields','com_finder','com_garyscookbook','com_installer','com_joomlaupdate','com_languages','com_login','com_mailto','com_media','com_menus','com_messages','com_modules','com_newsfeeds','com_plugins','com_postinstall','com_redirect','com_search','com_tags','com_templates','com_users','com_weblinks','com_wrapper')