0

So I have an application where I send a Bluetooth module underwater(in a waterproof case). I have the Arduino+module sending my computer on-land a constant stream of numbers. Predictably, when the module goes underwater the stream cuts. I then need to remove the Arduino+module from the housing and reconnect/restart the connection.

Is there any way for the connection to start again by itself once above water. On my computer it says the Arduino and computer are connected the whole time. Maybe the code is just "pausing" on the serial.write() step?

Any advice would be appreciated.

#include <SoftwareSerial.h>
SoftwareSerial MegaloDon(10,11); //TX = 10, RX = 11, Ground = Ground, VCC = 5V
int BluetoothData;

unsigned long myTime = 0;
int givenHour;
int givenMin;
int givenSec;
int storeMin = 0;
int hour = 0;
int mins = 0;
int sec = 0;
int store = 0;
int count = 0;
int interval = 0;
int countToMin = 0;

void setup() { //time being set from recieving computer before being submerged in housing
  Serial.begin(9600);
  MegaloDon.begin(9600); //megalodon is the recieving computer
  MegaloDon.println("Bluetooth ON");
  Serial.println("start");
  Serial.flush();
  while (!Serial.available());
  givenHour = Serial.readStringUntil(',').toInt();
  givenMin = Serial.readStringUntil(',').toInt();
  givenSec = Serial.readStringUntil('.').toInt();
  MegaloDon.println(String(givenHour) + " : " + String(givenMin) + " : " + String(givenSec));

}

//min --> 3,600,000
void loop() {
  while(!MegaloDon.available()){ //Megalodon is the recieving computer
  myTime = millis();
  sec = givenSec + (myTime/1000);
  if (sec < 60){
    MegaloDon.println(String(givenHour) + " : " + String(givenMin) + " : " + String(sec));
  }
  if (sec >= 60){
    store = (sec % 60);
     if (sec % 60 == 0){
       count = count + 1;
       if(count%52 == 0 || count > 52){
        countToMin = count/52;
        mins = givenMin + countToMin;
        hour = givenHour;
        if(mins%60 ==0){
          mins = 0;
          hour = givenHour + countToMin;
        }
        if(mins )
        if(mins > 60){
          mins = mins%60;
        }
       }
     }
    MegaloDon.println(String(hour) + " : " + String(mins) + " : " + String(store)); //send to onshore computer step
  }
  }
}

//to use, plug the USB in, run arduino code with COM6, then run the python code, then open the TeraTerm COM8 port, unplug the USB
4
  • Based on the code you have shown us, I believe you may be correct when you say "Maybe the code is just "pausing" on the serial.write() step?".
    – VE7JRO
    Apr 11, 2023 at 2:18
  • @VE7JRO Thanks so much for the response. I updated my question with the relevant code snippet and my "serial.write()" is "println". I don't know that there is much of a difference but was wondering if you had any ideas on how to fix the issue.
    – iceninja21
    Apr 11, 2023 at 3:19
  • Perhaps you could share your entire sketch with us?
    – VE7JRO
    Apr 11, 2023 at 3:23
  • @VE7JRO Will do. Thank you.
    – iceninja21
    Apr 11, 2023 at 4:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.