So I've been trying to use this new software serial software library but I'm getting the wrong output. I'm trying to connect an OS-5000S digital compass using the software serial port. I'm pretty sure my pin configuration is correct, and the compass outputs comma delimited data as a string of characters it seems: e.g. 192.6, 193.5, 196.4...
This is my current code:
#include <NewSoftSerial.h>
#define rxPin 4
#define txPin 5
NewSoftSerial CompassSerial(rxPin, txPin);
int compass;
int test;
int i = 0;
int j = 0;
void setup() {
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
CompassSerial.begin(4800);
Serial.begin(38400);
}
void loop() {
if(CompassSerial.available()) {
//if(CompassSerial.read()==46) {
//for(i = 0; i<6; i++) {
compass = CompassSerial.read();
Serial.println(compass);
//}
//}
}
// if(CompassSerial.available()) {
// Serial.println("Hello");
// if(CompassSerial.read() == 10) {
// Serial.println("Hello There");
// while(1) {
// compass = CompassSerial.read();
// if(compass == ',') {
// break;
// }
// i++;
// }
// }
// Serial.println("Hello There2");
// }
// for(j = 0; j < 6; j++) {
// Serial.println("Hello There3");
// CompassSerial.print(compass[j]);
// }
}
So basically I'm just printing out whatever I get, which is:
×
§
·
Û
×
«
¯
·
·
Û
ß
«
Ó
·
ß
ß
§
¯
÷
ï
Û
ß
×
«
×
·
·
Û
×
«
×
·
·
Û
ß
§
Ó
·
ß
ß
«
¯
÷
ï
Û
ß
×
«
ß
·
·
Û
×
§
×
·
·
ß
ß
«
Ó
·
Û
ß
«
¯
÷
ï
Û
ß
×
§
Ó
·
·
Û
×
«
×
·
·
Û
ß
«
×
·
Û
ß
«
¯
÷
ï
Û
¤
I
%
$
$
$
$
$
$
$
%
$
$
$
$
$
$
v
¶
which seems to be junk....can anyone help??
Thanks in advnce