smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Pi Powered Fan

Tue Jun 19, 2018 12:19 am

I recently followed this MagPi tutorial https://www.raspberrypi.org/magpi/pi-powered-fan/ and Wanting to know if there is any way to shut down the USB port to which the fan is connected? When I turn on the fan with the fan's switch, it runs constantly, no matter where any of the temperature settings are set.
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

PhatFil
Posts: 235
Joined: Thu Apr 13, 2017 3:55 pm

Re: Pi Powered Fan

Tue Jun 19, 2018 1:03 am

Part of the setup/install is the installation of the hub-ctrl s/w which is invoked to turn on off the usb port..

https://github.com/jeroenpeters1986/piF ... _on_off.py

Code: Select all

control_command = "sudo {}hub-ctrl -h 0 -P 2 -p {}"
complete_control_command = shlex.split(control_command.format(pifan_path, str(switch)))
subprocess.call(complete_control_command)
switch = 0 (fan off)
=1 (fan on)

so check you have that installed ok and try

Code: Select all

[code]hub-ctrl -h
0r
hub-ctrl -man
[/code]
for help.

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Tue Jun 19, 2018 2:08 am

Thanks for the reply. I checked to see the files were located in the pifan directory and they are.

The snippet you showed is there in switch_on_off.py:

Code: Select all

#!/usr/bin/python
import json
import shlex
import subprocess
import time

pifan_path = "/home/pi/pifan/"

with open("{}data/curr_threshold.json".format(pifan_path), 'r') as json_file:    
    curr_threshold = float(json.load(json_file).get('temperature'))

with open("{}data/curr_temp.json".format(pifan_path), 'r') as json_file:    
    curr_temp = float(json.load(json_file).get('temperature'))

# ./hub-ctrl -h 0 -P 2 -p 0
switch = 0
if curr_temp > curr_threshold:
    switch = 1

control_command = "sudo {}hub-ctrl -h 0 -P 2 -p {}"
complete_control_command = shlex.split(control_command.format(pifan_path, str(switch)))
subprocess.call(complete_control_command)

time.sleep(15)
This is take directly from the file switch_on_off.py

I ran

Code: Select all

[email protected]:~/pifan/python $ sudo python switch_on_off.py
sudo: /home/pi/pifan/hub-ctrl: command not found
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Tue Jun 19, 2018 2:41 am

The file hub-ctrl is there, just needed to change the permissions for execution. Did that, now the Pi hangs on boot.
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Tue Jun 19, 2018 9:42 pm

Starting back from scratch, re-installing the image and will go back thru the installation of the software on the blog page.

Strange.
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

PhatFil
Posts: 235
Joined: Thu Apr 13, 2017 3:55 pm

Re: Pi Powered Fan

Wed Jun 20, 2018 12:08 am

googleing hub-ctrl found the projects github page. perhaps try cloning installing the prerequisite libsub-dev and compiling the source as suggested in the readme to test ?

https://github.com/codazoda/hub-ctrl.c

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Pi Powered Fan

Wed Jun 20, 2018 9:06 am

I don't get it. Aren't you guys missing something obvious?

A standard "USB Fan" is only USB powered, not USB controlled. I can't see anything here which is able to turn the fan on or off by program control, because all you actually have is a 5V fan running off the power from a constantly-powered USB port.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Wed Jun 20, 2018 2:23 pm

Z80 Refugee wrote:
Wed Jun 20, 2018 9:06 am
I don't get it. Aren't you guys missing something obvious?

A standard "USB Fan" is only USB powered, not USB controlled. I can't see anything here which is able to turn the fan on or off by program control, because all you actually have is a 5V fan running off the power from a constantly-powered USB port.
As you are probably right, why then, does the project portrait the fan will turn on and off.. Hence the "clever code and a USB fan, you’ll be able to keep your cool" statement.

I don't know all of the inner workings of USB, but I'm willing to learn.
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Pi Powered Fan

Wed Jun 20, 2018 2:37 pm

