Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« on: June 14, 2007, 07:51:11 am » |
Hi all,
I've a quistion; has somebody used the INQUIRY command that is in the IWRAP manual? I'm trying to use it to search for other devices in teh area and save the Bluetooth adresses in a array, but I don't get the information back to the arduino or to processing. Could somebody give me a lead were to search for more information or a good example how to use the commands from the manual on the way that I could use the information that I get back from the bluetooth module.
Thanks in advance.
Gr... Arjen
|
|
|
|
|
Logged
|
|
|
|
|
Forum Administrator
Offline
Newbie
Karma: 3
Posts: 0
|
 |
« Reply #1 on: June 14, 2007, 09:48:11 am » |
i've done it the only thing is that the data comes back to arduino when it's not connected to the computer... if the computer is connected the arduino "Serial" port is busy talking to it.
there are two ways... 1 send the escape code to switch to command mode... send inquiry... collect the data.. send the escape again (now you're back in contact with the comp) and send the data back to the computer.
2 display the data on an lcd display on the arduino.
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #2 on: June 19, 2007, 06:52:12 am » |
Thanks for your response!
I'm trying to get the first option working. Sending the escape command has worked. But then I get a problem with saving all the incoming data. I think the problem is that I never know how much data is comming back, so that I can save it in a sting and send it later back to the computer. I'm also not sure about when the INQUIRY has ended so that I can send again the escape command and send the data back.
Could you help me with those problems?
Thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #3 on: June 21, 2007, 05:09:07 am » |
Is it possible to use the multiplexing mode to control the IWRAP module and the computer at the same time?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 183
|
 |
« Reply #4 on: June 21, 2007, 05:38:46 am » |
One of the problems with saving your data in an array is memory usage. You have only 1k of memory available so you can't make a huge array. I tried increasing the serial buffer but it didn't work either. I don't get the complete response from the WT11 and after the initial output of the WT11 it always sends 14 characters at a time. I don't have a clue what is going on.
Multiplexing would be interesting. BUT, if you set the WT11 to multiplexing and you want to change something of the WT11 parameters you have a problem, unless multiplexing is working flawless right away. Because in multiplexing the ASCII commands don't work anymore. You might try to escape this with the SET CONTROL BIND for a command issued by a signal on a pin of the WT11. But, I have had no luck yet with the hardware control on the WT11 pio's.
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #5 on: June 21, 2007, 06:27:24 am » |
So multiplexing will not work. Can somebody help me with the right settings for the control echo. I think that I don't do it on the right way.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 183
|
 |
« Reply #6 on: June 21, 2007, 06:33:33 am » |
So multiplexing will not work. Can somebody help me with the right settings for the control echo. I think that I don't do it on the right way. NO NO NO NO don't touch the control echo! If you do that then the WT11 will mess up programming the arduino. Not only are sending the program but there will also be events from the WT11 on the TX line to the atmega. NO NO NO NO don't touch the control echo! NO NO NO NO don't touch the control echo! NO NO NO NO don't touch the control echo! (I learned from experience >  )
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #7 on: June 21, 2007, 07:43:47 am » |
Could somebody help me with example code for switching from data to command mode. Preforming a command like the call or inquiry command and then switching back to the data mode?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 183
|
 |
« Reply #8 on: June 21, 2007, 07:53:38 am » |
Could somebody help me with example code for switching from data to command mode. Preforming a command like the call or inquiry command and then switching back to the data mode?
Yeah, I would to see a piece of code for that. But sondag, you already had the escape sequence working you said. Did you try an inquiry with little output, store it in a string and then switch back to datamode with the escape sequence? Let's say LIST, with only 1 connection there will be a "LIST 1" line and a "LIST 0 xxxxx" from your currenct connection.
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #9 on: June 21, 2007, 04:57:15 pm » |
At least I've got it working, here is the code:
#include <TextString.h>
int ledPin = 13; // LED connected to digital pin 13 int resetPin = 7; // BT module uses pin 7 for reset char inByte = 0; // incoming serial byte TextString incomingString = TextString(100);
void setup() // run once, when the sketch starts { pinMode(ledPin, OUTPUT); // sets the digital pin as output pinMode(resetPin, OUTPUT); Serial.begin(115200); // start serial at 115200 kbs }
void loop() { // if we get a valid byte, read analog ins: if (Serial.available() > 0) { inByte = getbyte(); // get incoming byte if (inByte == '&' ) { // look for a & getInfo(); }else if (inByte == '@' ) { // look for a 0 digitalWrite(ledPin, LOW); // set led LOW Serial.print("Get string: "); Serial.println(incomingString.getArray()); //print string Serial.println("Cleared string"); incomingString.clear(); // empty string }else{ saveCharToString(inByte); // no right char then save it to sting } } }
void getInfo() { digitalWrite(ledPin, HIGH); // set led HIGH delay(2000); Serial.print("+++"); delay(2000); Serial.println("INQUIRY 5"); for (int i=0; i <= 10; i++){ delay(1000); while (Serial.available() > 0) { inByte = getbyte(); // get incoming byte saveCharToString(inByte); // no right char then save it to sting } delay(1000); } delay(2000); Serial.print("+++"); delay(2000); digitalWrite(ledPin, LOW); // set led low }
char saveCharToString(char inByte) { incomingString.setCharAt(incomingString.length(), inByte); // save char to string at last position }
char getbyte() { while (Serial.available() == 0) { //look for aviable data // do nothing, wait for incoming data } return Serial.read(); //return data if aviable }
When you send in the serial monitor from arduino the symbol "&", the Arduino BT will start an INQUIRY. A led will blink that is connected on port 13. When the led go's off the INQUIRY is ready. You can send then a "@" to get the data back in the serial monitor.
Thanks all for your help!
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 183
|
 |
« Reply #10 on: June 21, 2007, 05:56:49 pm » |
Very nice. I changed the inquiry to SET so I could see the parameters of the module. I tried to get the interruts on the pio's working but did not succeed. Thanks to your program I could see that I didn't have these bind commands. I already got the parameters from the WT11 before but I couldn't believe that there were so little settings. Your programs shows the same, so, for some reason my set control bind commands don't stick.
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #11 on: June 21, 2007, 06:06:37 pm » |
When you get it working please let me now. Thanks in advance!
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 183
|
 |
« Reply #12 on: June 24, 2007, 01:28:16 am » |
I am still struggling with the SET CONTROL BIND. Your code was helpfull but I still haven't figured out why the BIND doesn't work. I changed your code a bit because I had the feeling that the output is not always complete. I store the output in the eeprom and read it back afterwards. #include <TextString.h> #include <EEPROM.h>
int ledPin = 13; // LED connected to digital pin 13 int resetPin = 7; // BT module uses pin 7 for reset char inByte = 0; // incoming serial byte int infoSize = 0 ; void setup() // run once, when the sketch starts { pinMode(ledPin, OUTPUT); // sets the digital pin as output pinMode(resetPin, OUTPUT); Serial.begin(115200); // start serial at 115200 kbs }
void loop() { // if we get a valid byte, read analog ins: if (Serial.available() > 0) { inByte = getbyte(); // get incoming byte if (inByte == '&' ) { // look for a & infoSize = getInfo(); } else if (inByte == '@' ) { // look for a 0 digitalWrite(ledPin, LOW); // set led LOW Serial.print("Get string: "); for(int i=0;i<infoSize;i++) //eeprom print lus { Serial.print(EEPROM.read(i)); } Serial.println(); Serial.print("Cleared string size: "); Serial.println(infoSize); } } }
int getInfo() { int j=0; digitalWrite(ledPin, HIGH); // set led HIGH delay(2000); Serial.print("+++"); delay(2000);
Serial.println("SET"); //Serial.println("SET CONTROL BIND 0 8 FALL INFO"); //Serial.println("SET BT PAGEMODE"); //Serial.println("SET BT ROLE"); //Serial.println("INFO"); for (int i=0; i <= 10; i++){ delay(1000); while (Serial.available() > 0 && j <512) { inByte = getbyte(); // get incoming byte EEPROM.write(j, inByte); j++; } delay(1000); } delay(2000); Serial.print("+++"); delay(2000); digitalWrite(ledPin, LOW); // set led low return j; }
char getbyte() { while (Serial.available() == 0) { //look for aviable data // do nothing, wait for incoming data } return Serial.read(); //return data if aviable }
|
|
|
|
|
Logged
|
|
|
|
|
Utrecht, The Netherlands
Offline
Newbie
Karma: 0
Posts: 21
Postmachina
|
 |
« Reply #13 on: June 24, 2007, 03:05:02 am » |
I think that the problem is the serial buffer. I found out that the serial buffer is 128 characters big. I'm not sure of the ArduinoBT in command mode can save characters out off the serial buffer in the mermory of the chip. If that's not a problem then it should not matter if you save the data in the eeprom like you do or in a string like I did. Hopes this will help.
Has somebody tried to get the serial buffer bigger and how does this go?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 183
|
 |
« Reply #14 on: June 24, 2007, 03:41:14 am » |
I forgot, I change the serial buffer constantly. It is i wiring_analog.c. But the serial buffer is in RAM if I am not mistaken, so increasing the buffer decreases space for your variables. Since you only have 1k there is a limit to what you can do.
Try changing it. At some point I also printed out the returned size of the string. If that equals the serial buffer you know that you are missing info. I also increased the textstring size. Eventually I tried the eeprom.
|
|
|
|
|
Logged
|
|
|
|
|
|