0

I'm really new on this Arduino thing, so I don't know whether what I'm gona ask is feasible or not.

I'd like to make a chronometer in the computer but the controlling button (beginning and end of count) not to be some computer key. So I was wandering if I could make a button controlled by the arduino - maybe via a piezoelectric element?

Besides the problem of not knowing what to use as a button, I don't really know if it's possible to make a graphical interface (i know how to programme in C, Python, ...) showing the numbers in the screen of the computer and the beginning and end of counting controlled by that button. Is this possible to do?

Thanks for any help to both questions!

5
  • Yes. Is there a particular reason you want to use a piezo rather than, say, a pushbutton?
    – Mark Smith
    Feb 4, 2017 at 22:09
  • 2
    Besides the problem of not knowing what to use as a button -- How about... a button...?
    – Majenko
    Feb 4, 2017 at 22:30
  • No, I just thought that with a piezo I could make a larger button (something like Buzz! game button - this is for a demonstration to use with kids)... What about the interface with software? Where can I read about it?
    – ajcoelho
    Feb 4, 2017 at 22:59
  • 1
    You should clarify your question by telling us WHAT should trigger the start and stop: human finger (then any push button is suitable), light detection, presence detection... Voting to close the question until clarification is provided.
    – jfpoilpret
    Feb 5, 2017 at 10:31
  • Yes, the human finger is the right answer. Like I said, it's somehting like Buzz! game button - this is to use for a demonstration with kids where they have to start and end the counting.
    – ajcoelho
    Feb 5, 2017 at 14:50

2 Answers 2

0

It's perfectly possible to do, and the way I would probably do it is to use one of the ATMega32U4 based Arduinos (such as the Arduino Leonardo or the somewhat smaller Arduino Micro) to act like a keyboard. A keyboard with just one key - your chosen button.

Then you program the computer to respond to the keycode the Arduino sends to start and stop the chronometer. You could even use an off the shelf chronometer program that starts and stops with a specific keypress and tell the Arduino to send that keypress. It would probably take about 5 minutes to write the software - if that.

7
  • Yes! That's exatcly the kind of think I want to do. My problem is just really how to make the connection between the Arduino software (I'm writing the code to programm Arduino via the official software provided in Arduino website) and the GUI - I will probably make the chronometer in Tkinter... Do you have any suggestion? Where can I read about that?
    – ajcoelho
    Feb 4, 2017 at 23:53
  • If you use an ATMega32U4 based Arduino and use Keyboard.print(...) there is no "connection" between the Arduino and your program. The PC just sees the Arduino as a keyboard and you just react to a keypress in your software. You could use the same software with any run of the mill keyboard too if you wanted.
    – Majenko
    Feb 4, 2017 at 23:55
  • I'm using Arduino Uno... Is it still possible to do so with this Arduino?
    – ajcoelho
    Feb 5, 2017 at 0:01
  • There are ways, but none of them very nice. For the Uno you are really limited to just a serial connection. There's millions of examples around showing you how to communicate through serial with a PC.
    – Majenko
    Feb 5, 2017 at 0:02
  • This simple communication cannot be done by the USB cable? Would it have to be through the serial?
    – ajcoelho
    Feb 5, 2017 at 0:11
0

I am already familiarized with the concept of serial communication. I can turn on/off LED via Serial Monitor.

I can also connect it with Python and I've made a small program that makes the LED blink - and this works perfectly.

However I now added a pushbutton to my circuit, so that when it is pressed, the blinking process is interrupted. But this is not working. My attempt was to send a Serial.print when the pushbutton is pressed with the message "Exiting\n".

Part of my Arduino code is:

if(digitalRead(BUTTON) == HIGH){
Serial.print("Exiting\n");
while(1){}
}

And part of my Python code is:

while True:
    arduino.write("Y")
    print arduino.readline()
    time.sleep(0.5)
    arduino.write("N")
    time.sleep(0.5)

    try:
       if arduino.readline() == 'Exiting\n':
          print arduino.readline()
          break
    except:
          print("nothing\n")

The problem is that when I run the program, it gets stucked in the line

if arduino.readline() == 'Exiting\n':

Any help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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