Shop OBEX P1 Docs P2 Docs Learn Events
Joystick to control BASIC Stamp — Parallax Forums

Joystick to control BASIC Stamp

CorbettROVCorbettROV Posts: 17
edited 2008-10-29 17:31 in BASIC Stamp
Hi, I have a BS2 with a Homework board hooked up to a computer via USB. To the BASIC Stamp, a Pololu TReX Jr. serial motor controller is hooked up. Here is a diagram of my setup:

stampdiagram.jpg

My question is: How can I program the BASIC Stamp to receive readings from a USB joystick and use those readings to send certain serial commands to the TReX Jr? As of now, I am controlling the motor by manipulating variables in the program with the keyboard through the Debug terminal. Instead of a keyboard, I want to use a USB joystick.

Thanks in advance

-Jacy

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-29 01:00
    You can't really use a USB joystick with a Stamp without some kind of USB host controller. The Parallax Memory Stick Datalogger does have a USB host controller inside (the Vinculum chip) and you can use that to control a USB joystick, but there's no ready-made code. Download the Vinculum Firmware Manual from Parallax's webpage for the Datalogger and look at the commands to control a HID (Human-computer Interface Device) like a keyboard / mouse / joystick.

    The other alternative would be to use your PC as the host controller. You'll need to write some kind of PC program that reads the joystick position and uses a serial port to talk to the Stamp to send the current joystick XY position and buttons. Again, there's no ready-made program although there may be past projects on these forums about that sort of setup. You'll need to do some searching (using search.parallax.com and browing).
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-29 01:05
    I was thinking of doing the latter - using the PC as a host. Would I just have to completely write my own program from scratch for that?

    I saw a post in which a teacher was talking about using joyticks with his BASIC Stamps in class all the time, and I was curious about that also.
  • FranklinFranklin Posts: 4,747
    edited 2008-10-29 01:13
    If you saw a post you should ask in that post not start a new one.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-29 01:44
    The post was on a completely different subject, it just mentioned that.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-29 02:09
    It's possible that he used some sort of differnt joystick. For example, you can (fairly) easily hookup a serial joystick to a BS2, or some specialty electronics joystick that outputs either a voltage divider or resistance. USB just makes things difficult...
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-29 02:18
    So are there any suggestions as for how I should proceed?
  • SRLMSRLM Posts: 5,045
    edited 2008-10-29 03:07
    Depends. Do you know a computer language such as Java, C, C++, or VisualBasic? If you do, then you can figure out how to get the incoming data and send it back out to the uC.

    If you don't know one of these languages, then I suggest dropping the USB joystick idea and going to an simpler device. You could use the Datalogger, but my experience is that it's a tough beast. Your experience may differ.

    The easiest thing to do would be to hook up some pots and build a joystick from them, or to buy an equivelent device. Then you just use RCTIME to figure out where the joystick is.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2008-10-29 14:28
    CorbettROV--

    Attached is a program kindly given to me by a forum member.·This program·does exactly what you want IF you have a Logitech Dual Action Game Controller. (I bought one at Radio Shack--or maybe it was Nebraska Furniture Mart--for $19.95.)

    The advantage of the Logitech device is that it has TWO joysticks and ten buttons. It also has another control called a D-pad which is not functional with the software attached, which is written in VB and may have some of my comments in it, but I am not its author.

    I recommend you simply buy a Logitech Dual Action Game Pad, load the attached software into VB 6.0, and start pushing buttons.

    Eventually, my Parallax based, remote control lawnmower will use this game pad along with a version of the attached software.

    This is an extremely popular subject. A PC is an extremely useful device to hang on a Parallax Stamp. It extends the possibilities of using the Parallax Stamps in far more powerful applications.

    Remember that this software is one way. All it does is read the game pad actions. I also have some Parallax Stamp/Bluetooth/BlueTooth/PC VB 6.0·code that will allow you to blink two LEDs ON COMMAND at least 100 feet away. (That's as far as I've tested it through concrete, anyway.) That code will also become part of my remote controlled lawn mower. The dirt simple VB 6.0 interface says it is controlling a lawnmower, but all it does is make one of two LEDs blink, or shuts them both off.

    Good luck and thank you to the member that helped me with this HUGELY popular topic that receives so little attention.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-29 14:38
    Wow, thank you very much. You have been extremely helpful. [noparse]:)[/noparse]

    Where can I get VB 6.0?

    Post Edited (CorbettROV) : 10/29/2008 2:43:39 PM GMT
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2008-10-29 14:48
    CorbettROV--

    Unlike me and almost everyone else on this forum that freely shares software, Microsoft wants to make MONEY on their stuff! Hey! What's up with that, anyway?

    You have to buy VB6.0, probably as part of Microsoft's Visual Studio. If you are a student, this can be a DIRT CHEAP deal and well worth the investment. (My college sold it for about $25.00.)

    Microsoft also allows a person to download something called Visual Basic Express at no charge. Many folks on this forum use it. I know nothing about it. I just hope you are a student.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Beau SchwabeBeau Schwabe Posts: 6,563
    edited 2008-10-29 16:12
    CorbettROV,

    While it's not VB 6.0, chances are you might already have a flavor of Visual Basic within Microsoft Excel. If you already have Microsoft Excel, here is a guideline to getting COMPORT control through this VB package.

    1) Search for MSCOMM32.OCX on your computer... it might already be there. If not do an internet search for this file and download it.

    2) Open up Microsoft Excel

    3) Turn on Visual basic Tool Bars.... View --> Toolbars --> Visual Basic

    4) Click on the 'Visual basic Editor' under the 'Visual Basic Tool Bars'

    5) Add 'MSCOMM32.OCX' functions to Microsoft Excel ... Tools --> References... --> Browse (find location where you saved the 'MSCOMM32.OCX' file)
    Note the OCX extension... you might need to change this from the default extension used in the file browser.

    6) You should now have access to Serial port commands and functions under the "Object Browser" that you can include in your own programs.


    In many cases, the USB port is "seen" as a COM port, so this becomes a matter of setting the correct COM port and reading the data from within your VB program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-29 17:10
    I am a high school student, so I could probably get that deal. Before that I will try using Excel.

    I tried the Excel thing, and I got everything to be as it should, but I have absolutle no idea what to do now.

    Post Edited (CorbettROV) : 10/29/2008 5:23:52 PM GMT
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2008-10-29 17:23
    CorbettROV--

    Good! There is no telling what it will really cost. The head of the bookstore sets the price in colleges. In fact, you could probably go to your local community college, tell them you are a high school student very interested in Visual Basic and would consider enrolling in one of their courses if you could buy it from them at the student discount. (I am a retired college dean, that's why I know this stuff.)

    On the other hand, try what Mr. Schwabe suggested. He has forgotten more than I'll ever know. (Beau, I USED to know a lot, so what's that mean for you? [noparse]:)[/noparse]

    --Bill



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-29 17:31
    So with the Excel thing, what do I do once I finish the last step suggested by Beau Schwabe?
Sign In or Register to comment.