A ROV with PS2 command

Buenos días a todo el mundo

He abierto un tema en el foro en la parte de ESPAÑOL, que se llama “Un ROV con mando de PS2”, y me gustaría que alguien pudiese mirar el proyecto y aconsejarme alguna solución, muchas gracias a todos por su tiempo e interés.

este es el enlace

https://forum.arduino.cc/index.php?topic=672563.0

Un saludo

Good morning to everyone

I have opened a topic in the forum in the SPANISH part, which is called "A ROV with PS2 command", and I would like someone to be able to look at the project and advise me some solution, thank you all for your time and interest.

this is the link

https://forum.arduino.cc/index.php?topic=672563.0

A greeting

You might find your answers using the forum search feature and searching for "ROV". Many years of discussion on the topic.

Muchas gracias, por su tiempo, un saludo.

Thank you very much, for your time, a greeting.

Buenos días a todo el mundo, como ya dije anteriormente, abrí un tema en el foro, en la primera respuesta esta el enlace, el proyecto esta bastante avanzado, pero tengo problemas con la programación, por eso es que pido ayuda, por favor, para que alguien revise mi código y me oriente de las posibles soluciones, muchas gracias, un saludo.

Good morning to everyone, as I said earlier, I opened a topic in the forum, in the first reply this link, the project is quite advanced, but I have problems with programming, that's why I ask for help, please, for someone to check my code and I possible solutions, thank you very much, a greeting.

Buenas noches a todos.
Como ya dije en mi anterior comentario tengo el proyecto bastante avanzado, y me gustaría que por favor, alguien mirase mi código, por los errores que tengo, como ya he dicho, he seguido los pasos de
http://www.techmonkeybusiness.com/tag/rov.html
He mirado casi todas las publicaciones de
http://www.homebuiltrovs.com/rovforum/
Ya ha habido compañeros que me han indicado utilice las opciones de búsqueda del foro, cosa que ya he hecho, pero no encuentro solución a mi problema, casi todas las respuestas terminan igual, “busca ayuda en Homebuilt ROVs Forum - Index page, “, por desgracia esa respuesta no me sirve, necesito ayuda concreta sobre programación con Arduino
Espero que alguien se apiade de esta alma perdida, en el purgatorio de la programación, y me oriente hacia el cielo, o hacia el infierno, pero que no me deje más tiempo en esta situación.
Muchas gracias

Good night, everybody.
As I said in my previous comment I have the project quite advanced, and I would like someone to look at my code, for the errors I have, as I said, I have followed the steps of
http://www.techmonkeybusiness.com/tag/rov.html
I've looked at almost every publication of
http://www.homebuiltrovs.com/rovforum/
There have already been colleagues who have indicated me to use the forum search options, which I have already done, but I find no solution to my problem, almost all the answers end the same, "seek help in Homebuilt ROVs Forum - Index page, "unfortunately that answer does not serve me, I need concrete help on programming with Arduino
I hope that someone will have mercy on this lost soul, in the purgatory of programming, and orient me to heaven, or to hell, but that he will leave me no longer in this situation.
Thanks a lot

01_Maestro_28_03_2020_arreglando_Mando_PS2.ino (20 KB)

02_Esclavo_28_03_2020_arreglando_Mando_PS2.ino (20.7 KB)

Si alguien al visitar la página tiene algún problema con el idioma que me lo diga, muy gustoso le traduciré todo lo que pueda.
Muchas gracias

If someone when visiting the page has any problem with the language you tell me, I will gladly translate everything you can.
Thanks a lot

Suggestions:

  1. Post the spanish in the spanish section where you have also started a topic.

  2. use </> code tags to post your code if possible so people can see it.

  3. Be specific with the issue you have, just posting "I need help" will probably be ignored. I have no clue as to your specific issues as you have posted none.

  4. Be prepared to hear that possibly your project is too complex or not practical at the arduino hobby level. If you have searched to the ends of the internet and not found your answer, maybe there is not one.

Thank you very much for your time.

Right now the code is too big to be able to publish within the post, so I've attached it.
I have not found a solution to my problems on the Internet, because I have a specific programming problem, because as I have written before "I am not an experienced programmer", only an amateur.
I tell you my problems

At first I got the code I made, as they are now working on the two Arduinos, and I do not know why, it has stopped working properly, the codes compile, but I suspect that when using the Serial communication between the two Arduinos, and use a MPU6050 gyroscope, that's what can create me conflicts

I go on to explain the project I intend to carry out
The idea is that with 2 Arduinos Mega 2560, one inside the ROV called Slave, and another on a surface called Master, and a PS2 controller, control the movements of ROV, and that on a 5-inch Nextion screen of the Basic type, show me the data of the different sensors that I have punctured in the Arduino Slave.

