Shop OBEX P1 Docs P2 Docs Learn Events
Connecting and/or networking BS2 processors — Parallax Forums

Connecting and/or networking BS2 processors

stuartXstuartX Posts: 88
edited 2012-02-24 10:46 in BASIC Stamp
Is there a way to connect two BS2 chips together so that one could send a condition to the other to perform a condition on it?
In other words, If BS2-1 has a sensor, (some condition is met) send that condition to BS2-2, and have BS2-2 perform some function?

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2012-02-14 09:16
    One possible method is to use the SERIN and SEROUT commands to send the status from one to the other.

    As a starting point, look in the Editor's helpfile under SERIN or SEROUT. There is a sample application there.

    Cheers,
  • stuartXstuartX Posts: 88
    edited 2012-02-14 09:34
    I'll check it out. But would it be any particular syntax stating a particular pin?
  • stamptrolstamptrol Posts: 1,731
    edited 2012-02-14 09:44
    Use any pins p0 - p15. You can use a single pin for both transmit and receive if you wish, or use one for each direction. Note that the example uses one extra pin for flow control.
  • Nick ErnstNick Ernst Posts: 138
    edited 2012-02-14 10:05
    For a reference of how you can interface two BS2's together to work cooperatively, check out this Boe Bot that was made, that is named Abbot, or Advanced Boe Bot. They use two Boards of Education, and they both work together. They have their manual and code for you to look at also.

    http://forums.parallax.com/showthread.php?110211-ABBot-Advanced-Boe-Bot
  • stuartXstuartX Posts: 88
    edited 2012-02-14 10:39
    Ahhh. Its starting to come together now. I would just want to pass a bit (not byte) for a condition so that I can perform a function on the other BS2.
    Great example.
    All,
    Thanks for all your quick help for a peon like me.
    Much appreciated.
    This will help move my robot project along.
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-14 14:28
    Hello,

    Funny thing to see this post tonight as this was the subject of my torture (self inflicted) all week and tonight I managed to make 4 LED's blink when buttons are pressed on the master and boy was I happy!

    Forgive me as I do not want to hijack the OP thread but thought my example might help us both...

    DSCF1510.JPG


    I have 2 BS2 (OEM Boards) on a breadboard and wanted to make one talk to the other.

    Master BS2 = 4 push-button's <----> Slave BS2 = 4 LED's

    I am building (rebuilding!) a 1984 Tomy Omnibot 2000 into a more modern robot with 2 OEM BS2's (because it's what I have) and all the 'normal' Parallax peripherals. I need some way to teach myself how to not only program in PBasic but how to make the stamps "talk" to each-other. I have to admit that I searched the web and this forum for a full week before typing anything and am still not sure how I got it to work but it does. Next, I need to expand into controlling my drive motor (Paulou) serial motor controller via the buttons and then next step is a joystick... Baby steps!!

    Stamp - Slave Test.bs2
    Stamp - Master Test.bs2

    So, I am a complete NOOB at coding and the only way I seem to understand this stuff is via "code snippets" or single purpose examples that I then combine into a bigger program, that being said I am SURE that the way I have managed to do this is inefficient and a waste of memory or something so ANY recommendations are greatly appreciated before I move to the next step. Also, the one thing I do not like about my current code is that if you press more then one button at once you get nothing so I am going to try to figure out the "button" command and see if that helps.

    PS... My main reference was Jon Williams "A Tale of Two Stamps" Nuts & Volts #81 2002 http://www.parallax.com/Resources/NutsVoltsColumns/NutsVoltsVolume3/tabid/445/Default.aspx

    Look forward to any feedback and have to say that I have no idea what I would do without this forum!

    Jeff
    Stavanger, Norway
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-15 01:27
    Here is the spot I am stuck at today...

    I can send a byte (cmd) to the slave for example "1 = move forward" but on the slave how should I (best method) for program to receive the command (button press) and be able to "loop" to check for the button being pressed / released and if there is a new command being sent?

    ' receive command byte from master (push button)
    ' ' ' do as instructed (keep moving while button is held down)
    ' loop around and check for button release and if there is a new button being pressed

    Also in the future there will be sensors to be checked and other functions to perform so understanding how do I code the "receive input" / "perform action" and which of the 2 stamps will perform what and when is crucial to me.

    Thanks for any feedback!
  • stamptrolstamptrol Posts: 1,731
    edited 2012-02-15 05:58
    As you will find, the Stamps don't have comm buffers so your program has to be sitting on the SERIN when the data is expected. Otherwise, you'll miss all or part of it.

    What I usually do is set up the receiving end to constantly loop and use the timeout and WAIT functions to help make sure the SERIN is ready when the data arrives. Once a command is received, you can signal the master that the message was received then let the slave act on the command before going back to wait for the next command.

    The timeout function lets the slave check on things if no data is received (but be aware, any incoming data, whether real or noise will keep resetting the timeout and the slave will never go do the housekeeping).
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-15 07:26
    Thanks Tom,

    So how do you recommend that I "distribute" the processes on a 2 stamp "big Boe-Bot" setup? should I put the motor control, ping and avoidance/collision decisions on 1 and the LCD, PIR, sound, etc, etc. on the other? I have been trying to interpret the Advanced Boe Bot code listed above and need to understand it better.
  • stamptrolstamptrol Posts: 1,731
    edited 2012-02-15 08:10
    You're on the right track to split up the tasks. Theres no magic formula for the division of tasks but it makes sense to have related measurement and control on one processor to avoid total dependence on the comm link.

    I think you'll quite quickly get to the point where you'll have a two-way link between the Stamps. The master sends commands to the slave who does the action then sends back sensor data for the master to act on.

    You can see one control scheme I've done on www.youtube.com/stamptrol1 Its the third one listed, I believe.

    And, like most concepts, its better to gradually work through the challenges in stages rather than trying to come up with a multi-part solution in one go.

    I'd suggest getting a solid comm link going, then send data back and forth and finally add the control aspects.
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-15 09:07
    Cool! Thanks for that... I have the one way figured out and now will work on bi-directional.
  • stuartXstuartX Posts: 88
    edited 2012-02-15 11:06
    Just Jeff,
    Very good post (for me). The project that you have brought in a better understanding of the connectivity and code of how it works. I have to take baby-steps into it. Once I receive my second BS2 I'll connect it up.
    Stamptrol,
    I'll take your advice also and try a few things. I'll review your youtube.

    Thanks again. This is very, very helpful. I'll stay posted for more information.
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-15 11:25
    @stuartX - It's nice to know that somebody else is suffering the same headaches! :) Misery loves company, let's keep each-other posted!

    I will say that I was going about this wrong in that I was in such a hurry to make the 2 stamps "talk" that I forgot to have a plan for what I wanted to accomplish.... so back to the design stage to divide up the process and steps - the Advanced Boe Bot is a great example!
  • CatspawCatspaw Posts: 49
    edited 2012-02-15 14:09
    SX and JF.....Since I have nothing better to contribute (being a noobie to stamps) I'll tell you that most professional programming is done in a modular fashion. You build a program that performs a certain function...and you'll learn how to do that. Then you'll build something else...then combine the two...etc, etc. Sum of the parts, greater than the whole thing.

    What I'm doing/learning right now is not so dissimilar from what you guys are doing. Except I'm including a PC for the main brains of the thing. So I have three parts to deal with (the PC, the Stamp(s), and the output. Breaking it down into steps/parts to learn a particular function/instruction is basically the same as writing subroutines that will all get combined in the end. You'll know your code better and it keeps you from getting overwhelmed by the full program. You can't build a car until you know how to build an engine, transmission, wheels, etc.

    I'm going to follow this thread, since ultimately it will help me when I too start networking multiple stamps. Right now I have just the PC to Stamp to Output and back. One can never have too many stamps.
  • stuartXstuartX Posts: 88
    edited 2012-02-15 19:20
    @Catspaw,
    Thanks for the advice. I'm trying to get into and understand interfacing the stamp with a PC, so all your advice is soaking in for me. I'm not a programmer, but I try to figure things out. It just may take me a little longer.
    Just like programming the modular approach works. I try to work on one piece of the puzzle at a time then work my way up. Once all the worked out pieces are together then I try to debug the collective.....lol fun.
    I learn by my mistakes, do research and from you all.
    @All,
    Thanks for the input this is good stuff. I have a few projects on the table in which its helping with all of them.
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-20 01:08
    Spent all weekend trying different ways of making my motor controller work from the Parallax 2-axis joystick and came up with the attached code that works just great. It is only working on one stamp at this time and next I want to work out how to have one stamp using ping to avoid obstacles and the other will be able to accept inputs from joystick, button presses etc. (automatic mode vs manual) Fun stuff!

    Thinking about setting up the joystick in a "remote control" box for my robot that will send some bit/pulse/trigger to tell the master BS2 when it is turned on and ready to send commands so that the stamp will "listen" for the "Manual Override" commands from the remote. I will do this "wired" first go round and then figure out "wireless" next and this is to allow for remotely controlling an arm that will be on the bot and driving around just for fun via remote.

    So StuartX how is your project proceeding?

    Components in this code example;
    OEM BS2, 2-Axis Joystick #27800, Pololu SMC20B Motor Controller, 2 6v DC motors
  • stuartXstuartX Posts: 88
    edited 2012-02-23 18:19
    @Just Jeff, I'm sorry for the delay. I was waiting on my 2nd stamp.
    I received the stamp and hook up the circuit. I only hooked up three switches and three LEDs (pin 10, 11, 12)
    When I pressed buttons I did get the response........cool! This will solve alot of problems.
    It was strange but LED @pin 12 constantly blinked until I pressed switch pin10 or 11. Then LED @pin 12 continued to blink. There seem like a delay. Is this due to the fact that the BS2 doesn't have multiple cogs?
    But, at any rate, i'm sifting through the code to understand it better. Thanks Jeff this opens up a lot of possibilities.

    I'm working on two projects, LED lighting in the house (two flights of stairs, foryer, hallway, MBR short hall). The second project is the robot. I receive my sonar sensors and I will be hooking them up on the board and testing trying to figure out code.
    By the way, I'm going to be trying to test my autonomous to manual mode, but in a different way.
    Keep me posted.
  • Just JeffJust Jeff Posts: 36
    edited 2012-02-24 10:46
    stuartX wrote: »
    @Just Jeff, I'm sorry for the delay. I was waiting on my 2nd stamp.
    I received the stamp and hook up the circuit. I only hooked up three switches and three LEDs (pin 10, 11, 12)
    When I pressed buttons I did get the response........cool! This will solve alot of problems.
    It was strange but LED @pin 12 constantly blinked until I pressed switch pin10 or 11. Then LED @pin 12 continued to blink. There seem like a delay. Is this due to the fact that the BS2 doesn't have multiple cogs?
    But, at any rate, i'm sifting through the code to understand it better. Thanks Jeff this opens up a lot of possibilities.

    I'm working on two projects, LED lighting in the house (two flights of stairs, foryer, hallway, MBR short hall). The second project is the robot. I receive my sonar sensors and I will be hooking them up on the board and testing trying to figure out code.
    By the way, I'm going to be trying to test my autonomous to manual mode, but in a different way.
    Keep me posted.

    Hey sounds like you are having fun!! Let me know if I can help with the code at all and if you get it going. I have been busy with work stuff... maybe this weekend a bit more playing with the stamps!
Sign In or Register to comment.