Need help with Softserial communication, bluetooth, Razor IMU, Nano

I have a Razor IMU from Sparkfun. It is programmed to spit out a stream of sensor data at 57600 baud serially.

I tried an example which has me hooking it up to an arduino nano using the GND, 3.3v, and tx/rx pins 0 and 1
I plugged the tx pin to the nano's tx1 pin and opened up the serial monitor.

The stream of data looked like this:
#YPR=100.56,-18.25,-178.22
#YPR=100.62,-18.12,-178.21
#YPR=100.51,-18.22,-178.31
etc.....

I seems to me that this setup has the data coming straight out from the IMU and through the serial port straight to the serial monitor on my pc...without really any processing by the arduino nano.... right???
What I really need it to do is to have it enter the arduino through a Software Serial port and then exit out the hardware serial port.
The reason is that in the next step of the project, I will have to combine it with additional data from two analog input pins from the Nano then the combined data stream will go out serially & wirelessly using a bluetoothmate gold to be received by my pc and then Processing will take over from there.... just trying to get there in baby steps...

When I try receiving the data through the software serial and outputting through the hardware serial port the serial monitor just shows a stream of unrecognizable characters... I know the bauds are matching on the monitor so its probably something to do with the type of data being transmitted and how it is being read at the other end... I am not sure where to begin solving this...

The code I used is based on the soft serial example included with arduino 1.0.2:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX

void setup()  
{
 // Open serial communications and wait for port to open:
  Serial.begin(57600);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(57600);
  }

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
 }

Any ideas????

I plugged the tx pin to the nano's tx1 pin and opened up the serial monitor.

Strange, since the nano doesn't have a TX1 pin. It has a TX pin.

I seems to me that this setup has the data coming straight out from the IMU and through the serial port straight to the serial monitor on my pc...without really any processing by the arduino nano.... right???

The RX and TX pins form the serial port. When you have three things on the port (the PC, the IMU, and the Arduino), you don't know what data is coming from where. Not a good thing, usually.

The reason is that in the next step of the project, I will have to combine it with additional data from two analog input pins from the Nano then the combined data stream will go out serially & wirelessly using a bluetoothmate gold to be received by my pc and then Processing will take over from there.... just trying to get there in baby steps...

Then you need to get the IMU off the hardware serial port.

Serial.write() sends binary data to the serial port. Serial.print() sends ASCII data. Serial.write() and Serial.print() do the same thing when the argument is a char. The do NOT do the same thing when the argument is an int.

You should be casting the value from Serial.read() (an int) to a char.

Any ideas????

Configure your IMU to use a lower baud rate. The SoftwareSerial will probably not work with 57600. The best value I got with SoftwareSerial is 38400, many device won't go higher than 9600 baud. The hardware serial port is much more than just a hardware version of the things SoftwareSerial do. The hardware is adapting the speed if the rates don't match exactly and does a lot of other things to make the serial communication as reliable as possible. The software version cannot do this stuff because just transferring a few thousand bits per second is using that much of the processors resources it doesn't have time to do the additional stuff.

If you want or need to use 57600 for the IMU, get a Mega2560, that one has 4 hardware serial ports. The other option is a Leonardo, the hardware serial port is free to use there because the communication with the PC (USB) is handled internally in the main processor.

Thanks for that, maybe that's why my data looks scrambled. The test software that sparkfun links to is set at 57600 so I just left it there really don't need anywhere near that speed.

The main reason I went with the nano is that it is small (this is a portable head mounted wireless device so space and weight are huge considerations). I also chose it because the IMU is 3.3v and the other sensors are 5v so it had both...
I was going to use a micro pro (or is it pro micro) from sparkfun but it only had one voltage out not both 3&5.

I just did a second test and tried to bypass the whole Software Serial issue altogether.
Since the IMU only feeds data out but doesn't read any, and the nano only needs to send the pc data but doesn't need to receive any, I tried using tx and rx (hardware) to serve both purposes.

What I found is that the data can be read by the nanos Rx pin and displays on the serial monitor just fine, but when I try to serial.println(Serial.read()); it comes out garbage

I hope its a baud rate issue...

Oh and PaulS.... what nano are you referring to??? My version 3.0 has a TX1 pin .... not that it gets me any closer towards a solution, but its definitely there
if its reading text in and outputting decimals or hex guess that could cause a problem if it isn't converted back... I think that's what you are trying to tell me... I'll also look into that but If I misunderstood let me know.

but when I try to serial.println(Serial.read()); it comes out garbage

Serial.read() returns an integer and Serial.println() prints an integer in ASCII representation, so that doesn't work. Try this:

