Pages: [1]   Go Down
Author Topic: SOFTWARE SERIAL PROBLEM??  (Read 2206 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everyone, I am using software serial to communicate with the WT32 bluetooth breakout board using the arduino uno.

However during start up, I get garbage characters...
W©P,$êJ
%”J   rÁÄui¶²HSÓ)©¤4yàyr­E”¬’   ÁÍu20˜˜H(«•Îi³XHªk‹¹oÍR¢P©+©¤ü

Instead, what I should be getting is something like.
WRAP THOR AI (2.3.0 build 79)
Copyright (c) 2003-2007 Bluegiga Technologies Inc.
READY.

I have trying to debug this for hours. I've made sure that the baud rate is at 115200 (which is the default UART settings of the WT32), as well as tied CTS to GND since I am not using hardware flow control. I've tried with different baud rates, but I am still getting garbage.

My example code is shown below.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9);// RX, TX
int resetpin = 13;
long time;
void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  mySerial.begin(115200);
  pinMode(resetpin, OUTPUT);
  Serial.println("Starting Up!");
  digitalWrite(resetpin, LOW);
  delay(200);
  digitalWrite(resetpin, HIGH);
  delay(200);
  digitalWrite(resetpin, LOW);
  delay(200);

}

void loop() // run over and over
{
//  time = millis();
  if (mySerial.available())
    Serial.write((char)mySerial.read());
  if (Serial.available())
    mySerial.write((char)Serial.read());

}
Please help me?!
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

are you using the serial monitor? I just finished a project for work where I was using an attiny85 with the internal clock and software serial, and no matter how slow I set the com port speed I would get garbage >75% of the time

flipping over to minicom, cutecom, or putty I never saw it happen, and went about life at 9600 baud (though I should be able to do much faster even with an uncalibrated internal oscillator, its only 3 bytes at a time in my case, so no biggie)

the stupid thing is now sitting in a test fixture happily humming along at 9600, but if I use the serial monitor ... bam garbage. Seems that there is something overly tight in that part of the application.
« Last Edit: July 08, 2012, 02:32:28 am by Osgeld » Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question

Code tags.
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The mention of PuTTY set me thinking.... and apologies if this is what the other post was already saying...

Perhaps you could, perhaps it would be worth trying...

Cut the Arduino out of the picture altogether for the moment. "Talk" to your serial device directly from a PC with PuTTY or similar... see if it will "behave" then. Maybe there's nothing wrong with your Arduino or program... but rather a fault in what you are connecting to?

Another thing to look at... are the bits in the data stream inverted? A "gotcha" which arises, and gives garbled output. If the output your program gets is consistent, or somewhat so, this could be what's going on.

For more on PuTTY....

http://sheepdogguides.com/arduino/art4SeIntro.htm

(There are also notes about other serial comms issues there.)

Hope something above helps.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ Osgeld

Yes I am using the serial monitor of the Arduino IDE to monitor the "software serial" that is connected to the WT32. Unfortunately I don't have a way to directly connect the COM port to the WT32 device :/, but is what you are trying to say is that although I see garbage on the serial monitor, I can still send valid commands even if I don't read them correctly?

@tkbyd
I've just tried inverting the signal, but I still get garbage.

