Bluetooth RN41 does not respond - arduino

I want to send some commands to my RN41 Bluetooth Module connecting to Arduino Leonardo over the serial port using serial monitor, as the tutorial shows. But it does not respond. I can connect to the bluetooth modul and the status LED blinks right. I tried to send $$$ to change to command mode, and the blink rate does change to 10/sec, but module responds nothing. And when I send '---', the blink rate back to normal. I think it means the connection is successful but I just cannot see anything at serial monitor.
I set monitor's baud to 9600, as exactly the tutorial shows. (https://learn.sparkfun.com/tutorials/using-the-bluesmirf/example-code-using-command-mode)
Do you guys know what could be wrong?
Code attached:
/*
Example Bluetooth Serial Passthrough Sketch
by: Jim Lindblom
SparkFun Electronics
date: February 26, 2013
license: Public domain
This example sketch converts an RN-42 bluetooth module to
communicate at 9600 bps (from 115200), and passes any serial
data between Serial Monitor and bluetooth module.
*/
#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!
}

I was stuck on very simple case:
To enter command mode you have to send $$$ without any CR/LF.
after you entered command mode you have to send commands, and every command has to be followed by CR LF. if not - module will not response.
Hope that helps.

Yes, send only 3 characters, "$$$". I was also stuck for a bit. I also found that reading the Mate response "CMD" is necessary, which is not shown in the published sketch.

I've got some brandnew RN41VX modules.
I connect them by a XBEE Explorer USB module (almost same as RN41 EVAL Kit) to computer.
Using a terminal with 115 kbaud I send $$$ (without any trailing chars as 0x0d) to get into command mode. The LED switches to 10Hz blinhking - all fine.
But no respone appears in terminal.
Solution:
I had to switch on RTS Signal, even if manual tells "Flow Control: none"
kind regards Volker

Related

Arduino: Having trouble connecting/writing AT commands to Bluetooth HC05 module via USB serial

