ElectronicsNut
Posts: 7
Joined: Sun Apr 14, 2019 12:28 pm

Remote Pi and FONA 3G, for updating Arduino program

Wed Sep 11, 2019 2:17 pm

Scenario:
RV = Mountains in Northern Georgia
RV = FONA 3G (no local internet), Arduino Mega 2560, Raspberry Pi

Home = 600 miles from RV for 6 months at a time

I want to have REMOTE access to the Arduino to modify the program with more features while at home.

I "ALMOST" have the Arduino program up and running so that it sends me a 9PM text every night with the following data: Outside and Inside (RV) Temperature, Humidity, RV battery voltage and SOLAR panel voltage. Currently the program gets all the data from the sensors, now I need to get the FONA up and running on the Arduino (I have already had it up and running on the Pi, but have not tried to get the PI/Arduino to talk to each other.) I am working on the Arduino first as a default up and running "Plan A", with no remote access, in case I run out of time.

I would like to set up the remote site as follows:
HOME <><><>FONA 3G <><><> Raspberry Pi <><><> Arduino Mega 2560 <<<<< Sensors
My Cell Phone <<<< FONA 3G (9PM Status Text)

>> If I have enough time left (16 days before we leave for home)
- I am thinking of loading Arduino IDE on the remote RV Raspberry Pi
- Accessing the Remote Raspberry Pi from home using SSH through the FONA 3g
- Update the Arduino program remotely
- Use the Pi USB port to connect to the Pi for communications

Does this seem feasible?

Since I am better at hardware than software, I was thinking of connecting the FONA 3G connections to (2) DPDT relays NC position would connect to the Pi. When the Arduino wanted to use the FONA (for the 9pm text) , it would put 5 volts on the relays (2 digital Arduino outputs high) and the connections would be transferred to the ARDUINO for the 9 PM message send to my Cell phone. The default would be the Pi connection

Your thoughts, sorry for the length of the post.

