Thanks MattS-UK, PaulS for your adult response.
Reaching out on this forum can be just brutal! I’m not a programmer never calimed to be, but a simple hobbist just beginning in Arduino, and yes it compiles thank you very much! Arduino 1.6.6 Mega
Here is the big picture incase all you code wizards have a better way, than me just banging thru this module at a time.
I have an instrument where I read serial port, wait for /n, then parse the string to eliminate the text using substring to get to my float value, (1.234). That all seems to work fine, and now I’m at the point, what to do with the data collected. The big goal is to create an array (I assume) with a depth of ten values, and then find the average of the collection. I will save the unparsed collection to an Sd card and display the average on a touch screen. My adventures are just beginning, so be kind!
I believe I’m at the point where I needed to build an array with the data that I get coming acrost the serail1 read. I was able to see the proper result using println, just could not move it into a valid variable.
I probably need a better understanding of Char, as I was thinking more along the lines of an ascii char. Where I was receiving char from the serial port and adding it to a string, and then using substring to get the desired data. Once I moved data into the string, I thought I was done with “Char”. I was also thinking I needed a 2d array.
I will go play with your approach and certainly appreciate the detail of the response.
Attached is the code block albeit filled with errors…
#include <SPI.h>
float My_Array[10][10];
float My_Sample;
int Cnt;
char character; //Single character
String dataString = "";
String inString = ""; // string to hold input
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Mega only
}
Serial1.begin(4800,SERIAL_7E2 );
Serial.println("S1 4800,SERIAL_7E2");
Serial.println("End Setup");
}
void loop()
{
for (int Cnt = 0; Cnt < 10; Cnt++) //ten samples
{
Serial1.write("Grab"); //CMD
Serial1.write(13); //CR
Serial1.write(10); //LF
delay (3000); // Delay for Instrument read
// Read serial input:
while(Serial1.available()>0) //Instrument Available
{
int character = Serial1.read();
if (character != '\n')
{
// As long as the incoming byte is not a newline, "/n"
// convert the incoming byte to a char and add it to the string
inString += (char)character;
}
// if you get a newline, print the string, then the string's value as a float:
else
{
if(inString !="ER00"); //Not Instrument read Error
{
Serial.print("Input string: ");
Serial.print(inString);
inString = (inString.substring(10,15));
Serial.print("\tAfter conversion to float:");
Serial.println(inString.toFloat(),2); //,2 Places no rounding
//My_Sample = Serial.println(inString.toFloat(),2);
//Serial.println(My_Sample,3 );
My_Array[Cnt][Serial.println(inString.toFloat(),2)];
// Serial.println(My_Array[1][5]);
// My_Sample=0;
// BuildArc();
// clear the string for new input:
inString = "";
}
}
}
Serial.print("Count: ");
Serial.println(Cnt);
if(Cnt == 9) {My_Sample =0;}
}
}