UART issues please help

Posted on
  • so, i am interfacing esp8266 wemos d1 mini with atmega328. ATmega328 sending data to esp8266 using serial communication. I think the serial is not working correctly.

    when i powered up 2 board,the esp can connect to my local mqtt and sending "no_data", even though i see on my atmega328 lcd that the data was sent correctly.

    but when i connect to wemos using espruino ide over ip address. i magically can send the data to mqtt correctly.

    i've tries several times, that i need to connect to esp through espruino program on computer as if it is "openning the lock" on my uart port on esp.

    where is the mistake?

    Serial1.setup(19200,{rx:D3,tx:D1});
    
    var mqtt = require("tinyMQTT").create(server, {
        username: "a",
        password: "asdfghjkl",
        port: 1883
    });
    
    function konekwifi()
    {
      wifi.connect("qwer",{password:"asdfqwer"­},
      function(){
        mqtt.connect();
      });
    }
    
    function kirimdata()
    {
      var bsplit=buff.split(",");
      if(buff!='' && bsplit.length>=3)
      {
        mqtt.publish("posisi/"+clientid, JSON.stringify(
          {
            'name':clientid,
            'lat':bsplit[0], 
            'lon':bsplit[1], 
            'pm':bsplit[2]
          }));
      } else
      {
        console.log(bsplit.length+'_no_data_'+bu­ff);
        mqtt.publish("status/"+clientid, "no_data_"+bsplit.length);
      }
    }
    
    function onInit() {
      konekwifi();
      wifi.stopAP();
    
      setTimeout(function(){
        if (wifi.getIP().ip!='0.0.0.0'){
          console.log(wifi.getIP());
        } else {konekwifi();}
      }, 15000);
    }
    
    
    //event handler
    Serial1.on('data', 
    function (data) { 
      buff=data;
    });
    
    setInterval(kirimdata, 2000);
    
    
  • Not much familiar with the context, but if serial gets stuck or a like, check where the console goes. Give it another try after removing the console.log()s. There are ways to direct the console somewhere else. (console, connected, hang, etc.)

  • Serial1.setup(19200,{rx:D3,tx:D1});

    for a wemos board you have to use NodeMCU pin names

    http://www.espruino.com/Reference#NodeMC­U

    https://github.com/espruino/Espruino/blo­b/master/targets/esp8266/jswrap_nodemcu.­c

  • I solved the problem. I can do it after moving the console to Telnet. I read it on espruino documentation on the very bottom of the page.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

UART issues please help

Posted by Avatar for martinbandung @martinbandung

Actions