Shop OBEX P1 Docs P2 Docs Learn Events
Extreme Newbie needing alot of help with serial communication from computer to — Parallax Forums

Extreme Newbie needing alot of help with serial communication from computer to

eagletalontimeagletalontim Posts: 1,399
edited 2008-10-12 15:51 in General Discussion
I have been searching the forums for simple explanations, but I keep getting more and more confused [noparse]:([/noparse] I am attempting to make a 3 axis stepping motor control that gets information from my computer and moves the motors according to what is sent to the chip. It is fairly simple in my head, but getting the communication started is the problem.

What I am starting with is:
3 stepper motors (I am sure i can figure out the code to run them.),
Visual Basic 6.0 Pro (I am hoping to use this as the Windows controller that send the information to the chip)
Random electronic parts around the house.
No spare money!

How I have it pictured in my head is to have the Visual Basic program send only 3 variables to the SX....MotorA, MotorB, MotorC. Each variable will be either -1 for step backwards, 0 for do nothing, and 1 for step forward. What I need help with is how to send each variable from the computer and get the chip to read each variable. Any help will be greatly appreciated!

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-11 18:49
    ok, here is a simple question i hope. how do you hook up the serial port to the SX chip? I have read in the help files that I should use a 4.7k pullup resistor which I have done, but is that all I need? i am sure there has to be a common ground. Is there a schematic somewhere I can follow to hook up the serial connection.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-10-11 19:13
    It's not a pull-up, it's a series resistor.

    Also, you'll need to use inverted (not "true.")

    See attached pic.
    323 x 194 - 9K
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-10-11 20:01
    I've attached a ZIP (you'll need to fix the extension as the forum didn't like ZIP) file with an SX/B program and VB project to get you started. I used the MAX232 on the PDB; if you go with the resister route (as PJ suggests) then you'll need to change the Baud constant in the SX/B program to "N9600"

    This shows how to send a simple packet that allows the SX to re-establish synchronization with the PC should it be lost.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-11 20:06
    Thanks!!!, got the serial connection between the chip and the computer [noparse]:)[/noparse]

    Now for the hard part.....I have downloaded a program that I can send data through the serial port and it can receive what I send back from the chip. I am using it for testing purposes until I get things working somewhat right so I can design my own program to operate the chip. Here is the code from the help files that I have modified a bit :

    DEVICE         SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ         4_000_000
    ID         "SERIN"
    
    
    Sio         PIN     RA.0 INPUT
    LED         PIN     RB.2 OUTPUT
    
    Baud         CON     "N9600"
    
    serByte     VAR     Byte
    tmpB1         VAR     Byte
    
    PROGRAM Start
    
    RX_BYTE     FUNC     1
    
    Start:
      PLP_A = %0001
      PLP_C = %00000000
      LED = %00000000
    
    Main:
      serByte = ""
      serByte = RX_BYTE
      IF serByte == "L" THEN 
        LED = 1
        pause 1000
        LED = 0
        SEROUT RA.1, N9600, serByte
      ELSE
        LED = 0
      ENDIF  
    GOTO Main
    
    FUNC RX_BYTE
      SERIN Sio, Baud, tmpB1             ' receive a byte
      RETURN tmpB1
    ENDFUNC
    
    



    I can send the letter "G" to the chip, and it will send back "G" just like it is supposed to. The big question is how can I send 3 variables to the chip and the chip know which one is which? If i send T,E,S,T to the chip, I only receive back T. I was hoping to be able to send all 3 variables in one string and have the chip break it down to process them.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-11 20:09
    oops...forgot to add that I was attempting to check the variable serByte to see if equaled a certain letter.....that part is not working either.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-10-11 20:19
    Do you really have --···IF·serByte·==·"L"·THEN·?
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-11 20:22
    yeah, i am still getting used to the SX/B language and if it does not throw and error, I test it tongue.gif I am used to PHP but am doing my best to learn the SX language [noparse]:)[/noparse] I do best when there is working code in front of me and I can modify it. Thanks JohnnyMac for the zip file! I am messing with it now. Looks like a simple design actually.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-11 20:29
    can someone explain what this part of the code means :

    MTR_FWD        CON    $01
    MTR_STOP    CON    $00
    MTR_REV        CON    $7F
    
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-10-11 20:40
    Looks like CONstants: Motor Forward, Motor Stop, Motor Reverse.

    Attached a program I used to test serial with, if you haven't nailed that down yet.· Uses different baudmode, pins, etc., but easily modified.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-12 03:46
    So far so good, but now I run into a slight problem [noparse]:([/noparse] Does anyone know where or what I can get a heavier duty step motor from? I am using a step motor that has 6 wires coming from it. I have no idea what it is called except that it is a step motor tongue.gif I have modified the VB program and the SX program to run an X, Y, and X axis. Everything works so far but now I am at a halt till I can come up with bigger step motors.
  • CapdiamontCapdiamont Posts: 218
    edited 2008-10-12 03:56
    How big are your step motors
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-12 04:02
    hmmm. good question. It is the paper feeder step motor that came out of an old printer I had laying around. It is quite small. When i have it moving, I can place my finger on the gear and it will stop moving. I need something that has very good torque. Speed is not a really big thing, but it is a bonus if that is possible. I have tried using different timing on the outputs to see if holding the current a little longer would make it stronger, but that did not work as well as I need it to.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-10-12 13:56
    would these motors be strong enough to move a around 5lbs up and down some threaded rod?

    Would help if I added the link :P
    cgi.ebay.com/Nema-size-23-stepper-motors-1-4-shaft-cnc-automation_W0QQitemZ170269775558QQcmdZViewItem?hash=item170269775558&_trkparms=72%3A1205%7C39%3A1%7C66%3A2%7C65%3A12%7C240%3A1318&_trksid=p3286.c0.m14#ebayphotohosting

    Post Edited (eagletalontim) : 10/12/2008 2:17:34 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-10-12 14:37
    Who can say by looking at them?· "Well, they have some big ol' wires on 'em, maybe #20 or #18."··Ask mr. ebayseller·to send you a picture of the label/s, could have the specs right there or info enough to find the rest somewhere on the internet.
  • CapdiamontCapdiamont Posts: 218
    edited 2008-10-12 15:21
    The other way to do it, is to gear the motors down, so they produce more torque.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-10-12 15:51
    This thread has kind of degenerated away from programming the SX -- perhaps you should ask motor questions in an appropriate forum.
Sign In or Register to comment.