Thanks, once again, for the detailed response!
The altitude sensor is from Adafruit, and has a 3-5v vin. Real Time Clock is the same.
Before I get started, do you think I'd be better off using a software serial connection between the two Arduinos - rather than I2C? Seems like you're leaning towards I2C being the problem. Maybe 3 I2C busses? one between the to Arduinos, one for the Nano sensors, and one for the LCD screen? Or...?
Ground is shared with everything - all processors, I2C and Serial devices share a single ground.
No pullup resistors on the I2C - didn't know it needed them. I looked at your referenced posting about pullups - I can PROBABLY make sense of that tomorrow morning when my brain is fresh(er). Longest I2C cable is to the LCD - 25CM. Sensors are about 15cm. Inter-Arduino cable is short. I do have the I2C cables together here and there - I'll isolate them a bit.
TimerM is just there as a proof of life. This device is going in a car and will only be running while driving - 50 days on the timer is A-OK.
I could move the LCD display over to the Nano if that helps with the master/slave thing.
Serial Monitir is only used for troubleshooting - I'll minimize use of that.
By "I prefer that you use the I2C with fixed length of data packages", do you mean the communication between Arduinos? I can pad the fields out to make a fixed length.
I'm still chewing on what you sent me - I'll have more questions I am sure.
Thanks again - Steve.
This is the code on the Nano, in case there are any gotchas there:
// Blue Altitude and clock data provider v I2C
//
//------- I2C master
#include <DS3231.h> // Real Time Clock
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h" //Altitude board
#define PAYLOAD_SIZE 19
#define ANSWERSIZE 19
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BMP3XX bmp;
char Altx [7] = "99999";
char CurAx[5] = "CURA";
char CurBx[5] = "CURB";
DS3231 Clock;
bool h12;
bool PM;
char DateC[10];
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Adafruit BMP388 / BMP390 test");
if (!bmp.begin()) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
while (1);
}
Wire.begin(); //I2C MASTER
// Set up oversampling and filter initialization
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
void loop() {
unsigned long TimerMax;
unsigned long TimerPrev = millis();
unsigned long TimerCur;
Serial.println();
Serial.println("*****LoopStart");
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
GetAltitude(); ///////////////////////////////////
GetTime(); ///////////////////////////////////
I2CSend(); ///////////////////////////////////
// delay loop
TimerMax = 3000;
TimerPrev = millis();
TimerCur = millis();
while
((TimerCur - TimerPrev) < TimerMax)
{
TimerCur = millis();
}
Serial.println();
Serial.println("*****LoopEnd");
} // END loop
void GetTime() {
Serial.println();
Serial.println("*****GetTime");
char MinC[03];
char HourC[03];
bool h12 = true;
char AMPM;
int Hour = Clock.getHour(h12, PM);
int Min = Clock.getMinute();
// Add AM/PM indicator
if (PM) {
AMPM = 'P';
}
else {
AMPM = 'A';
}
/*
Serial.println();
Serial.print(" ZZZHour ");
Serial.print(Hour);
Serial.print(':');
Serial.print(Min);
Serial.print(AMPM); // [0] and [1]
*/
sprintf(HourC, "%2d", Hour);
sprintf(MinC, "%2d", Min);
DateC[0] = HourC[0];
DateC[1] = HourC[1];
DateC[2] = ':';
DateC[3] = MinC[0];
DateC[4] = MinC[1];
DateC[5] = AMPM;
DateC[6] = '\0';
Serial.print(" DateC:");
Serial.println(DateC);
}
void GetAltitude()
{ int Alt100;
float Altitude;
char xx;
Serial.println();
Serial.println("*****GetAltitude");
Altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA) * 3.28084 * 1.06; //1.06 is my own factor
Alt100 = 100 * round(Altitude / 100); // round to nearest 100
if (Alt100 < 0) {
Alt100 = 0;
}
sprintf(Altx, "%5d", Alt100);
/*
Serial.println();
Serial.print("Alt100: ");
Serial.print(Alt100);
Serial.print(" Altx: |");
Serial.println(Altx);
Serial.print('|');
*/
} // end GetAltitude
void I2CSend()
{ Serial.println();
Serial.println("*****I2CSend");
Serial.print("I2Cc:");
Serial.print('|');
Serial.print(Altx);
Serial.print(CurAx);
Serial.print(CurBx);
Serial.print(DateC);
//Serial.print(CurAx);
//Serial.println(CurBx);
Wire.beginTransmission(4); // transmit to device #4
Wire.write('|');
Wire.write(Altx);
Wire.write(CurAx);
Wire.write(CurBx);
Wire.write(DateC);
//Wire.write("|||");
Wire.endTransmission(); // stop transmitting
} // end I2CSend