Skip to main content
added 664 characters in body
Source Link

I tried your second sketch. It kind of worked. The data that printed to the serial monitor looked like this:

1, 1, 1, 1, 1, 519 518, 1, 1, 1, 1, 519 1, 1, 1, 1, 19, 9 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 518 1, 1, 519, 518, 1, 518 1, 1, 519, 518, 1, 518 1, 1, 518, 518, 1, 518 1, 1, 1, 1, 1, 8 1, 1, 1, 1, 1, 519 1, 1, 518, 1, 1, 1 8, 1, 518, 1, 1, 1 1, 1, 519, 1, 1, 1 1, 1, 1, 519, 1, 1 1, 1, 1, 519, 1, 1 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 519, 8 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 1, 520

it should have all been 1, 1, 1, 1, 1, 518(ish).

I tried your second sketch. It kind of worked. The data that printed to the serial monitor looked like this:

1, 1, 1, 1, 1, 519 518, 1, 1, 1, 1, 519 1, 1, 1, 1, 19, 9 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 518 1, 1, 519, 518, 1, 518 1, 1, 519, 518, 1, 518 1, 1, 518, 518, 1, 518 1, 1, 1, 1, 1, 8 1, 1, 1, 1, 1, 519 1, 1, 518, 1, 1, 1 8, 1, 518, 1, 1, 1 1, 1, 519, 1, 1, 1 1, 1, 1, 519, 1, 1 1, 1, 1, 519, 1, 1 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 519, 8 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 1, 519 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 1, 518 1, 1, 1, 1, 1, 520

it should have all been 1, 1, 1, 1, 1, 518(ish).

added 1210 characters in body
Source Link

I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. It's 6 numbers that I would like to have read as integers on the other side. I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "<" and an end marker ">".

The incoming data from the remote looks like this in the Bots Serial Monitor:

<1,1,1,1,1,512>
<1,1,1,1,1,512>
<1,1,1,1,1,513>
<1,1,1,1,1,512>
<1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?).

if (Serial1.available() > 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
}

But now that I have the markers I don't know the best way to initialize the code. Anyone have any ideas on how to parse these 6 numbers into usable integers?

EDIT: I've wrote a code based on VE7JRO's comments.

uint16_t myArray[6] = {};
int counter = 0;


void setup(){

Serial.begin(9600);

}

void loop(){
  if (Serial.available() > 0) {
  char* pch = strtok(Serial.read,"<>,\r\n");
   }
while(pch != NULL){
  myArray[counter] = atoi(pch);
  pch = strtok(NULL, "<>,\r\n");
  counter += 1;
 }

 trig1 = myArray[0];
 trig2 = myArray[1];
 trig3 = myArray[2];
 trig4 = myArray[3];
 trig5 = myArray[4];
 pot   = myArray[5];

 Serial.print (trig1);
 Serial.print (", ");
 Serial.print (trig2);
 Serial.print (", ");
 Serial.print (trig3);
 Serial.print (", ");
 Serial.print (trig4);
 Serial.print (", ");
 Serial.print (trig5);
 Serial.print (", ");
 Serial.println(pot);  
 }  

I'm getting this error code: invalid use of non-static member function
for this line:

      char* pch = strtok(Serial.read,"<>,\r\n");

Other than that. I subbed out the test input that VE7JRO put in and inserted "Serial.read". Not sure if that is the correct way to do this. Any ideas?

I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. It's 6 numbers that I would like to have read as integers on the other side. I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "<" and an end marker ">".

The incoming data from the remote looks like this in the Bots Serial Monitor:

<1,1,1,1,1,512>
<1,1,1,1,1,512>
<1,1,1,1,1,513>
<1,1,1,1,1,512>
<1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?).

if (Serial1.available() > 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
}

But now that I have the markers I don't know the best way to initialize the code. Anyone have any ideas on how to parse these 6 numbers into usable integers?

I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. It's 6 numbers that I would like to have read as integers on the other side. I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "<" and an end marker ">".

The incoming data from the remote looks like this in the Bots Serial Monitor:

<1,1,1,1,1,512>
<1,1,1,1,1,512>
<1,1,1,1,1,513>
<1,1,1,1,1,512>
<1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?).

if (Serial1.available() > 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
}

But now that I have the markers I don't know the best way to initialize the code. Anyone have any ideas on how to parse these 6 numbers into usable integers?

EDIT: I've wrote a code based on VE7JRO's comments.

uint16_t myArray[6] = {};
int counter = 0;


void setup(){

Serial.begin(9600);

}

void loop(){
  if (Serial.available() > 0) {
  char* pch = strtok(Serial.read,"<>,\r\n");
   }
while(pch != NULL){
  myArray[counter] = atoi(pch);
  pch = strtok(NULL, "<>,\r\n");
  counter += 1;
 }

 trig1 = myArray[0];
 trig2 = myArray[1];
 trig3 = myArray[2];
 trig4 = myArray[3];
 trig5 = myArray[4];
 pot   = myArray[5];

 Serial.print (trig1);
 Serial.print (", ");
 Serial.print (trig2);
 Serial.print (", ");
 Serial.print (trig3);
 Serial.print (", ");
 Serial.print (trig4);
 Serial.print (", ");
 Serial.print (trig5);
 Serial.print (", ");
 Serial.println(pot);  
 }  

I'm getting this error code: invalid use of non-static member function
for this line:

      char* pch = strtok(Serial.read,"<>,\r\n");

Other than that. I subbed out the test input that VE7JRO put in and inserted "Serial.read". Not sure if that is the correct way to do this. Any ideas?

Fixed title, code indenting.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

Parsing Integers from Serial data sttreamstream

I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. It's 6 numbers that I would like to have read as integers on the other side. I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "<" and an end marker ">".

The incoming data from the remote looks like this in the Bots Serial Monitor:

<1,1,1,1,1,512>
<1,1,1,1,1,512>
<1,1,1,1,1,513>
<1,1,1,1,1,512>
<1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?).

if (Serial1.available() > 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
     }

But now that I have the markers I don't know the best way to initialize the code. Anyone have any ideas on how to parse these 6 numbers into usable integers?

Parsing Integers from Serial data sttream

I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. It's 6 numbers that I would like to have read as integers on the other side. I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "<" and an end marker ">".

The incoming data from the remote looks like this in the Bots Serial Monitor:

<1,1,1,1,1,512>
<1,1,1,1,1,512>
<1,1,1,1,1,513>
<1,1,1,1,1,512>
<1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?).

if (Serial1.available() > 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
     }

But now that I have the markers I don't know the best way to initialize the code. Anyone have any ideas on how to parse these 6 numbers into usable integers?

Parsing Integers from Serial data stream

I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. It's 6 numbers that I would like to have read as integers on the other side. I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "<" and an end marker ">".

The incoming data from the remote looks like this in the Bots Serial Monitor:

<1,1,1,1,1,512>
<1,1,1,1,1,512>
<1,1,1,1,1,513>
<1,1,1,1,1,512>
<1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?).

if (Serial1.available() > 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
}

But now that I have the markers I don't know the best way to initialize the code. Anyone have any ideas on how to parse these 6 numbers into usable integers?

Source Link
Loading