I don't have an answer to that one - maybe you should put a query in the discussion area for that MagPi article. I hesitate to say it, but it looks like a scam to me.

A USB connector has a supply of 5V, handy for powering accessories on the desktop (the real one) because most desks have a computer and therefore a USB port. There are lots of toys that make use of 5V from a USB port, and some that have interface electronics and can be controlled from an app (eg robot arm, missile launcher...). A fan just needs 5V. On the RPi, the USB 5V is simply connected to the input 5V, so is always on (as long as the RPi is powered).

The only way that article makes sense is if they have acquired a fan that has some built-in control electronics that can be commanded by the USB data line. As far as I can see, that is not mentioned. Just any old USB fan won't do.

What you need to do with a normal, simple, 5V fan, is use a GPIO line and a transistor or relay to turn it on/off. There are plenty of examples on this forum, eg viewtopic.php?f=45&t=213994
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

pcmanbob
Posts: 3988
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi Powered Fan

Wed Jun 20, 2018 2:58 pm

Z80 Refugee wrote:
Wed Jun 20, 2018 9:06 am
I don't get it. Aren't you guys missing something obvious?

A standard "USB Fan" is only USB powered, not USB controlled. I can't see anything here which is able to turn the fan on or off by program control, because all you actually have is a 5V fan running off the power from a constantly-powered USB port.
I think what the code is supposed to do is turn off the 5v to the USB ports, I know this is possible but I am not sure its the same for all pi models.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Pi Powered Fan

Wed Jun 20, 2018 3:53 pm

pcmanbob wrote:
Wed Jun 20, 2018 2:58 pm
I think what the code is supposed to do is turn off the 5v to the USB ports, I know this is possible but I am not sure its the same for all pi models.
Is it? Since when? Please refer me to something that says so, and then I'll eat my hat.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Wed Jun 20, 2018 6:23 pm

Z80 Refugee wrote:
Wed Jun 20, 2018 2:37 pm
I don't have an answer to that one - maybe you should put a query in the discussion area for that MagPi article. I hesitate to say it, but it looks like a scam to me.
I did drop a couple questions in the comments, but there has been no replies. Thus the reason I post here.
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

pcmanbob
Posts: 3988
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi Powered Fan

Wed Jun 20, 2018 7:38 pm

Z80 Refugee wrote:
Wed Jun 20, 2018 3:53 pm
pcmanbob wrote:
Wed Jun 20, 2018 2:58 pm
I think what the code is supposed to do is turn off the 5v to the USB ports, I know this is possible but I am not sure its the same for all pi models.
Is it? Since when? Please refer me to something that says so, and then I'll eat my hat.
Hope you like hats.

viewtopic.php?t=93463
https://lb.raspberrypi.org/forums/viewt ... p?t=162539
https://raspberrypi.stackexchange.com/q ... -on-a-pi-3
https://gist.github.com/hfreire/32deb6b ... 8954e954fe
https://github.com/SkyJohn/Homebridge-R ... er-Control
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

PhatFil
Posts: 235
Joined: Thu Apr 13, 2017 3:55 pm

Re: Pi Powered Fan

Wed Jun 20, 2018 8:20 pm

Z80 Refugee wrote:
Wed Jun 20, 2018 9:06 am
I don't get it. Aren't you guys missing something obvious?

A standard "USB Fan" is only USB powered, not USB controlled. I can't see anything here which is able to turn the fan on or off by program control, because all you actually have is a 5V fan running off the power from a constantly-powered USB port.
My first reaction too but then i chased down the link and found the hub-ctrl project..

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Wed Jun 20, 2018 11:53 pm

pcmanbob wrote:
Wed Jun 20, 2018 7:38 pm
Z80 Refugee wrote:
Wed Jun 20, 2018 3:53 pm
pcmanbob wrote:
Wed Jun 20, 2018 2:58 pm
I think what the code is supposed to do is turn off the 5v to the USB ports, I know this is possible but I am not sure its the same for all pi models.
Is it? Since when? Please refer me to something that says so, and then I'll eat my hat.
Hope you like hats.

