Using a SF Razor 9DOF IMU connected to TX/RX I successfully, and simply, output YAW (in degrees) to the Serial window using the following code:-
void setup() {
Serial.begin(57600);
}
void loop() {
if(Serial.available()) {
Serial.write(Serial.read());
}
}
...the output is set to 57600 Baud & the output shows YAW=40.10 (for example) which is derived from the SF9DOF_AHRS Output code:-
/* This file is part of the Razor AHRS Firmware */
// Output angles: yaw, pitch, roll
void output_angles()
{
if (output_format == OUTPUT__FORMAT_BINARY)
{
float ypr[3];
ypr[0] = TO_DEG(yaw);
ypr[1] = TO_DEG(pitch);
ypr[2] = TO_DEG(roll);
Serial.write((byte*) ypr, 12); // No new-line
}
else if (output_format == OUTPUT__FORMAT_TEXT)
{
Serial.print("YAW=");
Serial.print(TO_DEG(yaw)); Serial.print(",");
// Serial.print(TO_DEG(pitch)); Serial.print(",");
// Serial.print(TO_DEG(roll));
Serial.println();
}
}
When I move the TX/RX to pin 10 & 11 respectively and adapt the code to read from Pin 10 I get sporadic ASCII outputs, here's my code:-
// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() {
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(57600);
Serial.begin(57600);
// while (!Serial);
delay(500);
}
void loop() {
if (mySerial.available()){
Serial.write(mySerial.read());
Serial.println();
delay(500);
}
}
Should be easy, shouldn't it...?
Any advice gratefully received.
Myles