User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 3:05 pm

Hello everyone,

I wondered if anyone had any ideas on methods by which the PI could trigger a keyboard press on a Windows PC?

What I want to do is allow the PI to interact with a Windows application that requires a press of the "Enter" key to capture images from a camera.

My plan was to use the PI to control a stepper motor to rotate a turntable (modified Lazy Susan from IKEA!). After each increment it would trigger the software on my PC that captures stills from connected camcorder. The software is third party so I can't modify it. It needs to see a key press. This is all for a stop motion animation project I'm working on.

I could then programme the PI to run scripts to turn the table and collect frames on my PC. Different scripts could give me different movements and frame rates. In the world of DIY garage stop motion this sort of automation would be cool.

The turn table could be replaced with other contraptions to automate object movement in front of a camera.

Any comments or suggestions would be appreciated.

Other thoughts :

1) I use my trusty Firewire camcorder so I don't want to consider capturing frames on the PI itself because that would require me buying a new camcorder.

2) Could I modify a PC keyboard and wire it to the GPIO header so the PI could "press" Enter as required? I've got old keyboards so that is a low cost option.

3) I guess the PI could physically hit the key on a keyboard but that could get a bit over complicated!
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 4:00 pm

My three suggestions would be:

1. Have a program running on the PC which emulates a software based keyboard - provide a mechanism which allows the RPi to trigger it over the network (simple serial port service which converts all input into keyboard presses? Have it poll a file modified by the RPi whenever a keyboard press is needed etc). Another avenue is to use a program designed for automated UI testing to actually click the button - see above for how you could interact with it.

2. Get a microcontroller (such as a Pic) which can act as a USB slave, make it emulate a keyboard, use the GPIO pins to interface to it (could be as simple as it only outputs an enter packet on the change of a pin).

3. Similar to above but purely use the GPIO ports to bit bang either USB or if available PS/2 output - watch out for voltage levels though.

Pirx-Danford
Posts: 62
Joined: Thu Oct 06, 2011 2:05 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 4:11 pm

This triggers a very interesting train of thought.

Would it be possible for the RasPi to behave as a USB device towards a computer?

If so it would allow to develop linux daemons that will do generic USB device emulation.

With this I mean the RasPi could identify itself as keyboard, mouse, webcam or any other supported type of device (all the drivers need to be written) towards another computing device.

This could be used to connect unsupported storage devices to an XBox, to emulate a keyboard on a PC ... it would be the ultimate universal compatibility adapter as well as automation device.

Yikes!

User avatar
grumpyoldgit
Posts: 1452
Joined: Thu Jan 05, 2012 12:20 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 4:12 pm

This really does seem a bit Heath Robinson, to have one computer bang a finger on the keyboard of another computer on a timed basis because the software you are using does not have a timer facility. I have visions of Mouse Trap with steel balls running down a helter skelter to activate a great big finger. Surely it must be a lot easier to use another piece of software! Or am I missing something?

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 4:13 pm

Simplest option is for the RPi to emulate a PS/2 keyboard if your PC has a PS/2 socket.

A PS/2 keyboard generates a keypress code and sends it via synchronous serial at 10kHz.

The RPi has a UART which seems to operate only in async mode, so you would have to use 2 GPIO pins to send sync serial data.

I think PS/2 expects 5v data, not sure if it would be happy with the 3v3 that the GPIO generates. Two transistors could change the 3v3 to (inverted) 5v very easily.

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 4:19 pm

Pirx Danford said:


This triggers a very interesting train of thought.

Would it be possible for the RasPi to behave as a USB device towards a computer?

If so it would allow to develop linux daemons that will do generic USB device emulation.

With this I mean the RasPi could identify itself as keyboard, mouse, webcam or any other supported type of device (all the drivers need to be written) towards another computing device.

This could be used to connect unsupported storage devices to an XBox, to emulate a keyboard on a PC ... it would be the ultimate universal compatibility adapter as well as automation device.

