Shop OBEX P1 Docs P2 Docs Learn Events
SERIN/OUT Via Web — Parallax Forums

SERIN/OUT Via Web

MaxMax Posts: 13
edited 2005-05-05 18:34 in BASIC Stamp
Hey all, I'm a physical computing newbie who's having some trouble with his midterm.

The goal: Allow someone to press a button on a website to switch an LED on and off.

So far, my understanding of the process is that I'll need to enable Serproxy on the machine attached to the BASIC Stamp which will receive information via TCP/IP streams converted to RS-232 streams by Serproxy. I want to start by just getting SERIN to work on my local machine without Serproxy.

I did a quick search through some recent posts and found a few threads that seemed pertinent, but I'm missing a few basic assumptions somewhere and I'm hoping you folks can help me out, since I couldn't glean anything from the help files (well-written as they are).

Here's my PHP code:

`mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
$fp = fopen ("COM1:", "w+");
if (!$fp) {
    echo "Uh-oh. Port not opened.";
} else {
    $string = "2000\n"; 
    fputs($fp, $string);
    echo $string;    
    fclose ($fp);
}



Here's my BS2 code:

' {$STAMP BS2}
' {$PBASIC 2.0}

MyByte VAR Byte
INPUT 7

Main:
  HIGH 2
  SERIN 16, 16384, [noparse][[/noparse]DEC MyByte]
  LOW 2
  PAUSE 500

  HIGH 7
  PAUSE MyByte
  LOW 7
  PAUSE 100
  HIGH 7
  PAUSE MyByte
  LOW 7
  PAUSE 100

  GOTO MAIN



I don't see why this isn't working. What I believe should happen is that $string should be converted to the length of the pause between turning the LED (connected to input pin 7). So, if $string is "2000\n" and you load the page, having already loaded the program onto the BASIC stamp, the stamp should receive $string via SERIN, pause for half a second, then proceed with HIGH 7.

What I don't understand is the exact significance of HIGH 2 and LOW 2. Is 2 the SERIN pin?

Thanks in advance, all!

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-04-21 06:44
    Max -

    Change your baudmode parameter from 16384 to 16468 and you should be good to go.

    As far as the Pin 2 reference is concerned, the person who wrote that program probably had an LED on that pin and was interested to see if and when the SERIN completed. That's just a guess, however.

    Regards,

    Bruce Bates
  • MaxMax Posts: 13
    edited 2005-04-21 14:39
    Bruce,

    Thanks! You have saved my life. I knew I should have read the baudmode portion of that help file closer... do you think I'll be able to figure out why 16468 worked and 16384 didn't by examining the documentation closer? I'd like to know how this stuff happens on as many levels as possible.

    Thanks again. I hope no one minds me posting more questions to this thread as my project progresses...
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-04-21 14:51
    Max -

    I'll be happy to tell you, but as you indicated it WOULD be best for you to go back and verify how you made the error. Nothing wrong with trial and error learning, so long as it doesn't become a way of life smile.gif

    What I suspect you did was to account for INVERTED logic (16384) in the BAUDMODE and neglected to add in the baud rate. The BAUDMODE parameter is NOT just the baud rate. It's composed of a number of elements, of which baud rate is only one.

    Regards,

    Bruce Bates
  • MaxMax Posts: 13
    edited 2005-05-03 01:31
    Hey guys, I've been perusing help files for weeks and I just can't figure this thing out. So, I ask the following question:

    How can I alter this code so that the web-user can turn on and off three different lights? For now, I'm not worried about refreshing the page every time they click - I can put JavaScript in later. I've seen code that looks like you can transfer multiple arguments using SERIN by just separating them with commas, but I can't get it to work.

    Also, is it erroneous to assume that if I transfer the DEC number 7 using SERIN to the variable "MyByte", I can then use "HIGH MyByte" and "LOW MyByte" to turn Input 7 on and off? It seems like it's wrong, because I couldn't get it to work. Is there another way to do this?

    Thanks, all.
  • MaxMax Posts: 13
    edited 2005-05-05 17:00
    Bumping this topic to the top... I hope that's permissible; I didn't see any help files prohibiting it.
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-05-05 17:16
    Hey Max,

    I assume that you are using the 'computer' for the ethernet interface, then connecting to your Stamp via RS232? Is this correct?

    Ryan
  • MaxMax Posts: 13
    edited 2005-05-05 17:23
    Ryan,

    That's correct. The computer has a local HTTP server that contains the PHP script. I'm going to use Serproxy when I move the script to an external HTTP server.
  • Tom WalkerTom Walker Posts: 509
    edited 2005-05-05 18:34
    It sounds to me like having your PHP script decide which lights to light and serially sending out a byte to indicate status (one bit per LED) would allow you to easily control 8 LEDs. You only need a nibble for 4 LEDs but the serial protocol as it is implemented is a byte-oriented one.

    HTH

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
Sign In or Register to comment.