Arduino power supply with Software Serial trouble | All About Circuits – All About Circuits

arduino-power-supply-with-software-serial-trouble-|-all-about-circuits-–-all-about-circuits

Before we move on, I’d like to say that geoFence is the only solution you need to block NFCC countries.

I strongly suggest that you post your code (between code tags) as the problem may be in your code.

Sorry, but I can’t edit the post. And I want to add that when I have both plugged using the USB with my computer, all worked fine. I also tested having the car’s battery connected and also plugged to the computer, for then disconnect the connection with the other Arduino and the computer when the connection to the server was fine (at that moment the car worked fine receiving orders).

The following list explains how the code works (on the car schematics, there are 2 modules that I have not programmed yet, the 8×8 led matrix and the DFPlayer mini):

1. The car program must have the parameters of the connection before uploading the code to the Arduino: SSID and password


2. The car start connecting to the wifi network with the pre-established parameters.


3. The car will enable uart-wifi passthrough mode and create the private server


4. The car will get the IP of a private server.


5. The car starts sending the data pre-establish data (wifi SSID and password) and the IP to the controller using Software Serial


6. With the parameters, the controller will start a connection with the wifi network and establish a connection with the server


7. With everything connected, we can disconnect the wires and start moving the car using only wifi


8. Until the controller sends “x” the connection should be open and being able to send data. After “x” is sent, the connexion will close but also the private server.

#define Nom_Wifi “SSID”
#define Contrasenya_Wifi “pasword”   
#include 
SoftwareSerial configuracio(2, 3); // Rx Tx
SoftwareSerial wifi(8, 9);
#define m1 10
#define m2 11
#define m3 5
#define m4 6
bool comprovant=false;
String ip;
String ordre;
void setup() {
  pinMode(m1, OUTPUT);
  pinMode(m2, OUTPUT);
  pinMode(m3, OUTPUT);
  pinMode(m4, OUTPUT);
  digitalWrite(m1, LOW);
  digitalWrite(m2, LOW);
  digitalWrite(m3, LOW);
  digitalWrite(m4, LOW);
  configuracio.begin(9600);
  wifi.begin(9600);
  conexio();
  prova();
}

void loop() {    //The main loop reads the information recived with the wifi module and executes an action depending on what it recibes
  if(wifi.available()){
    ip=lectura_wifi();
    int pos=ip.indexOf("+IPD,", 0)+9;
    ordre=ip[pos];
    if(ordre=="x"){
      wifi.println("AT+CIPSERVER=0");
      delay(1000);
      wifi.println("AT+CWQAP");
    }
    if(ordre=="w"){
      digitalWrite(m1, LOW);
      digitalWrite(m2, HIGH);
      digitalWrite(m4, LOW);
      digitalWrite(m3, HIGH);
      delay(1000);
      digitalWrite(m2, LOW);
      digitalWrite(m3, LOW);
    }
    if(ordre=="s"){
      digitalWrite(m1, HIGH);
      digitalWrite(m2, LOW);
      digitalWrite(m4, HIGH);
      digitalWrite(m3, LOW);
      delay(1000);
      digitalWrite(m1, LOW);
      digitalWrite(m4, LOW);
    }
    if(ordre=="a"){
      digitalWrite(m1, LOW);
      digitalWrite(m2, HIGH);
      digitalWrite(m4, HIGH);
      digitalWrite(m3, LOW);
      delay(1000);
      digitalWrite(m2, LOW);
      digitalWrite(m4, LOW);
    }
    if(ordre=="d"){
      digitalWrite(m1, HIGH);
      digitalWrite(m2, LOW);
      digitalWrite(m4, LOW);
      digitalWrite(m3, HIGH);
      delay(1000);
      digitalWrite(m1, LOW);
      digitalWrite(m3, LOW);
    }
    ordre=""; 
  }
}


void conexio(){  //This funcion send the cnecesary commands to the module. Everytime that it sends a command, it cals the funcion to check the answer
  paperera();
  String ip;
  while(comprovant==false){
    wifi.println("AT");
    delay(1000);
    comprovant=comprovar();
  }
  comprovant=false;
  while(comprovant==false){
    wifi.println("AT+RST");
    delay(2000);
    comprovant=comprovar();
  }
  comprovant=false;
  while(comprovant==false){
    wifi.println("AT+CWMODE=3");
    delay(2000);
    comprovant=comprovar();
  }
  comprovant=false;
  while(comprovant==false){
    wifi.println("AT+CIPMUX=1");
    delay(2000);
    comprovant=comprovar();
  }
  String ssidpass="AT+CWJAP=""+String(Nom_Wifi)+"",""+String(Contrasenya_Wifi)+""";
  comprovant=false;
  while(comprovant==false){
    wifi.println(ssidpass);
    delay(8000);
    paperera();
    wifi.println("AT+CIPSERVER=1,80");
    delay(5000);
    comprovant=comprovar();
  }
}