viewtopic.php?t=93463
https://lb.raspberrypi.org/forums/viewt ... p?t=162539
https://raspberrypi.stackexchange.com/q ... -on-a-pi-3
https://gist.github.com/hfreire/32deb6b ... 8954e954fe
https://github.com/SkyJohn/Homebridge-R ... er-Control
So in each of the links noted above, it shown the power can be stopped to the USB. Now, is this to a specific port or to the hub? If it is the hub, and one has a wifi dongle, then it will be dead too. have to wait until it gets hot to use the wifi!
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Pi Powered Fan

Thu Jun 21, 2018 7:38 am

Wow! (proxy for something more colourful) Thanks for that. I made the mistake of trusting the published schematics and did not spot they were incomplete - so actually they are not worth the paper they are printed on. :x

Let the hat fest commence...
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

pcmanbob
Posts: 3988
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi Powered Fan

Thu Jun 21, 2018 8:39 am

smilliken wrote:
Wed Jun 20, 2018 11:53 pm
pcmanbob wrote:
Wed Jun 20, 2018 7:38 pm
Z80 Refugee wrote:
Wed Jun 20, 2018 3:53 pm


Is it? Since when? Please refer me to something that says so, and then I'll eat my hat.
Hope you like hats.

viewtopic.php?t=93463
https://lb.raspberrypi.org/forums/viewt ... p?t=162539
https://raspberrypi.stackexchange.com/q ... -on-a-pi-3
https://gist.github.com/hfreire/32deb6b ... 8954e954fe
https://github.com/SkyJohn/Homebridge-R ... er-Control
So in each of the links noted above, it shown the power can be stopped to the USB. Now, is this to a specific port or to the hub? If it is the hub, and one has a wifi dongle, then it will be dead too. have to wait until it gets hot to use the wifi!
You can only turn off all the USB ports and the LAN chip using these mothods, there is no way to switch individual USB ports off.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

smilliken
Posts: 21
Joined: Fri Feb 06, 2015 4:04 am
Location: Beautiful BC
Contact: Twitter

Re: Pi Powered Fan

Thu Jun 21, 2018 10:27 pm

Thanks, that's what I thought. No good if you require any other USB device to work.
Raspberry Pi 2 B, 7" Raspberry Pi Touchscreen
Raspberry Pi 3, PiPhat, Pi Zero W

PhatFil
Posts: 235
Joined: Thu Apr 13, 2017 3:55 pm

Re: Pi Powered Fan

Fri Jun 22, 2018 7:33 am

Control USB power on a port by port basis on some USB hubs.
first line in the readme of the ctrl-hub project..

seems to me that its quite an easy test to clone/download the project and its prerequisite and compile it on your pi for a suck n see test..


sourcing a compatible hub is an option too

D-Link-DUB-H7-High-Speed-7-Port (Tested with old Silver versions (A3, A4 & A5). Also tested with newer Black version C1).
Elecom: U2H-G4S
Sanwa Supply: USB-HUB14GPH
Targus, Inc.: PAUH212
Hawking Technology: UH214
B&B Electronics: UHR204
Belkin: F5U701
Linksys: USB2HUB4

User avatar
Z80 Refugee
Posts: 357
Joined: Sun Feb 09, 2014 1:53 pm

Re: Pi Powered Fan

Fri Jun 22, 2018 7:51 am

pcmanbob wrote:
Thu Jun 21, 2018 8:39 am
You can only turn off all the USB ports and the LAN chip using these mothods, there is no way to switch individual USB ports off.
smilliken wrote:
Thu Jun 21, 2018 10:27 pm
Thanks, that's what I thought. No good if you require any other USB device to work.
Nonetheless, it is interesting to know projects (that don't need USB) have a source of switchable 5V power. That could be used for a low-power standby mode, or even direct drive for a relay coil. Excellent. Now to find a way to access it in Forth...
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 10 guests