Pages: [1] 2 3   Go Down
Author Topic: Serial Communication  (Read 2481 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For a senior project, I am trying to get an Arduino Duemilanove to talk to a Microstrain InertiaLink unit (a 3 axis accelerometer and 3 axis gyroscopes). I have a MAX 232 chip installed to insure the two units talk in TTL language. How can I send a command "0xC2" which is the initiating command to prompt the Microstrain unit to output acceleration and angular rates?

Thank you
Logged

UK, Southwest
Offline Offline
Full Member
***
Karma: 5
Posts: 138
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure I'm answering the right question, but

char c = 0xc2;
Serial.print(c);

should do what you want.

(Are you using the standard hardware serial line, because when I used a serial connection to a MAX 232 as well as the USB serial port, I had to disconnect the MAX 232 connections to serial pins 0 and 1 to allow the bootloader to work.  Duemilanove board.)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well thanks. here is what i have but dont see a response.

#include <SoftwareSerial.h>
 
#include <NewSoftSerial.h>
 
 
int Tx = 1;                 // Set Tx to 1
int Rx = 0;
int incomingByte = 0;     // for incoming serial data
 
 
void setup()
{
  pinMode(Tx, OUTPUT);      // sets the digital pin as output
  pinMode(Rx, INPUT);
char c = (0xC2);              //44 equal Hex 2C
Serial.print(c);
delay(1000);
 
 
            Serial.begin(115200);      // opens serial port, sets data rate to 9600 bps
}
 
void loop() {
 
            // send data only when you receive data:
            if (Serial.available() >= 0) {
                        // read the incoming byte:
                        incomingByte = Serial.read();
 
                        // say what you got:
                        Serial.print("I received: ");
                        Serial.println(incomingByte, DEC);
            }
}
Logged

UK, Southwest
Offline Offline
Full Member
***
Karma: 5
Posts: 138
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm confused about your hardware connections.  Can you post a schematic please.

I think you are NOT using SoftwareSerial, the Serial.xxx calls are to the hardware serial port, which is the build in UART, on pins 0 and 1.

You need to connect your Inertial Link to some other pins, then use SoftwareSerial to define a software serial port on those pins.  

Have a good look at the softwareserial manual page.
 - What pins are allowable?
 - What pins are not good ones to use?
 - Can you find the example?
 - In the example, how is the port declared and started?
 - In the example, how is a call to a softwareserial port made?

 I don't understand the comment in the code either - what speed are you trying to talk to the Inertial Link?

What speed are you trying to talk to the host computer?

(I'm happy to answer more questions, but will not be around for the next 4 days or so now.  I have been working an implementation of
a software serial, driven by interrupts, for slower serial speeds and have been using a MAX232 chip  - but for general purpose stuff you are right to use software serial or new software serial).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well thank you. this was not my latest progress but the coding is generically the same. The software serial was not used and forgot to comment it out on this one. Dont worry about the comments but the content of the code for I want 115200 baud rate to communicate with the Inertia Link. The code works enough to send a command signal "0xC2" out to the Inertia Link. The protocal manual says it needs to be a command byte of 0xC2. So instead of char c = 0xC2, should it be byte c = 0xC2?

does the output of a square O, y with two dots over it, and a A with a carot over it mean anything?
Logged

UK, Southwest
Offline Offline
Full Member
***
Karma: 5
Posts: 138
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A byte and character are both 8 bits long; it won't make any difference for your serial output.  The print statement should print out the single character value if given a char type.  It should print out the number representing the value if given a byte.  So I think that char is the right one to use.

The funny characters could be that you are receiving at the wrong speed.

I still don't understand how you are talking to the Inertial device and the COM port on your computer using the same port.
Your code is going to - send 0x2c on the serial port (to the Interial Device?)
Next its going to send <whatever you receive> on the serial port (to the Intertial Device?)
« Last Edit: April 26, 2009, 05:13:56 pm by shelleycat » Logged

UK, Southwest
Offline Offline
Full Member
***
Karma: 5
Posts: 138
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code is wrong too:

- you need to start the serial port BEFORE sending out data.
- don't think you need to set the TX and RX pin directions, that's already done for you.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

start the serial port?

if it is wrong, I would still get the light to flash on on the Inertia Link signifying a data byte received?
Logged

UK, Southwest
Offline Offline
Full Member
***
Karma: 5
Posts: 138
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Blackdragon,
I'm just pointing out that you are starting the serial port after using it.  That is not how you are supposed to use it, so your results in terms of speed or output may be peculiar. It might output at some default speed if used before starting it, and the Inertial receive light might flash but receiving garbage.

You seem to be ignoring my questions about your hardware configuration.  I think that might be key to your system working and would be happy to give advice if you provide some type of schematic or diagram of how your connections are done.

I still cannot understand how you are talking to both the Inertial device and your host computer using one serial port.  If you can address that, it might help.

I've got to go now, back on Thursday or Friday.   Good luck.

P.S.  Have a look at Serial.begin on http://arduino.cc/en/Reference/HomePage and then have a look at Serial.print(b, BYTE).
« Last Edit: April 27, 2009, 01:39:59 am by shelleycat » Logged

Califonia, US
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:

Code:
int incomingByte = 0;     // for incoming serial data
char c;

void setup()
{
Serial.begin(115200);
c = 194;              //194 equal 0xC2
Serial.print(c);
delay(1000);
}

void loop() {

           // send data only when you receive data:
           if (Serial.available() >= 0) {
                       // read the incoming byte:
                       incomingByte = Serial.read();

                       // say what you got:
                       Serial.print("I received: ");
                       Serial.println(incomingByte, DEC);
           }
}

Based on your posts I can't tell if the code should actually be 0x2C or 0xC2, the posts say C2 but your code comments looked like 2C, if it's wrong change the c initialize statement to c = 44;

Are you connecting the device to the TX/RX pins of the Arduino and expecting the Serial.print() statements to debug to the screen via USB?  If so you may need/want the software serial after all.  

If you have a character LCD lying around try debugging using that instead of the serial line.  Program the Arduino, disconnect the USB, and hit reset and see if messages start showing up on the LCD.
Logged

Cheers!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Update: i got the unit to run in continuous mode now so i know i have a lot of data coming at me. i am now using the following: i cleared up the comments so it is clear. I am now getting 32 1s do to the binary output. any suggestions to get more readable data? should i make a pure transmit pin (not pin 1) and the receive pin as 0 to ensure there is no interference when i write "i receive" ?


#include <NewSoftSerial.h>

//===========================================================================
// SetContinuousMode
//---------------------------------------------------------------------------
// Start continuous mode
//===========================================================================

NewSoftSerial SerialIn(0, 1);

int incomingByte = 0;      // for incoming serial data
  
void setup(){
  //pinMode(Tx, OUTPUT);
 // pinMode(Rx, INPUT);
  SerialIn.begin(115200);      // opens serial port, sets data rate
  //delay(100);
 
  byte a = B11000100;  //binary for 0xC4
  SerialIn.print(a);
  byte b = B11000001;   //binary for 0xC1
  SerialIn.print(b);
  byte c = B00101001;  //binary for 0x29
  SerialIn.print(c);
  byte d = B11000010;  //binary for 0xC2
  SerialIn.print(d);


 
 if (SerialIn.available() >= 0) {
 

 }
}
//delay (100);

void loop() {

      // send data only when you receive data:
      
            // read the incoming byte:
            incomingByte = SerialIn.read();

            // say what you got:
            SerialIn.print("I received: ");
            SerialIn.println(incomingByte, BIN);
      
}

Thanks
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well THANK YOU so much mdowning   I cannot believe it was so simple. You dont know how many hours went into this. So now I just need to pull off the data into readable numbers for acceleration and angular rate? I am still abit unsure how to seperate this out, but this definitely puts me forward to the next step.
Logged

Califonia, US
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have a link to the microstrain datasheet or do you know how it spits the data back over the serial line?  That should offer some clues.

I'm guessing here, but if it sends data as multiple bytes that will always come in the same order (X acc, Y acc, Z acc, for instance) you can change your if statement from waiting for any data to be received to when a certain amount of data is received.

if (SerialIn.available() > 0) changes to

if (SerialIn.available() >=3) meaning there are at least 3 bytes in the buffer.

Then in the loop you can assign each of the three bytes to a different variable, or read it into an array in a way that makes sense.

I actually haven't used NewSoftSerial so I don't know how big the buffer is.  Just make sure it doesn't overflow because if bytes are lost the group of three bytes may not be synced anymore and you'll get bogus data.
Logged

Cheers!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes it does command in certain number of ordered bytes. the link is the following:

http://www.microstrain.com/pdf/dcp/Inertia-Link-3DM-GX2-data-communications-protocol.pdf

My concern is that if I put the final print value as BYTE, then I get a y with a double dots over it.

Thanks
Logged

Califonia, US
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Boy, that sensor has some tricky communications...

OK, if I'm reading this right you're going to need to structure your input routing carefully because there's probably some data you want and some you don't (confirmations, checksums and such).

Just out of curiosity, why are you using continuous output mode instead of polled mode?  Seems like it would be easier to structure the communications if you asked for say accelerometer data, read it in, then asked for something else.  Instead in continuous output you have to parse huge amounts of data not knowing exactly what it is?

Also keep in mind - I don't know how large the NewSoftSerial buffer is but the regular serial buffer is only 64 bytes.  Most of the data packets on here look to be 30+ bytes in length so if you are parsing data while two packets are received, the next one may be lost.

Good luck!

Logged

Cheers!

Pages: [1] 2 3   Go Up
Jump to: