Shop OBEX P1 Docs P2 Docs Learn Events
Control pc with propeller. — Parallax Forums

Control pc with propeller.

BotdocterBotdocter Posts: 271
edited 2010-11-19 13:23 in Propeller 1
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
«1

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-11-12 16:07
    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.
  • BotdocterBotdocter Posts: 271
    edited 2010-11-12 17:09
    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_AculaDr_Acula Posts: 5,484
    edited 2010-11-12 17:30
    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.
  • kwinnkwinn Posts: 8,697
    edited 2010-11-12 21:09
    You could als use the prop as a replacement for the keyboard to send keystrokes/commands to the PC.
  • prof_brainoprof_braino Posts: 4,313
    edited 2010-11-12 22:16
    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.
  • BotdocterBotdocter Posts: 271
    edited 2010-11-13 04:47
    kwinn wrote: »
    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?
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-11-13 06:43
    @Botdocter: No, it is a very difficult concept, and though many attempts have been made, no one has had success.
  • kwinnkwinn Posts: 8,697
    edited 2010-11-13 09:02
    @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.
  • kwinnkwinn Posts: 8,697
    edited 2010-11-13 10:47
    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.Heater. Posts: 21,230
    edited 2010-11-13 10:59
    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.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-11-13 12:13
    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.
  • obrienmobrienm Posts: 65
    edited 2010-11-13 12:48
    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.Heater. Posts: 21,230
    edited 2010-11-13 22:32
    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2010-11-14 01:39
    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.
  • PliersPliers Posts: 280
    edited 2010-11-14 07:12
    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.
  • hinvhinv Posts: 1,255
    edited 2010-11-14 10:00
    This is a related thread that may be of some use:
    http://forums.parallax.com/showthread.php?p=953773#post953773
  • PliersPliers Posts: 280
    edited 2010-11-15 10:26
    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.
  • RagtopRagtop Posts: 406
    edited 2010-11-16 06:37
    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?
  • PliersPliers Posts: 280
    edited 2010-11-16 07:43
    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.
  • RagtopRagtop Posts: 406
    edited 2010-11-16 09:00
    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.
  • PliersPliers Posts: 280
    edited 2010-11-16 09:37
    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. :)
  • RagtopRagtop Posts: 406
    edited 2010-11-16 11:13
    Pliers wrote: »
    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.
  • RagtopRagtop Posts: 406
    edited 2010-11-16 11:28
    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.
  • PliersPliers Posts: 280
    edited 2010-11-16 11:33
    Yes I just did the same thing.

    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]
  • RagtopRagtop Posts: 406
    edited 2010-11-17 07:51
    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.
  • RagtopRagtop Posts: 406
    edited 2010-11-17 10:36
    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.ReadExisting, 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
    
  • PliersPliers Posts: 280
    edited 2010-11-17 11:20
    Programming with visual basic is fun.
  • BotdocterBotdocter Posts: 271
    edited 2010-11-17 14:21
    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?
  • PliersPliers Posts: 280
    edited 2010-11-17 14:59
    Nope.
    I have no experience with Roborealm.
    I did goto the WEB site. It's an interesting place.
  • john30340john30340 Posts: 5
    edited 2010-11-19 08:52
    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).
Sign In or Register to comment.