Hello there.
My main purpose is to send an array of 60 elements to the arduino via serial port with an interface I wrote in c #.
As a preliminary work I wanted to send information from the Arduino program serial monitor and save this information to another array in sequence. I am trying to see the recorded information when a button is pressed.
My Problem:
I read the information correctly, but sometimes it doesn't save at all in the "savedata" directory or it saves meaningless characters.
I couldn't find where I got the error. I hope you can help.
My code
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
int inPin = 7;
String recdata[10];
String savedata[10];
int sayac=0;
void setup() {
pinMode(inPin, INPUT);
Serial.begin(9600);
Serial.println(""); }
void loop()
{
int val=0;
recvWithStartEndMarkers();
showNewData();
val = digitalRead(inPin);
if (val == 1)
{
savedata[0] = recdata[0];
savedata[1] = recdata[1];
savedata[2] = recdata[2];
savedata[3] = recdata[3];
savedata[4] = recdata[4];
savedata[5] = recdata[5];
savedata[6] = recdata[6];
savedata[7] = recdata[7];
savedata[8] = recdata[8];
savedata[9] = recdata[9];
for (int i = 0; i < 10; i++) {
Serial.print("kaydedilen ... ");
Serial.println(savedata*);*
- }*
}
}
void recvWithStartEndMarkers() { - static boolean recvInProgress = false;*
- static byte ndx = 0;*
- char startMarker = '<';*
- char endMarker = '>';*
- char rc;*
// if (Serial.available() > 0) { - while (Serial.available() > 0 && newData == false) {*
- rc = Serial.read();*
- if (recvInProgress == true) {*
- if (rc != endMarker) {*
- receivedChars[ndx] = rc;*
- ndx++;*
- if (ndx >= numChars) {*
- ndx = numChars - 1;*
- }*
- }*
- else {*
- receivedChars[ndx] = '\0'; // terminate the string*
- recvInProgress = false;*
- ndx = 0;*
- newData = true;*
- }*
- }*
- else if (rc == startMarker) {*
- recvInProgress = true;*
- }*
- }*
}
void showNewData() { - if (newData == true)*
- {*
- savedata[sayac]=receivedChars;*
- recdata[sayac]= receivedChars;*
- Serial.print("received ... ");*
- Serial.println(recdata[sayac]);*
- delay (2);*
- }*
- sayac= sayac + 1;*
- newData = false;*
}