Shop OBEX P1 Docs P2 Docs Learn Events
Serial communication with Scribbler — Parallax Forums

Serial communication with Scribbler

st33dst33d Posts: 4
edited 2006-02-27 10:26 in Robotics
I want to use the Scribbler robot for a large scale drawing project. I've already seen that I can communicate with the scribbler from the keyboard and thus effect actions using PBASIC. I would like to know if I can use the SERIN and SEROUT commands to install a program that will allow me to stream commands to the Scribbler. I intend to use Processing to write a a program that will stream commands down the serial cable to the Scribbler. I feel that using a higher level language than PBASIC will allow me to have a lot of freedom with what I can do with the Scribbler - I'll be able to jump into the conceptual side with out trying to patch it out in PBASIC. All I'll have to do is write the interface for the Scribbler.

If this is actually possible could someone show me a basic script in PBASIC for serial communication please? I just want to be able to turn an LED on and off at the very least with SERIN. If SERIN works then I can deduce how to work SEROUT for the sensors myself.

Thanks.

Comments

  • Tom WalkerTom Walker Posts: 509
    edited 2006-02-23 16:41
    Since the Stamp "brain" of the Scribbler only "understands" PBASIC, this task would have to be handled by a program (written in PBASIC) running on the Scribbler that interprets commands sent to it through a serial line. An example might be a program that just waits for a 3 character command to arrive via SERIN such as "F05", which indicates to the Scribbler that it needs to move (F)orward (5) units or R45 indicating a (R)ight turn of (45) degrees. The programming on the Scribbler would have to handle interpreting the commands and performing them using "standard" PBASIC commands. One luxury that this could afford is to allow simple commands to execute "macro" actions...like "Q62" meaning something like "draw a (6)-pointed star that's (2) units large". In essence, you create your "higher-level language".

    Communication like this covered in good detail in various free downloads and several threads on these fora.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • st33dst33d Posts: 4
    edited 2006-02-27 10:26
    Ah yes. That much I had already divined. I figured out that seeing as DEBUGIN worked on the Scribbler, therefore SERIN should work as well. The following is a hello world method of sending info to the Scribbler from Processing ->

    Scribbler:
    ' Turn on each LED one at a time
    '  {$STAMP BS2}
    '  {$PBASIC 2.5}
    
    ' I/O Declarations
    
    LedRight      PIN 8   ' right green LED
    LedCenter     PIN 9   ' center green
    LedLeft       PIN 10  ' left green LED
    
    ' Rotate thru LEDs
    
    state VAR Byte
    states CON 3
    
    Init:
      state = 0
    
    Main:
      'DEBUGIN DEC1 state
      'pin 16 is the serial programming port
      '$4054 is a baud rate that I know nothing about
      'the state variable is recieved as an integer
      SERIN 16, $4054, [noparse][[/noparse]state]
      BRANCH state, [noparse][[/noparse]state_0, state_1, state_2]
    
    state_0:
      HIGH LedLeft
      LOW LedRight
      LOW LedCenter
      GOTO Main
    
    state_1:
      HIGH LedCenter
      LOW LedLeft
      LOW LedRight
      GOTO Main
    
    state_2:
      HIGH LedRight
      LOW LedLeft
      LOW LedCenter
      GOTO Main
    
    


    Processing:
    import processing.serial.*; 
    Serial myPort;
    int i = 0;
    void setup(){
    println(Serial.list()); 
    myPort = new Serial(this, Serial.list()[noparse][[/noparse]0], 9600); 
    framerate(1);
    }
    void draw(){
      i = (i + 1) % 3;
      myPort.write(i);
      println(i);
    }
    
    
Sign In or Register to comment.