Just to share with you, for anyone that may be thinking of doing the same, here is the Arduino code that is working at this point (need to add the inside temp data and SOLAR panel voltage, and sending to the Pi Function that is just a print statement at this time, if I have time. I also added a rough diagram of using the relay method. Drawing does not show the Pi USB to Arduino connection for updating.

Code: Select all

#include <Wire.h>
#include <TimeLib.h>                                                     // RTC-Clock
#include <DS1307RTC.h>                                                   // RTC_Clock
#include "DHT.h"                                                         // Temperature
#define NUM_SAMPLES 50                                                   // Voltage - number of samples to take
#define DHTTYPE DHT11                                                    // Temperature/Humidity Sensor Type DHT 11
#define DHTPIN 3                                                         // Temperature/Humidity Sensor Assigned Pin Number  

DHT dht(DHTPIN, DHTTYPE);                                                // Initialize DHT sensor.
int sum = 0;                                                             // Voltage - sum of samples taken
unsigned char sample_count = 0;                                          // Voltage - current sample number
float voltage = 0.0;                                                     // Voltage - calculated voltage

void setup()
{
  Serial.begin(9600);
  while (!Serial) ;                                                      // Wait for serial
  Serial.println("Starting RTC_Temperature_Voltage_Test_5!");            // RTC-Clock Test Print
  Serial.println ();
  Serial.println ();
  dht.begin();                                                           // RTC-Clock
  //  delay(200);                                                        // Serial Communications delay if needed
}

void loop()
{
  tmElements_t tm;
  if (RTC.read(tm))                                                      // Reading the Clock
    if ((tm.Second) == 03)                                               // Select Hour or Minute or Seconds ...using Seconds for testing
    {
      Serial.println("Second 01 code");
      Serial.println();
      delay(1000);
      SaveDataToPi();                                                    // This function will save the hourly sensor data to the SQLdB on the Raspberry Pi
    }

  if ((tm.Second) == 06)                                                 // Select Hour or Minute or Seconds ...using Seconds for testing
  {
    Serial.println("Second 05 code");
    Serial.println();
    delay(1000);
    SendTextMessage();                                                    // This function will save the hourly sensor data to my cell phone
  }

  if ((tm.Second) == 01)                                                 // Select Hour or Minute or Seconds...using Seconds for testing
  {
    Serial.println("Reading Sensors");
    Serial.println();
    delay(1000);
    ReadSensors();                                                       // This function will read the Temperature/Humidity/Voltage sensors for current hourly data
  }

  else
  {
    Serial.println("Restart time loop,  ");                              // This print line is used for testing
    Serial.println();
    if ((tm.Second) != 01)
      delay(1000);
  }
}
void ReadSensors()                                                       // Read sensor function
{
  Serial.println("<<<<< Reading_Sensors >>>>>>");
  Serial.println();

  // This function will start reading the sensors for current hourly data
  {
    while (sample_count < NUM_SAMPLES)                                   // Voltage - add up sample count
    {
      sum += analogRead(A8);                                             // Voltage reading and calculating
      sample_count++;                                                    // Voltage reading and calculating
    }

    voltage = ((float)sum / (float)NUM_SAMPLES * 4.88) / 1024.0;         // Voltage reading and calculating
    // Serial.println(voltage);                                          // Actual voltage reading at pin A8
    Serial.print (" Battery Voltage = ");                                // Voltage reading and calculating
    Serial.print(voltage * 11.132);                                      // Voltage reading and calculating
    Serial.println(" Volts");                                            // Voltage reading and calculating
    Serial.println();
    sample_count = 0;                                                    // Voltage reading and calculating
    sum = 0;                                                             // Voltage reading and calculating
    // delay (100);
  }

  {
    // Wait a few seconds between measurements.
    delay(1000);                                                         // Reading temperature or humidity takes about 250 milliseconds!
    float h = dht.readHumidity();                                        // Read humidity
    float t = dht.readTemperature();                                     // Read temperature as Celsius (the default)
    float f = dht.readTemperature(true);                                 // Read temperature as Fahrenheit (isFahrenheit = true)

    // DHT11 Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f))                                // DHT11
    {
      Serial.println("Failed to read from DHT sensor!");                 // DHT11 Display Sensor Error Message
      return;
    }
    Serial.println("Outside Temperature");                               // DHT11 Display Sensor Data
    float hif = dht.computeHeatIndex(f, h);                              // DHT11 Compute heat index in Fahrenheit (the default)
    float hic = dht.computeHeatIndex(t, h, false);                       // DHT11 Compute heat index in Celsius (isFahreheit = false)
    Serial.print("Humidity: ");                                          // DHT11 Display Sensor Data
    Serial.print(int(round(h)));                                         // DHT11 Display Sensor Data Rounded
    Serial.print(" %\t");                                                // DHT11 Display Sensor Data
    Serial.print("Outside Temp: ");                                      // DHT11 Display Sensor Data
    Serial.print(int(round(f)));                                         // DHT11 Display Sensor Data Rounded
    Serial.print(" *F\t");                                               // DHT11 Display Sensor Data
    Serial.print("Heat index: ");                                        // DHT11 Display Sensor Data
    Serial.print(int(round(hif)));                                       // DHT11 Display Sensor Data Rounded
    Serial.print(" *F");                                                 // DHT11 Display Sensor Data
    Serial.println();                                                    // DHT11 Display Sensor Data
  }




  {
    Serial.println();
    Serial.println("This Section is for DS18B20 Sensor reading");        // DS18B20 Temperature Sensor Data
    Serial.println();                                                    // DS18B20 Temperature Sensor Data
  }
}

void SaveDataToPi()                                                      // Save sensor data to Pi dB function
{
  Serial.println("<<<<<< Saving_Sensor_Data to the Pi >>>>>>");          // This is a test print of line
  Serial.println();

}

void SendTextMessage()                                                   // Send Text Message to My Cell Phone
{
  Serial.println("<<<<<< Sending Message To My Cell Phone >>>>>>");      // This is a test print of line
  Serial.println();

}
Attachments
FONA_PI_ARDUINO.jpg
FONA_PI_ARDUINO.jpg (73.25 KiB) Viewed 80 times

ElectronicsNut
Posts: 7
Joined: Sun Apr 14, 2019 12:28 pm

Re: Remote Pi and FONA 3G, for updating Arduino program

Sat Sep 14, 2019 11:39 am

Well, I need to temporarily be delay this project until I get home, I am leaving tomorrow. Ran out of time... will work on the project at home and get it done before returning to our RV next year.

Return to “Interfacing (DSI, CSI, I2C, etc.)”