As an introduction, I bought myself an arduino and a few modules to learn some software stuff. The project is to eventually connect to a bluetooth OBD2 reader on my car to display real time data on a small LCD.
The problem
I am either not able to connect to, or not write to, my HC05 module via software serial. I think I have narrowed this down to a couple possibilities.
I am unable to connect to the module in the first place.
I have a Mega 2560 and HC05.
5V <-> VCC
GND <-> GND
D2 <-> RXD
D3 <-> TXD
Note that I have seen 9600 and 38400 baud rates for connecting but neither worked, so I made this function to try them all for me...
//set up serial relay into HC05.
SoftwareSerial hc05(2,3);
//computer serial baud rate 115200
bool hc05_connect() {
long baud_list[] = {300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400};
Serial.println("Attempting to connect to HC05 bluetooth module...");
bool success = 0;
for (int i=0; i<(sizeof(baud_list) / sizeof(baud_list[0])); i++) {
Serial.print("Baud rate ");
Serial.print(baud_list[i]);
Serial.print("...");
hc05.begin(baud_list[i]);
hc05.write("AT");
delay(1000);
if (hc05.available()) {
Serial.println(" successful!");
success = 1;
return success;
} else {
Serial.println(" failed");
}
}
return success;
}
Notes:
This has always returned failed for every baud rate.
I have the bluetooth module in command mode, initiated by pressing the button as I supply power.
I have tried unplugging the TX/RX pins while uploading the sketch. No difference noted.
My attempts to send commands to the HC05 are failing.
Below is my function for sending commands to the module.
void loop() {
// listen for communication from the ESP8266 and then write it to the serial monitor
if (hc05.available()) {
Serial.write(hc05.read());
}
// listen for user input and send it to the ESP8266
if (Serial.available() > 0) {
Serial.println("Writing to hc05...");
Serial.println(Serial.available());
Serial.println(Serial.read());
hc05.write(Serial.read());
}
}
I have added in a few lines which write back to Serial so I can see what's being sent, and the monitor returns weird stuff. For example, if I send "AT", this is what the monitor reads:
Writing to hc05...
3
65
Writing to hc05...
1
10
Notes:
Why is it sending 2 different items?
Why is it sending integers rather than the characters I said?
Does this indicate I'm just sending it nonsense commands so it's not responding?
I can provide full code if you want, this is already a huge textwall though. Please help me!
Edit
So I have been able to get communication two ways via the bluetooth module using a modified version of the code in this instructable: https://www.instructables.com/How-to-Set-Up-and-Test-Arduino-Bluetooth-Connectio/
I was able to send from PC only and not receive to an android bluetooth terminal using SoftwareSerial with HC05's RX - TX0 / TX - RX0.
And I was able to receive to PC and not send using hardware serial / Serial1 with HC05's RX - TX1 / TX - RX1.
So now I have RX - TX0 / TX - RX1. It seems to communicate through terminal like this.
void setup() {
Serial.begin(9600); //open the serial port
Serial1.begin(9600);
}
void loop() {
if (Serial1.available()) {
Serial.print("(Received)");
Serial.println(Serial1.readString()); // send from serial to bluetooth
}
if (Serial.available()) {
Serial.print("(Sent)");
Serial.println(Serial.readString());
Serial1.println(Serial.readString()); // send from bluetooth to serial
}
}
But if I apply this to my code, I still can't get it to work.
Before I try to hack this together, why am I getting serial to work across 2 different serial channels? Weird...
Okay, so I figured it out. (I can't say I fully understand, but maybe this will help people in future.)
1. Unable to connect to module
Thanks #ukBaz for suggesting I connect with the terminal app on my phone, this allowed me to debug the connection to the module in the first place. and #Juraj for suggesting that the Mega uses hardware serial.
Serial1 apparently is broken on my board, so I am using Serial3. I bluetoothed to the device with my phone, and was able to send commands back and forth between Serial and Serial3 both on 9600 baud rate. Here is the code I used:
void setup() {
Serial.begin(9600); //open the serial port to PC
Serial3.begin(9600); //open serial port to HC05. TX -> 15, RX -> 14
}
void loop() {
if(Serial3.available()){
Serial.print(Serial3.readString()); // send from serial to bluetooth
}
if(Serial.available()){
Serial3.print(Serial.readString()); // send from bluetooth to serial
}
}
I suspect I was using the wrong read/readString and write/print/println for my purpose initially.
2. Unable to issue commands to the module
Once I got that working, I changed the baud rate to 38400, and tied the STATE pin of the module to VCC (rather than using the button). Uploaded code, disconnected 5V, reconnected 5V, reset arduino.
At that point, I could issue "AT" to the module via Serial Monitor, and receive "OK" back. Woohoo!
I think I understand now that #hlovdal was suggesting that I was issuing a command to the module and never parsing a response I got, so it was.. clogged parhaps? In any case. I can now successfully issue commands and receive responses from the module.
Thanks everyone for your help.
There are some problems with how you are communicating AT command lines to your device. For instance:
hc05.write("AT");
delay(1000);
You do not send an AT command to a modem, you send an AT command line that contains zero or more AT commands, followed by a command line terminating character (that always should be '\r', aka carriage return (or <CR>)).
You are missing that terminating character here, so the modem will never send you a reply, because you have not sent it a command line.
And also, you should never, ever use delay as a substitute for reading and parsing the responses that the modem sends back. See this answer for some more details.

Program is executing but AT commands not showing in serial monitor

My purpose was to send SMS using GSM SIM800L coreboard and Arduino UNO. Here is the code
#include <SoftwareSerial.h>
//Create a software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(115200);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(115200);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CMGS=\"+ZZxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print("TEST"); //text content
updateSerial();
mySerial.write(26);
}
void loop()
{
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
And here is the serial monitor output
22:31:19.430 -> Initializing...
However, when I run the code, I get the text message to my mobile phone, but I can't see any AT commands in the serial monitor. It only outputs "Initializing..." .
All the connections and baud rates are okay, checked a thousand times. Has connected 2A, 4.4v power supply to the GSM coreboard and shorten the wires, and sho No bad soldering joints. GSM module red led flash per 3 seconds. And again, I'm getting the text message to my phone. So that means the problem is with the Arduino serial monitor or code, not in the hardware. I need to see AT commands because I need to put more commands through the serial monitor, I tried typing and click send, But it's not showing anything. Any assistance you can provide would be greatly appreciated.
Your logic is reversed in the updateSerial() function.
Actually, you are sending the AT command over mySerial at the setup function, then you need to wait for the answer to come in that object mySerial.
So, you should do the while (!mySerial.available()) ; to be able to read something from it. Once this loop ends, you can read from mySerial.
However, you want to forward it to the serial monitor so, you also need to check if the Serial is available to be written to, that is why you also waits for it, resulting in the while (!mySerial.available() || !Serial.available()) ;.
Once you are sure both serials are available, you can read from one and write what you just read into the other one: Serial.Write(mySerial.read()).
Also, I do not see any need for the mySerial.write(Serial.read()) call, because the Serial is being used just to forward what you are receiving from the SIM800L, thus, you could simply remove that part.
Thus, the correction of your function would result in this:
void updateSerial()
{
delay(500);
while (!mySerial.available() || !Serial.available())
;
Serial.write(mySerial.read());
}
So, with this, everything you receive from the SIM800L is forwarded to the serial monitor.

arduino suddenly shows "avrdude: ser_open(): can't open device "\\.\COM3" after last upload

I am using arduino uno to make a sound detector.
I uploaded a program, found error in the code that it returns unintended numbers unreasonably big. I also think I used wrong code for the module, but it was connected in the way that can work properly with the proper code.
The code I uploaded was:
const int ledPin =13;
const int middleValue = 512;
const int numberOfSamples =128;
int sample;
long signal;
long averageReading;
long runningAverage = 0;
const int averagedOver = 16;
const int threshold=400;
void setup(){
pinMode(ledPin, OUTPUT)
Serial.begin(9600)
}
void loop(){
long sumOfSquares = 0;
for (int i=0; i<numberOfSamples; i++){
sample = analogRead(0);
signal = (sample - middleValue);
signal *= signal;
sumOfSquares += signal;
}
averageReading = sumOfSquares/numberOfSamples;
runningAverage=(((averagedOver -1 )*runningAverage)+averageReading)/averagedOver;
if(runningAverage>threshold){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
Serial.println(runningAverage);
}
When the arduino suddenly stopped sending serial numbers, I pressed reset button and uploaded the default code:
void setup() {
}
void loop() {
}
but now it shows that it cannot connect to COM3 (arduino) and cant find the device, When I can see arduino uno successfully connected to PC using device manager (windows 8.1). The led light of arduino also turns on when I connect it to power source or usb.
it shows "port not found" when I click to see the serial output
Did I just fry Arduino?
How should I fix this?
Also, i checked the led pin 13 blinking three times when i plug in the usb. I just cant upload anything
What worked for me:
Tools>Port>(your COM)
Just selecting that solved the error.
You should do a few checks in order to jump to a conclusion, your Arduino may be just fine. As far as I know, Code cannot destroy a controller.
Check if any other software is using the same serial port. Two softwares cannot use the same serial port at the same time
Restart your PC and then try again
Remove the Microcontroller from the board, connect it to the PC and try to open the com port. If it opens then connect your Tx pin with the Rx pin, send some data and check if you are getting the data back. This way you will ensure your USB-TTL converter is fine
If this goes successful, then insert your microcontroller in some other board and check if it is getting programmed
I am sure after these checks you will find out the reason of the failure of your board/microcontroller.
Yes, check everything.... especially the USB cable or the USB port. It is crucial. My problem was just dirt on the computer USB port. Dirt, dust and grime. Crazy isn't it ? Just clean up the USB port and connector and the problem solve.
I also had a same problem and solved it.
try this one.
1. disconnect all cables from your arduino
2. connect external power
3. connect usb cable
4. then upload it.
I used my arduino with CNC shield(GRBL) and plugged external power to arduino.
after this. it was not possible to upload new firmware to arduino with usb cable only.
Once you success to upload with usb + external power then you can upload any firmware with usb cable only.
To solve the problem.
Method-1:
Go to Tools>Port>Select the Port
Method-2:
Unplug your board and plug it back in.
Method-3:
Restart your computer or laptop and reinstall Arduino software.
For more details you can visit "https://arduinopoint.com/fix-most-common-error-uploading-to-arduino/"

Arduino Timing issue with Digi Xbee V1 Read function in Loop()

I am beginning to work with XBee RF Modules and have a general concern as to how and why this timing issue occurs... The two XBee do indeed communicate, and I am testing one thru Shield on Arduino Uno and the other via USB Connector on PC and X-CTU. The code is (generally) as follows, using the sample code from Sparkfun as a base (located at https://learn.sparkfun.com/tutorials/xbee-shield-hookup-guide)
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}
void loop()
{
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Xbee.write("ready");
Serial.write(XBee.read());
}
}
My concern comes with the fact I am sending packets of 2 ASCII chars (2 digits, 10, 20, 30, etc) just to test. In the console monitor of X-CTU, I notice the following. (bold being received, italic being sent.)
10 readyready 20 readyready 30 readyready etc...
Can someone explain to me in layman's terms of how this is occurring? I cannot understand how the code executes in this order.
You're using "AT mode" or "transparent serial" mode on your XBee, so characters arrive one at a time. There isn't any packetizing going on.
So you send a packet with 10 from X-CTU. The XBee on your Arduino receives that packet and starts sending the payload to the Arduino. The Arduino receives 1 which triggers the code to send ready in response. Then the Arduino receives 0 and sends another ready.
You would need to add some sort of framing to your serial stream (like adding a carriage return after each line of data) or switch to API mode (which delivers network payloads wrapped in headers and a checksum) if you want to look at your data in chunks, instead of as a stream.
I haven't used it, but there's an xbee-arduino library designed for using XBee modules in API mode on Arduino microcontrollers.

Seeedstudio SIM900 Arduino GPRS Shield V2.0 does not reply response to terminal

I have Arduino Leonardo and Seeedstudio GPRS Shield v2.0. Both of them working seamlessly.
Following tutorial on main gprs shield link here, I've succesfully compiled the following code to arduino:
//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0; // counter for buffer array
void setup()
{
GPRS.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the Serial port of Arduino baud rate.
}
void loop()
{
if (GPRS.available()) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
while(GPRS.available()) // reading data into char array
{
buffer[count++]=GPRS.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
GPRS.write(Serial.read()); // write it to the GPRS shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
{ buffer[i]=NULL;} // clear all index of array with command NULL
}
the code above take AT Command from serial as input and pass it to gprs module. So, I could type something like: "ATD + +1XXXXXXXX" which code to call numbers, and it worked. The problem is I can't get response from gprs module serial, it's just blank after. I read that the response to serial terminal should be: "OK". My questions are:
a. Is there something I missed? I want to get response written to the terminal.
b. I want to make http request, does someone has experience how to do it? What I mean is this gprs opening website blablablabla.com/cs/blabla.php?name=blabla
thx before
It's possible that your SIM900 is in "Result Codes Suppressed" mode. When in this mode, it simply doesn't send result codes such as "OK".
Try to send it an "ATQ0" command to get it to transmit result codes. (Take a look at the ATQ command in the AT Command Manual).
I'm by no means an expert on this stuff, but...
At no point do I see a line which would print or display data.
Example:
Assuming you established something like a variable: int inByte=0 at the beginning
like your buffer[count++] or BufferArray(), which I'm somewhat unfamiliar with
then you could retrieve the data by using
Serial.println(inByte);
or
GPRS.println(inByte);
which would display this info in your COM port window
So....?
something like
Serial.println(buffer[count++]);
or
GPRS.println(buffer[count++]);
Both of which will compile BTW
Examples with 7 pin with Leonardo do not work. With 10 pin (need connect a wire instead jumper) work ok.

Resources