Communicating serially with a Propeller Proto Board

3 views (last 30 days)
Hi all,
I'll preface this by saying that while I have a fair bit of programming in Matlab and Python under my belt, and some electronics knowledge, I'm very new to serial communication. It doesn't seem to complicated in principle, but I'm still getting used to all the jargon, etc.
I have built a simple circuit with an IR emitter and a phototransistor that outputs high/low voltage when the IR beam is unbroken/broken. I use a Propeller Proto Board to detect this change in volage, and want to have it communicate with a computer via a simple serial connection when the beam is tripped, so the computer can play a sound file. My objective is summarized like this:
  • have the IR trigger a voltage change
  • have that voltage change read by the Propeller Proto Board
  • have the board tell the computer the trigger has been activated, and
  • have the computer play a sound file
I've written a program in the Spin programming language (written by Parallax, the company who makes the Proto Board) to load onto the Proto Board that reads these voltages on pin 0, and communicates them to the Parallax Serial Terminal. Here's the code, in case anyone reading this is familiar with Parallax.
CON
_xinfreq = 5_000_000
_clkmode = xtal1+pll16x 'The system clock is set at 80MHz
OBJ
pst: "Parallax Serial Terminal" 'call parallax serial terminal object
'PUB Main | T1, T2, TT
PUB Main
pst.start(115200) 'start terminal
dira[0]~ 'set P0 as an input
repeat
pst.str(string("the binary state of Pin 0 is",9))
pst.Bin(ina[0],1) 'give the binary state of P0 note, 0- beam unbroken, 1- beam broken
pst.str(string(10))
pst.str(string(13)) 'terminator bit is the line feed (LF) character
'pst.Chars(pst#NL,1)
'pst.Chars(pst#NL,1)
waitcnt(clkfreq/2+cnt) 'waits 0.5s after completing the code to restart loop
Using this program, I am able to display the simple text "the binary state of P0 is...", so I've been informed by the Parallax community that the computer and the board are definitely communicating serially. I figured my next step is to try and reproduce the messages displayed on the Parallax Serial Terminal using a Matlab script. I've worked through a bunch of the documentation, and have been trying this script:
s = serial('COM3','BaudRate',115200)
fopen(s)
out = fscanf(s);
fclose(s)
delete(s)
clear s
The problem I'm having is that Matlab doesn't read anything - it keeps timing out, and 'out' is being assigned an empty list. As I mentioned, I'm fairly new to serial communication, and apart from ensuring I'm using the correct COM port and baud rate, I really don't know where to start troubleshooting. I'm pretty sure I'm not setting something right no Matlab, though, as I'm getting messages on the computer using the Parallax program.I really wish I could be of more help here...
Any help or advice would be much appreciated, and I'd be happy to provide any info that would help you in helping me
Much thanks!
-Mark
  1 Comment
rwl7532
rwl7532 on 26 Oct 2022
Seeing you have no answer, have you solved your problem? Did you try COM2 or a different BAUD rate?

Sign in to comment.

Answers (0)

Categories

Find more on Troubleshooting in Instrument Control Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!