Arduino power supply with Software Serial trouble

Thread Starter

Miquel19

Joined Aug 16, 2020
37
Hi everyone,I have been working this lasts month on a little Arduino project about making a remote control car. I'm using 2 Arduino Uno boards, one for the car and the other for the remote controller. I'm also using the module ESP8266 12-f for sending and receiving orders (I use the AT COMMANDS). This project, it's not fully optimized. The first time you establish a connection, the code will run completely. But if you don't quit the uart-wifi passthrough mode, the code won't need to run (the ESP8266 12-f can do an automatic connection)
I will refer to each part as "controller" and "car". With these names, I also include their respective ESP8266 12-f.

I also want to sat that these two Arduinos are both connected at the beginning to transfer some essential data (SSID, password, and the server IP). The connections are between pins 2, 3, and GND. The car has Rx on pin 2 and Tx on pin 3, and the controller is the opposite (both have connected a GND between them).

Until here everything it's okay, but I was only testing with serial USB power supply (less the motors, that I used a voltage converter). The problem started when I tried to run this code powering the different parts with different power supply (with 2 different batteries for example). When I try it, the code seems to work well, but I'm only able to send one order before the wifi modules start doing nothing.

Car circuit
Cotxe_1.2.png
Controller circuit


Mando_1.1.png

Thanks in advance for your help
 

djsfantasi

Joined Apr 11, 2010
9,163
Hi everyone,I have been working this lasts month on a little Arduino project about making a remote control car. I'm using 2 Arduino Uno boards, one for the car and the other for the remote controller. I'm also using the module ESP8266 12-f for sending and receiving orders (I use the AT COMMANDS). This project, it's not fully optimized. The first time you establish a connection, the code will run completely. But if you don't quit the uart-wifi passthrough mode, the code won't need to run (the ESP8266 12-f can do an automatic connection)
I will refer to each part as "controller" and "car". With these names, I also include their respective ESP8266 12-f.

I also want to sat that these two Arduinos are both connected at the beginning to transfer some essential data (SSID, password, and the server IP). The connections are between pins 2, 3, and GND. The car has Rx on pin 2 and Tx on pin 3, and the controller is the opposite (both have connected a GND between them).

Until here everything it's okay, but I was only testing with serial USB power supply (less the motors, that I used a voltage converter). The problem started when I tried to run this code powering the different parts with different power supply (with 2 different batteries for example). When I try it, the code seems to work well, but I'm only able to send one order before the wifi modules start doing nothing.

Car circuit
View attachment 214884
Controller circuit


View attachment 214885

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

Thread Starter

Miquel19

Joined Aug 16, 2020
37
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 8x8 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.

Arduino (Car sketch):
#define Nom_Wifi “SSID”
#define Contrasenya_Wifi “pasword”   
#include <SoftwareSerial.h>
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;n<n+1;n++){                           
    if(ip[pos+n]!='.'& isdigit(ip[pos+n])==false){
      break;
    }   
    link+=ip[pos+n];   
    }
  return link;
}


String prova(){  //It gets the IP. There is a little loop that calls twice the IP, and check's is both answers are the same before sending this data.
  char car;
  String ip;
  String link="";
  String link1;
  String link2;
  link1=direccio();
  link2=direccio();
  int l1=link1.length();
  int l2=link1.length();
  int x=1;
  while(link1!=link2 || l1<7 || l1<7 || link1=="" || link2=="0.0.0.0" ){
    delay(500);
    link1=direccio();
    delay(500);
    link2=direccio();
    l1=link1.length();
    l2=link2.length();
    x+=1;
  }
  paperera();
  configuracio.print(Nom_Wifi);
  delay(1000);
  configuracio.print(Contrasenya_Wifi);
  delay(1000);
  configuracio.print(link1);
  delay(1000);
}


String lectura_wifi(){  //Reads the wifi characters and returns an string with them
  char car;
  String ip;
  while(wifi.available()){
    car=wifi.read();
    ip+=car;
    delay(10);
  }
  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;
  }
}


void paperera(){  //It discartes the characters stored in the serial buffer (I founded that the funcion that did that was removed or changed)
  char paper;
  if (wifi.available()>0){
    while(wifi.available()){
      paper=wifi.read();
    }
  }
  if(configuracio.available()>0){
    while(configuracio.available()){
      paper=configuracio.read();
    }
  }
}
Arduino (Controller sketch):
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>
#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;
  }
}
 

djsfantasi

Joined Apr 11, 2010
9,163
Until here everything it's okay, but I was only testing with serial USB power supply (less the motors, that I used a voltage converter). The problem started when I tried to run this code powering the different parts with different power supply (with 2 different batteries for example). When I try it, the code seems to work well, but I'm only able to send one order before the wifi modules start doing nothing.
What do you mean by different parts? All devices connected to the Arduino must share a common ground. Let’s say you are controlling a device with an Arduino pin, then you MUST connect the Arduino and device grounds. If the Arduino is powered by a battery and other, separate batteries power the device, then they cannot work together unless both battery’s grounds are also connected.
 

Thread Starter

Miquel19

