I'm having some issues altering my sketch to make my arduino connect wirelessly through serial to my pc. Ultimately I want to be able to send a character on hyperterminal and have the arduino receive it and perform an action. Right now I can do this with a physical serial connection, the problem is the wireless. I'm using the bluesmirf silver v2.
For some reason the bluesmirf always starts up in command mode so I have to send an AT command to put it into data mode. The most successful method seems to be :
Serial.println("AT+BTCLT=address,port");
That is the only line I add into setup(), right after "Serial.begin(9600);". I tried various ports, and most of them wouldn't work. Though port 1 turned on the green connection light on the smirf, my computer didn't recognize the connection and I do not have a com port 1 on my computer What am I misunderstanding here?
Has your PC been "paired" with the bluetooth device? Make sure your BlueSMIRF is set to be 'discoverable' and then use the Bluetooth features of your PC to locate the device and pair with it. Once it's paired you should see it as a COM device.
that is probably it, the only time that my BTCLT command worked was when I had them paired. I removed the pair foolishly since it didn't seem like my computer recognized a connection after the BTCLT connected.
Aside from that though, I'm also suspecting a problem from my circuit setup. I have both the bluesmirf and a usb breakout board attached to my arduino, having them both attached prevents me from uploading sketches. Does it also prevent the bluetooth from connecting as well?
I expect that the USB board and BlueSMIRF are both trying to use the hardware serial port and getting in each other's way. You might be able to disconnect the USB interface and program the Arduino through the Bluetooth connection if you do a manual reset on the Arduino when you see the "Binary sketch size:" message in the sketch window.
hmm yea that makes sense, its really a pain how they interfere with each other. I've heard that its possible to program the arduino via smirf, but it seems quite a bit of trouble for my purposes.
Just so I'm completely in the clear in my sketch, here it is, nothing sticks out like a sore thumb i hope?
#include <Servo.h>
const int servoPin = 9; // control pin for servo motor
Servo myservo;
int angle = 86;
void setup()
{
myservo.attach(servoPin);
myservo.write(angle);
Serial.begin(9600);
//com port 12 and 13 are supposedly the serial ports to my bluetooth, or at least my bluetooth software tells me. I
// Serial.println("AT+BTCLT=0011E00*****,12");
Serial.println("AT+BTSRV=12");
}
void loop()
{
if (Serial.available() > 0) {
int moveServo = Serial.read();
//1-0,2-30,3-60,4-90,5-120,6-150,7-180
if (moveServo == '1') {
angle =0;
}
if (moveServo == '2') {
angle =30;
}
.... more of the same
if (moveServo == '7') {
angle =180;
}
angle = constrain (angle, 0, 180);
myservo.write(angle);
}
}
I decided to go with AT+BTSRV since it turns on discovery and allows me to pair, where AT+BTCLT just goes for a connection. I assume that since the smirf is server that my computer's bluetooth would/can be configured for auto-reconnect?
When the arduino is on and disconnected from the usb, I will pair with it and connect from my computer. If I do this, port 12 hopefully would be connected and I would be able to send chars through hyperterminal to the arduino. Does it seem like this would be fine? I fear of hidden settings that would make this not work, nothing ever works out smoothly as planned