Basic Stamp serial connection Raspberry Pi
Moi
Posts: 5
Hi,
I'm trying to connect a BS2 on a Board of Education Develompemnt Board - USB with a Raspberry Pi running Raspbian through serial connection via USB.
First I program the BS2 with an Windows PC, when I got it programmed unplug from PC and plug in the Raspberry Pi, then run the Python program.
The code I'm working in BS is attached:
and the python code:
I use dmesg to see in which ttyUSB is connected the BS since it changes everytime I plug and unplug the BS to the Raspberry.
When I exeute the Python code the led blinks, so I suposse the BS restarts and so the connection is made, but it's only a supposition, I'm just a begginer both BS and Raspberry Pi.
Although the led blinks it do not respond to the '1' and '2' inputs in the Raspberry Pi and I really don't know why. What am I doing wrong?
Best regards,
Mois
I'm trying to connect a BS2 on a Board of Education Develompemnt Board - USB with a Raspberry Pi running Raspbian through serial connection via USB.
First I program the BS2 with an Windows PC, when I got it programmed unplug from PC and plug in the Raspberry Pi, then run the Python program.
The code I'm working in BS is attached:
' {$STAMP BS2} ' {$PBASIC 2.5} Baud CON 84 SerialPin CON 16 state VAR Byte HIGH 9 PAUSE 200 LOW 9 Main: SERIN SerialPin, BAUD, [state] IF state = 1 THEN HIGH 9 ELSEIF state = 2 THEN LOW 9 ENDIF PAUSE 1000 GOTO Main
and the python code:
import serial ser=serial.Serial(port='/dev/ttyUSB2', baudrate=9600, bytesize=8, parity=''N', stopbits=1, timeout=None) print("Starting!") while True: val=raw_input('Value: ') ser.write(val) if val == '1': print('LED ON') elif val =='2': print('LED OFF') elif val=='exit': ser.close() exit() ser.close()
I use dmesg to see in which ttyUSB is connected the BS since it changes everytime I plug and unplug the BS to the Raspberry.
When I exeute the Python code the led blinks, so I suposse the BS restarts and so the connection is made, but it's only a supposition, I'm just a begginer both BS and Raspberry Pi.
Although the led blinks it do not respond to the '1' and '2' inputs in the Raspberry Pi and I really don't know why. What am I doing wrong?
Best regards,
Mois
Comments
Hello!
What was the problem and how did you solve it?
The problem as you've described it isn't solved since you didn't change the settings from "unsolved" to "solved". So what was the solution?
Best regards,
Mois
and it should be:
You have to know which port is the BS attached to the RPi, the first time you plug it usually would be '/dev/ttyUSB0' but if you unplug it and plug it again it may have changed so you can type dmesg in the command line to see in which ttyUSB is connected the BS and edit that parameter.
Although isn't the main problem it's true that in the write lines should be "1\n" and "2\n".
So the final Python code is:
Finally I've seen you have changed the SerialPin from 16 to 15, I've used 16 because if Rpin is set to 16, the BASIC Stamp uses the dedicated serial-input pin (SIN, physical pin 2), which is normally used by the Stamp Editor during the download process.
I let you the code you have on the other post with little modifications, I think this should work:
Unfortunately I no longer have the BS so I can't try it by myself.
Here you have a little video I made when I was starting this project: http://youtu.be/4zM54iNZajs
Best regards,
Mois
Congratulation on the project! Looks great.