PDA

View Full Version : Control pc with propeller.



Botdocter
11-12-2010, 11:32 PM
I need to run files or programs on my pc. This has to be automated through sensor readings. So for example: if the sensor is true, the computer has to start playing an audiofile. How do i do this??

Any help is welcome!!

So just to be clear: control the pc with the propeller. NOT control the propeller with the pc

Dr_Acula
11-13-2010, 12:07 AM
There are many ways to do this. One way is to run a program on the PC and talk to the propeller with a serial link.

Basic building blocks are a program on the PC and a program on the propeller.
For the PC side, you need to decide on your favourite language. I've done a fair bit of work in vb.net and the serial port drivers are easy to use. C is another option.
On the propeller side, you will need a serial port object. And you will need to work out what sensors you are using, whether they are digital or analog, and the code to convert those to serial data.
And then you need a protocol. You might get the propeller to send two bytes - a 'control' byte, and a 'data' byte. The control byte might be 04, which indicates the value is from sensor number 4. And the data might be 255 for on, 0 for off, or a value if the reading is analog.

The PC can then do clever things such as process that data, send it back to the propeller, or even upload it to the internet.

I wrote up something similar for the picaxe here http://www.instructables.com/id/Control-real-world-devices-with-your-PC/

So you would replace the picaxe with a propeller.

vb.net can play wav files if that is what you want to do.

Botdocter
11-13-2010, 01:09 AM
I will also show pictures and more but yeah, that sound like the thing!

I don't know anything about VB. do you maybe have a little working setup that i can expabd myself?

Dr_Acula
11-13-2010, 01:30 AM
That instructables link has more about vb.net - I wrote it as a step by step guide. Only thing is that I think the 2008 version is now the 2010 version. I hope the code ports over ok.

kwinn
11-13-2010, 05:09 AM
You could als use the prop as a replacement for the keyboard to send keystrokes/commands to the PC.

prof_braino
11-13-2010, 06:16 AM
One way to start is to define exactly what you want the PC to do in response to what situation. It is much easier to get what you want if you can say what it is. Then look at each one, one at a time; divide and conquer. Folks will give very specific answers to specific questions, maybe give that a try.

Botdocter
11-13-2010, 12:47 PM
You could als use the prop as a replacement for the keyboard to send keystrokes/commands to the PC.

Yes!! That sounds like an idea! Is there a example of this in the obex?

Microcontrolled
11-13-2010, 02:43 PM
@Botdocter: No, it is a very difficult concept, and though many attempts have been made, no one has had success.

kwinn
11-13-2010, 05:02 PM
@Botdocter: No, it is a very difficult concept, and though many attempts have been made, no one has had success.

There was a discussion on this recently, but I do not recall if it was in the prop or general forum. I suggested the comboKeyboard object would be the place to start at that time, and emulating a PS2 keyboard would be easier than emulating a USB one.

Older operating systems (including dos and windows 3.1) used to be able to reassign console I/O to a serial port, file, or other port. Not sure the latest versions of windows allow that but it might be worth checking out.

kwinn
11-13-2010, 06:47 PM
If using keyboard entry to control your PC is a viable solution there is a relatively simple way to accomplish that. Use an existing keyboard and cmos switches/multiplexers controlled by a micro to simulate key presses.

Heater.
11-13-2010, 06:59 PM
How can you get any control of your PC via the keyboard port, you have no feedback?

How will you know when the PC is ready to accept a command?
How will you if the command is executed and does it fail with an error?
etc etc.

Cluso99
11-13-2010, 08:13 PM
Simulating a PS2 keyboard (if not already in the obex as I saw a thread not so long ago) is not too difficult.

However, if you require any feedback as heater has suggested, then you will need to expand this. Then serial may be better. Remember, serial on the prop via a PropPlug (FTDI) will give you serial via USB to the PC.

obrienm
11-13-2010, 08:48 PM
botdoctor,
Another alternative is to use the open source SUN/Oracle javax.comm API for Java 3.0 on the PC under windows or linux. For your scenario using the reverse Propeller to PC control - the system will still need a listener thread on the PC the same as the other way. I have a recent ad-hoc project where I needed to see live internet data on an LED display board. Of course the Parallax Propeller was excellent for this device because I could use 5 of the 8 cogs realizing this design. In my case I reflect the internet downloaded data back to the PC only for diagnostic/display and future exception handling purposes, but you could treat a certain code-combination as a state change and do anything on the PC like playing your audio file.

http://javahardware.blogspot.com/2010/11/led-display-board-driven-by-javaxcomm.html

thank you
/michael

Heater.
11-14-2010, 06:32 AM
obrienm,

Except no body is using Java for new projects, especially anything open source, until the legal issues hanging over it have been resolved.

If you want to do something like this "if the sensor is true, the computer has to start playing an audiofile. How do i do this??" then I suggest you use FullDuplexSerial object on the Prop end.

On the PC end you need some program to listen to a serial port and accept commands from the Propeller.

The are a million ways to do this, what programming skills do you have?

I might me tempted to do this in something like Python which:
1) Can easily work with serial lines.
2) Can easily run programs on your PC.

Windows guys will say use C#. I might say use C++ and Qt.

Loopy Byteloose
11-14-2010, 09:39 AM
Keyboard input may be very difficult - at least USB keyboard. The older serial keyboard may be possible to mimic.

But it you are flexible on an OS, Linux on the PC may be the easiest resolution as well as offering more powerful options to do exactly what you want.

Why so? Unix/Linux has deep development roots in using RS232 dumb terminals with multi-users. The Propeller could log in as a particular user with particular rights. These may even be an automated script on log in. Meanwhile, other users can share the computer in the background and if the hardware is adequate, nothing will bog down.

