USB in python

A

Astan Chee

Hi,
Im trying to write a program for my USB device and I'm thinking of using
python to do this. The USB device is of my own making and it is
activated when one of the two data pins of the USB is given about 5V (or
similar to whatever the power pin is getting). Now I'm confused to if
the software to activate this can actually be written and how do I do
it? Any examples? I've seen pyUSB but it doesn't give me control over
the hardware and how much power is going through the data pins.
Thanks for any help.
Cheers
Astan
 
D

Diez B. Roggisch

Astan said:
Hi,
Im trying to write a program for my USB device and I'm thinking of using
python to do this. The USB device is of my own making and it is
activated when one of the two data pins of the USB is given about 5V (or
similar to whatever the power pin is getting). Now I'm confused to if
the software to activate this can actually be written and how do I do
it? Any examples? I've seen pyUSB but it doesn't give me control over
the hardware and how much power is going through the data pins.

This doesn't sound like an USB-device to me. The USB-standard defines a
serial line protocol, where of course the state of the TX-line is set to
whatever the protocol dictates. And as not all of the things put out on the
line are of the programmer's own doing, it will be on and off all the time.

And no piece of software is going to control that - it's already implemented
in the USB-host-controllers inside your computer.

Even with a considerably more primitive RS233 line you'd not stand a chance
with that design.

Unless I'm not getting something here.

