SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By SVFeingold
#118263
So I'm having a bit of a problem...I am starting development of a prototype involving remote sensing.

I decided that it would be better - for the time being - to use an Arduino due to the wide user/knowledge base. I am currently trying to read data over I2C from a temperature sensor using an Arduino Pro 3.3V board, and send this over a bluetooth link (using the BTM-182) to a terminal program.

So far, the temperature sensor is working just fine, and I can connect to the bluetooth module, but after finally getting SOMETHING to print out over the terminal monitoring the Bluetooth serial port, all I get is gibberish!

My setup is as follows:

1) Arduino Pro (3.3V) with LiPo battery pack
2) Temperature sensor connected to +V and GND, and also to ANALOG IN ports 4,5
3) Bluetooth module (BTM-182) connected to Arduino. The connections are BTM RX -> Arduino TX-0 and BTM TX -> Arduino RX-1. I installed a small decoupling cap just near the bluetooth module's power supply, and attached three status LEDs to ports 5,7,8 on the bluetooth module. I also added a jumper between RTS and CTS on the BT module.

Here's a picture of the setup and of the bluetooth module pinout:

Image
Image

The two wires connected to the Arduino on the bottom right are not connected to anything else.

Anyway, I am using this code that I found to test to connection:
Code: Select all
/***********************
 Bluetooth test program
***********************/

int counter = 0;
int incomingByte;

void setup() {
  Serial.begin(115200);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital R, reset the counter
    if (incomingByte == 'R') {
      Serial.println("RESET");
      counter=0;
    }
  }
  
  Serial.println(counter);
  counter++;
  
  delay(250);
}
The code works fine with just the Arduino - I can monitor the serial port through the USB connection and see the printout of numbers. The RESET function works as well.

The problem comes when I try to introduce the bluetooth module. I used the same program but now connected the bluetooth module to the TX and RX pins of the Arduino as stated above. Based on the BTM-182 documentation (which is pretty sparse IMHO, I am starting to regret buying this module as nobody seems to use it) the default baud rate is 19200, data bit 8, parity 1, and flow control enabled.

I tried using several different terminal programs with those settings, but I get either nothing or gibberish. There are also usually 2-3 options for hardware flow control and I am not sure which one I should use. I tried all manner of different encodings (ANSI, ASCII, HEX, etc...) for decoding the data but I still get nothing but gibberish. Here's a screencap of the terminal program:

Image

So...what am I doing wrong? I feel like I'm so close but I don't know what other settings to try...I feel like I've tried them all. Perhaps it is something very simple, but this is my first experience with bluetooth and the lack of documentation about the BTM-182 is really discouraging. There are a billion articles about the bluesmirf and the xbee and etc... but for this just a command set and some specifications.

So, any ideas? I really appreciate any help. Sorry about the length but I tried to be thorough and provide as much info as possible - if I left anything out please let me know! Thank you once again.
By waltr
#118277
That is a very common problem when connecting new serial devices.
First try different Baud rates.
I see your RealTerm is set to 19.2k Baud and you code is set to:
Code: Select all
  Serial.begin(115200);
Next ensure that your device is sending ASCII characters.
Code: Select all
  Serial.println(counter);
  counter++;
This would be sending BINARY.
By SVFeingold
#118285
Yes I feel quite silly...not ten minutes after posting this I noticed the baud rate mismatch. After correcting that I am getting the correct output. A weird thing though, when I run the code I posted through the FTDI USB/serial converter it works exactly as it's supposed to, counting upwards (1,2,3,4,5...) until it receives an "R" at which point it prints "RESET" and starts from zero.

If I remove the FTDI usb/serial and do the same through bluetooth, it will randomly print RESET and start over several times in a row - even with no command to do so. After a minute it seems to "stabilize" and count up normally. Could this be a power supply issue?

I do feel like a dummy for not noticing the baud rates...live and learn I guess. :) Thanks for the reply!

EDIT: You mentioned ensuring that it is sending ASCII characters rather than binary. How would I do this? Would I send the numbers as strings rather than integers?
By waltr
#118287
I do feel like a dummy for not noticing the baud rates...live and learn I guess. :) Thanks for the reply!
Don't feel so bad, there is a good reason I listed this as the first thing to check. lol