Serial.write((uint8_t) Serial.read());

what nano are you referring to?

This one:

An RX pin and a TX pin. No RX1 or TX1 pins to be seen.

Don't set the hardware serial (Serial.) and the software serial (mySerial.) to the same baud rate will cause conflicts.

Don't set the hardware serial (Serial.) and the software serial (mySerial.) to the same baud rate will cause conflicts.

You have some proof of this statement? I do it all the time, with no problems.

Don't set the hardware serial (Serial.) and the software serial (mySerial.) to the same baud rate will cause conflicts.

I agree with PaulS. The two are quite independent and the baud rates are completely independent. The SoftwareSerial is using much of the processors resources and does turn of the interrupts for some time which might interfere with the hardware implementation (transferring from and to buffers) but these problems are not related to setting the same baud rate for both channels. They are related though to setting high baud rates in the SoftwareSerial, though.

They are related though to setting high baud rates in the SoftwareSerial, though.

A higher baud rate for SoftwareSerial would mean that an individual byte is received faster, resulting in interrupts being disabled for shorter times, wouldn't it?

On the other hand, it means that more bytes can be sent in any given period of time, negating the benefit of shorter times per byte.

Thanks for all the great info... I'll put it to use today and report back hopefully with news of success.
Btw PaulS that link shows the pic of a v2.2 nano... My nano is 3.0 if ur a little obsessive compulsive like me I can send a pic...it might also show in the eagle files???? Haven't checked

I am not having any luck with software serial.
What if I switch my nano for a Arduino Micro... looks like it has 3v and 5v outputs and it can get hardware serial inputs from my sensor and transmit USB... does this look like a better way to go???

photo.JPG

looks like it has 3v and 5v outputs and it can get hardware serial inputs from my sensor and transmit USB

Does you Nano really have two hardware serial ports? Nothing in the Arduino site mentions this.

The Micro does appear to have 2 hardware serial ports.

The Micro (ATmega32u4) is a miniaturized version of the Leonardo (more or less) and therefore has one hardware serial port but it has USB capability built into the main processor which enables it to communicate with a PC and use the hardware serial port at the same time. In your case it's almost as if the Micro would have two serial ports (one real, one virtual).

PaulS I meant when I mentioned dual ports it was in reference to the Micro not Nano... I started with the nano hoping to use SoftwareSerial as my second port but haven't had luck wiring/coding it yet so I thought the micro might be a good alternate route.

As for the circuit, here are the components:

If I just hook up power, GND, and TX on the IMU (the more square board pictured) I can read a stream of Text data that looks like this:

#YPR=100.56,-18.25,-178.22
#YPR=100.62,-18.12,-178.21
#YPR=100.51,-18.22,-178.31
etc.....

Now that IMU goes into some form of arduino so I can get analog inputs from two additional sensors.
Then a serial output from the arduino needs to go into the Bluetooth board (the skinny one pictured) so it can relay it into the pc.

The IMU is just outputting data and does not require input.

If any of you could help me with the right wiring method I would really appreciate it.

BTW the IMU is 3.3v only but the Bluetooth module works in both 3.3v or 5v.

If any of you could help me with the right wiring method I would really appreciate it.

Open your drawer. Drill a couple of small holes in the bottom of the drawer. Take some wire that will fit through the holes, and lash the bluetooth device down quite firmly. Close the drawer.

OK, now that you are only dealing with two pieces of hardware at a time, connect the 3.3 V pin to the 3.3 V pin on the Arduino. Connect the ground pin to a ground pin on the Arduino. Connect the RX(I) and TX(O) pins to two digital pins on the Arduino.

Create an instance of SoftwareSerial that uses those two pins. The RX on the IMU will be connected to the TX pin of the SS instance. The TX pin on the IMU will be connected to the RX pin of the SS instance.

Now, in a while loop in loop(), test for data on the SS instance. If there is any, read it and write it to the hardware serial port.

Let us know how that goes.

YES!!! finally something is working!!! PhilS, I tried the softwareSerial and your notes got it working although it was having some issues spitting out clean data from the Software port. By clean I mean that It was obviously the sensor data coming out but with some random intermittent noise... I need at least 9600 baud so maybe I'm pushing the 3v pro mini too hard.

I then found a Pro Micro 5v unit and did the same setup but without softwareSerial since it already has a hardware Serial and Serial1..... it worked great!!! Im getting sensor data in from serial1 and its being sent out USB its exactly what I need less wireless connectivity, but that can be another stage later on.

Right now it is at a point where I can attach the other analog sensors and have a working prototype in a day or two!!!

Thanks for all the help!!