Raspberry Pi 400 Docking Station

 1 month ago
source link: https://www.codeproject.com/Articles/5331308/Raspberry-Pi-400-Docking-Station
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


Raspberry Pi 400 is a small computer built into keyboard. While the usual Pi is a board that you can build into your project, Pi 400 is more like a finished consumer product – “complete personal computer buit into a compact keyboard“, as they say on the website. So you can just connect a monitor (or TV), power supply and mouse and you have a personal computer with 4 GB of RAM and quad-code processor for less than $100. Sounds great, right?. Well, if you wanted to use it as your main computer you would probably be a bit disappointed (see, for example, here), but for many tasks it is great. But there are some things missing.

For me, the first thing I missed was real-time clock (RTC). In case you never heard of it, RTC is a small circuit used in computers (and other devices) to keep the time. It has a backup battery, so it does not loose the time when the computer is turned off. And when the computer is turned on again, it can read the date and time from the RTC circuit. This is how it works in computers and laptops.

In Raspberry Pi 400 the designers decided not to include RTC. Thus the Pi is supposed to get the date and time from the internet. As long as you are online this works fine. You may just notice that the clock is wrong when your Pi starts, but after few seconds it will be updated. But what if you are not connected to the internet? Yes, I know that you are now online almost all the time everywhere, and actually you need the internet for most of the things you do on your computer, so without it, there is no computing. But what if your Wi-Fi is down and you would just like to work on your document? I don’t like the idea of working on something with the wrong system time. It would be nice to have correct date and time even if you are offline.

The second thing missing is battery power. Since the Pi 400 is so small it would be nice to be able to use it in portable mode, without AC power. And actually, even if it sits on your desk, you may want to have a backup in case the AC power goes down.

So, basically, I started from these two requirements, battery power and RTC, and the result is the “Pi 400 dock” presented here. The features are:

  • battery power and AC power with seamless switching (like in a laptop)
  • show the status of the battery
  • date and time from RTC 

Here is how it looks:

Image 1

And the front view:

Image 2

The Body of the Dock

My first idea was to build everything inside the original Pi 400 case. This proved unrealistic - you simply cannot fit all the circuitry and battery into the original body. The next option would be to replace the bottom red part of the body with custom body with more space. This is tempting, but not feasible for me because 1) I did not want to open the Pi 400 (it is not that simple) and 2) the new bottom would have to be precisely printed so that the top could be snapped on it. I am not that confident in my 3D printing skills.
So my solution is a “docking station” into which the complete Pi 400 is inserted. It does not look that good but it is simple to make and it provides a lot of extra room for the circuitry.

Here is the dock in 3D model:

Image 3

The body is printed in 2 parts (it is too large to fit common home 3D printer). I used black PLA+ filament and 10% infill for the protorype and each part took about 5 hours to print on my GeeTech A10 printer.

Left side:

Image 4

Right side:

Image 5

The two parts are glued together with polyurethane glue. There are two holes for 4 mm rods to align the parts correctly and make the connection stronger.

Pi 400 is inserted under the rim at the back and secured through the Kensington lock with a 3D printed bolt. This bolt should be as tough as possible. I printed it with 100% infill from the same PLA+ as the body, but it’s not ideal. The front part can be broken quite easily. A better option would probably be to print it from ABS or make the front part from a piece of aluminum and glue it inside a hole in the bolt. You are free to experiment.

Image 6

The locking bolt in detail:

Image 7

You may also notice the dovetail rails on the front. These are intended for connecting a display to turn the dock into a laptop. To be done later...

Attach some self-adhesive bumper pads (rubber feet) on the bottom of the dock to improve cooling.

Real-time Clock

Adding real-time clock to Pi is easy. You can buy cheap module with I2C interface and connect it to GPIO header of your Pi. I used PCF8563 breakout board which costs about $2.

It is connected to GPIO header pins 1 (3.3V), 2 (SDA), 3 (SCL) and 5 (GND).

Then you need to configure your OS to load the time from the RTC upon startup. This is described in many tutorials, I used this one.

The PCF8563 is not among the RTCs mentioned in the tutorial but it works fine. The line to add into boot/config.txt is:

Copy Code

Power Supply

First, I will describe the final configuration which I use. For info on other options I also tried please see the Power options section below.
Here is block diagram showing how everything is connected together:

Image 8

I used breakout board which combines TP4056 Li-ion charger and MT3608 boost. The names TP... and MT... identify the chips used in the board; you can find the datasheets with their specifications. In short, this board takes input voltage through USB micro connector, charges the connected battery, if needed, and on the output it provides 5V “boosted” from the battery voltage (which is 3 to 4.2V). Maximum output current is 2 A, though only 1 A is recommended. Here is how the board looks:

Image 9

The charger+boost board is connected to single-cell Li-pol battery with 5000 mAh capacity. Of course, you can use a different battery provided it will fit into the dock below the Pi 400, which means it should not be thicker than some 10 mm. My battery dimensions are 100 x 60 x 6 mm and it costs about $16.

