Turn on usb ports when connecting to printer

Hello Everyone,

I hope this is the correct place to post this question. I use hub_ctrl to shut off the usb ports at startup on my raspberry pi3. I am running the raspberry pi and a 7" touch screen off of 5vsb on a computer power supply. if the usb is enabled at start up i get the power warning. I have added commands to the system menu to take care of controlling the usb ports but was wondering if there is anyway to add this to the connect button. I would like to be able to hit the connect button and have it first turn on the usb ports then connect to the printer.

Any help would be greatly appreciated.

Kevin

My setup is:
Pi 3
Latest OctoPrint
PSU Control plug in
Prusa i3 clone

An analogy:

When I turn on my car, a number of power-on tests occur and one of the tests indicates that my brakes are too worn down. As a result of this, it won't start. But if I do a MacGuyer and jam a paperclip in the relay socket for that test, the car will start and then I can pull out that paperclip...

When you toggle the USB back on, it's going to draw so much power that again, the 5V level will be too low for the Raspberry Pi's logic to work right.

Instead, work at this from the inbound power side. Read this entire thread carefully. I still have yet to find the power consumption for the official Pi 7" display, for what it's worth. A proper solution would be to determine the current/power for the entire Raspberry and its peripherals and to power it accordingly.

You suggest that you have the PSU Control plugin. We might assume from this that you're powering the Pi from an ATX power supply...?

1 Like

Yes, I am powering from a ATX power supply 5vsb. The pi will still connect to the printer even if it is in low power mode. Then I can turn on the power supply and the low voltage indicator will go away. I typically leave the pi and touch screen on when not printing. That is why I shut off the usb. The power indicator will toggle on and off which I am assuming means I am running at about the max output of the 5vsb. Ultimately, I would like to turn on the usb ports, connect to the printer and turn on the PSU with a press of the connect button. Just not sure how to add this.

The power supply I am using is a cheaper power supply. It is advertised at 2.5 amps on 5vsb, but get anywhere near 1.5 and the pi starts giving a power warning. To fix the power issue, I need a better power supply. Would like to add all the steps into the press of one button

Below are the recorded amp readings.

Pi only
Peak 6 mA
Running 3 mA

Pi + Screen
Peak 1.25 A
Running .95 mA

Pi + Screen + usb
Peak 1.47 A
Running 1.05 A

Kevin

1 Like

I was running one of my projects from a "switching power supply". Many now are of this type, btw. I believe that it means that the power supply will sense the load; if it's below a certain current it will switch off. In some cases, it's necessary to add a resistor in parallel to the load to slightly increase the load so that the power supply doesn't switch off. My situation resulted in the input power cycling ON/OFF, for what it's worth. It's possible that this could be related to what you were seeing there.

I'm confused. You indicated that you're using an ATX power supply and then you suggest that it's advertised to be 5V @ 2.5A so that doesn't make sense to me. A typical ATX power supply is silvery-looking and boxy and includes several sets of wiring harnesses from it; a typical Raspberry power adapter is a.k.a. a "wall wart", has prongs and a black plastic covering which encloses a transformer, some coils and capacitors mainly. It only has the one connection either as a USB Type A receptacle or as a micro USB plug.

I suppose I shouldn't be too surprised at the numbers you're throwing with respect to power. Later, you should also profile what it looks like when you've added a webcam and further, when you're streaming the output back to your workstation. The Raspi3 has four cores and there are moments when OctoPrint uses all of them simultaneously. Personally, I've found that deleting a large timelapse file seems to be unnecessarily hungry for processing for some unknown reason. Give yourself some wiggle room. Note also that percentage of time uploading/downloading via wi-fi can also change those numbers as well as writing to the microSD. You might try using scp to push a large temporary file to the microSD from your workstation and see what the power requirements look like then.

That said, the topic of USB power toggling has been discussed before on here.

1 Like

The 5v + is capable of 18 amp, 12v has 2 separate rails one capable of 17 amps and one at 18 amps. I am running on the 5v Stand By. With the power supply in the off state (on pin not shorted to ground) the power supply still provides a constant 5 volts at 2.5 max amps, as long as the main power switch is on. The switching might be the key. will try adding a resistor. Thank you.

