Category : Advanced

Raspberry Pi Zero USB Hub Hack

As much as we all love the Pi Zero, the connectivity options are very limited. With only one (micro) USB port (for peripherals) it means you need a micro <=> ‘normal’ USB adapter to get any of the usual accessories (keyboard, Wi-Fi dongle etc.) plugged in, and when you have that’s it – nothing else can be plugged in. Also, those little USB adapters just look a little bit to precarious for my liking. So, what I needed was a ‘Raspberry Pi Zero USB Hub Hack’.

I’d seen that the USB power and data lines are presented as pads on the board itself. I wasn’t alone in noticing this, and seemingly a bunch of people had success soldering on USB hubs directly. So I though I’d give it a go. I bought myself this little ‘no name’ 4 port USB2 hub from eBay for the princely sum of £2.09 (including delivery) – how they make any profit on these is beyond me.

IMG_20160705_201003IMG_20160705_201035

As soon as it arrived, I pulled the case apart exposing the board itself and cut the USB cable off. (NOTE: I probably should have tested it on the laptop, or Pi first, but I was a bit too eager).

IMG_20160705_201158IMG_20160705_201530

A simple soldering job had the 4 individual cables soldered to their respective pads on the Pi Zero. It wasn’t a great success to start with, as it was ‘hit and miss’ whether it showed up on the Pi after booting.

IMG_20160706_201802IMG_20160706_201856

I guessed that it was likely that not enough power was being delivered, to the hub, by the super thin cables. I decided to remove those completely and replace themwith some thicker cable to make sure there was enough power to the hub. I also used some thicker signal wire for the Data + and –.

IMG_20160707_134138IMG_20160707_134146

However, now it never showed up, not even for a short time.

lsusb

lsusb_no_hub

It looked like it was recognising that a hub was plugged in, but it saw it as a ‘new low-speed USB device’. The seller on eBay had advertised this as a high-speed hub, so the ‘low-speed’ was odd. I would also get a lot of ‘device descriptor read/64, error -71’ errors in dmesg when the hub did not show up.

dmesg | grep usb

dmesg_usb

Googling around suggested trying out a bunch of dwc_otg settings in cmdline.txt, but none of those seemed to work. I also switched it to low speed (dwc_otg.speed=1) and that didn’t help. I knew all the connects were good and there were not shorts, so I began to think I had killed the IC on the hub somehow.
A last ditch attempt was to swap around the Data + – wires. I didn’t expect this to work as it was being ‘seen’ by the Pi, just not working. I figured, how could it ‘see’ the hub without being able to read ‘something’ from it). WRONG….

Swapping round the Data + – wires brought it to life, every time I powered on the Pi. Excellent. So now a little tidying things up, getting some anti-static foam between the boards and squishing them together with and elastic band (temporary) got me to the finish line.

lsusb

lsusb_with_hub

dmesg | grep usb

dmesg_with_hub

Here are some pictures of the finished Raspberry Pi Zero USB Hack project (although it still needs tidying and a case etc.)…

IMG_20160707_134618IMG_20160707_134629IMG_20160707_134645IMG_20160707_134715IMG_20160707_134725

Next up is to replace one of the hub ports with a directly soldered Wi-Fi dongle. Watch this space…

Raspberry Pi P6 Reset Hack

I’ve been trying to get some code running on my Pi 2. The code has been ‘problematic’ to get running, and I’m running into frequent hangs on the Pi where I cannot initiate a new SSH or console session. It’s also complicated because the Pi is outside in the garage (I have a GPS hooked up so it needs some visibility of sky). That means that every time it hangs I have to head out to the garage, pull the micro USB cable, reinsert it and then start the whole ‘Edit, Compile, Run, Head out to the garage to Reset’ cycle again.

Anyway, in an effort to simplify things I was looking around for a way of remotely resetting the Pi without having a connection to it. I found a ton of sites talking about the P6/RUN header on the newer boards, but this was mostly just about adding pins to short out with a jumper or adding a momentary switch to do the same. What I wanted was something more like connecting an Arduino pin, or a pin from another Pi to the P6/RUN on the target Pi and forcing a reset that way. What I wanted was a “Raspberry Pi P6 Reset Hack” – unfortunately AdaFruit don’t sell a kit for that.PiP6PullUpResistor_thumb

I was initially concerned about the current that the watchdog Pi would have to sink on the GPIO0 pin, but looking at schematics it seems the RUN pin is pulled up to 3.3V by a 10K resistor – a little bit of Ohms law says this will mean 3.3v/10K = 0.33mA will flow, well within the recommended limits of the GPIO pins 2mA to 16mA

I have an ESP8266-12 laying around just waiting for this kind of thing, but for the sake of speed I opted for another Pi I had (already hooked up, working and configured). So this essentially came down to :

  • Solder header pins on the target Pi (the one to be reset)
  • Connect the grounds of the target and ‘watchdog’ Pis together
  • Connect a GPIO pin from the ‘watchdog’ Pi (GPIO0) to the RUN pin on the target Pi
  • Putting together a small app to force the GPIO0 pin low for a few milliseconds and then high again.

PiP6WithHeaderPins_thumb Pi2P6WithGndAndGpioConnected_thumb

For the app to be run on the ‘watchdog’ Pi, I’m making use of the excellent wiringPi library. Instructions for downloading and building it can be found at http://wiringpi.com/
The code for ‘reset-app’ is simply (nano reset-app.c):

 

#define <wiringPi.h> 
int main (void) 
{
      wiringPiSetup();
      pinMode(0, OUTPUT);
      digitalWrite(0, HIGH);
      delay(500);
      digitalWrite(0, LOW);
      delay(500);
      digitalWrite(0, HIGH);
      return 0; 
}

… then to build it just execute :

sudo gcc –Wall –o reset-app reset-app.c –lwiringPi

Now when my target Pi hangs I can just ssh into the watchdog Pi, and run sudo  ./reset-app  and the target Pi reboots.
Also, when I’m done with this testing/hanging stuff I may simply connect a switch to the header for ‘’future ‘just-in-case’ things…

DISCLAIMERS

This is a QuickAndNasty™ solution. I am not responsible for any damage to your Pi, your electrics, your health or anything else – anything you do as a result of reading this is at your own risk.
Using this to reset you Pi can result in SDcard corruption !!   All calculations are off the top of my head, and could be wrong.

There are a ton of things to improve it also:

  • It relies on the GPIO pin on the watchdog ‘floating high’ while it is an input – it really should be set as an output (HIGH) at start-up.
  • I’ve not tested what happens when the watchdog Pi reboots – there’s a chance (likelihood?) that it will reboot the target Pi.
  • The ‘reset-app’ can be improved (drastically!!)

EDIT: I have tested what happens when the watchdog Pi reboots and, for me, it does not reboot the target Pi – however there is a chance (likelihood ?) that it will reboot the target Pi.
Anyway – enjoy, and let me know if you found it useful….