Shop OBEX P1 Docs P2 Docs Learn Events
Programming A BS2 — Parallax Forums

Programming A BS2

SolenoidSolenoid Posts: 2
edited 2005-09-28 14:51 in Learn with BlocklyProp
Hi Guys,

I am a novice to microcontrollers and electronics in general. I do have lots of experience in software though. I·have·downloaded the BS2 manual and FAQ and given them a cursory go through. The·"What is a microcontroller" section deals in examples where one uses the PBASIC editor to program the ·BS2. One can view DEBUG output from the BS2 in the editor too. I was wondering whether there is a way to program the BS2 to recieve instructions and send output to and from a JAVA program instead of the editor.

Please enlighten me rolleyes.gif

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-09-25 13:56
    Solenoid -

    Since I drink Java, and don't use it for programming, I can't help you directly there. However, you can easily establish an asynchronous serial link (RS-232) with a Stamp very easily using the SERIN and SEROUT commands. See the PBASIC Manual or the PBASIC Help File for more information.

    Just make sure you use the appropriate (common) BaudMode (aka baud rate, parity, inverted / non-inverted, etc) parameters as you may choose to specify (however it's done) in your Java program. The rest is pretty much a 2 or 3-wire connection (depending more on Java than the Stamp). Also be aware that the Stamp is only capable of half-duplex communication, which is usually not a barrrier to communication.

    Regards,

    Bruce Bates
  • ForrestForrest Posts: 1,341
    edited 2005-09-25 14:08
    You can only program the BS2 (and all the other BASIC Stamps) in BASIC. If you want to program in Java - you should get a Java Stamp www.parallax.com/javelin/index.asp
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-09-27 16:49
    Yes, you can run a JAVA program on your PC, which then talks to a BS2 programmed in PBasic, when then sends strings back which you can read in JAVA. If that's what you're talking about.

    If you want to program your stamp IN Java, by all means get the Javelin kit.
  • SolenoidSolenoid Posts: 2
    edited 2005-09-28 13:18
    Thanks allanlane5,

    Thats right I am looking at writing a JAVA program that communicates with a BS2. It should be able to listen to data sent by the BS2 and should be able to send back data to the BS2. I would also need a BS2 program that can listen to data sent from a PC and reply back. But, hardware communication looks like an abyss to me . Can you suggest some good sites with loads of sample code to give me a good start.

    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-28 13:38
    Give Jan Axelson's book "Serial Port Complete" a look -- it goes into a great deal of detail on these matters. For additional infor checkout her web site at www.lvr.com.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-09-28 13:59
    Solenoid -

    Parallax offers two distinct programming platforms, and two different versions of their Stamp modules. One is the Javelin Stamp which is programmed using a subset of the Java language. The other is the PBASIC Stamp which is programmed in a varient of Dartmouth Basic. Which of the two microcontroller platforms were you hoping to use? That will make the matter of providing sample programming code, and asynchronous serial communication tutorials a bit more doable.

    You might even want to write a short, simple program of your own, in pseudo-code (see below), and post it here or on the Java Stamp forum. I'm sure one of us would be happy to convert to the appropriate language (Java or Basic) for you persusal, just so you can get a feel for what you being faced with insofar as syntax and format is concerned. If your concern is with purely the hardware aspect, you can probably ignore this entire message.

    Sample of pseudo-code:

    read serial input, 3 data items (1 x text 1 byte, 1 x text 8 bytes, 8 x numeric 2 bytes each)

    save text data item

    if ID (first text byte) = "A"
    average all 8 numeric data items
    store average

    if ID = "M"
    find the median of 8 numeric data items
    store median

    if ID = "R"
    range the 8 numeric data items, finding the min and max
    store min, store max

    write serial output in the following format:
    8 byte text item, calculated value(s) (as above)

    End program

    Regards,

    Bruce Bates
  • gnomebotgnomebot Posts: 6
    edited 2005-09-28 14:51
    I wrote some java for a remote webcam platform I made with servos and a servo control board.

    It's basically just like a java servlet. open up a socket, wait for a command, read command, send serial data to com port, wait for a command.

    I wrote the command app to send the commands to the ip address: port of the remote computer.

    You will need to get the javacomm library from Sun.

    Attached is the library that was available for the servo control chip. It creates an object with all the serial port and servo control params included. It's been a while since I've done any work with java, so you can probably find the code you need quicker than I can.

    Hope this helps,

    Sean

    Post Edited (gnomebot) : 9/28/2005 11:32:47 PM GMT
Sign In or Register to comment.