I've created USB-devices based on the AT90USB1287 from Atmel, and there you
can of course use the libusb (and it's wrapping PyUSB) to acccess the
device, and e.g. drive a single port-pin of the uC high - to activate,
whatever you want to activate.

Diez
 
A

Astan Chee

Diez said:
Astan Chee wrote:


Unless I'm not getting something here.
Hi,
Thanks for all the responses but I forgot to mention that I have very
little hardware understanding (at least in english) and the device
itself it very simple and only needs about 5V power to be active. The
problem here is that I want to control when the device is active using a
computer so I thought USB might be a good choice since its simple (but
didn't turn out to be). I'm open to any other suggestions on how I might
achieve this hardware and software-wise (as in what interface should I
use, etc). Also I'm trying to stay away from (complex) micro controllers.
Any ideas?
Thanks again
Astan
 
B

Brian Allen Vanderburg II

Hi,
Thanks for all the responses but I forgot to mention that I have very
little hardware understanding (at least in english) and the device
itself it very simple and only needs about 5V power to be active. The
problem here is that I want to control when the device is active using
a computer so I thought USB might be a good choice since its simple
(but didn't turn out to be). I'm open to any other suggestions on how
I might achieve this hardware and software-wise (as in what interface
should I use, etc). Also I'm trying to stay away from (complex) micro
controllers.
Any ideas?
Thanks again
Astan
How about a different interface? From what I have read the parallel
port is a bit easier to program. I think you can control the data lines
of the parallel port though. There is also a python wrapper for it on
the pyserial web site (pyparallel maybe?)

If you don't have a built-in parallel port then there are those USB to
serial/parallel converters.


Brian A. Vanderburg II
 
D

Diez B. Roggisch

Astan said:
Hi,
Thanks for all the responses but I forgot to mention that I have very
little hardware understanding (at least in english) and the device
itself it very simple and only needs about 5V power to be active. The
problem here is that I want to control when the device is active using a
computer so I thought USB might be a good choice since its simple (but
didn't turn out to be). I'm open to any other suggestions on how I might
achieve this hardware and software-wise (as in what interface should I
use, etc). Also I'm trying to stay away from (complex) micro controllers.
Any ideas?

Others suggested the parallel port. It is the natural choice for such
things, with two caveats:

- it is legacy, and thus often not available on modern hardware,
especially on mobile ones. So if you want it be prepared to additionally
buy a usb2parallel-adapter.

- it's electrical specs aren't as robust I fear. USB allos up to 500mA
to be drawn, and shouldn't break if you try more & fail (albeit, that
might be something that isn't true all the time). So you can draw quite
a bit of current from it (the stupid USB-cup-warmers are an example of
that). I have often had broken parallel-ports, and I think the reason is
that they *ARE NOT* specified to drive anything - they only provide
low-current control-lines. So whatever you design, you need a second
power-source then.

All in all, using a USB-controller is IMHO the best solution. The
AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit of
example-code, and there is other FOSS available.

I have to admit though that the whole USB-topic isn't the easiest thing.


Diez
 
A

Astan Chee

Diez said:
Others suggested the parallel port. It is the natural choice for such
things, with two caveats:

- it is legacy, and thus often not available on modern hardware,
especially on mobile ones. So if you want it be prepared to additionally
buy a usb2parallel-adapter.

- it's electrical specs aren't as robust I fear. USB allos up to 500mA
to be drawn, and shouldn't break if you try more & fail (albeit, that
might be something that isn't true all the time). So you can draw quite
a bit of current from it (the stupid USB-cup-warmers are an example of
that). I have often had broken parallel-ports, and I think the reason is
that they *ARE NOT* specified to drive anything - they only provide
low-current control-lines. So whatever you design, you need a second
power-source then.

All in all, using a USB-controller is IMHO the best solution. The
AT90USBKey is a low-cost evaluation-board. ATMEL provides quite a bit of
example-code, and there is other FOSS available.

I have to admit though that the whole USB-topic isn't the easiest thing.
Yeah, I forgot to mention that the device is requires about 70-80mA and
the parallel port (according to the spec) only provides 1mA. Thats why I
was looking into the USB solution.
Thanks for the suggestion though. Also, yes, the device is rather mobile
and that is why it is powered by the computer/laptop but legacy isn't
really an issue for me I guess.
Cheers
Astan
 
D

Diez B. Roggisch

Astan said:
Yeah, I forgot to mention that the device is requires about 70-80mA and
the parallel port (according to the spec) only provides 1mA. Thats why I
was looking into the USB solution.
Thanks for the suggestion though. Also, yes, the device is rather mobile
and that is why it is powered by the computer/laptop but legacy isn't
really an issue for me I guess.

If all you need is on-off - why can't you just use a switch?

Diez
 
T

Tim Roberts

Astan Chee said:
Im trying to write a program for my USB device and I'm thinking of using
python to do this. The USB device is of my own making and it is
activated when one of the two data pins of the USB is given about 5V (or
similar to whatever the power pin is getting). Now I'm confused to if
the software to activate this can actually be written and how do I do
it? Any examples? I've seen pyUSB but it doesn't give me control over
the hardware and how much power is going through the data pins.

Sorry, but you have NOT created a USB device, and I sincerely hope you do
not try to plug it in to a real USB port.

Despite the "serial" in the name, USB is much more than just a pair of
wires, like RS-232. USB is a standard protocol-based bus, like Ethernet,
and anything that is plugged into it must follow the protocol. You don't
get a "voltage", you get a 480 MHz differential digital signal train. The
wires are controlled by a USB host controller. You cannot override its
behavior.

You might be able to achieve your goal by using a parallel port, or by
using a USB-to-serial port adapter, or by using one of the many simple and
affordable USB experimenter's kits in the world.
 
A

Astan Chee

Tim said:
Sorry, but you have NOT created a USB device, and I sincerely hope you do
not try to plug it in to a real USB port.
Sorry, by USB device, I meant a device that is powered/activated by a
bunch of wires that I want to control using a computer and since I had a
spare USB jack lying around, I used that instead. But so far I haven't
tried it, nor will try it if it wont work properly. Yes, it is not a
proper USB device, because I didnt build it to specifically interface
with the USB port; but I had to start somewhere. Also, the device
requires more power than the standard parallel port can give.
Anyway, it looks like the easiest solution for my case is a microcontroller
 
L

Lie Ryan

Because I want to control the on-off the device using a computer and
write software for it (which I am confident I can do if I had references
to how the wrappers to said interface). Cheers
Astan.

How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little
Hardware Experience). High pitched sound (or anything in sound-ology that
means high voltage) means the device is on and low pitched sound off. The
device will need an additional transistor to separate low voltage from
the high voltage. I don't know how much power can be pulled from jack
out, but for a home brewn device it is still feasible to draw power from
USB and signal from jack out.
 
S

Steve Holden

Lie said:
How about (a crazy idea) using the audio jack out? (DISCLAIMER: Little
Hardware Experience). High pitched sound (or anything in sound-ology that
means high voltage) means the device is on and low pitched sound off. The
device will need an additional transistor to separate low voltage from
the high voltage. I don't know how much power can be pulled from jack
out, but for a home brewn device it is still feasible to draw power from
USB and signal from jack out.
Congratulations. You just invented the modem.

regards
Steve
 
S

Steve Holden

Astan said:
Sorry, by USB device, I meant a device that is powered/activated by a
bunch of wires that I want to control using a computer and since I had a
spare USB jack lying around, I used that instead. But so far I haven't
tried it, nor will try it if it wont work properly. Yes, it is not a
proper USB device, because I didnt build it to specifically interface
with the USB port; but I had to start somewhere. Also, the device
requires more power than the standard parallel port can give.
Anyway, it looks like the easiest solution for my case is a microcontroller

In which case the Arduino may be a good place to start. The recent
duemilanove boards use USB to communicate with the host, and so the USB
port should be available to the microcontroller. We areg etting some way
away from Python now, of course ...

regards
Steve
 
B

Brian Allen Vanderburg II

Sorry, by USB device, I meant a device that is powered/activated by a
bunch of wires that I want to control using a computer and since I had
a spare USB jack lying around, I used that instead. But so far I
haven't tried it, nor will try it if it wont work properly. Yes, it is
not a proper USB device, because I didnt build it to specifically
interface with the USB port; but I had to start somewhere. Also, the
device requires more power than the standard parallel port can give.
Anyway, it looks like the easiest solution for my case is a
microcontroller
I've played around in this area a little bit. Microcontrollers still
require hardware programming and for simple circuits I think it is
overkill. If you want to use USB then you may be able to use the FTDI
chips. They have both serial (FT232) and parallel (FT245) chips and are
quite cheap. They are surface mount devices though, but you can get a
kit that includes USB port, the chip already connected to a board with a
DIP plug and some essential circuits. libftdi, which runs on top of
libusb, can control both of these and they require no programming
(unless you want to change the USB configuration settings such as vendor
ID, etc, from the default value)

This is the FT245 chip which is basically USB-to-Parallel.

Chips: http://www.ftdichip.com/Products/FT245R.htm
Kit/Board: http://www.ftdichip.com/Products/EvaluationKits/UM245R.htm

The spec sheet for the board seems quite simple. It's pin out is
similar to that of a parallel port in that you have your data lines
DB0-DB7, etc. It can also be connected in bus-powered configuration
(~100mA) or self-powered configuration. The kit is more expensive than
the chip itself, but probably easier especially if you don't have any
experience with surface mount.

You could build it into your device. You could also create a simple
switch box out of it to control external devices, maybe connecting each
of the data lines to relays to turn on/off eight devices, etc.

Brian Vanderburg II
 
Ð

Дамјан ГеоргиевÑки

Sorry, by USB device, I meant a device that is powered/activated by a
In which case the Arduino may be a good place to start. The recent
duemilanove boards use USB to communicate with the host, and so the
USB port should be available to the microcontroller. We areg etting
some way away from Python now, of course ...

I second that.
Arduino to microcontrolers, is what Linux was to kernels back in the
90ties (now it's mainstream), or maybe what python is/was to Java.
 
A

Astan Chee

Brian said:
This is the FT245 chip which is basically USB-to-Parallel.

Chips: http://www.ftdichip.com/Products/FT245R.htm
Kit/Board: http://www.ftdichip.com/Products/EvaluationKits/UM245R.htm

The spec sheet for the board seems quite simple. It's pin out is
similar to that of a parallel port in that you have your data lines
DB0-DB7, etc. It can also be connected in bus-powered configuration
(~100mA) or self-powered configuration. The kit is more expensive than
the chip itself, but probably easier especially if you don't have any
experience with surface mount.
That is a good idea. The main factor (aside from complexity) that I
forgot to mention is the cost. I live very far away from the US and
sometimes it is cheaper to buy a microcontroller here than have bits n
pieces shipped from the US.
Anyway, I'll see if I can find these parts here and maybe use that.
Thanks for all the ideas!
Cheers
Astan
 
L

Lie Ryan

1) Pitch has nothing to do with voltage. A high-pitch sound
and a low pitch sound can have the exact same voltage.

2) The OP's device requires quite a bit of power. There is
almost no power available from the line-out jack, and the voltage is
limited to about 1V. If his sound card has a power-amp (none do
these days), he might be able to get a usable amount of power.


He'll need more than a transistor. He needs a power supply, some sort
of rectifier/detector, and a comparitor. It would be more interesting to
use notch filters to detect different frequencies so that you could have
multiple output "bits".
From the little I know on electronics, a simple, single transistor would
(almost) immediately switch from on-to-off-to-on depending on the voltage
of the control pin (I think it was the middle pin). I was suggesting this
simplistic hack because as far as I comprehend the OP's need, he only
need on-off switch instead of a complex multiple output bits.
Almost none, and what's there is very low voltage.

That's why the power is taken from USB port.
It would probably be easier to buy a USB-parallel port chip. Then he's
got power from the USB bus and something like 14 parallel I/O pins he
can control. Alternatively A USB-serial chip will provide 2 outputs and
4 inputs.

The idea was made on the basis that a USB microcontroller is not used.
Getting power from USB should be much easier than getting data while the
jack out can provide simple on-off signal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top