Yikes!


I agree it would be really interesting - there's been discussion on the practicalities of it in this thread http://www.raspberrypi.org/for.....38;ret=all   - the summary is for the Model B it's possibly impossible due to the extra USB chip, for the Model A it is possibly possible but would require various driver support which is probably not currently present. The best alternative is to add an extra USB slave chip (Either a dedicated chip or microcontroller with USB support) and drive it over GPIO.

Pirx-Danford
Posts: 62
Joined: Thu Oct 06, 2011 2:05 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 4:26 pm

mole125 said:


The best alternative is to add an extra USB slave chip (Either a dedicated chip or microcontroller with USB support) and drive it over GPIO.


This gets better every moment.

So basically someone could develop a both-way usb device that would on the RasPi side provide a means to send it specialized data and on the USB-emulation side would fake to be anything we would want it to be.

This would mean the RasPi could have multiple such devices under control and be many generic USB devices at the same time...

I hope someone is able to develop something like this!

redman684
Posts: 48
Joined: Fri Dec 09, 2011 5:25 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 5:32 pm

Building something that acts as a usb slave device (e.g. a keyboard) just for pressing one key, seems a lot of work when you can just get an old keyboard, open it up, trace the two wires from the enter key to the points on the circuit board and strip the keys and stuff (you'll probably end up with just a small circuit board and the usb/ps2-cable).

When you connect the beforementioned two points on the circuit board it'll be like pressing the enter key on the attached computer.

Now all you need is a way to have the Pi to connect those points for you, a job the GPIO wil be more than happy to do for you. (You'll probably want to use an optocoupler)

Althought the usb slave device is much more interesting, I must agree.

I'm a bit puzzled by how you seek help on pressing a key, while controlling the stepper motor seems to be no challenge to you at all.

mole125
Posts: 228
Joined: Tue Jan 10, 2012 2:01 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 5:41 pm

Pirx Danford said:


mole125 said:


The best alternative is to add an extra USB slave chip (Either a dedicated chip or microcontroller with USB support) and drive it over GPIO.


This gets better every moment.

So basically someone could develop a both-way usb device that would on the RasPi side provide a means to send it specialized data and on the USB-emulation side would fake to be anything we would want it to be.

This would mean the RasPi could have multiple such devices under control and be many generic USB devices at the same time...

I hope someone is able to develop something like this!


Hopefully someone will, I may get round to it sometime.

First I'm planning to do a similar project but pretending to be an SD card - so the RPI can plug into a camera and automatically upload files or whatever else it wants to do. I'd also connect the GPIO pins up to allow it to use the shutter release.

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 8:48 pm

I have thought of a much easier way using infrared.

Get a USB remote control (like an MCE remote) which acts like a keyboard. Record the IR sequence for the Enter key that this remote control generates.

Create a WAV file on the RPi which is the same IR sequence modulated at 20kHz. Connect a pair of IR leds to the audio output of the RPi and play the WAV file to the audio output. The end result should be that the USB IR receiver should see the IR sequence for the Enter key.

This would require no hardware to be built. You can buy the IR led pair already connected to an audio plug. See for example http://thinkflood.com/products/redeye-mini. A DIY version is at http://www.instructables.com/i.....hone-iPod/

No software will be needed on the RPi or the PC. All the RPi needs to do is to play a WAV sound every time it wishes to press the Enter key.

The only work that needs to be done is to generate the WAV file. This can be done with a program such as LedRem.

See http://www.slatedroid.com/wiki....._IR_Output for more information.

Velko
Posts: 7
Joined: Mon Feb 20, 2012 9:50 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 9:14 pm

As for sending keypresses to a Windows application, it could be done purely in software. Just read up on Win32 API SendInput function. It's pretty straightforward to use (given that you know a bit how to write software for Windows).

For controlling a stepper motor, R-Pi sure could do that, but it feels like using a sledgehammer to crack a nut. So much power at such a simple task. Not that I'm trying to discourage you from getting one, but may I suggest an Arduino instead?

They are cheap, extensively documented, have quite a large community, easily connects to PC. There are numerous "shields" (add on boards) available (both for purchase and DIY schematics), including ones to control stepper motors.

And they've been on sale for years!

spock
Posts: 223
Joined: Sun Oct 02, 2011 10:33 am

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 9:59 pm

velko is right. some of the suggested solutions are a bit overcomplicated. funny and interesting though.

i bet it could be done with some lines of python. send a network message, and on windows react to it and call the win32 function from python.

error404
Posts: 351
Joined: Wed Dec 21, 2011 11:49 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 10:28 pm

Teensy is a good tool here. Cheap, native USB, and Arduino IDE support. Add a USB cable, motor driver, any sensors you need and you have the device you want. Code will be marginally more difficult to write, but it'll be a much more elegant and less hack-y solution.

oninoshiko
Posts: 76
Joined: Sun Jan 29, 2012 9:16 pm

Re: Stop Motion - PI to PC Key Presses?

Wed Feb 22, 2012 11:20 pm

Velko said:


For controlling a stepper motor, R-Pi sure could do that, but it feels like using a sledgehammer to crack a nut. So much power at such a simple task.


Here I am, brain the size of a planet, and they ask me to take you to the bridge. Call that job satisfaction, 'cause I don't.

1+10 = 3

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Stop Motion - PI to PC Key Presses?

Thu Feb 23, 2012 1:14 pm

Thanks for all the responses.


For controlling a stepper motor, R-Pi sure could do that, but it feels like using a sledgehammer to crack a nut. So much power at such a simple task.


Completely true. It would be easier to just use the PC to control the stepper motor directly and handle it's own keypresses. I was only considering a Pi because I was going to get one anyway and this would just be one of many tasks I could get it to perform.


Create a WAV file on the RPi which is the same IR sequence modulated at 20kHz.


That is a good idea! Could be a useful technique for doing other stuff.


This really does seem a bit Heath Robinson, to have one computer bang a finger on the keyboard of another computer on a timed basis because the software you are using does not have a timer facility. I have visions of Mouse Trap with steel balls running down a helter skelter to activate a great big finger. Surely it must be a lot easier to use another piece of software! Or am I missing something?


The software on the PC is specifically designed for stop motion so it does a lot more than just capture frames. It can take multiple frames and combine to reduce noise, organise the frames, manage the frames and video previews etc.

The idea was that the Pi would click the turntable round one increment, trigger a frame to be captured and then repeat as required. The Pi needed to trigger the capture because the PC software would have no idea when to take a frame. Even if it could take timed frames they would never be in-between turntable movements.

Having done a bit of googling I was considering the "use an old keyboard" approach. Once stripped down you can replicate the keypress press quite easily.

Then I had a better idea. The animation software can also respond to a mouse click ... and given a mouse button is just a micro-switch it would be even easier to dismantle a mouse and use the GPIO to activate that.

The mouse on my desk is starting to look worried ...
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Stop Motion - PI to PC Key Presses?

Sat Feb 25, 2012 1:39 am

I suggest that, for the Windows side of this, you look into a programing language called "WinBatch" (www.winbatch.com).  WinBatch makes Windows automation easy, and comes with "Extenders" to handle tasks such as TCP/IP networking.

I've done this sort of thing many times -  setup a WB program that acts as a TCP/IP server, waiting for connections from other machines, which trigger the WB program to control (e.g., send keystrokes or mouse movements to) programs running on the same machine that the WB server is running on.  Its quite straightforward once you've done it once or twice.

As others have suggested, you would use some Unix-y tool, such as Python, on the Pi side, to initiate the TCP/IP connection to the WB program.

HTH - feel free to ask any questions you may have about WB.  Note that WB is noted for their absolutely excellent tech support, so if you have any problems, you can usually get help in hours at worse.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Other projects”