C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-14-2009, 12:06 PM   #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
Mywk is offline   Reply With Quote
Old 06-14-2009, 12:45 PM   #2
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-14-2009, 01:20 PM   #3
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,680
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.

Salem is offline   Reply With Quote
Old 06-14-2009, 01:52 PM   #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?
Mywk is offline   Reply With Quote
Old 06-14-2009, 02:20 PM   #5
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,680
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.

Salem is offline   Reply With Quote
Old 06-14-2009, 02:40 PM   #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
Mywk is offline   Reply With Quote
Old 06-14-2009, 03:01 PM   #7
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,680
> 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.

Salem is offline   Reply With Quote
Old 06-14-2009, 03:16 PM   #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.
Mywk is offline   Reply With Quote
Old 06-14-2009, 05:24 PM   #9
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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
__________________
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.

Last edited by matsp; 06-14-2009 at 05:29 PM.
matsp is offline   Reply With Quote
Old 06-14-2009, 06:21 PM   #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
Mywk is offline   Reply With Quote
Old 06-15-2009, 07:30 AM   #11
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,783
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-15-2009, 01:55 PM   #12
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 06-15-2009, 02:19 PM   #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
Mywk is offline   Reply With Quote
Old 06-15-2009, 02:28 PM   #14
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 06-16-2009, 04:54 AM   #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.
Mywk is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printers On USB (TNT) A Brief History of Cprogramming.com 1 03-10-2002 11:48 AM


All times are GMT -6. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22