ACCELEROMETER AND GPS
ADDING THE TWO CODES TOGETHER
I have been working this weekend on adding the 2 pieces of codes together, i had to settle for 4800 Serial communication and i have been having some isses in displaying and parsing the string of the GPS.
First i fixed the GPS code so that i could finally have the serial printing stop after the date and then add a new line feed. So now it looks like this:

Although it still has a few issues.
The new accelerometer and GPS code is this:
#include
#include
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6;
byte tx = 7;
byte SWval;
char dataformat [7] = "$GPRMC";
char messageline[80] = " ";
int i = 0;
int ledPin = 13;
int xPin = 2;
int yPin = 1;
int zPin = 0;
int valX = 0;
int valY = 0;
int valZ = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
//digitalWrite(rx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
//SWprint('h'); //debugging hello
//SWprint('i');
//SWprint(10); //carriage return
Serial.begin (4800);
}
void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}
int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit4800Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit4800Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}
void char2string()
{
i=0;
messageline[0] = SWread();
if (messageline [0] == 36) //string starts with $
{
i++;
messageline [i] = SWread();
while (messageline[i] != 13 & i<64) //carriage return or max size
{
i++;
messageline [i] = SWread ();
}
messageline [i] = 0; //make end to string
}
}
void loop()
{
digitalWrite (13,HIGH);
char2string();
if (strncmp(messageline, dataformat, 6) == 0 & i>4){
for (int i=0; i
}
Serial.print(10, BYTE);
}
// read the accelerometer pins
valX = analogRead(xPin);
valY = analogRead(yPin);
valZ = analogRead(zPin);
Serial.print("X: ");
Serial.println(valX, DEC);
Serial.print("Y: ");
Serial.println(valY, DEC);
Serial.print("Z: ");
Serial.println(valZ, DEC);
delay (250);
//Serial.print(SWread(), BYTE); use this to get all GPS output comment out from char2string till here
}
This is what i get:

But it only displays one byte of the GPS reading at the time, while i want the entire string. I can't figure out what's wrong with it.