Hi to everybody!
I know that there are lots of posts similar to mine, but I can't find any solution to my problem:
I'm using arduin Mega to read analog inputs and print them on OLED display and I wanto to pass some data to arduino YUN in order to be printed on a html page, stored in the micro SD card and published on Thingspeak.
The sketches for the Mega and the YUN are already done, but I'm having a lot of trobles with serial comunication, I think that bridge functions are perturbating the system and I dont't know how to read serial data properly.
First I tested the comunication between an arduino Mega and arduino Nano (just for debugging the sketch) and everything was working good using these sketches:
SENDER:
const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter = '>';
int ActualTempV, ActualTempF, ActualTempA, ActualpH;
void setup ()
{
Serial.begin (9600);
} // end of setup
void loop ()
{
//ricava valori
ActualTempV = (millis() / 1000);
ActualTempF = (millis() / 20);
ActualTempA = (millis() / 35);
ActualpH = (millis() / 425);
//Scrivi valori
mandaSeriale();
delay (1000);
}
void mandaSeriale ()
{
Serial.print (startOfNumberDelimiter);
Serial.print ('v'); //identificativo variabile
Serial.print (ActualTempV); // send the number
Serial.print (endOfNumberDelimiter);
Serial.println ();
Serial.print (startOfNumberDelimiter);
Serial.print ('f'); //identificativo variabile
Serial.print (ActualTempF); // send the number
Serial.print (endOfNumberDelimiter);
Serial.println ();
Serial.print (startOfNumberDelimiter);
Serial.print ('a'); //identificativo variabile
Serial.print (ActualTempA); // send the number
Serial.print (endOfNumberDelimiter);
Serial.println ();
Serial.print (startOfNumberDelimiter);
Serial.print ('p'); //identificativo variabile
Serial.print (ActualpH); // send the number
Serial.print (endOfNumberDelimiter);
Serial.println ();
}
RECEIVER:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter = '>';
long serialTempVasca, serialTempFondo, serialTempAmb, serialpH ;
void setup ()
{
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
} // end of setup
void loop ()
{
while (Serial.available ())
leggiSeriale (); //leggi ingressi
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("T Acqua: ");
display.print(serialTempVasca/10,1);
display.print("T Acqua: ");
display.print(serialTempFondo);
display.print("T Acqua: ");
display.print(serialTempAmb);
display.print("T Acqua: ");
display.print(serialpH);
display.display();
}
//leggi ingressi
void leggiSeriale ()
{
static long receivedNumber = 0; //appoggio
byte c = Serial.read (); //singolo byte
static boolean v, f, a, p;
switch (c)
{
case endOfNumberDelimiter:
if (v)
serialTempVasca = receivedNumber;
else if (f)
serialTempFondo = receivedNumber;
else if (a)
serialTempAmb = receivedNumber;
else if (p)
serialpH = receivedNumber;
//....elsif...
// fall through to start a new number
case startOfNumberDelimiter:
receivedNumber = 0;
v = false;
f = false;
a = false;
p = false;
//....
break;
case '0' ... '9':
receivedNumber *= 10;
receivedNumber += c - '0';
break;
case 'v':
v = true;
break;
case 'f':
f = true;
break;
case 'a':
a = true;
break;
case 'p':
p = true;
break;
}
}
But when I load the sketch on the YUN whit software serial, it didn't behave like expected: If Bridge is called softwareserial don't work; the values are not collected in the same way.
Can you hel me please?
Later I will need to send data (exact time) to Mega from YUN, so I need biderectionability.
Thanks in advance.