The output of the board needs to have USB-C connector that goes into the Pi 400 power input. In case you are wondering about powering the Pi through the GPIO header, this is not possible for Pi 400, see here.
You can buy a cable with USB-C connector on one end and wires on the other, or you can buy just the connector and use your own wire. I tried both options. My final setup uses USB-C connector soldered to a thin flat wire which it is easier to route through the dock.

The charger and boost board is inserted into 3D printed frame which is then inserted to the main body from the left side. The design with removable “drawer” is to provide variability - if you need to use a different charger and boost board, you don't need to print the whole dock body, just the drawer customized for your circuit.

There is also a power switch in the drawer which disconnects the USB-C output. This is needed because the Pi 400 takes about 50 mA from the power source even if it is turned off. So, if you just shut down the system and do not disconnect the USB-C supply connector, you would still be drawing 50 mA from the battery and after some 3 days the battery would be empty.

This is the drawer in 3D model:

Image 10

and here is the real thing:

Image 11

Battery Measurement

When powering your Pi from battery, you don’t want to run out of energy in the middle of your work. So you need to measure the battery somehow. I looked at various projects and what turned out as the best option for me was using INA219 current sensor. You can get it as a breakout board for about $4, it can measure both voltage and current and send the results over I2C, so it can be connected to Pi I2C interface through the GPIO port.

You could use Arduino or the like to measure the battery, but it would take more work and more money than just connecting the INA219. Also, with INA219 you get the bonus of measuring not just the voltage but also current. And if you measure the current going from/to the battery, you can tell whether the battery is charging or discharging and estimate how long it will last more precisely than just from the voltage.

Here is the schematics of all the parts together:

Image 12

The INA219 and RTC share the same I2C and power pins of the Pi 400 GPIO header. I made a custom Y-cable for this which connects the 3.3 V, GND, SDA and SCL pins both to the RTC and INA219.

Here is how the things are placed in the dock:

Image 13

1 – Charger & boost circuit
2 – Battery
3 – Locking bolt
4 – USB-C connector
5 – RTC circuit
6 – INA219 sensor
7 – I2C and power cable for the RTC and INA219

Just a note on the INA219 sensor: you can connect the measured current using screw terminals or the pin-header. It is better to use the screw terminals because the current drawn from the battery is rather high and the usual jump wires do not provide sufficient connection. You can encounter various low voltage problems just because of this.

Battery-level Indicator

You know this from your laptop – an icon which shows remaining capacity or time. Wouldn’t it be nice to have this for our Pi dock?  I found pi-battery-widget project that does just this. There are many forks of this project on github and I forked this one which has a decent method of estimating the remaining capacity (though there is room for improvement, more on this later).

Image 14

The widget is written in C, but uses Python script to read data from the sensor that measures the battery. This is good in that you can easily modify the script to use your sensor, but I did not like the idea of starting a Python script every 5 seconds to do something the C program could do itself. It seems like wasting computing power (and energy in your battery).

So I decided to remove the Python script and read the INA219 sensor directly. There is a C++ library for this, but since it is C++, I had to switch the project from C to C++ and fix the things that the C++ compiler did not like. While at it, I also did some changes (hopefully for better) in the code and created install script for Twister OS, which is the OS I like to use on my Pi 400.

My version of the widget is included in the zip file for this article and it's also available on github here. Please see the Readme in the package for instructions on building and installing the widget.

Some Thoughts on Power Options and Constraints

The official power supply recommended for Pi 400 is 5V 3A. I read somewhere that the power consumption is 2.5W at idle, which gives 0.5A current ( 0.5A x 5V = 2.5W). In my experience, the current drawn from the battery is from some 0.6 A minimum (idle) up to some 1.5A at full CPU load. Note that this is the current from the battery where the voltage is not 5V but less, about 3.8V. So it currents corresponds to power consumption between 2.3W and 5.7W (0.6A x 3.8V = 2.3W).

Wiith these numbers in mind you should choose your components – the battery, charged and boost, switch, cables, current sensor. I put the limits into the following picture with numbered points of interest.

Image 15

Point 1: Battery

My battery has a built-in protection circuits that will disconnect it if the voltage is below 3V or the current is over 3A. The voltage is important when setting up the low voltage limit in the pi-battery-widget. Normally you could use 2.9V or so, but if the battery shuts down itself at 3V while the widget thinks voltage is still good, you may loose data. For the widget to work, I set the empty battery voltage to 3.1V (see BATTERY_VMIN in the code).