I'm using the Library of Bill Porter PSXLib, known to many of you, which I will attach in this publication, along with all the ones I've used for the project, to control the PS2 command.
Now I go on to list the sensors I'm using, they're very normal, but for this project I think they're the right ones for their value for money
I have 3 DHT22 temperature and humidity sensors, known to everyone you've messed up a little bit with Arduino.
I'm also using a DS18B20 temperature sensor, with its metal encapsulation, and connected by a resistance of 4.7 k.
I am also using a HK3025 5MP pressure sensor, which will definitely have to be 2, one to mark the internal pressure of the ROV, and try not to burst, and another to mark the outside pressure to know how deep the ROV is.
I'm also using an E18D80NK infrared sensor,
Also a relay module to turn on a spotlight, which will later be 2 spotlights, but for the moment for testing with one that works it's good for me, in the final assembly, I don't know if I'll put 2 relays, one for focus, or if I can fix myself with a single relay for the two spotlights , that will be seen in the not too distant future
Two brushless motors, with its speed inverter, which I have been able to check on various Internet pages, are controlled just like a servo, this in principle has no greater control problem

And as not a servo that will move me an axle where the motors will be placed, and will move according to the needs up and down to sink the ROV, or bring it to the surface
I also have connected a GY 5121 MPU6050 gyroscope, so that I mark the inclinations of the ROV, on the axes of the three planes X, Y, Z, to know in what position the ROV is in
The current for now I'm pulling it out of a PC ATX source, so as not to expend batteries with project tests, and the cables are connected to an Arduino power board called YFRobot
And of course in the electrical assembly all the masses are connected to each other, both those of the tracks of the protoboarding, as the GNDs of the Arduinos, and the black cables, Negative of the PC source
For the transmission of data between one Arduino and another, for the moment, as I have everything on the table, with two dupont type bridge cables, for the time being can serve me, but then that transmission will be done with a CAT5 network cable , 100 meters, which I already got at the time and that is waiting for you to use it.
For live video streaming I'm not going to complicate my life, I'm going to use a Raspberry Pi3+, a USB camera, and a laptop.
The video system works as follows.
The Raspberry Pi3+, is connected a video camera via USB, starts the Raspberry and directly from the computer, with a program called VLC media player, it is sent to play a web address, which is the ip address of the Raspberry , and you're already watching the video on your computer.
The only thing to do to the Raspberry is to load the operating system, update everything, and to show you its ip address, I have not complicated myself with the programming language, I have only followed the tutorial of the start of the official Raspbery page. I already have enough programming problems with a single language the C++, arduino, as for learning the other from the Raspberry, the Python.
Well so far the project exhibition, I hope I've explained enough that you understand the idea and can help me.
Now I'm starting to explain the problem I have.
So far, I've been incorporating sensor to sensor, one at a time, first connecting only the new sensor on a board and in a new program.
Then I connected it in an Arduino, and through Serial Communication, by the RX and TX pins, to another Arduino, to check that the assembly works, and that I can see the data through the Serial Monitor.
And then incorporating it into the program where the rest of the instructions are, both in the Arduino Maestro, and in the Slave, and connecting it in place, to check that it works.
This has worked well for me, until it has suddenly stopped working, without being able to find a coherent explanation why the fault.
Suddenly it has stopped reacting to the command orders of the PS2, and it is not because the batteries of the controller are worn out, as one can tell me, it has been by incorporating the gyroscope, and I think there is some order that is interfering in the program , and I do not find what it is, in principle there is no Arduino pin that in the program does two functions, I have checked the electrical installation of the circuit several times and I think I can ensure that there is no connection failure, I lean more towards a programming problem.
With the Slave program, if I can see the data on the Serial Monitor, and they are quite consistent, it gives me the temperature of the 4 sensors, the humidity of the three DHT22, marks the battery voltage.
But the infrared sensor does not mark well, it randomly marks the proximity of an object or not, without cutting off the sensor light.
And the gyroscope data doesn't vary depending on the tilt, it's fixed in a number.
And the Master Series monitor, goes to your air, or marks nothing, or just prints the lines of text without any value, or displays random sensor data and the failure of any of them.
I've already tried to change the two Arduinos, and change the controller, in case it was any failure of these, but nothing I can fix it.
I attach the two programs, and of course I offer to clarify any doubts you have about the project that I have not explained well in this publication.

I have already been told by a colleague of the forum, which could be a problem caused by the many "serial. Print", which is in the program, necessary to control the proper functioning of the sensors, if you look at the code, I have started two serial ports, to separate the data that I want to be sent from one Arduino to another, from the data that I want to be seen in the Serial Monitor.
I have also been told by another partner, and I have implemented a "DEBUG 0" command, so that the data is not printed on the Serial Monitor, or "DEBUG 1", so that if the data is printed on the Serial Monitor.
Greetings to all

"This has worked well for me, until it has suddenly stopped working, without being able to find a coherent explanation why the fault."

