I have two Arduino Mega (I using serial port 1) . First arduino control 7" touch screen, control generator excitation circuit. And second arduino measure all electrical quantities of generator. I have maybe 20 values and I need all send from arduino n.2 to arduino n.1. But I don't know how write this code for receiver and sender. Because I need in same time send 20 values (10 int, 10 float). And I need send this values in real time (maybe +/- 1 second) Anybody can help me ? pleeeease
yes I need use a lot of outputs ... and if I use one mega I need use 40 pin cable to connect display .. distance between arduino and display is 2 meters .. cheapest is use two Arduinos
Because i use TFT Shield v2.2. and his output is 40 pin connector. This is model of Watter Power Plant .. and my arduino must be in instrumental panel and display is 2 meters away .. and in box with display I don't have place for connect 25 cables from sensors etc.
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial1.available() > 0 && newData == false) {
rc = Serial1.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 parseData() { // split the data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars,","); // get the first part - the string
strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ",");
floatFromPC = atof(strtokIndx); // convert this part to a float
}
//============
void showParsedData() {
myGLCD.fillScr(WHITE);
myGLCD.setFont(BigFont);
myGLCD.setColor(BLACK);
myGLCD.setBackColor(WHITE);
myGLCD.printNumI(integerFromPC, 100, 100);
myGLCD.printNumF(floatFromPC,3, 100, 200);
myGLCD.print(messageFromPC, 100, 300);
}
void setup()
{
myGLCD.InitLCD();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
/// INICIALIZACIA SERIOVEHO PORTU
Serial1.begin(115200);
}
void loop()
{
recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData();
showParsedData();
newData = false;
}
}
I can't see the video, I doubt have an account on Vimeo.
Please post the serial outputs you see in your next post (use code tags please).
Your code looks more complex than it needs to be. I suggest trying to use Serial.readBytesUntil(), Serial.parseInt(), Serial.parseFloat() so that you can read values directly from serial without needing a buffer, then parsing/tokenising the buffer etc.
You might be making the mistake that because the shield plugs in , if you want the display remote you need to carry all the wires across .
That is not the case the shield plugs in , but only uses a handful of the wires .
“ This shield needs fewer pins than our v1 shield, so you can connect more sensors, buttons and LEDs: 5 SPI pins for the display, another pin or two for the touchscreen controller and another pin for uSD card if you want to read images off of it.”
What is "not good" about this output? I can see that it does not have the same format <HelloWorld,1,1.11111> as your earlier code. Is that why it is not good?