Shop OBEX P1 Docs P2 Docs Learn Events
Help needed with BS2/ Pololu qik2s9v. — Parallax Forums

Help needed with BS2/ Pololu qik2s9v.

DonNDonN Posts: 11
edited 2010-11-24 18:20 in BASIC Stamp
Good Morning all.
I have been working with a BS2 and a qik2s9v controller. I would like to have both motors run in opposite directions as in most applications. But no cigar.
I am thinking baud problem ?? Listed below is my code.
Thanks in advance.
'MY EXPEREMENT WITH Qik2s9v MOTOR CONTROLER.

' {$STAMP BS2}
' {$PBASIC 2.5}

'++++++++++ DECLARATIONS ++++++++

Baud CON 170
SO PIN 8 'INPUT to "qik"
RESET PIN 9 'RESET

' ********** Initialize ****
Setup:
HIGH SO
GOSUB Reset_qik

Reset_qik:
LOW RESET
PAUSE 1
HIGH RESET
RETURN

'********* MAIN *************
DO
SEROUT SO, Baud, 9, [0,0,0,127] 'M0 FORWARD.
SEROUT SO, Baud, 9, [0,0,1,127] 'M1 REVERSE.

PAUSE 2000

SEROUT SO, Baud, 9, [0,0,1,127] 'M0 REVERSE.
SEROUT SO, Baud, 9, [0,0,0,127] 'M1 FORWARD.

PAUSE 2000