What I'm noticing is that the garbage I got initially seems to share some characters that it SHOULD show. For example 
"W©P,$êJ
%”J   rÁÄui¶²HSÓ)©¤4yàyr­E”¬’   ÁÍu20˜˜H(«•Îi³XHªk‹¹oÍR¢P©+©¤ü"

Starts with W and R, which should spell "WRAP" in
"WRAP THOR AI (2.3.0 build 79)
Copyright (c) 2003-2007 Bluegiga Technologies Inc.
READY."


I've seen other posts of people using software serial to work with WT32, I am just confused as to how they did it :/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way that I can just use the Arduino's default UART serial instead of software serial?
I guess the thing I am confused about is that when I use "Serial.begin(115200)", I am just opening a serial channel between the computer IDE and the arduino right?
So for example, if I want to read something from the WT32,
Code:

int resetpin = 13;
void setup()
{
  Serial.begin(115200);
  pinMode(resetpin, OUTPUT);
  digitalWrite(resetpin, LOW);
  delay(200);
  digitalWrite(resetpin, HIGH);
  delay(200);
  digitalWrite(resetpin, LOW);
  delay(200);
}

void loop()
{
    if (Serial.available()>0)
  {
    Serial.println((char)Serial.read());
  }
}

But when I do serial.println, doesn't that just mean I am writing out what I am reading ONTO the WT32 as well? Is there a way that I can just use the arduino as a way to solely monitor the TX and RX pins?

Thanks!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I guess the thing I am confused about is that when I use "Serial.begin(115200)", I am just opening a serial channel between the computer IDE and the arduino right?
No. You are opening a connection to the serial port. Some application on the PC needs to open the other end. The Serial Monitor is one such application. The IDE is not.

Quote
But when I do serial.println, doesn't that just mean I am writing out what I am reading ONTO the WT32 as well?
Yes.

Quote
Is there a way that I can just use the arduino as a way to solely monitor the TX and RX pins?
Sure. Plug the BT into some other pins. The hardware uart can not be used for two separate purposes.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@PaulS

So you are saying that the purpose of the Tx/Rx on the arduino is only for communication between the computer and the arduino? Unless I use software serial, I can't use the serial monitor to communicate with a device connected to the arduino?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So you are saying that the purpose of the Tx/Rx on the arduino is only for communication between the computer and the arduino? Unless I use software serial, I can't use the serial monitor to communicate with a device connected to the arduino?
No, I didn't say that. I said that the hardware serial port (or a software serial port) can be used to talk to ONE other device. That device can be the BT device OR the PC. It can't be both.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I use hardware serial to talk to a RFID reader. You can even plug something into pin 0 (Rx) and receive from (say) a GPS, and still send debugging stuff out of pin 1 (Tx) to the computer. They would have to be at the same baud rate though.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Nick Gammon

Thank you for your recommendation, I now got the ready message from the unit.
The only thing I changed, was to NOT CONNECT the Tx of the arduino.
Here is the basic code

Code:
int resetpin = 13;
long time;
void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  pinMode(resetpin, OUTPUT);
  Serial.println("Starting Up!");
  digitalWrite(resetpin, LOW);
  delay(200);
  digitalWrite(resetpin, HIGH);
  delay(200);
  digitalWrite(resetpin, LOW);
  delay(200);

}
void loop() // run over and over
{
//  time = millis();

  if (Serial.available())
  {
    Serial.write(Serial.read());
  }
}

The results I got is


Starting Up!
WRAP THOR AI (4.0.0 build 317)
Copyright (c) 2003-2010 Bluegiga Technologies Inc.
READY.


It seems that the software serial is a bit buggy, because it should communicate similarly. I guess I will either keep trying to debug the software serial or code using the built in UART blindedly.

Thanks for all your guy's help!!!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there anyone who might have any suggestions as to why it only works with the hardware serial, as opposed to the software serial?
I feel like it might be because of the WT32's  high default baud rate of 115200.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Software serial, by its nature, is more likely to drop characters than hardware serial. At 115200 baud you are getting a character every 86.8 uS. That's not a heap of time over. You can do a bit in that time ... not a lot.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi anjianwu

I had a similar problem. Through hardware serial everything was fine but with the software serial I had the same problems like you.

Now I reduced the baud rate of the Bluegiga module and everything is fine now through software serial.

With this command you can configuring local UART to 9600bps, 8 data bits, no parity and 1 stop bit:
SET CONTROL BAUD 9600,8N1

Afterwards send
SET
and then
RESET

This works fine for me.

Cheers
Logged

Pages: [1]   Go Up
Jump to: