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.
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
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}
'Rpi_serialcomm_BoeBot.py is simultaneously running on Raspberry Pi 3 Model B and
'the below BS2 code solves the problem addressed at this link:
'https://forums.parallax.com/discussion/159762/connect-raspberry-to-basic-stamp-2
' 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
'https://www.parallax.com/go/PBASICHelp/Content/LanguageTopics/Commands/SERIN.htm
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
ENDIF
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)
print("Starting!")
while True:
val=raw_input('Value: ')
if val == '1':
print('LED ON')
ser.write('1')
elif val == '2':
print('LED OFF')
ser.write('2')
elif val == 'exit':
ser.close()
exit()
ser.close()
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.
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 serial.tools.miniterm" 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.
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.
Comments
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.
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:
Python code:
Next enter terminal mode on your rasberry Pi. Type in "python -m serial.tools.miniterm" 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.