Shop OBEX P1 Docs P2 Docs Learn Events
Noob question <SOLVED> — Parallax Forums

Noob question <SOLVED>

jknilinuxjknilinux Posts: 26
edited 2008-03-18 20:52 in Propeller 1
Hello,

I am working on a laptop-based robot, and I would like to interface the propeller to it for sensor/motor control. Could I have a setup where my laptop can just tell the propeller "Have cog 1 loop until this condition, and let me know when it is reached. Now make cog 2 drive both motors forward until I tell it to stop." etc... What possibilities are out of the question? Thanks!

Post Edited (jknilinux) : 3/18/2008 8:58:29 PM GMT

Comments

  • RaymanRayman Posts: 14,162
    edited 2008-03-18 16:46
    Easiest way is to use Fullduplexserial object on Prop side and Hyperterminal on laptop side.
  • hippyhippy Posts: 1,981
    edited 2008-03-18 16:50
    There's also the capability to use the Propeller as a USB slave for serial comms so a direct USB cable with Virtual Serial Port on the PC-side.
  • jknilinuxjknilinux Posts: 26
    edited 2008-03-18 17:17
    Hi,

    How does the Hyperterminal/full duplex serial connection work, and how do I set it up? Or, how do I make the propeller a slave USB device? Sorry, I'm a bit of a noob with microcontrollers. Thanks!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-18 17:21
    You will also have to write a "supervisor" program for the Propeller that can interpret commands from the laptop and do the things that are commanded. For example, if you had two one-letter commands, "F" for Forward and "R" for Reverse, say, your supervisor program might have a section that looks like this:

        cmd := Serial.rx
        if (cmd == "F")
          GoForward
        elseif (cmd == "R")
          GoBack
    
    
    


    where Serial refers to the FullDuplexSerial object, and GoForward and GoBack are your own routines that do the actual moving.

    -Phil

    Update: Of course that's Serial.rx, not Serial.getc. So much for memory.

    Post Edited (Phil Pilgrim (PhiPi)) : 3/18/2008 6:23:26 PM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-03-18 17:38
    jknilinux,

    The programming USB interface can be used for serial comms because it emulates a serial port at the PC end.

    Graham
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-18 17:49
    Hyper terminal is an older program that comes with windows to communicates on various ports that the laptop or computer has a drive written for. Just make your propeller program shoot a string of data out to the computer and while running hyper terminal you'll receive the string.

    I should finish my program that is slightly better than hyper terminal for others to use
  • jknilinuxjknilinux Posts: 26
    edited 2008-03-18 17:52
    Hi,

    Thanks for the help, but can anyone give me a quick example or how-to with the full duplex serial object/USB interface?
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-18 18:05
    here try this using hyper terminal

    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
     
    OBJ 
    
      SER   :"Fullduplexserial"
      
        
    pub start   | TEMP_data
      temp_data := 100
      
      SER.start(31, 30, 0, 9600)                            'Sets up Com port for computer (Rxpin,TXpin,mode,baud)
      repeat
       waitcnt(100_000 * 20 + cnt)
       ser.tx(10)                                            'line feed
        ser.tx(13)                                            'carriage return
        ser.str(string("Results =   "))    
        ser.dec(TEMP_data)                                    'display decimal value of temp
        ser.str(string("binary value is   "))     
        ser.bin(TEMP_data,16)                                 'display binary value of temp 
        ser.tx(13)                                            'line feed
        ser.tx(10)                                            'carriage return
                 
    
    



    make sure you have the Fullduplexserial object
  • tpw_mantpw_man Posts: 276
    edited 2008-03-18 18:05
    The Parallax Objects Lab has some wonderful usage examples for fullduplexserial. Here is short code for using it.
    CON
    _clkmode = xtal1 + pll16x         'set clock frequency 
    _xinfreq = 5_000_000
    
    OBJ
    serial : "FullDuplexSerial"          'fullduplexserial object
    
    PUB main
    serial.start(31, 30, 1, 9600)       'start fullduplexserial on the programming pins, with inverted communications, at a baudrate of 9600
    serial.str(string("Hello World!"))    'transmit the string Hello World! 
    
    


    This code will work with the default hyperterminal settings.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1010, so be surprised!
  • jknilinuxjknilinux Posts: 26
    edited 2008-03-18 18:49
    Hi,

    How could I make the computer talk to different Cogs, though? Great answers!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-18 18:54
    As I alluded to above, the computer doesn't "talk to different cogs". You have to write a supervisor program for the Propeller that reads commands from the serial port and causes the commands to be executed. The Propeller, by itself, has no way to interpret what an external device, like a PC, tells it to do, aside from loading programs into RAM or EEPROM.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 3/18/2008 7:23:09 PM GMT
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2008-03-18 19:10
    You are jumping into a pretty sophisticated application. I highly recommend you start with the basics of the Propeller (use the PEK labs, etc) and work up to this level, or people here will have to end up doing it for you. I don't mean to sound mean, but I it's hard to give answers for which you'll have 20 more questions.

    -Martin
  • jknilinuxjknilinux Posts: 26
    edited 2008-03-18 19:34
    Hi Everyone,

    You have a good point, martin, and I will start small. I was just asking these questions to see if it what I wanted to do was possible, before I buy a whole propeller dev kit. Last question: How hard will it be to do all this? I don't want to be working on communication for two weekends or something. Sorry about the newb questions... Thanks!
  • tpw_mantpw_man Posts: 276
    edited 2008-03-18 19:40
    Doing raw communications is pretty easy, but it is a slight bit harder to interpret the commands and make a command set that suits your application.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1010, so be surprised!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-18 19:42
    jknilinux said...
    Last question: How hard will it be to do all this? I don't want to be working on communication for two weekends or something.
    That will depend on how quick a study you are. smile.gif

    Seriously, it sounds like a worthwhile goal, regardless of the time spent. Besides, if any of us knew ahead of time how much was involved with the projects we do, we probably wouldn't start most of them! Such is life.

    Good luck with your project!
    -Phil
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-03-18 20:06
    hello jknilinux,

    tell us about your programming skills on PCs. This will help to adjust the level of the answers that were posted here in the forum.

    Minimum would be to answer with one o the following choices:

    a.) i'm a complete newbie to programming at all on PCs and for microcontrollers

    b.) i made some simple programs in a high level language like visual basic, delphi, java

    c.) i made quite a lot programs in a high level language like visual basic, delphi, java

    d.) i have developed a lot of applications in c/c++ using the windows API but never programmed a serial connection

    So make a choice for one of the letters a-d.

    Even better would be to answer in complete sentences what kind of programs in which language you made on a PC

    It's sure possible to start learning programming with SPIN - the propellerlanguage.
    But it will start with lower things than controlling a robot.

    Your former questions showed that your understanding of the propeller is not very deep.

    That's REALLY REALLY OK. But asking for quick examples for controlling a robot is NOT possible, because this is a quite complex thing.
    There are NO QUICK examples for doing that. Except somebody has finished a project and could paste "quickly" his complete sourcecode
    which will have hundreds or thousands of commands in summary.

    Without a deeper knowledge about programming and the propellerhardware you would be only able to rebuild exact the same robot
    loading up the software and maybe making small changes like changing some words showing on a LC-Display


    If you ask for specific and concrete details you will get a lot of help here. As long as we (all the other members of the forum) can see
    that YOU thought about the last answer and made some steps forward BY YOURSELF and then comes up a new but CONCRETE question
    you can ask three times every day and you will get answers.

    I guess most of us do not like to write a one week tutorial about programming a robot as ONE PIECE for you.
    And even then it would not be clear where your specific problems are. Maybe the tutorial would say a lot of about things you know
    very well and things you do not now are short in two sentences. So the best way is if you are asking very CONCRETE questions

    best regards

    Stefan
  • jknilinuxjknilinux Posts: 26
    edited 2008-03-18 20:33
    Hi Stefan,

    I have some experience with C, C++, Java, PBasic, and Assembly, but never used I/O such as serial ports. I certainly never wanted anyone to write a one-week tutorial; when I asked for a small example I meant 5 lines of pseudocode. Sorry about the dumb questions. I know my understanding of the propeller will improve when I get one. Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-18 20:43
    You should have a reasonably easy time since Spin is very much like C. Start off just forgetting that there are 8 cogs. Think of them as peripheral processors that will take care of putting up a display or handling servos or sensors or managing a serial channel. That's often how they're used anyway. Once you get comfortable with Spin and with the Propeller Tool, you can use some of the tutorials in the Propeller Education Kit to begin experimenting with forking tasks to other processors yourself.
  • jknilinuxjknilinux Posts: 26
    edited 2008-03-18 20:52
    Sounds great mike- I'll do that. Just wanted to ask if I could connect them instead of buying one and finding out later that it was impossible in the first place. Thanks everybody!
Sign In or Register to comment.