Skip to content

Commit 4db82fe

Browse files
committed
Se añade anexo con añadidos de ejemplos y amplicacion de la explicacion del uso de las particiones y datos de EPROM ESP32
nuevos ejemploa Ej_INT uso de interupciones externas, que se añade ya que el capitulo del libro no las tenia. GranEjemplo de motores con configuraciones de wifi y web en EPROM
1 parent 68af4f2 commit 4db82fe

File tree

20 files changed

+545
-8
lines changed

20 files changed

+545
-8
lines changed
-28.1 MB
Binary file not shown.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/********************************************************************************************************
2+
* Autor: Fco. Javier Rodriguez Navarro *
3+
* WEB: www.pinguytaz.net *
4+
* https://github.com/pinguytaz *
5+
* *
6+
* Descripción: Ejemplo de desarrollo en Arduino de la ina ISR (Interruption Service Rutine) *
7+
* se describen en el capitulo 7.1.4 *
8+
* Este ejemplo pretender mostrar el uso interrupciones externas en lugar de estar *
9+
* mirando constantemente el valor del boton y cambiando el estado de la entrada *
10+
* *
11+
* Historico: *
12+
* Creación: 1.0 Enero 2025 FJRN *
13+
* *
14+
********************************************************************************************************/
15+
16+
// Variables que cambian en la funcion para indicar que existe un cambion, luego en loop otra vez false.
17+
volatile bool cambio0=false;
18+
volatile int contador=0;
19+
volatile bool cambio1=false;
20+
21+
void setup()
22+
{
23+
Serial.begin(9600);
24+
pinMode(2, INPUT_PULLUP);
25+
pinMode(3, INPUT_PULLUP);
26+
27+
// Definimos las interrupciones con sus funciones CallBack
28+
attachInterrupt(digitalPinToInterrupt(2), funcionISR0, CHANGE); // Se produce cuando existe un cambio.
29+
attachInterrupt(digitalPinToInterrupt(3), funcionISR1, CHANGE); // Se produce cuando existe un cambio.
30+
31+
Serial.println("******** Comenzamos el programa *******");
32+
}
33+
34+
void loop()
35+
{
36+
if(cambio0) // Existe uncambio en el pin D2 por lo que leemos valor eimprimimos.
37+
{
38+
Serial.print("Cambio realizado en D2 a ");
39+
Serial.println(digitalRead(2));
40+
Serial.print("El contador en "); // Nos marca cambios y rebotes.
41+
Serial.println(contador);
42+
contador=0; // Serestablece a 0 y asi vemos cuantos cambios antes de realizar un ciclo de bucle.
43+
cambio0=false;
44+
}
45+
46+
if(cambio1) // Existe uncambio en el pin D3 por lo que leemos valor eimprimimos.
47+
{
48+
Serial.print("Cambio realizado en D3 a ");
49+
Serial.println(digitalRead(3));
50+
cambio1=false;
51+
}
52+
delay(10000);
53+
}
54+
55+
// Funcion de llamada de la interrupción 0 cuando se realice un cambio en la entrada D2
56+
void funcionISR0()
57+
{
58+
cambio0=true;
59+
contador++;
60+
}
61+
62+
// Funcion de llamada de la interrupción 1 cuando se realice un cambio en D3
63+
void funcionISR1()
64+
{
65+
cambio1=true;
66+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include "CartesianoX.h"
2+
3+
CartesianoX::CartesianoX(int pasos, int pps, int pin_FinCarrera )
4+
{
5+
_pasos = pasos;
6+
_pps = pps;
7+
retardo = 60L*1000L/920;
8+
_pin_FinCarrera = pin_FinCarrera;
9+
}
10+
void CartesianoX::Inicia(int pin_M1 ,int pin_M2, int pin_M3, int pin_M4)
11+
{
12+
_driver = DRIVE_L298N;
13+
_pin_M1 = pin_M1;
14+
_pin_M2 = pin_M2;
15+
_pin_M3 = pin_M3;
16+
_pin_M4 = pin_M4;
17+
secuencia = -1;
18+
19+
pinMode(_pin_M1, OUTPUT);
20+
pinMode(_pin_M2, OUTPUT);
21+
pinMode(_pin_M3, OUTPUT);
22+
pinMode(_pin_M4, OUTPUT);
23+
pinMode(_pin_FinCarrera, INPUT);
24+
25+
// Nos colocamos en 0
26+
while (digitalRead(_pin_FinCarrera))
27+
{
28+
retrocede();
29+
delay(250);
30+
}
31+
xActual = 0;
32+
}
33+
34+
void CartesianoX::avanza(void)
35+
{
36+
if(++secuencia > 3) secuencia=0;
37+
paso();
38+
xActual++;
39+
}
40+
41+
void CartesianoX::retrocede(void)
42+
{
43+
if(--secuencia < 0 ) secuencia=3;
44+
paso();
45+
xActual--;
46+
}
47+
48+
void CartesianoX::paso(void)
49+
{
50+
switch(_driver)
51+
{
52+
case DRIVE_L298N:
53+
// Motor Bibolar de 4 Hilos
54+
digitalWrite(_pin_M1, sec4[secuencia][0]); // Los pines se activan en secuencia
55+
digitalWrite(_pin_M2, sec4[secuencia][1]);
56+
digitalWrite(_pin_M3, sec4[secuencia][2]);
57+
digitalWrite(_pin_M4, sec4[secuencia][3]);
58+
delay(retardo);
59+
digitalWrite(_pin_M1, LOW); // Ponemos en reposo las bobinas
60+
digitalWrite(_pin_M2, LOW);
61+
digitalWrite(_pin_M3, LOW);
62+
digitalWrite(_pin_M4, LOW);
63+
delay(retardo);
64+
break;
65+
case DRIVE_POLOLU:
66+
Serial.println("No implementado Pololu");
67+
break;
68+
}
69+
}
70+
int CartesianoX::get_X(void ){ return xActual; }
71+
void CartesianoX::irA(int x)
72+
{
73+
Serial.println("Vamos de " + String(xActual) + " a "+String(x)) ;
74+
if (xActual == x) return;
75+
if (x > xActual)
76+
{
77+
int golpes = x-xActual;
78+
for (int i =0; i< golpes ; i++) avanza();
79+
}
80+
else
81+
{
82+
int golpes = xActual-x;
83+
for (int i =0; i < golpes; i++) retrocede();
84+
}
85+
xActual = x;
86+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef CartesianoX_H
2+
#define CartesianoX_H
3+
#include <Arduino.h>
4+
5+
//#define RETARDO 50
6+
typedef enum
7+
{
8+
DRIVE_L298N = 0,
9+
DRIVE_POLOLU = 1
10+
} Tipos_Driver;
11+
12+
typedef enum
13+
{
14+
MPaP_ = 0,
15+
} Error_CartesianoX;
16+
17+
18+
class CartesianoX
19+
{
20+
private:
21+
Tipos_Driver _driver;
22+
int _pasos;
23+
int _pps;
24+
long retardo;
25+
int secuencia;
26+
int xActual;
27+
28+
// Datos para Pololu
29+
int _pin_paso;
30+
int _pin_dir;
31+
32+
// Datos para L298 4 Hilos
33+
int _pin_M1;
34+
int _pin_M2;
35+
int _pin_M3;
36+
int _pin_M4;
37+
int _pin_FinCarrera;
38+
int sec4[4][4] = {{HIGH,HIGH,LOW,LOW}, {LOW,HIGH,HIGH,LOW}, {LOW,LOW,HIGH,HIGH}, {HIGH,LOW,LOW,HIGH}};
39+
40+
void paso(void);
41+
42+
public:
43+
CartesianoX(int, int, int);
44+
void Inicia(int ,int , int, int );
45+
void avanza(void);
46+
void retrocede(void);
47+
void irA(int);
48+
int get_X(void);
49+
};
50+
51+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef Coordenadas_H
2+
#define Coordenadas_H
3+
4+
int cordenada[][2] = {
5+
// 0 1 2 3 4 5 6 7 8 9
6+
{55,0},{85,0},{77,0},{68,0},{9,0},{12,0},{33,0},{55,0},{44,0},{85,0},
7+
// A B C D E F G H I J
8+
{9,0},{9,0},{9,0},{12,0},{12,0},{12,0},{33,0},{33,0},{33,0},{44,0},
9+
// K L M N O P Q R S T
10+
{44,0},{44,0},{55,0},{68,0},{68,0},{77,0},{77,0},{77,0},{77,0},{85,0},
11+
// U V W X Y Z
12+
{85,0},{85,0},{55,0},{55,0},{55,0},{55,0}};
13+
14+
#endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "Disco.h"
2+
3+
Disco::Disco(char*montar)
4+
{
5+
Serial.println("Constructor");
6+
if (!pdatos.begin(true,"/WEB",10,montar)) // Monta partición
7+
{
8+
while(true);
9+
}
10+
}
11+
12+
float Disco::cargaPagina(String pagina, char *texto)
13+
{
14+
int i=0;
15+
File file = pdatos.open(pagina);
16+
if(!file)
17+
{
18+
return -1;
19+
}
20+
21+
while(file.available()) texto[i++]=(char) file.read();
22+
texto[i]=0; //Ponemos un fin para que pueda tratarse como String.
23+
file.close();
24+
25+
return i;
26+
}
27+
28+
void Disco::ficheros()
29+
{
30+
File root = pdatos.open("/");
31+
if(!root)
32+
{
33+
Serial.println("Fallo al abrir el directorio");
34+
return ;
35+
}
36+
37+
File file = root.openNextFile();
38+
while(file)
39+
{
40+
Serial.print(" Fichero: ");
41+
Serial.print(file.name());
42+
Serial.print("\tTamaño: ");
43+
Serial.println(file.size());
44+
file = root.openNextFile();
45+
}
46+
root.close();
47+
}
48+
49+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************************************
2+
* Autor: Fco. Javier Rodriguez Navarro
3+
* WEB: www.pinguytaz.net
4+
*
5+
* Descripción: Clase gestion disco WEB
6+
*
7+
***********************************************************************************************/
8+
#ifndef Disco_H
9+
#define Disco_H
10+
11+
#include "FS.h"
12+
#include "SPIFFS.h"
13+
14+
class Disco
15+
{
16+
private:
17+
fs::SPIFFSFS pdatos;
18+
19+
public:
20+
Disco(char *);
21+
float cargaPagina(String , char*);
22+
void ficheros();
23+
};
24+
25+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /bin/sh
2+
3+
. $HOME/esp/esp-idf/export.sh
4+
BLOQUE=4096
5+
PAGINA=256
6+
DIRECCION=0x9000
7+
IMAGEN=nvs
8+
#TAMANO=20480
9+
TAMANO=24576
10+
11+
#Generamos las nvs con datos
12+
python ~/esp/esp-idf/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py generate $IMAGEN.csv $IMAGEN.bin $TAMANO
13+
esptool.py --chip esp32 write_flash -z $DIRECCION $IMAGEN.bin
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /bin/sh
2+
3+
. $HOME/esp/esp-idf/export.sh
4+
BLOQUE=4096
5+
PAGINA=256
6+
directorio=./WEB
7+
#DIRECCION=0x290000
8+
DIRECCION=0x2f0000
9+
IMAGEN=WEB
10+
#TAMANO=1441792
11+
TAMANO=1048576
12+
13+
#Generamos Subimos datos WEB
14+
~/.arduino15/packages/esp32/tools/mkspiffs/0.2.3/mkspiffs -c $directorio -b $BLOQUE -p $PAGINA -s $TAMANO $IMAGEN.bin
15+
esptool.py --chip esp32 write_flash -z $DIRECCION $IMAGEN.bin
1 MB
Binary file not shown.

0 commit comments

Comments
 (0)