Joined Aug 16, 2020
37
What do you mean by different parts? All devices connected to the Arduino must share a common ground. Let’s say you are controlling a device with an Arduino pin, then you MUST connect the Arduino and device grounds. If the Arduino is powered by a battery and other, separate batteries power the device, then they cannot work together unless both battery’s grounds are also connected.
With part, I mean that the project has the controller and the car. In the beginning, both need to be connected to share some information before they connect via wifi. In the beginning, they are connected with software serial, and common ground (but each one has his own battery). The objective is to finally disconnect all the wires between the controller and the car, so they communicate only using wifi. Should I connect the 2 battery ground together?
Thanks
 

Thread Starter

Miquel19

Joined Aug 16, 2020
37
Yes, seems that level converter and ESP module grounds are not connected with Arduino uno-s ground
Well, until I changed the USB to batteries, I had no problem with the esp8266 alimentation, so I don't know. Also, when I send my first order and everything stops, the controller esp8266 led starts blinking until I reset it manually (it haves a button because its the Wemos d1 mini)
 

trebla

Joined Jun 29, 2019
547
If MCU supply power is not properly connected then it may get powered through MCU-s GPIO internal protection diodes. But this current is very small and MCU core may not get enough power to operate correctly, also RF peripherial cannot operate with such conditions.
 

Thread Starter

Miquel19

Joined Aug 16, 2020
37
If MCU supply power is not properly connected then it may get powered through MCU-s GPIO internal protection diodes. But this current is very small and MCU core may not get enough power to operate correctly, also RF peripherial cannot operate with such conditions.
Mh, interesting, what I should do? I don't really know how to solve this. I have tried to connect each battery before connecting each Arduino, but the reaction was the same.
Thanks a lot
 
Last edited:

trebla

Joined Jun 29, 2019
547
In your scematics wires going to level converters U3 and U13 is not connected as it should. Wires going to HV1 and LV1 must go to GND instead. Wires going to HV2 (5V) must go to HV instead. Wires going to LV2 (3.3V) must go to LV. And it will be good idea measure the current from Arduinos 5V output, it must not be near his maximum capability. ESP is quite power hungry.
 

Thread Starter

Miquel19

Joined Aug 16, 2020
37
In your scematics wires going to level converters U3 and U13 is not connected as it should. Wires going to HV1 and LV1 must go to GND instead. Wires going to HV2 (5V) must go to HV instead. Wires going to LV2 (3.3V) must go to LV. And it will be good idea measure the current from Arduinos 5V output, it must not be near his maximum capability. ESP is quite power hungry.
Oh, true, I have it with a wrong connection. I also found that one of my regulators it's not working perfectly, so I will pick another, and I will try. If it doesn't work I will ask here again.
Many thanks
 

Thread Starter

Miquel19

Joined Aug 16, 2020
37
H
In your scematics wires going to level converters U3 and U13 is not connected as it should. Wires going to HV1 and LV1 must go to GND instead. Wires going to HV2 (5V) must go to HV instead. Wires going to LV2 (3.3V) must go to LV. And it will be good idea measure the current from Arduinos 5V output, it must not be near his maximum capability. ESP is quite power hungry.
Hi again. I have changed the power shifters and the problem still is the same. But I found that if don't remove the wires, I can give all the instructions and nothing stops working. But when I remove the wire between the two Arduino everything stops working. I don't know if I can remove the wires, but its what I need to do. If you have some Idea to solve it will be amazing

Thanks
 

djsfantasi

Joined Apr 11, 2010
9,163
H

Hi again. I have changed the power shifters and the problem still is the same. But I found that if don't remove the wires, I can give all the instructions and nothing stops working. But when I remove the wire between the two Arduino everything stops working. I don't know if I can remove the wires, but its what I need to do. If you have some Idea to solve it will be amazing

Thanks
The receiving (or transmitting) Arduino cannot understand signals from the other because it has no reference point for the voltage of the signal. That’s why you need to connect the grounds together from each device.
 

djsfantasi

Joined Apr 11, 2010
9,163
But there is no ground connection between the Arduino and the EDP modules! That’s why I’m my post I said “devices” and not “Arduino’s”
 

trebla

Joined Jun 29, 2019
547
Maybe TS should upload new scematics. In my post #11 i described misconnected wires and i understood that TS is changed those.
 

Thread Starter

Miquel19

Joined Aug 16, 2020
37
The receiving (or transmitting) Arduino cannot understand signals from the other because it has no reference point for the voltage of the signal. That’s why you need to connect the grounds together from each device.
The schematics when the components are connected its that one:Captura de pantalla (17).png
The width wires are the ones that connect one Arduino with the other. The problem is that I need to unplug these wires, and when I do it everything stops working. Do you have some ideas to solve it?

Thanks
 

trebla

Joined Jun 29, 2019
547
You have'nt make corrections to the scematics as i suggested in posting #11 and therefore your system ca'nt work. Please read this posting again and make right connections.

Edit: At the moment your system communicates via serial connection on pins 2 and 3, wireless connection can not work due wrong wiring.
 
Last edited:
Top