I had read that post, maybe i misunderstood it but I didn't think it covered exactly what I was looking for.

Kevin

1 Like

Do a little research first. (Your mileage may vary.) In my case, I could clearly hear a relay toggling inside my power supply to coincide with the output. I put a multimeter on it and could clearly see that it was toggling the 5V output to coincide with what I was hearing.

No-load specs
in-rush current
minimum load

A little knowledge of electronics/electrical-design and math skills helps in a situation like this so that you don't end up creating smoke signals.

I ended up pulling the switching power supply and replacing it with a beefy six-port USB charger in my case and re-purposing that 10A 5V supply to another project.

5v sb from an ATX supply rarely actually can provide more than 1 amp of current. You can't reliably run the pi from it even without all your accessories

1 Like

My very simple ATX PS has 3A on the 5V SB rail...

Just a note, while many PSUs do have this feature, that's not what's meant by switch mode. Switch mode PSUs use a switching regulator to very efficiently control power conversion.

1 Like

Well, it seems like the technology inside a switching power supply makes them susceptible to no-load problems.

Indeed, happens a lot with cheaper units. If you have a multi-rail supply, the accessory rails will often not be at the right voltage until the main line is has some load or the voltage limits react with each other. They are not normally separate single rail supplies. With a single transformer the pwm is normally determined by the 5v line if no load the rest tend to be low volts. My understanding is that the reason for this, is mostly a cost thing. So better supplies likely wont have the load issue.

Thank you to everyone who responded! new atx power supply is on the way. How would i go about adding commands to the connect button on the gui? I would like to add the command to turn on the usb ports for the raspberry pi3 when connecting to the printer.

Follow the second link I provided in this thread.

Please excuse my ignorance because I must be missing something. I am not seeing anywhere in that topic how to modify the connect button to add my commands to it.

I have tried using system command editor but that doesn't recognize the connect command because it is not part of the etc/init.d file. I have buttons to turn on and off the usb ports under the system commands. I am looking to be able to establish a connection to the printer. The usb ports are off when octoprint starts so it can not connect to the printer serial connection automatically. I am looking for a way to do all three of the following with one button. Preferably with the connect button on the gui of octoprint.

1 turn on the usb ports(so I can establish a connection to the printer)

2 establish a connection to the printer

3 turn on the atx power supply which is controlled via the aux pins on the ramps board.

Please let me know what I am missing in that post.

The easiest way would be two buttons, leaving the original Connect button's functionality alone. It's easy enough to add either a button on the System menu or a button on the Control tab.

Any of these should work...

  • Editing the System menu, one could add a reference to a shell script which could do the work.
  • Editing the Control tab (in ~/.octoprint/config.yaml), one could add a button to run a pseudo Gcode command...
  • Editing the ~/.octoprint/config.yaml to add an event, tie into the event for Connected

It's not even necessary to write a plugin for this sort of stuff. I do encourage you to read a little and figure out how great OctoPrint is. There are a lot of docs available.

Thank you for the response!

I started reading the users guide yesterday. I might try my hand at a plug in. I am not a coder by any means but it seams fairly intuitive. I tried doing it under the control tab but quickly realized the control tab isn't active unless the printer is connected. Under the system menu it appears I would have to make a shell script to call the octoprint connect script. I am not sure how to do that and I am either using the wrong search terms or there is not a lot of information out there on doing that. Knowing me it is not finding the correct term to search yet. I already made a shell script for usb on and off and can execute them from the system menu. Which works nicely but would like it all under one button.

Thank you for all of your help,
Kevin

Kevin, try the third bullet. This involves editing the config.yaml, identifying the Connected event and pointing this to your external script. This shouldn't need a plugin.

I use a script to do this, with curl, called from system menu.

#!/bin/bash
sudo hub-ctrl -h 0 -P 2 -p 1
sleep 5
curl -k -d '{"command":"connect"}' -H "X-Api-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -X POST http://localhost/api/connection
sleep 3

1 Like

Could you connect that to the "Connecting" event to automate this?

I've just created another command in the power menu. Didn't try to automate, but knowing how much time is needed , you can add this to start at boot, waiting a few seconds. Simpler.