Autor Tema: Comunicacion SERIAL entre un PIC16F877A y modulo ESP8266  (Leído 6233 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado adoher

  • PIC10
  • *
  • Mensajes: 13
Comunicacion SERIAL entre un PIC16F877A y modulo ESP8266
« en: 24 de Agosto de 2017, 15:45:13 »
En el momento estoy desarrollando tratando de enviar una datos entre un PIC16F877A un modulo ESP8266

Por el pin 25 del PIC16F877A envío “L01Z01C01P01B61”  así:

El pin 25 del PIC, esta conectado pin 11 del MAX232 y pin 14 al pin 2 de un servidor industrial SENA LS100 y este envía el dato a una IP y puerto, el socket servidor, lee el dato y lo almacena en una tabla en MySQL, muy bien.

Realizo el procedimiento anterior, pero cambio el servidor industrial SENA LS100 por el modulo ESP8266, el pin 4 del modulo RxD al ping 14 del MAX232 y el dato no llega a la base de datos..

Si ejecuto el procedimiento manual, por CMD “type dato1.txt 1>COM4:” conectando el puerto serial pin 2 con 14 MAX232 y pin 3 con 13 MAX232 y el modulo ESP8266 pin 4 RxD con el pin 12 MAX232 el dato llega a la base de datos.

Pero cuando conecto el pin 25 del PIC16F877A al pin 4 RxD del modulo el dato no llega al base de datos.

Codigo en PIC16F877A
--------------------------------------------------
#include <16F877a.h>
#use delay(clock=4M)
#fuses XT,NOWDT,HS,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,PUT
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,parity=N,bits=8)

#Byte PORTB = 0X06
#Byte PORTC = 0X07

#Byte TRISB = 0X86
#Byte TRISC = 0X87

#Bit  RB0 = PORTB.0

#Bit  RC5 = PORTC.5

int1 zb0=0;


void main(VOID) {
port_b_pullups(FALSE);
TRISB=0B11111111;

TRISC=0B00000000;
RC5=1;

CICLO:
IF(RB0==1){IF(zb0==0){zb0=1;printf("%s","L01Z01C01P01B01");}} delay_ms(5); IF(RB0==0){IF(zb0==1){zb0=0;printf("%s","L01Z01C01P01B02");}};
GOTO CICLO;
}
--------------------------------------------------

Codigo en modulo ESP8266-01
--------------------------------------------------
#include <SoftwareSerial.h>
SoftwareSerial SerialESP8266(4,5); // RX, TX
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti WiFiMulti;

String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
boolean newData = false;

void setup() {
// initialize serial:
Serial.begin(9600);
delay(10);
// reserve 15 bytes for the inputString:
inputString.reserve(15);

// We start by connecting to a WiFi network
WiFiMulti.addAP("dlink", "");

//Serial.println();
//Serial.print("Wait for WiFi... ");
//Serial.print("1 IP : ");
//Serial.println(WiFi.localIP());

while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print("2 IP : ");
Serial.println(WiFi.localIP());
delay(500);
}

//Serial.println("");
//Serial.println("WiFi connected");
//Serial.println("IP address: ");
//Serial.println(WiFi.localIP());

delay(500);

}
//Fin Setup

void loop() {
  // print the string when a newline arrives:
  //Serial.print(" Dios ");
  while (Serial.available() > 0 ) {
        //Serial.print(" Dato available() > 0 ");
        // get the new byte:
        //char inChar = (char)Serial.read();
        char inChar = Serial.read();
        // add it to the inputString:
        inputString += inChar;
        // if the incoming character is a newline, set a flag
        // so the main loop can do something about it:
        if (inChar == '\n') { stringComplete = true;Serial.print(" Evento "); }
  }

  if (stringComplete) {
     //Serial.println(inputString);
     //Serial.print("Recibio RxD\n");
     //Codigo copia ejemplo ClienteBasic
     const uint16_t port = 1961;
     const char * host = "192.168.0.100"; // ip or dns

     //Serial.print("connecting to ");
     //Serial.println(host);

     // Use WiFiClient class to create TCP connections
     WiFiClient client;

     if (!client.connect(host, port)) {
        Serial.println("connection failed");
        Serial.println("wait 3 sec...");
        delay(3000);
        return;
     }
     //http://forum.arduino.cc/index.php?topic=409456.0
     //Serial.print(buffer);

     // This will send the request to the server
     // "Send this data to server"
     client.print(inputString);

     //read back one line from server
     String line = client.readStringUntil('\r');
     client.println(line);

     //Serial.println("closing connection");
     client.stop();

     //Serial.println("wait 5 sec...");
     //delay(5000);
   
     //Fin codigo copia
     // clear the string:
     inputString = "";
     stringComplete = false;

  }
//Serial.print("Loop\n");
}
//Fin Loop
--------------------------------------------------

Quedo muy agradecido por el apoyo que me puedan brindar.

Desconectado adoher

  • PIC10
  • *
  • Mensajes: 13
Re:Comunicacion SERIAL entre un PIC16F877A y modulo ESP8266
« Respuesta #1 en: 04 de Septiembre de 2017, 21:47:32 »
Mucho gusto, quedo muy agradecido por la atencion,

La novedad que se me presento, en mi consulta en el foro, de tanto buscar, lo solucione asi:

Como el circuito lo tengo implementado en un protoboard, conecte en la misma perforacion del pin 25 del PIC  el alambre de conexion del pin 4 RxD del modulo ESP8266. Por lo tanto ya logre enviar los datos del pic al modulo ESP8266 y este al socket en un servidor linux.

Los protoboar nos ayudan a probar los circuitos, pero nos dan problemas.

Muchas gracias.

Desconectado Aicubo

  • PIC10
  • *
  • Mensajes: 1
Re:Comunicacion SERIAL entre un PIC16F877A y modulo ESP8266
« Respuesta #2 en: 21 de Noviembre de 2017, 02:14:29 »
Hola,muy didáctico tu post. Ojala subas más info de este tipo  :-/


 

anything