Control pc with propeller.
Botdocter
Posts: 271
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
Any help is welcome!!
So just to be clear: control the pc with the propeller. NOT control the propeller with the pc
Comments
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.
I don't know anything about VB. do you maybe have a little working setup that i can expabd myself?
Yes!! That sounds like an idea! Is there a example of this in the obex?
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.
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.
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.
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
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.
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.
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.
http://forums.parallax.com/showthread.php?p=953773#post953773
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.
of the terms were not defined.
Where does the serialport object/method come from?
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.
I will do the tuts as I can not even figure out how to define variables.
More stuff to learn.
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.
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.
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.
Here is the code I used in the fourm loader.
[PHP]
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
[/PHP]
I have no experience with Roborealm.
I did goto the WEB site. It's an interesting place.