Programming A BS2
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
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](http://forums.parallax.com/images/smilies/rolleyes.gif)
Comments
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
If you want to program your stamp IN Java, by all means get the Javelin kit.
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 Williams
Applications Engineer, Parallax
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
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