Seeedstudio Bluetooth module with Arduino

Hi there,

first of all, sorry for my - maybe terrible - english. ; )

I’m using your Serial Port Bluetooth module:
seeedstudio.com/depot/serial … th=139_142

with my Arduino Pro mini 3V 8mhz.

My problem is, that when I send a command to the Bluetooth module it returns strange values.
I created following code: main.cpp

#include <WProgram.h>
#include "NewSoftSerial.h"

extern "C" void __cxa_pure_virtual(){
  for (;;);
}

NewSoftSerial bluetooth(3,4);

void sendbt( const char pCommand[] ){
	char cmd[3+strlen(pCommand)+2];
	strcpy( cmd, "\r\n+");
	strcat( cmd, pCommand );
	strcat( cmd, "\r\n");
	bluetooth.print(cmd);
	Serial.println(cmd);
}

int main(void)
{
	init();

	char a, b;
	int bla;

	Serial.begin(9600);
	Serial.println("And go.");

	bluetooth.begin(38400);
	//sendbt("STBD=38400");
	delay(1000);

	sendbt("STNA=myBluetoothName");
	delay(1000);

	sendbt("STWMOD=0");

	delay(2000);

	pinMode(13, OUTPUT);

	for (;;){
		if( bluetooth.available() ){
			bla = bluetooth.read();
			Serial.print(bla);
			Serial.print(" ");
			if( bla < 127 )
				Serial.println( (char)bla );
		}
	}
	return 0;
}

So, when I run this programm and look at the Serial-Console it returns on every run another result (even bigger), the returned values looks something like this.

[code]And go.

+STNA=myBluetoothName

+STWMOD=0

43 +
85 U
34 "
9
142 43 +
23
186 180 26
183 66 B
23
57 9
130 82 R
104 h
135 152 2
252 43 +
85 U
34 "
9
142 95 _
170 166 161 144 253 29
7
114 r
162 86 V
104 h
143 152 33 !
128 253 29
7
114 r
162 86 V
248 43 +
85 U
34 "
9
142 43 +
21
186 180 26
183 66 B
7
114 r[/code]

So, as you can see, it returns many times ascii codes higher than 128 and other stupid things.
I thought that i will receive something like:

+OK

But only the first char (+) is always right.

Maybe someone else runs in this situation too and can give me a hint - its really frustrating.

Greeting,
Marc

After playing a bit with the command, i’ve got now a better result, but again, unreadable:

[code]
bluetooth.begin(38400);
sendbt(“STBD=38400”);
delay(1000);

sendbt("STNA=myBluetoothName");
delay(1000);

sendbt("STWMOD=0");

sendbt("INQ=1");

delay(2000);[/code]

Result

[code]And go.

+STBD=38400

+STNA=myBluetoothName

+STWMOD=0

+INQ=1

43 +
85 U
34 "
29
239 43 +
85 U
34 "
9
14
17
34 "
9
43 +
85 U
34 "
9
14
17
34 "
9
206 43 +
85 U
34 "
9
14
17
34 "
9
14
131 235 190 161 167 237 10

43 +
85 U
34 "
9
14
17
34 "
9
14
131 187 180 128 167 16
61 =
141 43 +
85 U
34 "
29
47 /
21
34 "
9 [/code]

I don’t have a bluetooth module, but the string you pass to bluetooth.print will not be null terminated. (strlen doesn’t count the terminating null character, so you need +1 just to accommodate the original string, then add the space required for your additional chars.)

Hey,

thanks you for your reply and hint. I’ve fixed that but this doesnt change the result. So, I’ve changed the bluetooth module to a new one yet und tried the same code with some more commands: The result is now way better, but again, partially with strange output. My first guess was, that the wires are broken or not fine soldered, but i’ve changed the wires many many times with no difference.

[code]And go.

+STBD=38400

+STNA=blaa

+STWMOD=0

+STAUTO=0

+STOAUT=1

+INQ=1

13
13
10

83 S
83 S
84 T
130 ‚
68 D
61 =
51 3
56 8
100 d
48 0
48 0
13
10

13
10

159 Ÿ
75 K
13
22
13
13
10

83 S
83 S
84 T
158 ž
65 A
61 =
98 b
108 l
193 Á
97 a
13
18
13
10

175 ¯
79 O
146 ’
75 K
58 :
167 §
76 L
65 A
174 ®
69 E
210 Ò
13
10

13
10

91 [
66 B
84 T
163 £
84 T
193 Á
84 T
69 E
114 r

[/code]

Looks like you are at least communicating now (although with lots of errors).
I missed that you are using a mini running at 8Mhz.
Which version of NewSoftSerial are you using? According to the spec, with an 8Mhz board, v9 or v10 only work reliably up to 31.25K baud and v8 only works to 14.4K.
See if it you can get it working with a lower baud rate.