Javelin Stamp & eb500. Help write code to check the state
Hello everyone,
My Name is Yosuf and I am a new member.
For a project at my study we are using Javelin and eb500 to communicate with pc program via bluetooth.
The boebot will be connected to the pc. A program written in java will listen to a button on boebot. if the button is pressed, the program should know that and will take some steps further.
I have attached the eb500 to the board and it can be found and I can connect to it and make a serial connection on port60.
But my main problem is how can I write a java code to listen to a button which is located on the board?
I was thinking of something like a thread which sends masks to the board and calculates wether the value is changed. Or are there some easier ways?
I am a beginner in programming and I can only work with Java.
All your help is welcome.
Thankyou in advace.
wbr
Yosuf
My Name is Yosuf and I am a new member.
For a project at my study we are using Javelin and eb500 to communicate with pc program via bluetooth.
The boebot will be connected to the pc. A program written in java will listen to a button on boebot. if the button is pressed, the program should know that and will take some steps further.
I have attached the eb500 to the board and it can be found and I can connect to it and make a serial connection on port60.
But my main problem is how can I write a java code to listen to a button which is located on the board?
I was thinking of something like a thread which sends masks to the board and calculates wether the value is changed. Or are there some easier ways?
I am a beginner in programming and I can only work with Java.
All your help is welcome.
Thankyou in advace.
wbr
Yosuf
Comments
import stamp.core.*;
public class one{
static Uart EB500RX = new Uart(Uart.dirReceive,CPU.pin0, Uart.dontInvert, Uart.speed9600, Uart.stop1);
static Uart EB500TX = new Uart(Uart.dirTransmit,CPU.pin1, Uart.dontInvert, Uart.speed9600, Uart.stop1);
//The manufacter recommends that on each start up you run this code (coverted from the PBasic example)
public static void main()
{
// eb500 clear & Initialize
if (CPU.readPin(CPU.pin5) == true)
{
System.out.print("EB500 is alive in DATA mode, clearing.....");
// drive pin LOW
CPU.writePin(CPU.pin6,false);
CPU.delay(2000);
// disconnect
EB500TX.sendString("dis");
EB500TX.sendByte(13);
System.out.println("ok");
}
else
{
System.out.print("EB500 is alive in CMD mode, clearing.....");
EB500TX.sendByte(13);
EB500TX.sendByte(13);
System.out.println("ok");
}
}
}
Welcome to the forum.
Assuming you have the eb500 connection working, all you need
to do is implement a protocol for exchanging data with your
pc program.
A simple protocol would be:
the pc sends a command
the javelin repsonds with data
Uart ebRx = new Uart(Uart.dirReceive,CPU.pin0,Uart.dontInvert,Uart.speed9600,Uart.stop1);
Uart ebTx = new Uart(Uart.dirTransmit,CPU.pin1,Uart.dontInvert,Uart.speed9600,Uart.stop1);
static void main() {
· eb500.connect(); //assuming·you have a connect function
· while (true) {
··· if (ebRx.byteAvailable()) { //check for command send by pc program
····· int cmd = ebRx.receiveByte();
····· switch (cmd) {
······· case 0x01: //assuming cmd 0x01 is "read pin 2"
······················ if (CPU.readPin(CPU.pin2)) {
························ ebTx.sendByte(1); //respond with 'true'
·······················}
······················ else {
························ ebTx.sendByte(0); //respond with 'false'
······················ }
······················ break;
····· } //end switch
··· } //end if
· } //end while
}
regards peter
Would you please look at my second reply in this post?
thank you for the response. What I mean with I the connection which I have is that I can connect my eb500 via Bluesoleil and make a serial connection.
I have tried to make a serial connection by any java program, but it just doesn't work.
so the code you just posted me, I can program it on my javelin. Do you have any example how I can communicate from pc?
Thank you
http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/wireless/eb500/
That should make it easy to setup a connection.
regards peter
I cannot program my javelin anymore. It is right after I programmed the following code:
public static void main()
{
// eb500 clear & Initialize
if (CPU.readPin(CPU.pin5) == true)
{
System.out.print("EB500 is alive in DATA mode, clearing.....");
// drive pin LOW
CPU.writePin(CPU.pin6,false);
CPU.delay(2000);
// disconnect
EB500TX.sendString("dis");
EB500TX.sendByte(13);
System.out.println("ok");
}
else
{
System.out.print("EB500 is alive in CMD mode, clearing.....");
EB500TX.sendByte(13);
EB500TX.sendByte(13);
System.out.println("ok");
}
}
I get error ide-0054
if I choose manually a port by debugger, it give me cannot find any javelin. Very wierd.
the javelin JIDE port to the pc?
Try disconnect the eb500 from the javelin.
Recycle power to the javelin.
See if the javelin test connection works.
(closing and restarting IDE is also a good idea)
regards peter
I tried everything. Pc restarted, ide restarted, reset the eb500, but no success, also the power suppy and everything else.
But it happened right after I programmed the above code. Is there any possibility it would have affected it?
br
http://forums.parallax.com/showthread.php?p=656527
Usually soldering a 1k resistor between pin SIN (2) and pin GND (4)
of the 24 pin socket, resolves this problem.
I don't think the code you downloaded has affected the javelin
but it is a small program and sometimes a small program has this
effect.
regards peter
The 1K resistor worked. I soldered 2 times 470 ohm in serial between Sin and GND as I didn't have a 1K resistor and it works! I can program it again.
I have no experience with serial communication so far. So I will now have to take a closer look at it.
Meanwhile all your help is welcome.
p.s.
as you mentioned on your example, how can I make the connect class? eb500.connect(); mentioned in your example above
See this thread
http://forums.parallax.com/showthread.php?p=618934
for a little explanation of the eb500_test class.
The eb500 class merely transmits commands and assembles responses.
See this thread (forelast post)
http://forums.parallax.com/showthread.php?p=467798
how to connect.
When·I have some·time I will write some higher level connect method
that simply returns true when connected. For now the example
given in the above thread is the best guide to get it to work.
regards peter
It has really helped me out alot!
I can now successfully connect the board to eb500 and see wether it is in cmd mode or data mode. I have also succeeded to transmit a true or false via bluetooth. The only thing I still have to do is to write a class in pc to listen to the serial port and upon recieving a message like a byte, it should let me know.
Any simple java example which listens to serial port?
thank you very much. I hope I am not asking too much [noparse]:)[/noparse]
br
Yosuf
http://www.captain.at/howto-java-serial-port-javax-comm-rxtx.php
regards peter
EB500TX.sendString("somd data");
EB500TX.sendByte(13);
What does the second line do here? ends the command?
br
as given, so the CR character is also transmitted to the pc.
You could have written:
EB500TX.sendString("somd data\r");
To get back to command mode, just call eb500.commandmode();
To get into datamode, call eb500.sendCommand(eb500.ReturnToDataMode);
regards peter
It finally worked! I really have to thank you for your help! Thank you very much for your great help.
The board is equipped with EB500, One led and one push button.
when the board is started it will automatically make a connection with the pc upon which it enters data mode.
The button is used to send a signal to the pc. when the button is pressed the led is turning on too and by release it goes off.
The button also makes a connection to the pc if there is no connection by some means or the connection is broken.
The PC is equipped with a blutooth usb dongle which is being used with Bluesoleil. Bluesoleil makes automatically incomming comport which is very usefull for me.
Then there is a serial port listener, written in java which listens to the desired comport. When the button on boebot is pressed, the program will catch the signal and I go further with my program.
Without your help, it wouldn't have been accomplished successfully I think.
I will soon post my very beginners code.
have a nice time and until the next time,
wbr,
Yosuf