Hi,
I'm sending a chain 'azerty' for example from my pc to the arduino.
All is Ok except that the arduino receives it character by character. what is the good way to have the whole 'azerty' in one time or to reconstruct it ?
Thanks a lot
seb
Moderators: adafruit_support_bill, adafruit
#define INLENGTH 16
#define INTERMINATOR 13
char inString[INLENGTH+1];
int inCount;
inCount = 0;
do {
while (!Serial.available()); // wait for input
inString[inCount] = Serial.read(); // get it
if (inString [inCount] == INTERMINATOR) break;
} (++inCount < INLENGTH));
inString[inCount] = 0; // null terminate the string
#define INLENGTH 16
#define INTERMINATOR 13
char inString[INLENGTH+1];
int inCount;
void setup() {
}
void loop(){
inCount = 0;
do {
while (!Serial.available()); // wait for input
inString[inCount] = Serial.read(); // get it
if (inString [inCount] == INTERMINATOR) break;
} (++inCount < INLENGTH));
inString[inCount] = 0; // null terminate the string
} #define INLENGTH 16
#define INTERMINATOR 13
char inString[INLENGTH+1];
int inCount;
void setup() {
}
void loop(){
inCount = 0;
do
{
while (!Serial.available()); // wait for input
inString[inCount] = Serial.read(); // get it
if (inString [inCount] == INTERMINATOR) break;
} while(true);
(++inCount < INLENGTH);
inString[inCount] = 0; // null terminate the string
}how I can compare the "text" that i receive to another string.
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600); // Initialize serial port
}
void loop()
{
serialReader();
}
void serialReader(){
int makeSerialStringPosition;
int inByte;
char serialReadString[50];
const int terminatingChar = 13; //Terminate lines with CR
inByte = Serial.read();
makeSerialStringPosition=0;
if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)
while (inByte != terminatingChar && Serial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
makeSerialStringPosition++; //Increment position in array
//if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
inByte = Serial.read(); // Read next byte
}
if (inByte == terminatingChar) //If we terminated properly
{
serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
Serial.println(serialReadString);
if (strcmp(serialReadString, "LEDOn") == 0) digitalWrite(13, HIGH);
if (strcmp(serialReadString, "LEDOff") == 0) digitalWrite(13, LOW);
}
}
}
boolean started = false;
boolean ended = false;
char inData[24]; // Size as appropriate
byte index = 0;
#define SOP "{"
#define EOP "}"
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
started = true;
index = 0;
inData[index] = '\0';
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 24-1) // Array size
{
inData[index++] = inChar;
inData[index] = '\0';
}
}
}
if(started && ended)
{
// Parse the data in inData here...
}
}Return to General Project help
Users browsing this forum: Google [Bot] and 8 guests