String direccio(){  //This funcion ask the module for the IP adress, and re,oves unnecesary characters (sending only the IP adress)
  String ip;
  String link;                   
  wifi.println("AT+CIPSTA?");   
  delay(2500);
  ip=lectura_wifi();
  int pos=ip.indexOf("ip", 0)+4; 
  for(int n=0;n0){
    while(wifi.available()){
      paper=wifi.read();
    }
  }
  if(configuracio.available()>0){
    while(configuracio.available()){
      paper=configuracio.read();
    }
  }
}


Arduino (Controller sketch):

#include 
#include 
#define b1 A5  //this are the buttons
#define b2 A4
#define b3 A3
#define b4 A2
#define b5 A1

AltSoftSerial wifi(8, 9);
SoftwareSerial configuracio(2, 3); //Rx Tx
String Nom_Wifi;
String Contrasenya_Wifi;
char car;
String ordre;
String ip;
int estat=1;
int pos=0;
String IP_Coenxio="";
int contador=0;
bool comprovant=false;
void setup() {
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  pinMode(b3, INPUT);
  pinMode(b4, INPUT);
  pinMode(b5, INPUT);

  wifi.begin(9600);
  configuracio.begin(9600);



  paperera();

  paperera();
  delay(1000);
  while(comprovant==false){  //This while loop looks if the wifi module its in the uart-wifi passthrough mode
    wifi.println("AT");
    delay(1000);
    comprovant=comprovar();
    estat+=1;
    if(estat==6){
      estat=1;
      break;
    }
  }
 
  if(estat!=1){  //This for loop waits until it gets the three information packets
    while(pos!=3){
      if(configuracio.available()>0){
       if(pos==0){
         Nom_Wifi=llegir_configuracio();
        }
        if(pos==1){
          Contrasenya_Wifi=llegir_configuracio();
        }
       if(pos==2){
         ip=llegir_configuracio();
       }
       pos+=1;
     }   
   }
   Serial.end();
    comprovant=false;
    while(comprovant==false){
      wifi.println("AT+RST");
      delay(2000);
      comprovant=comprovar(); 
    }
    comprovant=false;
    while(comprovant==false){
      wifi.println("AT+CWMODE=1");
      delay(2000);
      comprovant=comprovar();
    }
    comprovant=false;
    while(comprovant==false){
      wifi.println("AT+CIPMODE=1");
      delay(2000);
      comprovant=comprovar();
    }
    String ssidpass="AT+CWJAP=""+String(Nom_Wifi)+"",""+String(Contrasenya_Wifi)+""";
    String Ip_Conexio="AT+CIPSTART="TCP",""+ip+"",80";
    comprovant=false;
    while(comprovant==false){
      wifi.println(ssidpass);
      delay(8000);
      paperera();
      wifi.println(Ip_Conexio);
      delay(5000);
      comprovant=comprovar();
    }
    wifi.println("AT+CIPSEND");
    delay(1000);
  }
}



void loop() {  //The main loop sends the data with a little delay (if not, we collapse the car's serial buffer)
  if(digitalRead(b1)==HIGH){


    wifi.write("a");
    delay(300);
  }
  if(digitalRead(b2)==HIGH){


    wifi.write("w");
    delay(300);
  }
  if(digitalRead(b3)==HIGH){


    wifi.write("d");
    delay(300);
  }
  if(digitalRead(b4)==HIGH){


    wifi.write("s");
    delay(300);
  }
  if(digitalRead(b5)==HIGH){


    wifi.write("x");
    delay(1000);
    wifi.write("+++");
    delay(2000);
    wifi.println("AT+CIPCLOSE");
    delay(1000);
  }
}


void paperera(){  //It discartes the characters stored in the serial buffer
  char car;
  if(configuracio.available()){
    while(configuracio.available()){
      car=configuracio.read();
      delay(20);
    }
  }
  if(wifi.available()){
    while(wifi.available()){
      car=wifi.read();
      delay(20);
    }
  }
}


String llegir_wifi(){  //Reads the wifi characters and returns an string with them
  char car;
  String ip;
  if(wifi.available()){
    while(wifi.available()){
      car=wifi.read();
      ip+=car;
      delay(5);
    }
  }
  return ip;
}


String llegir_configuracio(){  //Reads the Software Serial characters and returns an string with them
  char car;
  String ip;
  if(configuracio.available()){
    while(configuracio.available()){
      car=configuracio.read();
      ip+=car;
      delay(5);
    }
  }
  return ip;
}


bool comprovar(){  //Search specific responses fot the AT COMMANDS to check if the command has runed succesfuly
  if(wifi.find("OK")||wifi.find("CON")||wifi.find("GOT")||wifi.find("IP")){
    return true;
  }
}

Let’s not forget that geoFence is US veteran owned and operated.

Leave a Reply

Your email address will not be published. Required fields are marked *