I was wondering if i could use my own computer to interact with the real world.So, if i have a sensor of some sort plug it in via USB or a certain information from a USB , then can i get the data from the USB and upload it to a programming language (like python)?

Does it mean I can also send data to the ports from a programming language?

if i could obtain the information then can you give me a web link or some name of a book which discusses about USB ports and the libraries and drivers for this purpose ,thanks?

  • 1
    \$\begingroup\$ Yes, that works. If it's a commercial USB sensor, get the right libraries for your OS and python. If it's analogue output, it's probably easiest to use an Arduino to digitise voltage and talk to the USB port. \$\endgroup\$
    – Neil_UK
    Oct 23, 2016 at 16:18
  • \$\begingroup\$ Here's a raspberrypi question about doing this which quotes a library 'pyusb': raspberrypi.stackexchange.com/questions/3465/… \$\endgroup\$
    – pjc50
    Oct 23, 2016 at 19:10
  • \$\begingroup\$ Yes, but you need to learn about USB first \$\endgroup\$ Dec 12, 2022 at 10:48

1 Answer 1


You can and should use your computer to obtain USB traffic to a device, however you should first to overcome your misconceptions about USB. To begin, you need to study some introductory materials like this one,

You will learn that you can't communicate over USB just by writing some ports in a computer language. The USB uses highly sophisticated and complex serial interface that implements "pipes" instead of plain registers/ports. To get the pipes running, one needs to construct complex data structures in main memory, a whole linked list of them, and instruct USB controller to run the list. This is a pretty complicated layer, which is normally hidden in system host driver and in a driver that gets loaded upon discovery of connected USB device. Applications communicate with USB device drivers via system messages and other OS-defined system mechanisms.

if you really want to try, here are specifications for the most used host controller EHCI.

  • \$\begingroup\$ Your second paragraph is kind of unhelpful - if someone is running Python, the OS will usually handle much of the plumbing for you. Especially for serial and HID devices. \$\endgroup\$
    – pjc50
    Oct 23, 2016 at 19:09
  • \$\begingroup\$ How it is unhelpful? It is exactly what I was trying to convey. The point is that you can't "write ports", you have to communicate with an "event handler" or something like that, which is layers and layers distanced from actual USB hardware. Python is an user-level application, an interpreter. Python uses own API, which is isolated from system-specific details via "backend" libraries. \$\endgroup\$ Oct 23, 2016 at 20:50
  • \$\begingroup\$ @AliChen are you saying that i can not send/recieve data from my usb to python? \$\endgroup\$
    – Socre
    Oct 31, 2016 at 18:33
  • \$\begingroup\$ No, I am saying that it is not productive to completely abstract yourself from real world (as you seems are trying). Every "USB device" is different, you can't get "certain information from a USB", you need to understand that each USB has specifics, and to get the specifics you need to have a driver that converts this specifics into some fiction of "a port". "Your USB" is too generic, unless you mean some already pre-defined class of USB devices, where the Python has API libraries. However, you did mention "a sensor", so you need to have specific data for this USB device to access it. \$\endgroup\$ Oct 31, 2016 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.