Pages: [1] 2   Go Down
Author Topic: Need help with Softserial communication, bluetooth, Razor IMU, Nano  (Read 2559 times)
0 Members and 1 Guest are viewing this topic.
Los Angeles
Offline Offline
Full Member
***
Karma: 1
Posts: 148
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:

#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????
« Last Edit: November 19, 2012, 06:34:01 pm by fxmech » Logged

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

Quote
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.

Quote
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.

Quote
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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Los Angeles
Offline Offline
Full Member
***
Karma: 1
Posts: 148
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 19, 2012, 08:52:19 pm by fxmech » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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:

Code:
Serial.write((uint8_t) Serial.read());
Logged

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

Quote
what nano are you referring to?
This one:
http://arduino.cc/en/Main/ArduinoBoardNano
An RX pin and a TX pin. No RX1 or TX1 pins to be seen.
Logged

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

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

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

Quote
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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

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

Quote
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.
Logged

Los Angeles
Offline Offline
Full Member
***
Karma: 1
Posts: 148
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Los Angeles
Offline Offline
Full Member
***
Karma: 1
Posts: 148
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 (109.08 KB, 640x480 - viewed 32 times.)
Logged

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

Quote
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.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Los Angeles
Offline Offline
Full Member
***
Karma: 1
Posts: 148
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2   Go Up
Jump to: