Shop OBEX P1 Docs P2 Docs Learn Events
matlab and basic stamp 2 interface problems.. — Parallax Forums

matlab and basic stamp 2 interface problems..

wawlohwawloh Posts: 2
edited 2007-12-15 17:12 in BASIC Stamp
hi folks,
i'm trying to interface matlab to my BS2 and if it works, will blink
an LED

bs2 code :
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}
status_pin VAR Word

main:
SERIN 16,84,[noparse][[/noparse]DEC status_pin]
IF status_pin = 0 THEN LOW 8
IF status_pin = 1 THEN repeat
GOTO main

repeat:
PAUSE 500
HIGH 8
PAUSE 500
LOW 8
GOTO repeat


%matlab code :

status_pin = 1;
s=serial('com1')
set(s,'baudrate',9600)
set(s,'terminator','CR')
fopen(s);
fprintf(s,'%s\d',[noparse][[/noparse]status_pin]); %if data is sent, i should see the LED
blinking once this line is executed am i rite??
fclose(s)

any ANY help is very much appreciated..really frustrated with such a
simple code but nothing seems to work?!

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-15 06:50
    The baud rate for the serial string should read··SERIN 16,16468,[noparse][[/noparse]DEC status_pin], thats 9600 8 bit no parity inverted.

    Hope that helps put you on track

    Jeff T.
  • sylvie369sylvie369 Posts: 1,622
    edited 2007-12-15 11:59
    Okay, I'm new to this myself, and this raises a question.

    How do you know when it's inverted and not true? In this example, how did you know?

    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-12-15 16:08
    The IDE help file SERIN has a fairly good explanation to help get started
    the IDE help file said...

    Most circuits that work with RS-232 use a line driver/receiver. This component does two things: (1) it converts the ±12 volts of RS-232 to TTL-compatible 0 to 5-volt levels and (2) it inverts the relationship of the voltage levels, so that 5 volts = logic 1 and 0 volts = logic 0.

    All BASIC Stamps (except the BS1) have a line receiver on its SIN pin (Rpin = 16).

    Jeff T.
  • sylvie369sylvie369 Posts: 1,622
    edited 2007-12-15 17:12
    Thanks. I see. Bleeped right over that part when I was learning about serial communications.
Sign In or Register to comment.