Trossen Force Sensor  Top Banner
Results 1 to 4 of 4

Thread: Processing to arduino with key press help

  1. #1

    Processing to arduino with key press help

    I'm trying to control a stepper motor and turn on and off a relay with key press. What I would like in the end is by hitting one key (for example "A") it would make the stepper go to the left, and when I would hit another key (for example "D") it would make the stepper go to the right, and when I press a key (for example "S") it would turn the relay on and keep it on for as long as I held down that key and when I release it turn off the relay. I havn't used processing to arduino before so any help on this would be amazing and I would be very grateful.

  2. #2

    Re: Processing to arduino with key press help

    Hey jiokl,

    I would try using the serial port on the Arduino to take in information from the computer. The Arduino board could then process whatever input you send it. You can send such information through one of the computer's serial ports via a keypress.

    Here's some tutorials that have helped me. The first uses python and pySerial to communicate with Arduino via serial communication over a serial port (like USB). The second is python code that uses python's GUI builder, "Tkinter," to take keyboard input from the keyboard in real time.

    1. Serial Communication Tutorial:
    http://postneo.com/2007/01/18/arduin...on-with-python


    2. Dynamic Keyboard input Tutorial:

    Code:
    # respond to a key without the need to press enter
     
    import Tkinter as tk
     
    def keypress(event):
        if event.keysym == 'Escape':
            root.destroy()
        x = event.char
        if x == "w":
            print "blaw blaw blaw"
        elif x == "a":
            print "blaha blaha blaha"
        elif x == "s":
            print "blash blash blash"
        elif x == "d":
            print "blad blad blad"
        else:
            print x
     
    root = tk.Tk()
    print "Press a key (Escape key to exit):"
    root.bind_all('<Key>', keypress)
    # don't show the tk window
    root.withdraw()
    root.mainloop()
    source:
    http://www.daniweb.com/software-deve...threads/115282


    If you do not wish to use python, you can use pretty much any other language to do the same thing. Many languages, like C and Java, also are capable of serial communication.

    I've been trying to do something similar with Arbotix and have had some helpful suggestions from others on this forum here:
    http://forums.trossenrobotics.com/sh...2-via-Keyboard

    Hope this helps,
    -CyberPenguin

  3. #3

    Re: Processing to arduino with key press help

    Thank you very much CyberPenguin. I will look into this and hopefully be able to use it, I did change how I was going to control it from manual with a computer to now with some sensors all in all I think it will be better but it wouldn't hurt to have both ways in it.

  4. Trossen Distance Sensor  Thread Banner
  5. #4
    Join Date
    Apr 2012
    Posts
    1,860
    Images
    25
    Rep Power
    64

    Re: Processing to arduino with key press help

    You need to handle both "key down" and "key up" events.
    When you get a "key down" event, send "start" commands to the Arduino.
    When you get a "key up" event, send "stop" commands to the Arduino.
    "Start" for movement might be "start moving left" or "start moving right."
    "Start" for the relay would be "start pulling the relay."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. IMAGE PROCESSING-Kurukshetra 2012, CEG
    By robotix in forum Robotics General Discussion
    Replies: 0
    Last Post: 12-26-2011, 09:44 AM
  2. Warning about dealing with the press
    By Toymaker in forum Robotics General Discussion
    Replies: 6
    Last Post: 08-15-2010, 12:46 PM
  3. Replies: 2
    Last Post: 02-06-2010, 09:50 PM
  4. PVision library for Arduino (Pixart/Wiimote to Arduino)
    By shobley in forum Robot Computers
    Replies: 1
    Last Post: 03-01-2009, 06:07 PM
  5. Pentagon's Unmanned Spokesdrone Gives Press Conference
    By Droid Works in forum Off Topic
    Replies: 1
    Last Post: 08-21-2008, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •