Thread: [Hardware + Software][C++ or C#] USB Fan

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9

    Post [Hardware + Software][C++ or C#] USB Fan

    Hey All,

    I am a newbie C#, VB and PHP programmer and I know also some stuff in C++.

    I started to play around with hardware last week when i had to fix some stuff in my mouse and i kinda liked it so:

    I picked a old usb mouse cable and a old motherboard fan, then i stripped the usb cable, conected usb white wire to fan red wire and usb blue wire to black wire and fan is now working (i think the usb has only 5 volts because its a 12volts fan so its working at half of the speed).

    There are two wires left, orange and green, i presume they are the wires that used to send data from mouse to the computer, here is a pic of the little stuff i made:
    http://www.techcoders.net/mywk/usb.jpg

    I want to do a software that first detects if it plugged in (is it possible to send a number through the orange or green wire then it reads it? if its the correct number it means the fan is plugged in), then it will increase or decrease the voltage of the blue or white wires! (It can be C# or C++)

    Thanks In Advance,
    Best Regards,
    Mywk

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I suppose you need to write a driver, then. And if you are doing it for Windows, it has to be C.
    You can forget C# for anything hardware-related.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You'll need something like this
    USB Experiment Interface Board > Maplin

    and this
    Jan Axelson's Lakeview Research

    Or perhaps even this
    Arduino - HomePage
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9

    Arrow

    Hey,

    @Salem I will actually try to find that here where i live (Portugal), thats seems interesting.

    @Elysia I can't find any article about building drivers or such, do you have any?

    Is USB Experiment Interface Board really needed? Can't i just build the USB hardware myself then code the drivers?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You could, but at the least you would probably need some kind of USB interface chip on your homebuilt kit.

    Even dumb RS232 typically needed a UART chip to do the grunt work of converting serial bits into useful bytes. USB is much more complicated that that.

    If you can find a simple kit then use it (and study everything in detail). Inventing the whole thing using TTL logic would be hard work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9

    Arrow

    Quote Originally Posted by Salem View Post
    You could, but at the least you would probably need some kind of USB interface chip on your homebuilt kit.

    Even dumb RS232 typically needed a UART chip to do the grunt work of converting serial bits into useful bytes. USB is much more complicated that that.

    If you can find a simple kit then use it (and study everything in detail). Inventing the whole thing using TTL logic would be hard work.
    I will buy the kit however it arrives in only ~10 days since it comes from UK.

    With the kit will i be able to develop my own driver (with C) so i can use my device without the kit?

    References, links or ebooks, all information will be greatly apretiated!

    Thanks once again

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > With the kit will i be able to develop my own driver (with C) so i can use my device without the kit?
    It comes with a DLL, so you can write normal user-space programs to drive the board.

    > I will buy the kit however it arrives in only ~10 days since it comes from UK.
    Can't you find the same (or similar) from a local supplier?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9

    Arrow

    Quote Originally Posted by Salem View Post
    Can't you find the same (or similar) from a local supplier?
    Unfortunately not in Portugal, not even similar, anyway i emailed Maplin asking for re-sellers near and why does it takes so long to export a item to here.

    Quote Originally Posted by Salem View Post
    It comes with a DLL, so you can write normal user-space programs to drive the board.
    What i mean is, will i be able to build my own DLL/driver or whats needed to control the USB device without needing the board?

    My aim is to be able to do my own hardware for computer without having to use stuff that i can't build myself, I'm available to learn no matter how difficult it is.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A UART (serial port) has some 3-15 registers depending on the design of the UART. It takes a couple of dozen lines of code to communicate with a serial port.

    A USB controller has a whole bunch extra registers over a serial port, and the communication is much more complex (although a fair bit of it is implemented in hardware, so the software layer need not concern itself with it).

    Generally, USB drivers consist of several layers, where there is a USB chipset driver at the bottom, which handles the low level communication with the specific chipset components - sending and receiving packets of data and determining when new devices are plugged in, what type of device it is.

    THere are various generic driver models at the top [such as a generic keyboard or mouse driver].

    In the middle is the device specific driver - it takes for example mouse data and translates it to "standard windows mouse information".

    There may be more levels in some cases, such as a USB hard-disk would have the USB chipset driver at the bottom, a disk-specific driver next, then the generic disk driver layer, and a layer or two of file-system componets before it gets to the OS generic parts.

    Edit: And I'm 99.9% sure that you can not regulate the voltage on a USB port. It is 5V unless the device is drawing too much current (which would probably end up with the system shutting the port down to prevent damage to your system).

    --
    Mats
    Last edited by matsp; 06-14-2009 at 05:29 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9

    Arrow

    Quote Originally Posted by matsp View Post
    I'm 99.9% sure that you can not regulate the voltage on a USB port. It is 5V unless the device is drawing too much current (which would probably end up with the system shutting the port down to prevent damage to your system).
    Thanks for the information provided, I'm actually reading the following book: USB Complete (Actually I'm reading the third edition not the fourth) To know more about Universal Serial Bus

    I did some more research and you are actually right, i can't regulate the voltage of the USB port, however i can power the fan using external 12v power adapter then regulate the amount of volts the fan will receive with my device.

    May i just simply develop a chip that when HOST (my computer) sends data to the chip it will change the voltage for one of my options? (example i have velocity 4v,6v,8v and 12v in a self made circuit)

    I don't have much electronic experience and i like this forum so please don't ask me to ask somewhere else since i want to use C and do my own driver and so on.

    Something interesting i found while searching, but actually i think it can't help me much (you can find it interesting anyway): Coding4Fun : Controlling Your Festive Lights with the .NET Micro Framework

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Out of interest, how much current can the USB host deliver maximum? It is possible to change the voltage yourself with some circuitry, but you can never change the maximum wattage you draw from the port.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Out of interest, how much current can the USB host deliver maximum? It is possible to change the voltage yourself with some circuitry, but you can never change the maximum wattage you draw from the port.
    The spec says 100mA of current -> 500mW. That's not to say that there are manufacturers that have devices that use more than 100mA current draw. There is also quite possibly manufactures that do not limit the current to 100mA - in fact, there are machines which are said to be "no current-limit".

    Quote Originally Posted by Mywk View Post
    Thanks for the information provided, I'm actually reading the following book: USB Complete (Actually I'm reading the third edition not the fourth) To know more about Universal Serial Bus

    I did some more research and you are actually right, i can't regulate the voltage of the USB port, however i can power the fan using external 12v power adapter then regulate the amount of volts the fan will receive with my device.

    May i just simply develop a chip that when HOST (my computer) sends data to the chip it will change the voltage for one of my options? (example i have velocity 4v,6v,8v and 12v in a self made circuit)

    I don't have much electronic experience and i like this forum so please don't ask me to ask somewhere else since i want to use C and do my own driver and so on.

    Something interesting i found while searching, but actually i think it can't help me much (you can find it interesting anyway): Coding4Fun : Controlling Your Festive Lights with the .NET Micro Framework

    Using USB, which is a packet-based port, to control a voltage level is like walking three blocks around to get next door. There are chips already available for pulse-width-modulation of 12V devices using I2C (aka SMBus). These devices are simple, use a very simple protocol, and can be used directly to do what you want to do. The only slight difficulty is that it takes a bit of effor to get this OUT of the PC - but you could implement I2C with a parallel port.

    Of course, in either case, you will need to write a driver. That's C, and in Windows, it requires a Windows Driver Kit (WDK, formerly known as DDK). [And of course, if you take over the parallel port, you will need to stop the printer driver(s) from using the port. I think the simple approach would be to disable the device in Windows Device Manager - that will not actualy disable the device itself - it will just make Windows understand that it shouldn't be using that port.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9

    Post

    I just payed the USB Experiment Interface Board from Maplin and it will be here in 3~4 days, it will give me a more advanced knowledge about how USB actually works, however from what i know it already has a driver so i won't be able to make my own.

    Quote Originally Posted by matsp View Post
    Of course, in either case, you will need to write a driver. That's C, and in Windows, it requires a Windows Driver Kit (WDK, formerly known as DDK). [And of course, if you take over the parallel port, you will need to stop the printer driver(s) from using the port. I think the simple approach would be to disable the device in Windows Device Manager - that will not actualy disable the device itself - it will just make Windows understand that it shouldn't be using that port.
    Parallel port you mean for example USB if its a USB device created by me then for me to do the driver right?

    Thanks,
    Mywk

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, I mean the parallel port that used to be the standard printer several years ago, before USB. It is normally a 25-pin female D-Sub connector at the back of the machine. Modern machines, particularly laptops and small machines may not have a parallel port these days.

    Of course, if you are getting one of those boards, it has a couple of PWM pins - but it seems like 5V maximum, so it will still not run your 12V fan at full speed.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    Registered User
    Join Date
    Jun 2009
    Location
    Santarem, Portugal
    Posts
    9
    Quote Originally Posted by matsp View Post
    No, I mean the parallel port that used to be the standard printer several years ago, before USB. It is normally a 25-pin female D-Sub connector at the back of the machine. Modern machines, particularly laptops and small machines may not have a parallel port these days.

    Of course, if you are getting one of those boards, it has a couple of PWM pins - but it seems like 5V maximum, so it will still not run your 12V fan at full speed.

    --
    Mats
    Eheh, i have 5 pc's and none of them has parallel ports, well, anyway i will power the fan externally with a 12v power adapter then use some kind of chip that i have no idea how to do it then program it that also i have no idea how to do that so it can be controlled from the pc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printers On USB
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-10-2002, 11:48 AM