Not why...
you can not do it in a "Beautiful" way, a solution would be to turn off and on the USB output, but I am almost sure that OS will not let you do it so easy.
USB is fully dedicated to passing information, but in the cable you find outputs +5V and GND to power the plugged devices.
Controlling an electronic device by programming
First you need to understand electronics, at least the minimum (current, resistance, etc.)
you can use a microcontroller or a circuit capable of communicating with computer, nowadays the Arduous became the easiest and simplest project implementation platform for lay developers, Uino can be programmed in java,c,python being c the form adopted by the community.
Printing data in Serial output
int pushButton = 2;
void setup() {
Serial.begin(9600);
// informa que pino "2" é uma entrada de dados
pinMode(pushButton, INPUT);
}
void loop() {
// faz a leitura da saida "2" do dispositivo
int buttonState = digitalRead(pushButton);
// Mostra isso na saida Serial
Serial.println(buttonState);
delay(1);
}
You can make your program communicate with others through the serial port.
Arduino communication with python serial port
Python is a language with many facilitations, there is module for almost anything, including for Rduino, web, interfaces...
#!/usr/bin/env python
"""
Blinks an LED on digital pin 13
in 1 second intervals
"""
from Arduino import Arduino
import time
board = Arduino('9600') #plugged in via USB, serial com at rate 9600
board.pinMode(13, "OUTPUT")
while True:
board.digitalWrite(13, "LOW")
time.sleep(1)
board.digitalWrite(13, "HIGH")
time.sleep(1)
Check out the documentation Python-Arduino
Good question, I am also wanting to solve this. = X
– Rafael Souza
I’ve long been looking for an answer to that question.
– Julio Santos
@Juliosantos has some code to facilitate a possible response?
– Marconi
Perhaps Steven Mcdowell’s (Prentice-Hall) book "USB Explained" can help you solve your problem. Although it does not pass source code, in it you find details about the specification of the USB protocol.
– ramonritter
I understand this is a problem of electronics, not programming. And the programming part will depend on the type of chip that is connected to the USB, because you can not control consistently the USB as we did with parallel ports, because USB is a communication channel and not direct control - different from parallel ports that, in turn, already has the control electronics embedded in the specification.
– Bacco
A year after the previous comment I see that some answers, although correct, more complicated than they help. Extremely exaggerated to use an Arduino for a task that a parallel adapter of 10 real would solve. And the adapter comes particamente ready to use, just use a simple little drive to not pull excessive current from the parallel and ready.
– Bacco