Este es el programa llamado Esclavo, que es el que esta dentro del vehículo, pongo primero la cabecera con las explicaciones, y después el código.
This is the program called Slave, which is the one inside the vehicle, I put first the header with the explanations, and then the code.
/*
Modificado por asesorplaza1 en las diferentes fechas indicadas
Las primeras pruebas y cambios del código, se iniciaron en 2.016, debido a la cantidad de modificaciones
A partir de ahora 30/01/2020, se ponen las fechas y los cambios en la descripción del proyecto
Para facilitar la búsqueda de errores en los diferentes cambios del código
30/01/2020 ya se han comentado todas las líneas de control de la cámara y del LCD
Le añado 2 DHT22 y así estarán los 3 que me hacen falta
He borrado varias líneas de control de la cámara que no se va a utilizar
01/02/2020 le añado los controles del giroscopio facilitados por Dea de www.cambatronics.com
02/02/2020 le añado la orden para leer solo 1 vez X segundo el DHT22, truco de José Luis de
www.cambatronics.com
y se borran las líneas correspondientes al control de la cámara de video
No utilizadas por asesorplaza1, en esta modificación del proyecto original
04/02/2020 modifico las líneas de lectura de los sensores, porque hasta ahora solo me imprime en Monitor Serie el texto, no los datos
06/02/2020 se depura un poco el código, y se modifica el encabezado del código
08/02/2020 se corrige el error de lectura en los sensores, y se corrige la escritura del Monitor Serie
12/02/2020 para poder añadir cualquier código hay que seguir unas reglas especificas de programación
Se modifica la estructura del código siguiendo esas órdenes de programación, según la información obtenida y guardada
En la carpeta 01_UNIR_2_CODIGOS
Se crean varios bloques en el void loop, para el funcionamiento de cada uno de los sensores, eliminando los delay()
13/02/2020 se incluye el sensor de temperatura DS18B20, ayudado por DEA de www.cambatronics.com
16/02/2020 Se añade el sensor de distancia infrarrojo E18-D80NK, sin errores
y consigo adaptar un código para leer el sensor de presión SKU237545
08/03/2020 se conecta un relé en el pin 12 del Arduino Esclavo, para encender los focos de luz externos, no hace falta cambiar el código
26/03/2020 Se incluye la librería MPU6050, para controlar el giroscopio
Se arregla el envió de datos, separando los datos del Monitor Serie, y los datos que hay que enviar al Arduino Maestro,
iniciando dos puertos serie con las ordenes
Serial.begin(57600); // Puerto Serie USB
Serial1.begin(57600); // Puerto Serie en los pines 18 y 19
ETin.begin(details(rxdata), &Serial1); // Comienza la recepción de datos a través de Serial, en los pines 18 y 19
ETout.begin(details(txdata), &Serial1); // Comienza el envío de datos a través de Serial, en los pines 18 y 19
28/03/2020 Se incluyen el envió de todas las instrucciones del mando, para tener todos los botones operativos (no funciona)
03/04/2020 Se incluye la parte nueva del Giroscopio MPU6050, que muestra los 3 ejes de inclinación, más la temperatura del Giroscopio.
Se incluye el segundo sensor de presión
05/04/2020 se cambia el código del sensor infrarrojo E18D80NK, por uno mejor
11/04/2020 Corrijo el código según las instrucciones de mi amigo Atilano Belinchón
13/04/2020 Corrijo las lecturas y envió de datos del sensor de infrarrojos E18D80NK
15/04/2020 Se incluye el servo de dirección para accionarlo con los botones R1 y R2 del mando
según información obtenida de la pagina
https://arduparatodos.blogspot.com/2017/02/controlar-servomotor-con-arduino-varios.html
18/04/2020 Se cambian algunos " if ", por " else if ", para darle agilidad al código, siguiendo las instrucciones de DEA de www.cambatronics.com
Entre el día 24/03/2020 y el día 28/04/2020, se hacen varios cambios en el código para mejorarlo y conseguir que el mando funcione,
Siguiendo las instrucciones de bigbadbob en las publicaciones del foro
http://www.homebuiltrovs.com/rovforum/viewtopic.php?f=18&t=1908
A partir de la página 4
28/04/2020 Se corrige la ortografía de todo le texto que no son órdenes
03/05/2020 Se cambian las asignaciones de los pines, según el código de Github
Las nuevas asignaciones de pines son:
Salida de 3.3V a PIN rojo PS2
Pin 24 a PIN amarillo PS2 + resistencia 1k
Pin 23 a PIN naranja PS2
Pin 25 a PIN marrón PS2 + resistencia 1k
Pin 22 a PIN azul PS2
Se arregla el código para que me salga en el Maestro el estado de los focos, encendidos / apagados
04/05/2020 Se depura el código según los consejos de Bigbadbob de http://www.homebuiltrov.com
05/05/2020 Se incluye la Macro F, en todos los Serial.print, para reducir el consumo de memoria dinámica
Según los consejos de Bigbadbob de http://www.homebuiltrov.com, pero me da problemas
06/05/2020 Se depura el código para un mejor funcionamiento, según los consejos de Bigbadbob de http://www.homebuiltrov.com
y siguen los problemas con la Macro F
07/05/2020 Se depura el código para un mejor funcionamiento, según los consejos de Bigbadbob de http://www.homebuiltrov.com
y siguen los problemas con la Macro F
08/05/2020 Se corrigen los problemas de la Macro F, en todos los Serial.print de texto fijo
No se puede poner la Macro F, a los Serial.print de datos de los sensores
Y se consigue reducir el consumo de memoria dinámica considerablemente
09/05/2020 Se siguen corrigiendo líneas para la depuración del código, según los consejos de Bigbadbob de http://www.homebuiltrov.com
Pero siguen los problemas con el mando de la PS2
10/05/2020 Me doy cuenta de un error en la orden de encender los focos y lo corrijo
Pero el mando sigue sin funcionar como es debido
11/05/2020 Se modifican varias órdenes del control de los botones, pero el mando sigue sin funcionar correctamente
16/05/2020 Se hacen diversos cambios, segun los consejos de Tsanshon de www.foromodelismonaval.es
La versión original tomada como punto de partida es la siguiente
ROVPS2Control_Slavev8.ino
Hamish Trolove - 30 de marzo de 2016
www.techmonkeybusiness.com
Este boceto toma los comandos que se le envían desde la unidad maestra con el controlador PS2 conectado y lo convierte en comandos de motor,
Servo comandos, controles de luz, etc. Los datos se envían desde el Arduino (maestro) al ROV (esclavo) utilizando la biblioteca EasyTransfer de Bill Porter a través de un enlace en serie de 9600 baudios (anclaje de 100 m). La biblioteca MS5803_14 es de Luke Miller http://github.com/millerlp
Los datos enviados desde el maestro son configuraciones sin formato para el control ESC.
Este boceto está diseñado para un Arduino Nano con un solo puerto serie.
Yo lo estoy usando en un Mega 2560, y funcionba, hasta que empecé a introducir sensores
Para la transmisión del video asesorplaza1 utilizara una Raspberry Pi 3 plus, una cámara USB, y el programa VCL Media Player
Se cambian estos sensores por obsoletos, se usan los sensores DHT22 y el giroscopio MPU6050
Conexión serial de comunicaciones: modificado por Asesorplaza1, el 26/03/2020, para separar los datos mandados entre Arduinos, de los datos a mandar al Monitor serie
19 superior (TX) a ROV 18 (RX) Conexión serial: 18 superior (RX) a ROV 19 (TX)
Conecte el GND en ambos
Tenga en cuenta que los ESC ya se habrán programado en este punto del proyecto.
Los datos de voltaje interno, rumbo, profundidad y temperatura interna se envían a través del enlace serie de regreso al maestro
Para su visualización en una pantalla LCD de 16x2.
La pantalla LCD de 16x2, se cambiara por una pantalla Nextion básica de 5"
Se cambia este sensor por obsoleto, se usa el giroscopio MPU 6050
Ver también como se desarrolla el proyecto original con los siguientes códigos:
HoryzonTrigger.ino, ROVPS2Control_Masterv0.ino,
ROVDoNothing.ino, ROVSubBv0.ino, DigitalCompassv2.ino,
PTLoggerv4.ino y TMP36_Temperature_Sensor.ino.
En la página www.techmonkeybusiness.com
*/
/*
Modified byplaza advisor1 on the different dates indicated
The first tests and code changes were initiated in 2,016, due to the number of modifications
As of now 30/01/2020, dates and changes are made to the project description
To make it easier to find errors in different code changes
30/01/2020 all camera and LCD control lines have already been commented on
I add 2 DHT22 and so will be the 3 I need
I've erased several control lines from the camera that won't be used
01/02/2020 I add the gyroscope controls provided by Dea de [www.cambatronics.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.cambatronics.com)
02/02/2020 I add the order to read only 1 time X second the DHT22, trick by José Luis de
[www.cambatronics.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.cambatronics.com)
and the lines corresponding to the control of the video camera are deleted
Not used byplaza advisor1, in this modification of the original project
04/02/2020 I modify the reading lines of the sensors, because so far I only print in Monitor Series the text, not the data
06/02/2020 debugging the code a bit, and modifying the code header
08/02/2020 corrects the reading error in the sensors, and corrects the writing of the Series Monitor
12/02/2020 to be able to add any code you have to follow specific programming rules
The structure of the code is modified according to those programming orders, based on the information obtained and stored
In the 01_UNIR_2_CODIGOS folder
Several blocks are created in the void loop, for the operation of each of the sensors, eliminating the delay()
13/02/2020 temperature sensor DS18B20 is included, assisted by DEA of [www.cambatronics.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.cambatronics.com)
16/02/2020 E18-D80NK infrared distance sensor added, no errors
and I get to adapt a code to read the pressure sensor SKU237545
08/03/2020 a relay is connected on pin 12 of the Arduino Slave, to turn on the external light bulbs, there is no need to change the code
26/03/2020 The MPU6050 library is included to control the gyroscope
Fixed data sending, separating the data from the Serial Monitor, and the data to be sent to the Arduino Maestro,
initiating two serial ports with orders
Serial.begin(57600); USB Series Port
Serial1.begin(57600); Serial port on pins 18 and 19
ETin.begin(details(rxdata), &Serial1); Data reception begins through Serial, at pins 18 and 19
ETout.begin(details(txdata), &Serial1); Start sending data through Serial, at pins 18 and 19
28/03/2020 All control instructions are included, to have all buttons operational (not working)
03/04/2020 The new part of the MPU6050 Gyroscope is included, showing the 3 tilt axes, plus the temperature of the Gyroscope.
Included is the second pressure sensor
05/04/2020 the code of the infrared sensor E18D80NK is changed, to a better one
11/04/2020 I correct the code according to the instructions of my friend Atilano Belinchón
13/04/2020 I correct the readings and send data from the E18D80NK infrared sensor
15/04/2020 Steering servo is included to operate it with the R1 and R2 buttons on the controller
based on information obtained from the website
[https://arduparatodos.blogspot.com/2017/02/controlar-servomotor-con-arduino-varios.html](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=https%3A%2F%2Farduparatodos.blogspot.com%2F2017%2F02%2Fcontrolar-servomotor-con-arduino-varios.html)
18/04/2020 Some "if" are changed to "else if" to give the code agility, following the DEA instructions in [www.cambatronics.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.cambatronics.com)
Between 24/03/2020 and 28/04/2020, several code changes are made to improve it and make the controller work,
Following the instructions of bigbadbob in the forum posts
[http://www.homebuiltrovs.com/rovforum/viewtopic.php?f=18&t=1908](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=http%3A%2F%2Fwww.homebuiltrovs.com%2Frovforum%2Fviewtopic.php%3Ff%3D18%26t%3D1908)
From page 4
28/04/2020 Corrects the spelling of all text that are not orders
03/05/2020 Pin assignments are changed, according to Github code
The new pin assignments are:
3.3V output to red PS2 PIN
Pin 24 to PS2 yellow PIN + 1k resistance
Pin 23 to PIN Orange PS2
Pin 25 to PIN brown PS2 + 1k resistance
Pin 22 to PS2 Blue PIN
Fixed the code to get me out in the Master the state of the spotlights, on/off
04/05/2020 Code is debugged according to Bigbadbob's advice from [http://www.homebuiltrov.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=http%3A%2F%2Fwww.homebuiltrov.com)
05/05/2020 Macro F is included, in all Serial.print, to reduce dynamic memory consumption
According to Bigbadbob's advice from http://www.homebuiltrov.com, but it gives me trouble
06/05/2020 Code is debugged for better performance, according to Bigbadbob's advice from [http://www.homebuiltrov.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=http%3A%2F%2Fwww.homebuiltrov.com)
and the problems with Macro F follow
07/05/2020 Code is debugged for better performance, according to Bigbadbob's advice from [http://www.homebuiltrov.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=http%3A%2F%2Fwww.homebuiltrov.com)
and the problems with Macro F follow
08/05/2020 Fixed Macro F issues in all fixed-text [Serial.prints](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=Serial.prints)
You can't put Macro F, to [Serial.print](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=Serial.print) sensor data
And it reduces dynamic memory consumption considerably
09/05/2020 Lines are still corrected for code debugging, according to Bigbadbob's advice from [http://www.homebuiltrov.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=http%3A%2F%2Fwww.homebuiltrov.com)
But the problems with PS2 command continue
10/05/2020 I notice an error in the order to turn on the spotlights and correct it
But the controller still doesn't work properly
11/05/2020 Several button control commands are modified, but the controller still does not work properly
16/05/2020 Various changes are made, according to Tsanshon's advice from [www.foromodelismonaval.es](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.foromodelismonaval.es)
The original version taken as a starting point is as follows
ROVPS2Control_Slavev8.ino
Hamish Trolove - 30 March 2016
[www.techmonkeybusiness.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.techmonkeybusiness.com)
This sketch takes the commands that are sent to you from the master drive with the PS2 controller connected and converts it to engine commands,
Servo commands, light controls, etc. The data is sent from the Arduino (master) to the ROV (slave) using Bill Porter's EasyTransfer library via a 9600 baud (100 m anchor) serial link. The MS5803_14 library is by Luke Miller [http://github.com/millerlp](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=http%3A%2F%2Fgithub.com%2Fmillerlp)
Data sent from the master are raw configurations for the ESC control.
This sketch is designed for an Arduino Nano with a single serial port.
I'm using it on a Mega 2560, and it worked, until I started introducing sensors
For the transmission of the video advisorplaza1 will use a Raspberry Pi 3 plus, a USB camera, and the program VCL Media Player
These sensors are changed to obsolete, dhT22 sensors and the MPU6050 gyroscope are used
Serial communications connection: modified by Adviserplaza1, 26/03/2020, to separate the data sent between Arduinos, from the data to be sent to the Serial Monitor
19 top (TX) to ROV 18 (RX) Serial connection: 18 top (RX) to ROV 19 (TX)
Connect the GND on both
Note that THE ESCs have already been scheduled at this point in the project.
Internal voltage, heading, depth, and internal temperature data are sent via the series link back to the master
For viewing on a 16x2 LCD screen.
The 16x2 LCD display will be replaced by a basic Nextion display of 5"
This sensor is changed to obsolete, the MPU 6050 gyroscope is used
See also how the original project develops with the following codes:
HoryzonTrigger.ino, ROVPS2Control_Masterv0.ino,
ROVDoNothing.ino, ROVSubBv0.ino, DigitalCompassv2.ino,
[PTLoggerv4.ino](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=PTLoggerv4.ino) and TMP36_Temperature_Sensor.ino.
On the [www.techmonkeybusiness.com](https://ssl.microsofttranslator.com/bv.aspx?ref=TAns&from=&to=en&a=www.techmonkeybusiness.com) page
*/