I have:
Arduino Pro 328 - 5V/16MHz
Bluetooth silvermate RN-42
Arduino protoshield v2
I try to receive something from arduino to serial monitor but I don't receive anything.
This is the initial code from sparkfun:
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
// and loop forever and ever!
}
This is mine right now:
#include <SoftwareSerial.h>
int bluetoothTx = 0; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 1; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
Serial.print("hello");
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
bluetooth.print("Hello world");
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop()
{
bluetooth.print("Hello world");
Serial.print("hello");
delay(1000);
}
Why are you using pin 0 and 1? They are your hardware Serial, can do that with software serial and using Serial at the same time... there was a reason they used pin 2 and 3....(and don't keep comments that do not match your code)
While the first code is insane and very clearly suggests that your Bluetooth is unsuitable for use with most Arduinos, it might work. Just make sure your wiring is correct. I assume you mean a Pro Mini, and I understand the pins on them are sometimes not well marked. If it does work, it is only because the idiot that wrote it got lucky. Software serial is unreliable at any speed above 38400, and the author knows that but he hopes you're lucky too.
The second code is about the same but you might get a result if you leave the wiring where it is - on D0,D1. Then use.
void setup()
{
Serial.begin(115200); // Begin the serial at 115200bps for bluetooth
}
void loop()
{
Serial.println("hello");
delay(1000);
}
J-M-L:
Why are you using pin 0 and 1? They are your hardware Serial, can do that with software serial and using Serial at the same time... there was a reason they used pin 2 and 3....(and don't keep comments that do not match your code)
Pin 2 and 3 are occupied by a sensor. I tried to use pin 5 and 6 ( randomly selected ) but still no results. I used pins 0 and 1 because I though it'll work like a ftdi.
Nick_Pyner:
While the first code is insane and very clearly suggests that your Bluetooth is unsuitable for use with most Arduinos, it might work. Just make sure your wiring is correct. I assume you mean a Pro Mini, and I understand the pins on them are sometimes not well marked. If it does work, it is only because the idiot that wrote it got lucky. Software serial is unreliable at any speed above 38400, and the author knows that but he hopes you're lucky too.
The second code is about the same but you might get a result if you leave the wiring where it is - on D0,D1. Then use...
This is the arduino i use ( not pro mini ) :
Today I'll test your method and I'll come with an answer. Thank you.
krazilec:
Pin 2 and 3 are occupied by a sensor. I tried to use pin 5 and 6 ( randomly selected ) but still no results. I used pins 0 and 1 because I though it'll work like a ftdi.
OK, we all learn. While the pin markings are very clear, I can't see the point of it, but all Arduinos are much the same as far as this problem is concerned and my comment stands - 115200 is no good in software serial, but fine in hardware serial. Hence the code I posted.
If, after great care, you really cannot get the first programme to work, it is not necessarily down to you. It is just as likely that, as anybody except the idiot who wrote it would expect, it is not possible to get a coherent software serial signal through to bluetooth @ 115200 in order to get it slow down to something you can use with software serial. Any success in this arena is probably down to luck.
The idiot's comment, clearly written
// 115200 can be too fast at times
should really read
// 115200 should always be regarded as too fast
I think there is a way out of this to configure bluetooth, but just try the posted code at the moment. At least it might give some peace of mind.
OK, we all learn. While the pin markings are very clear, I can't see the point of it, but all Arduinos are much the same as far as this problem is concerned and my comment stands - 115200 is no good in software serial, but fine in hardware serial. Hence the code I posted.
What you suggest is not a great design choice in my opinion. What is going to happen if you send something from the arduino IDE console and the BT at the same time ? Having 2 serial devices connecting to one hardware serial unit is not great - all the more when you have one in 5V and te other possibly in 3v...
OP Does need two serial ports - and needs to ensure voltage adaptation between BT Rx and ARDUINO software Tx and make sure baud rate is acceptable.
I do have software serial working fine at rates faster than 38k with care at connexion level, power and understanding also on interrupts dependency to not create bottlenecks
J-M-L:
What is going to happen if you send something from the arduino IDE console and the BT at the same time ?
Read the code. There is no provision for sending something from the monitor, so the answer to your question is: nothing. It is just a substitute for the code OP is currently using, which has no provision either. I submit it is quite kosher to use the monitor to see what is going on, thereby proving alles in ordnung, but that is all.
I imagine OP has had a gutful of instructions about how to set this up and what to do, hence my comment about retrying the original code, but it is pretty clear that the real problem is that this bluetooth is a rather poor choice for use with Arduino.
I have never heard of anybody claiming reliable operation under software serial at 115200 before but, again, we all learn. If you can get get the poor bugger's gear to work on software serial at 115200, now is the time to strut your stuff while the gathered multitude watches. You will notice that very little coherent signal has to get through, so go for it.
Read the code. There is no provision for sending something from the monitor, so the answer to your question is: nothing. It is just a substitute for the code OP is currently using, which has no provision either. I submit it is quite kosher to use the monitor to see what is going on, thereby proving alles in ordnung, but that is all.
Sure I get that - but what prevents an operator from typing something? this is not robust. That's why I say it's not a great design choice in general.
have never heard of anybody claiming reliable operation under software serial at 115200 before but, again, we all learn. If
well - I said "faster than 38k". I get correct behavior at 57.6K on a 16MHz arduino. indeed I don't push to 115200.
Also if you look at the documentation, looks like Mikal Hart is claiming it... It's documented as
The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.
The version of SoftwareSerial included in 1.0 and later is based on the NewSoftSerial library by Mikal Hart.
OK. Probably a triumph, but utterly irrelevant, and I don't know why you bothered raising the matter when you know full well that 115200 is the only speed that counts.
Nick_Pyner:
OK. Probably a triumph, but utterly irrelevant, and I don't know why you bothered raising the matter when you know full well that 115200 is the only speed that counts.Ah yes, I do remember that. I recall that the general view was that Mikal Hart is a bloody liar.
I don't think that is a fair assessment. SoftwareSerial DOES work at 115200. The caveat is that the data transfer quantity must be relatively small. 20 characters per second is possible. 2000 characters per second is really pushing things. The Arduino can not be doing much else.
I tried some of the ideas but none of them seems to work.
I tried to connect tx and rx to other "ports" than 0 and 1 but I don't receive anything from my arduino.
I tried this one with 0 and 1:
void setup()
{
Serial.begin(115200); // Begin the serial at 115200bps for bluetooth
}
void loop()
{
Serial.println("hello");
delay(1000);
}
And I receive some weird signs. When I changed the Serial.begin to 9600 the arduino gave me nothing ( no weird signs, nothing ). I don't understand where is the problem ...
There I read that on arduino pro 328 I must reverse rx with tx and not as I initially connected them :
Incorrect:
RX-1 -> RX
TX-0 -> TX
After reversing them I have the exact same result ( no data sent ) .
As test code I tried this:
void setup()
{
Serial.begin(115200); // Begin the serial at 115200bps for bluetooth
}
void loop()
{
while(Serial.available()){
char incoming = Serial.read();
Serial.print(incoming);
}
}
I tried to decrease the serial down to 9600 but I got nothing.
The TX-O and RX-I pins could really be connected to any digital pin (besides 0 and 1), so if you need 2 and 3 for something else, feel free to move those around.
And I receive some weird signs. When I changed the Serial.begin to 9600 the arduino gave me nothing
I guess that proves nothing is broken, nothing is wrong with the wiring, the pairing is OK, and the code is probably OK too. At least the is little doubt about what you are trying to send. Getting weird signs like ASCII symbols or Greek etc. is usually a sign that the speeds are mismatched but you have consistently tried the only speeds that matter and, even if you did change bluetooth to 9600, I don't think it sticks. Indeed, I guess you have proven that too.
After all you have done, there is a faint possibility that the problem is at the other end - the computer. Can you try Arduino with an Android? I only raise this because there are no grey areas in setting up with Android, and I don't know what other success you have had with the computer. You need a standard Android terminal app, like Bluetooth Terminal.
I might also point out that, while I said this is a poor choice of bluetooth, which I'm sure is true, it is not useless, you are not the first to use it, and it will probably be fine in the end. I just wish to hell that some of the others who actually have used it would jump in with a comment.
J-M-L:
What do you do on the PC side? How do you know it's paired? Is that the one you have? Can you show a picture of your setup? Does it look like this?
This is the one i own .
On windows I just pair through windows settings , i put the password and voila it's paired. Than i go to serial monitor from the arduino ide and the light from the bluetooth turns green ( this means that the arduino succesfully connected to windows ) .
Nick_Pyner:
I guess that proves nothing is broken, nothing is wrong with the wiring, the pairing is OK, and the code is probably OK too. At least the is little doubt about what you are trying to send. Getting weird signs like ASCII symbols or Greek etc. is usually a sign that the speeds are mismatched but you have consistently tried the only speeds that matter and, even if you did change bluetooth to 9600, I don't think it sticks. Indeed, I guess you have proven that too.
After all you have done, there is a faint possibility that the problem is at the other end - the computer. Can you try Arduino with an Android? I only raise this because there are no grey areas in setting up with Android, and I don't know what other success you have had with the computer. You need a standard Android terminal app, like Bluetooth Terminal.
I might also point out that, while I said this is a poor choice of bluetooth, which I'm sure is true, it is not useless, you are not the first to use it, and it will probably be fine in the end. I just wish to hell that some of the others who actually have used it would jump in with a comment.
Thank you for your advice, I didn't thought at this one. I'll try to test out on android to see if it gives me something.
On windows I just pair through windows settings , i put the password and voila it's paired. Than i go to serial monitor from the arduino ide and the light from the bluetooth turns green ( this means that the arduino succesfully connected to windows ) .
Have you tried to
upload the code
power your unit not from USB
disconnect USB cable / FTDI (is this what you use?)
opening up a Serial terminal on windows and connected to the Bluetooth Serial port