LOOP

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2010-11-22 05:23
    Are you sure a Baud constant of 170 is correct?
  • DonNDonN Posts: 11
    edited 2010-11-22 08:41
    No I am not sure 170 is correct, thus the question. I have the qik set to auto-detect baud. Also should add the qik operates as it should in demo. mode.
    Also the green LED on the qik does not indicate communication with the BS2.
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-11-22 10:40
    170 is not a standard BS2 Baudrate, and it represents a fairly fast rate. If I were you I'd go to the baudrate table (click on the help button in the PBASIC environment, and look under the SERIN command), and find the codes for the BS2 for some of the slower rates. You certainly don't need anything over 2400 for interacting with a motor controller.
  • DonNDonN Posts: 11
    edited 2010-11-22 14:07
    I have tried several different baud rates and still nothing. Is there a problem with the code itself ?:confused:
  • BenSBenS Posts: 8
    edited 2010-11-22 15:59
    Hello.

    I think you are misunderstanding how the qik works. When in auto-detect baud mode, you can use any baud rate you want between 1200 and 38,400 bps. The qik will learn the baud rate when you send it the byte 0xAA (170 in decimal):

    http://www.pololu.com/docs/0J25/4.b

    - Ben
  • DonNDonN Posts: 11
    edited 2010-11-22 17:41
    I am going to start all over after leaving it rest for a few days. If I could find a working example I could take it the rest of the way.
    Thanks to all for the help.
  • BenSBenS Posts: 8
    edited 2010-11-22 17:56
    I didn't look at your code beyond noting the obvious problem of failing to teach the qik the baud rate (by not sending the byte 0xAA), but now I notice you're also not sending valid commands to the qik. Where did you come up with the sequence of bytes you're sending? The qik commands are documented here:

    http://www.pololu.com/docs/0J25/5

    I don't have a sample program to give you, but I can tell you in words what you need to do:

    1) Send the serial byte 0xAA (170) so the qik can learn the baud rate. If you do this successfully, you will see the blinking pattern of the green LED change.

    2) Send the serial bytes: 0x88, 0x7F (or, in decimal: 136, 127). This will make the motor turn forward at full speed.

    - Ben
  • DonNDonN Posts: 11
    edited 2010-11-23 02:40
    Ben, It is my understanding of the qik doc that the commands it needs are as follows :
    Baud -170, Device ID - 9, 1st serial byte -0, Motor #- 0, Speed - 127.
    This is all new to me. The only other time I have used the SEROUT command is with a serial LCD.
    Don.
  • BenSBenS Posts: 8
    edited 2010-11-23 10:58
    You can see from the document that there are two possible protocols: the Compact Protocol and the Pololu Protocol. The Pololu Protocol is only required if you're trying to communicate with multiple Pololu devices on the same serial line. The Compact Protocol is simpler, so I recommend you use that (see my previous post for the specific bytes).

    I don't have any experience with the SEROUT command, but after two minutes of googling around it looks like you should be able to do something like:

    SEROUT SO, Baud, [170] 'baud indicator byte.
    SEROUT SO, Baud, [136,127] 'M0 FORWARD full speed.
    SEROUT SO, Baud, [136,63] 'M0 FORWARD half speed.
    SEROUT SO, Baud, [138,127] 'M0 REVERSE full speed.
    SEROUT SO, Baud, [140,127] 'M1 FORWARD full speed.
    SEROUT SO, Baud, [142,127] 'M1 REVERSE full speed.

    - Ben

    Edit: By the way, you need to get the "Baud" constant right (it should not be 170!). You want to be using non-inverted TTL serial with 8 bits of data, no parity, and a baud rate between 1200 and 38,400 bps. Maybe someone on this forum can help point you in the right direction? I think you can get this by using a "Baud" constant 16468 (9600 bps), but I'm not sure.
  • DonNDonN Posts: 11
    edited 2010-11-23 14:00
    Ben,
    Do understand non-inverted would be not holding Pin 8 high? I will try it both ways. I have a test code to try your suggestions in.
    Thanks.
  • BenSBenS Posts: 8
    edited 2010-11-23 14:30
    Don,

    I don't mean to sound harsh, but I feel like you're not even trying to read the user's guide at this point. I don't think it could more explicitly explain what kind of serial signal the qik is expecting:

    http://www.pololu.com/docs/0J25/4.a

    You shouldn't need to "try it both ways"; there's plenty of detailed documentation out there, both on the qik and the Basic Stamp, that makes it easy to figure out the correct way. You just have to be willing to put in the effort to look for it and read it (and post very specific questions if there's something you don't understand).

    - Ben
  • DonNDonN Posts: 11
    edited 2010-11-24 09:45
    First you need to get down off of your high horse and give your suggestions a try. Connect a BS2 to a qik and give it a try. I expected a workable answer not a should work answer.
    I noticed you are rather short with others on the "other" forum as well.
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-11-24 10:28
    Time out.

    Don, how about you recognize that Ben has put some significant time into trying to help you?

    Ben, how about you recognize that Don did say that he planned to try things? There's nothing wrong with a little trial-and-error.

    The rest of us will all be impressed if you both manage to make your next posts be about the details of getting the device to work, and keeping them free of comments about each other's behavior, or defenses of your own behavior.

    I'll bet you can both rise to the occasion. How about it?
  • DonNDonN Posts: 11
    edited 2010-11-24 11:29
    Thanks for jumping in there sylvie369.
    Good thing it is a slow day here at work I have time to research this more.

    " A man is not finished when he is defeated. He is finished when he quits."
  • DonNDonN Posts: 11
    edited 2010-11-24 12:03
    Quick question. Is there any reason I can't I use Bi colored LED's with appropriate resistors to indicate motor activity? I don't have any motors with me, they are at home!
  • BenSBenS Posts: 8
    edited 2010-11-24 15:33
    sylvie369 wrote: »
    The rest of us will all be impressed if you both manage to make your next posts be about the details of getting the device to work, and keeping them free of comments about each other's behavior, or defenses of your own behavior.
    Well, I'm afraid you might not be impressed, but I hope you see my following response as reasonable if not justified. It doesn't address the specific problem broached in this thread, but it does at least slightly address the more general problems of "how do I get help" and "how do I troubleshoot".

    I'm not an expert on the Basic Stamp (I think I might have programmed one once back in 1996) and I don't have one handy, which is why my guidance is limited to "shoulds", and I don't feel very compelled to spend even more time figuring something out for a person whose response to the time I've spent so far is a hypocritical accusation of "being on a high horse" followed by a criticism that I have not yet completed his project for him. It's not very endearing when the person you're trying to help demands:
    DonN wrote: »
    Connect a BS2 to a qik and give it a try. I expected a workable answer not a should work answer.

    My goal is not to do Don's project for him, it's to help him understand how to do it himself, and that requires he put forth some effort on his part rather than expecting me to physically try my suggestions, verify they work, and then give him the tested answer. Asking for help generally requires the recognition that (a) the person helping you is doing you a favor and (b) you need to work with that person to get your answer. Don, I hope you read this with an open mind and think about what I'm saying, because I think it can help ensure that your next request for help with a project goes much more smoothly. I wish you the best of luck getting your project up and running.
    sylvie369 wrote: »
    There's nothing wrong with a little trial-and-error.
    I definitely disagree with this point, at least in this particular case, and I stand by my attempt to strongly discourage it. I understand that there are times when trial and error is the best (or only) solution, but when the resources are there to understand what you're doing ahead of time, take ten minutes and do it right! Trial and error with electronics is a great way to destroy something. I've heard way too many people wonder why their device isn't working after they used trial and error to figure out how to connect power or some other peripheral ("It wasn't turning on, so I tried the wires the other way and smoke came out") rather than looking at the manual. It's a sloppy attitude to have when there are other much better recourses.

    All of Don's problems in this thread can be traced back to that "trial-and-error" mentality, and in the end he would have saved so much time (both mine and his) if he had just read the qik user's guide and the Basic Stamp documentation for the SEROUT command! I completely understand that there might be residual confusion even after reading the documentation, and would welcome questions like "What does the user's guide mean when it says x?". My problem is not with the lack of understanding, its with the lack of effort and the sense of entitlement.

    Just my thoughts, for whatever they're worth. I hope this doesn't come off as antagonistic because this is definitely not my intent. Once again, good luck with the project, and happy Thanksgiving!

    - Ben
  • DonNDonN Posts: 11
    edited 2010-11-24 18:20
    Ben,
    I accept your apology and am will remain in an open state of mind.
    I should leave my work mentality at work as I do not accept "should be, should have" answers from my staff. That is not the view to have on a public forum. Especially when asking for help.

    Although I do not fully agree with our view of trial and error.
    I have been writing code for Allen Bradley PLC's for at least 10 tears and a lot of that is educated trial and error. Seldom does a block of code work exactly as you want the first time out. You build it, test it, adjust it.

    I have studied the documentation on both the qik and BS2 and have came to the conclusion the problem is in the baud setting. I have ran your suggestions and what I have learned from the doc's. No progress so far. On the upside NO smoke.
    I am going to leave this rest for a few days.

    Happy Thanksgiving to all!
    Don.
Sign In or Register to comment.