The maximim current of 3A may also be a problem - the battery voltage goes down as the battery discharges, so if the battery is almost empty, say 3.2V and maximum allowed current is 3A, this gives us 9.6W maximum power (Power = Voltage x Current). Or in other words, we can draw 1.9A max on the 5V output that goes to the Pi (Current = Power / Voltage = 9.6 / 5 ). Looking at the current range given above, 1.9A doesn't leave much extra current for anything else that just the Pi itself (for example, if you connect an external hard drive to your Pi).


  • Consider power consumption when connecting external peripherals (such as external hard drive) to battery-powered Pi. Use AC power if not sure. 
  • Buy a battery with sufficient ratings or a battery without protection (but then use a charger with protection!).

Point 2: Current sensor

The INA219 sensor board is rated for 3A. Since we are measuring the current from the battery, this  actually amounts to the same limitation as in my battery – you should not run more than 3A through the sensor, which is about 10W of power, which in turn gives you no more than 2A on the 5 V output. It seems we just have to live with the 10W limit in this configuration.

A way around this, if you need more power for the peripherals, would be to limit the maximum CPU speed, so that the consumption of the Pi itself is limited. This can be done in a config file loaded at startup (I tried) but it would be nice if it was also possible dynamically, while the system is running (I did not look into this yet). This would actually mean we could be switching to lower CPU speed automatically if the current drawn from the battery was too high. There is a lot of room for further work, feel free to join :)

Point 3: Charger and boost

The board I used has maximum output current 2A but only 1A is recommended. As mentioned earlier the current consumption of Pi 400 is between some 0.6A at idle to about 1.5A at full speed. So we are over the recommended 1A but considering that the CPU load varies, it should work. So far it does work in my prototype. The board seems to be especially hot while running from AC supply and charging the battery at the same time. It could help to place the board on a piece of metal (isolated) and have vent holes below the board in the body. I made those holes in my prototype with a drill but they are not in the 3D model yet.

Power Options

While working on this project I tried various options for powering the Pi 400 and here are some notes I gathered along the way, in case you want to experiment.

Option 1 - Power Bank

Probably the first thing that comes to mind is to use a power bank. This works fine but you probably will not be able to power the Pi from the power bank while you charge it (most power banks do not support this). If you run out of battery, you need to shut down the Pi and charge the power bank. If you just carry the power bank with you, it is another cable you need to connect and adds to the disorder on your table. So, power bank is easy to use but it is not too comfortable. I can imagine building the power bank into the dock, but still I wanted to be able to use the Pi both from the wall supply and from battery, just as a laptop.

Option 2 - Battery, Charger and Boost

When you think about a battery, you probably realize you will need a charger. You may not realize that you will also need to boost the battery voltage. The Pi requires 5V while Li-pol battery only has 4.2 when fully charged, going down to about 3V when it is nearly empty.
Luckily, there are small and cheap boards which combine charger and boost circuits.
I encountered two kinds of such boards.

  • boards from power banks
  • boards not from power banks.

Power bank boards
These seem to be components of power banks available separately for the DIY users. Such boards usually include several LEDs to indicate the remaining capacity of the battery and automatic shut down when the discharge current is below some 50 mA. They can provide 2A or even more on the output. This sounds great – you get battery gauge and high output power, but there is one BIG catch. There is a short power cut on the output when it switches between battery and AC power. So, when you connect power supply, the output goes off for a moment. It only lasts about 20 milliseconds but it is enough for the Pi to notice and restart.

I guess you could live with this limitation if you use the Pi on battery power most of the time and remember never to plug in the wall charger while it is running. But if you want to use your Pi like a laptop, switching between battery and AC power as needed, this kind of boards is not the right solution. Imagine you are in the middle of some work and the battery is running low. So you connect the wall adapter and… your Pi restarts. Or vice versa, you are working on wall power and suddenly the circuit breaker in your house goes off. Your Pi shuts down and you loose all your unsaved work. 

I cannot say that all the 'power bank boards' have this power cut 'feature', but I tried two different types and both had it. So I decided to use something else – the kind I call 'non-power-bank boards'.

Non-power bank boards
These boards do not cut the power when AC power is connected or disconnected. But they also don’t have the LEDs to indicate battery voltage; just charging/charged LED.  They also seem to be only available with relatively low output ratings. It is not ideal but it can work.


The Pi 400 dock presented here is still a work in progress, so be prepared to experiment and improvise. There are things I already know could be improved and for sure there are other things that need improvement which I don’t know about yet.
Here are some of the things that oculd be improved:

  • Ventilation holes below the power board (the drawer with charger and boost) for better cooling.
  • A deepening in the dock body for the 'drawer' rim, so that it does not stick out.
  • Better power switch (with higher current rating; 2A would be ideal).
  • Stronger dovetail mount for display. There should be more material on the outside, or a different design should be used, perhaps with nuts and bolds to hold the display hinges.
  • The power widget estimation of remaining battery capacity could be improved. It seems it doesn't take info account that the battery voltage drops when higher current is drawn, so you may see 50% remaining at one moment when the Pi is doing some hard computing and a moment later it may show 55% as the power consumption is lower and voltage gets higher. 


  • 9th May, 2022 - Initial version

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK