I have tried the rs232 shifter from sparkfun, and have not been able to get any output. Is this a connection problem on the hardware part or is there a problem with my program.
Hello, thanks for your replies, I have updated my sketch after reading up on the product a bit more however I'm still unable to get an accurate reading for Gyro Outputs ( X & Y ) and Total Gyro Output
This is my sketch:
#include <NewSoftSerial.h>
#include <string.h>
#include <ctype.h>
#define rxPin 4
#define txPin 5
NewSoftSerial CompassSerial(rxPin, txPin);
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[6] = "$OHPR";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
int i = 0;
int j = 0;
void setup() {
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
CompassSerial.begin(9600);
Serial.begin(9600);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop() {
if(CompassSerial.available()) {
byteGPS = CompassSerial.read();
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
}
else {
linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer
conta++;
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
cont=0;
bien=0;
for (int i=1;i<6;i++){ // Verifies if the received command starts with $GPR
if (linea[i]==comandoGPR[i-1]){
bien++;
}
}
if(bien==5){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (linea[i]==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea[i]=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
Serial.println(""); // ... and write to the serial port
Serial.println("");
Serial.println("---------------");
for (int i=0;i<4;i++){
switch(i){
case 0 :
Serial.print("Heading(Degrees): ");
break;
case 1 :
Serial.print("Pitch Angle(Degrees): ");
break;
case 2 :
Serial.print("Roll Angle(Degrees): ");
break;
case 3 :
Serial.print("Temperature(C): ");
break;
case 4 :
Serial.print("Depth(ft): ");
break;
case 5 :
Serial.print("Acceleration Vector Length: ");
break;
case 6 :
Serial.print("Acceleration Reading(X): ");
break;
case 7 :
Serial.print("Acceleration Reading(Y): ");
break;
case 8 :
Serial.print("Acceleration Reading(Z): ");
break;
case 9 :
Serial.print("Total Gyro Output: ");
break;
case 10 :
Serial.print("Gyro Output(X): ");
break;
case 11 :
Serial.print("Gyro Output(Y): ");
break;
default :
break;
}
for (int j=indices[i];j<(indices[i+1]-1);j++){
Serial.print(linea[j+1]);
}
Serial.println("");
}
Serial.println("---------------");
}
conta=0; // Reset the buffer
bien=0;
cont=0;
for (int i=0;i<300;i++){ //
linea[i]=' ';
}
}
}
}
}