Of course, Python and Java are both available.
I realize this is a bit of a leap for the average Windows user, but Linux really can offer much more fun and power in a development context as documentation is easily available (O'Reily Publications, maybe at a local university library) and the software to make things work is generally free rather than expensive.

Pliers
11-14-2010, 03:12 PM
Communication with visual basic is easy.
first you need to down load visual basic 10 express.
here is a link to it. It's free.
http://www.microsoft.com/express/Windows/
Work through some tutorials to get an idea of how it works.

Don't down load the trial versions because the trial time will time out.

I don't have any code with me right now, but I'll try to get you some samples early next week.

I'm not well organized and I keep losing code I wrote months ago.

hinv
11-14-2010, 06:00 PM
This is a related thread that may be of some use:
http://forums.parallax.com/showthread.php?p=953773#post953773

Pliers
11-15-2010, 06:26 PM
Here is a text file for the Spin and for the Visual Basic.
Also a screen shot of the visual basic control panel.
My coding is a bit elementary, but it works.
Contact me if you have any simple questions.

If you have not started learning VB yet, don't be alarmed by the coding.
VB does most of it for you!

The middle button would be button#5 in the VB code.
It was button2 originally when I was testing the code.
I saw that It was still in the VB code that I posted.

Ragtop
11-16-2010, 02:37 PM
I tried cutting and pasting the VB code but it said alot
of the terms were not defined.

Where does the serialport object/method come from?

Pliers
11-16-2010, 03:43 PM
You cannot cut and paste visual basic.
The code is built by the visual basic program.

Have you done any of the VB tutorials?

Buttons and a text box is as simple as it gets.

I'll be glad to help if you need it.

You can find the serial port method in the toolbox.

Ragtop
11-16-2010, 05:00 PM
I have since found the serialport in the toolbox, but can't figure out how to use it to send text to a textbox.

I will do the tuts as I can not even figure out how to define variables.

More stuff to learn.

Pliers
11-16-2010, 05:37 PM
In the VB code I posted, the code associated with button2 put the received data into the text box.

Also there is a free program called HHD FREE SERIAL PORT MONITOR that is helpful.

Are you using Visual Basic 10?

My programming ability is very poor. I have to hack at it for a long time to get things to work.

Then I forget how I did it.

There should be a delay in the propeller code because multiple button pushes messes up the VB code if the wav file is still playing.

Also the VB code could be simplified.

I'll clean it up and put some comments in it.

I was a bit excited to help and rushed it out. It was my first time. :)

Ragtop
11-16-2010, 07:13 PM
Are you using Visual Basic 10?


Yes. Visual Basic 2010 Express. I downloaded it after reading this thread several days ago and have just got around to looking at it.

I have been able to get it to play two sound files associated with buttons but only if I add the while/if code to a textbox mouseclick. I tried to put the code in the Form1_Load sub but it would not load. I was hoping to put it somewhere were it ran on program startup.

Ragtop
11-16-2010, 07:28 PM
Correction it is working......just doesn't load window when a for ever loop is started in the form load sub.

Hmmm.....would make for a great co-worker prank. Put yes/no/maybe type audio responses and have the person's
computer seemingly answer questions on it's own.

Pliers
11-16-2010, 07:33 PM
Yes I just did the same thing.

Here is the code I used in the fourm loader.



Try
SerialPort1.Open()
Catch

End Try
Dim q As Integer = 1
Dim data As Char = "z"
Dim x As Integer

While q < 1000
x = 1
While x <> 0
Try
data = SerialPort1.ReadExisting
If data = "A" Then My.Computer.Audio.Play("C:\sound_1.wav", AudioPlayMode.Background)
If data = "B" Then My.Computer.Audio.Play("C:\sound_2.wav ", AudioPlayMode.Background)
If data = "A" Then x = 0
If data = "B" Then x = 0
data = "z"
Catch ex As Exception
End Try
End While
End While

Ragtop
11-17-2010, 03:51 PM
I think I found the way to "start another cog" in Visual Basic to run the continuous loop with a backgroundworker out of the toolbox, but I can not figure out how to get it to work.

Ragtop
11-17-2010, 06:36 PM
No luck with the backgroundworker but there is a timer tool that seems to get the job done as it is it's own continuous loop


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim data As Char = "z"
If Form1.SerialPort.IsOpen = True Then
data = Microsoft.VisualBasic.Left(Form1.SerialPort.ReadEx isting, 1)
Me.TextBox1.Text = data
'Data = Form1.SerialPort.ReadExisting
If data = "A" Then My.Computer.Audio.Play("C:\shared files\access denied.wav", AudioPlayMode.Background)
If data = "B" Then My.Computer.Audio.Play("C:\shared files\commandcode.wav", AudioPlayMode.Background)
End If
End Sub

Pliers
11-17-2010, 07:20 PM
Programming with visual basic is fun.

Botdocter
11-17-2010, 10:21 PM
Does either one of you also happen to know how i can get roborealm to send its data to the propeller? I have no propeller servocontroller bu a robot control board. I just want robirealm to control my motors through the onboard H-Bridge, and controll servos. For the camera movement etc. Is there maybe a default spin code for this?

Pliers
11-17-2010, 10:59 PM
Nope.
I have no experience with Roborealm.
I did goto the WEB site. It's an interesting place.

john30340
11-19-2010, 04:52 PM
Consider using RobotBASIC (www.RobotBASIC.com). It is free, and it can do everything you seem to want. You can start other PC programs and communicate with the propeller (there is even a downloadable tutorial for that).

Botdocter
11-19-2010, 09:23 PM
But would i still be able to communicate with roborealm?

Do you have any experience with this setup?