If it was working and then, without any hardware or software changes, it quit working, then I would suspect a wiring or possibly a power issue. If you made any hardware/wiring additions/changes, or code changes and it quit working, then I would suggest you go back to the condition that worked, then start making changes being careful to test each one before adding more.

Thank you very much for your time
That option I've already taken you into account, I've disconnected the circuit, and removed the entire part of the MPU6050 gyroscope from the program, and it works well.
That's when I include the gyroscope, when problems start.
You would mind looking at the code called 02 Slave, which is responsible for the control of the sensors, I have the doubt that for any circumstance that escapes me, there could be some order that was giving problems, or that some order was incompatible with another.
Thanks a lot
A greeting

02_Esclavo_28_03_2020_arreglando_Mando_PS2.ino (20.7 KB)

"the MPU6050 gyroscope from the program, and it works well.
That's when I include the gyroscope, when problems start."

You might check to see if their components use the same pins as this module causing a pin conflict. You might also check to see if this module has a timing conflict with other devices. When boards and their libraries are developed, they probably assume that other components are not being used that might cause pin conflicts or software issues.

Thank you very much for your time
The pin conflict to which you refer must be as to the internal communication protocol, between the Arduino and the gyroscope, because there is neither in the program, nor in the electrical circuit, any duplicate-defined pins, nor used twice.
One thing that I have not been clear since I started using the gyroscope, is that you do not have to define the communication pin between the Arduino and the gyroscope

The library is defined

#include <MPU6050.h>            // libreria i2c para el Giroscopio ***

The MPU is defined

#define MPU 0x68 // Direccion I2C del MPU6050

The axes is defined

double AcX, AcY, AcZ;

Are defined the pitch and the roll

int Pitch, Roll;

In the void setup it starts with

  init_MPU();                             // Comienza el trabajo del sensor MPU

And in the void loop, nothing is done until here

  loopMPU6050();

And here

void loopMPU6050() {

  FunctionsMPU(); // Adquirimos los ejex AcX, AcY, AcZ.
  Roll = FunctionsPitchRoll(AcX, AcZ, AcY);   //Calculo del angulo del Roll
  Pitch = FunctionsPitchRoll(AcY, AcX, AcZ);  //Calculo del angulo del Pitch
  Serial.print("Pitch: !");
  Serial.print(Pitch);
  Serial.print("\t");
  Serial.print("Roll: !");
  Serial.print(Roll);
  Serial.print("\n");
}

void init_MPU() {
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // Seteamos a cero (wakes up - Despertamos el MPU-6050
  Wire.endTransmission(true);
}
//Funcion para el calculo del angulo Pitch y Roll
double FunctionsPitchRoll(double A, double B, double C) {
  double DatoA, DatoB, Value;
  DatoA = A;
  DatoB = (B * B) + (C * C);
  DatoB = sqrt(DatoB);

  Value = atan2(DatoA, DatoB);
  Value = Value * 180 / 3.14;
  return (int)Value;
}

//Función para adquirir los ejes X, Y, Z del MPU6050
void FunctionsMPU() {
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // Empezamos con el registro 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // requerimos un total de 6 registers
  AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  // txdata.ROVHDG = angle;  // manda mensaje al Maestro de la lectura de la direccion del ROV (Degrees)
  // txdata.ROVDepth = (MS5803Press-1013)/98.1; // manda mensaje al Maestro de la lectura de la profundidad del ROV (m)
}

So I go off according to other sensors, where if you have to define the pin used for reading data by the Arduino.
But of course, since I'm mixing several types of sensors, that makes me think that this particular sensor works differently, and that's why you don't have to define the data reading pins of the gyroscope.
Being a digital sensor, only its name and its unique I2C address, MPU 0x68, is supposed to be able to identify itself, so that Arduino recognizes it, and can work.
What escapes me, is internally, that pins are used for communication, according to the mounting schemes I have seen, and have advised me, the best way to connect it is this from the photo.

Conexiones.png

Therefore, even if the pins are not assigned, when connecting it like this, it should work, since those pins are not being used for anything else, since the ports are the Arduino A5 pin SCL, and the Arduino A4 pin SDA.
Greetings.

Conexiones.png

Good night
As I was writing in the previous post, it occurred to me, to look again at the connection pins of the gyroscope, and the Arduino, and I noticed that above pin 13 of the Arduino, there is a pin marked with GND, and the next is marked as AREF , and the next is marked as SDA, and the next is marked as SCL. I tried to connect the gyroscope by crossing those pins SDA and SCL, and EUREKA, it works, the gyroscope marks the different positions of the pitch and roll, in Monitor Series of the program called 02 Esclavo, which is responsible for controlling the sensors, so it has been fixed one of the problems I had.

Therefore, I do not understand how dare someone can dare to post on different sites, a thing that does not work properly, at least they could warn that with some Arduino model, it may not work well

But not everything can be good news, still not sending me the data from one Arduino to another.

A greeting to all.