am trying to read my accelerometer data though wireless connection . my receiver connected to arduino and i recive this in the serial monitor :
7E 00 0E 83 00 01 3B 00 01 0E 00 01 FB 01 F9 02 70 C9
which is right
7E START packet , 00 0E is my packet length , 83 frame id , 00 01 source id , 3B RSSI , 00 OPTIONS ,01 TOTAL NUMBER OF SAMPLE , 0E 00 HEADER
01 FB 01 F9 02 70 this is my data i need 01 FB = X 01 F9 = Y 02 70 = Z C9 = check sum
am trying to read only my data and discard the other bytes . but how can i assign the vale for X , Y and Z
this is my code i would really appreciate your contribution to help me
am new in coding
thanks
void readPacket(){ // if serial has 18 bytes which what we need int he buffer my every packets contains 18 bytes
if (Serial.available() >= 18) {
// FIND MY START BIT
if (Serial.read()==0x7E)
// read the value we do not need out of the buffer
for(int i =0 ; i< 11 ; i++);
byte discard = Serial.read();
// down here is the problem am trying to read for X Y Z am not sure if this is right ?? i need help
for(int d=12 ; d<=18 ; d=d+2);
byte[(12)*256]+(13)] = Serial.read( ,x);
byte[(14)*256]+(15)] = Serial.read( ,y);
byte [(16)*256]+(17)] =Serial.read( ,z);
Serial.print(, x );
Serial.print( , Y );
Serial.print( , Z);
int a = 4;
if( a > 3 )
a++; //Only this line is part of the above if
a++; //This will run weather or not the if does anything.
if( a > 4 ){
a++; //Both these are part of the same if
a++;
}
for( int b = 0 ; b < 5 ; ++b );
a++; //Due to semicolon on for statement, this a++ is not part of it and will only run once when the loop is finished.
for( int b = 0 ; b < 5 ; ++b )
a++; //This is part of the loop
a++; //This is not
for( int b = 0 ; b < 5 ; ++b ){
a++; //These two instructions are part of the loop
a++;
}
//This is completely wrong
byte[(12)*256]+(13)] = Serial.read( ,x);
byte[(14)*256]+(15)] = Serial.read( ,y);
byte [(16)*256]+(17)] =Serial.read( ,z);
the ‘[’ and ‘]’ brackets dont match, and byte is a data type, not a variable.
Serial.read( ,x);
Functions cannot have empty paramaters. ( Serial.read doesn’t take any paramaters ).
yes i agree am totally wrong but really coding is not my thing , am sorry if i wrote stupid code and i wanted you to explain .
however i did another aproch and am getting data from my serial port but they r not correct .
can you check this code please
void setup(){
Serial.begin(9600);
delay(100);
Serial.print("reading.. ");
Serial.println();
}
void loop() {
readPacket();
}
void readPacket(){
// if serial has 18 bytes which what we need int he buffer my every packets contains 18 bytes
if (Serial.available() >= 18) {
// FIND MY START BIT
if (Serial.read()==0x7E)
// read the value we do not need out of the buffer
for(int i =0 ; i< 11 ; i++)
byte discard = Serial.read();
//which contains x value for my 12th byte and 13 byte
if(int i=12 )
{
int analogHigh = Serial.read( );
int analogLow = Serial.read();
x = analogLow + (analogHigh * 256);
Serial.println(x, DEC);
}
else
// he is for my y value for my 14th and 15 byte
if (int i=14) {
int analogHigh = Serial.read( );
int analogLow = Serial.read();
y = analogLow + (analogHigh * 256);
Serial.println(y, DEC);
Serial.flash ();
}
else
// here is for my z value
if (int i=16){
int analogHigh = Serial.read( );
int analogLow = Serial.read();
z = analogLow + (analogHigh * 256);
Serial.println(z, DEC);
Serial.flash ();
}
}
}