Connect Raspberry to Basic Stamp 2



  • ElectrodudeElectrodude Posts: 1,437
    edited 2015-01-19 15:01
    satriaoo wrote: »
    Not work sir. :/

    am i must installing any software or package (maybe Pbasic) on raspberry pi? The LED doesn't works. If i push "1" button, it only show "LED ON" on the terminal, but the LED didn't on. -.-

    If you're sending commands to the BS2 over the serial (programming) port, you need to make SerialPin equal to 16, not 15. Right now, it's expecting commands to come in on 15, but pin 15 has the LED on it.

    Ignore my earlier DEBUG suggestion for now - maybe just comment it out instead of completely removing it.
  • bostonpatriotbostonpatriot Posts: 1
    edited 2015-06-03 14:45
    Hello; I am essentially attempting the same procedure as discussed above: connect my Basic Stamp 2 (on Carrier Board) to my Raspberry Pi 1 Model B using Python code. However, i can now see my efforts will prove futile unless I've got the Board of Education - USB rig? Is it possible for me to transmit some cursory data, say "Hello World" from the Stamp 2 I have now to my Pi via LX Terminal? Thank You
  • carlozofjuancarlozofjuan Posts: 4
    edited 2020-12-04 20:29
    5 years late to the game, but I was able to solve this issue so I'm posting my solution in case it helps anyone else.

    On the Board of Education:
    1) SerialPin is changed back to 16.
    2) Baud mode with Inverted polarity.

    On the Raspberry Pi:
    1) On the Raspberry Pi, causes the port to switch between USB0 and USB1 (at least on my Pi). Check what's available with ls /dev/tty*

    Thanks to the efforts of the OP,@satriaoo, and everyone else trying to make USB serial communication work between Raspberry Pi and Boe-Bot (Basic Stamp 2). My setup is the Board of Education board Rev. D (BOE), with LED and resistor which is essentially the same as that of the OP (Rev C board). The BOE is connected over USB to a Raspberry Pi 3 Model B running a Python 2 (version 2.7.9) script.

    PBasic code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' is simultaneously running on Raspberry Pi 3 Model B and
    'the below BS2 code solves the problem addressed at this link:
    ' I/O Declaration (Added)
    LedPin PIN 15                ' Added
    SerialPin CON 16             ' Must be CON type, PIN cannot be greater than 15
    ' Constant Declaration (Added)
    Baud_9600_True CON 84        '9600 Baud, 8-Bit, No-Parity, True (non-inverted)
    Baud_9600_Inverted CON 16468 '9600 Baud, 8-Bit, No-Parity, Inverted
    LoopDelay CON 1000
    ' Variable Declaration (Added)
    state VAR Byte
    HIGH LedPin
    PAUSE 200
    LOW  LedPin
    DO ' Changed from Main: to DO
      'SERIN SerialPin, BAUD, [state]
      SERIN SerialPin, Baud_9600_Inverted, [state]
      IF (state = 49)  THEN
        HIGH LedPin ' The "1" key is ASCII 49
      ELSEIF (state = 50)  THEN
        LOW LedPin ' The "2" key is ASCII 50
      PAUSE LoopDelay
    LOOP ' Changed from Goto Main to LOOP

    Python code:
    #Use this script with Python 2.7.9 and migrate to Python 3 later
    #Get this working first
    #Check USB devices with: ls dev /dev/tty*
    import serial
    #ser=serial.Serial(port='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None)
    ser=serial.Serial(port='/dev/ttyUSB1', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None)
    while True:   
        val=raw_input('Value: ')
        if val == '1':
            print('LED ON')
        elif val == '2':
            print('LED OFF')
        elif val == 'exit':
  • I'll have to try this out on Tkinter
  • I would go back and check my Pi serial. Plugin the Bs2 board to the rasberry pi with the USB, enter terminal mode on the Pi and type in "dmesg | grep tty " and see if it list the FT232 on the Bs2 board.
  • This is a simple byte transmitting from my BS2 to the RasberryPi via the USB
    1200 x 1600 - 560K
  • Update, first load this program into your BS2, then plug in your USB from your BS2 into your Rasberry Pi, make sure your BS2 is powered up.
    Next enter terminal mode on your rasberry Pi. Type in "python -m" select option 2, now the 7878 from your BS2 program will display on your Pi terminal. Note you have to configure your serial on your rasberry Pi first, in "sudo raspi-config" interfacing options.
  • Should look like this, Now you have comm. from your BS2 to your Pi
  • This is the Python code to read the value from the BS2, Next I'll make the write statements turn on LED's on the BS2. Some of the other posted Python code doesn't work, Python 3 does not support Raw_input, its Val=input.
  • This is it in Thonny python Tkinter, and how the GUI looks
  • This is it in Python 3.7.3 I used my Lcd on the BS2 but you don't need it to run.
Sign In or Register to comment.