Avatar for maman

maman

Member since Aug 2018 • Last active Dec 2018
  • 1 conversations
  • 12 comments

Most recent activity

  • in ESP8266
    Avatar for maman

    Hello @allObjects,

    What is espruino version do you use ?
    Previously, I used espruino_2v00.17 on ESP-07. It was periodically crashed.
    Changed to espruino_1v99, using the same script code, it is no problem.

  • in ESP8266
    Avatar for maman

    var MAX485_DE = D12;
    var RXPIN = D13;
    var TXPIN = D14;
    var Serial3 = new Serial();
    Serial3.setup(9600, {rx:RXPIN,tx:TXPIN, parity:'even'});
    Serial1.setup(9600, {parity:'even'});

  • in ESP8266
    Avatar for maman

    Hello @MaBe,

    Now, I am trying to use software serial to communicate with MODBUS energy meter.
    The RS485 MODBUS protocol required 1 stop bit, 8 databits, 1 even parity and 1 stop bit.
    So, need 11 bits in total.

    The software serial can send the command to the meter, however, get error data from the meter.

    If I change to use hardware serial, using the same code, the ESP can receive data, properly.

    The error data is consistent. The first byte is should be 0x01 (00000001), but we get 0x80
    (10000000). The second byte should be 0x03, in serial monitor I get data as follows :
    10000000 00000001 10000010
    first byte second byte third byte, respectively.
    It seem that the second byte is shifted to the right.

    Is there any hint to correct the bytes ?

    Thanks,

  • in ESP8266
    Avatar for maman

    LED matrix display (P10), the size is about 1m x 6m

  • in ESP8266
    Avatar for maman

    Sorry, just now, I updated the espruino code to the latest one.
    It is working perfectly. This is my test code :

    var status=0;
    function swap() {
        status = !status;
        digitalWrite(D2, status);
    }
    
    var Serial3 = new Serial();
    Serial3.setup(9600, {rx:D4,tx:D5});
    //Serial1.setup(9600);
    Serial3.on('data', function (data) { 
      console.log(data);
      swap(); 
    });
    
    var buf1 = new ArrayBuffer();
    buf1 = [0x01, 0x03, 0x00, 0x00, 0x00, 0x05, 0x85, 0xC9];
    var count = 0;
    setInterval(function() {
      if (count > 7) {
        count = 0;
      }
      console.log("send data", count);
      Serial3.write(buf1);
      count += 1;
    }, 2000);
    

    However, if we increase the baud-rate to 115200, the ESP will be crashed.
    But, for my application, it is Ok. For displaying the data to the LED matrix display, that required highspeed UART at 115200, I will use hardware serial.

    Thanks for your help, @MaBe

  • in ESP8266
    Avatar for maman

    yes. Yesterday, I updated the source.

    We also tested for sending data from ESP to PC, we found that the PC get the wrong data, at any baudrate. So, for receiving, the software serial is ok for up to 9600, while for sending data is failed.

    My code is tested on hardware serial (Serial1), it is no problem for sending or receiving.
    We need two serials on my ESP-12, one is for getting data from sensor and the other for displaying the data to LED matrix display.

  • in ESP8266
    Avatar for maman

    Hello @MaBe,

    I have tested your code on Wemos D1 Mini (ESP8266, ESP-12) using Espruino 2.00,

    var status=0;
    function swap() {
        status = !status;
        digitalWrite(D2, status);
    }
    var Serial3 = new Serial();
    Serial3.setup(9600, {rx:D4,tx:D5});
    Serial3.on('data', function (data) { 
      console.log(data);
      swap(); 
    });
    

    Serial3 is assigned as software serial.
    If we send one-by-one character, I can see the console log is Ok. Perfectly working.
    If we send for example "test" string, then in the console.log will be displayed "t" and "est".

    However, if we increase the baudrate to 115200, software-serial will get the wrong data.

    Thanks @MaBe

  • in Projects
    Avatar for maman

    Hello @Wilberforce,

    Yes, I am using esp8266 (wemos d1 mini).
    I have put the program on "save on send" option.
    The script should be small in size as follows

    I2C1.setup({scl:D5,sda:D4, bitrate:100000});
    var PID = require('pid-controller');
    var bme = require("BME280").connect(I2C1);
    var WIFI_NAME = "xxx";
    var WIFI_OPTIONS = { password : "xxx" };
    var MQTT_HOST = "192.168.0.156";
    var PATH = "/mydevice/";
    var LED = D13;
    var RELAY = D12;
    var BTN = D0;
    var mqtt;
    var wifi;
    var hum = 20,
        humSetpoint = 55;
    
    var Kp = 100,
        Ki = 0,
        Kd = 0;
    
    var ctr;
    var timeframe = 30000;
    var dacMin = 100;
    var dacMax = 3000;
    
    wifi = require("Wifi");
    var nodeID = wifi.getIP().mac;
    nodeID = nodeID.replace(/:/g, "");
    nodeID = nodeID.toUpperCase();
    
    function updatePid() {
      hum = bme.getData().humidity;
      hum = hum.toFixed(1);
      hum = E.clip(hum, 10, 100);
      ctr.setInput(hum);
      if (ctr.compute()) {
        var dataDac = ctr.getOutput();
        dataDac = E.clip(dataDac, dacMin, dacMax);
        I2C1.writeTo(0x60, [dataDac >> 8, dataDac]);
        setTimeout(function() {
          var adc = analogRead().toFixed(3);
          var bufText = "{\"H\":"+hum+",\"DAC\":"+dataDac+",\"AD­C\":"+adc+"}";
          console.log(bufText);
          mqtt.publish(PATH+"status",bufText);
        }, 3000);
      }
    }
    
    function setState(v) {
      RELAY.write(v);
      LED.write(!v);
      mqtt.publish(PATH+"status", v?1:0);
    }
    
    function mqttMessage(pub) {
      console.log("MQTT=> ",pub.topic,pub.message);
    
      if (pub.topic == PATH+"set") {
        setState(pub.message!=0);
      }
      if (pub.topic == PATH+"eval") {
        try {
          mqtt.publish(PATH+"response", eval(pub.message));
        } catch(e) {
          mqtt.publish(PATH+"exception", e.toString());
        }
      }
    }
    
    function mqttConnect() {
      mqtt = require("MQTT").connect({
        host: MQTT_HOST,
        client_id : nodeID,
      });
      mqtt.on('connected', function() {
        console.log("MQTT connected");
        setTimeout(function() {      
          mqtt.subscribe(PATH+"#");
        }, 1000);
      });
      mqtt.on('publish', mqttMessage);
    }
    
    
    function onInit() {
      ctr = new PID(hum, humSetpoint, Kp, Ki, Kd, 'direct');
      ctr.setSampleTime(timeframe);
      ctr.setOutputLimits(dacMin, dacMax);
      ctr.setMode('auto');
      digitalWrite(D16,0);
      console.log("Connecting WiFi");
      setInterval(updatePid, timeframe);
      setInterval(function() {
        if (!mqtt) return;
        if (!mqtt.connected) {
          console.log("MQTT disconnected... reconnecting.");
          mqtt.connect();
        }
        digitalWrite(D16, 1);
        setTimeout( function d16() {
          digitalWrite(D16,0);
        }, 300);
      }, 60*1000);
    
      wifi = require("Wifi");
      wifi.on('connected',function() {
        console.log("Connected to WiFi");  
      });
      wifi.on('disconnected',function() {
        console.log("Disconnected from WiFi");  
      });
      wifi.setHostname("MYDEVICE");
      wifi.stopAP();
      wifi.connect(WIFI_NAME, WIFI_OPTIONS,
                   function(ap){ 
        console.log("Successful connect.");
      });
      // wait, and connect MQTT
      setTimeout(function() {
        console.log("MQTT connecting");
        mqttConnect();
      }, 10000);
    }
    

    and bellow is the error message

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     1v99 (c) 2018 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 4MB:1024/1024, manuf 0xc8 chip 0x4016
    >
    =undefined
    Running onInit()...
    Connecting WiFi
    Successful connect.
    Connected to WiFi
    MQTT connecting
    ERROR: Error processing Serial data handler - removing it.
    Execution Interrupted during event processing.
    New interpreter error: CALLBACK,LOW_MEMORY,MEMORY
    > 
    
  • in Projects
    Avatar for maman

    Hello @ClearMemory041063, @Wilberforce

    I am using pid-controller and mqtt modules for our project, now.
    We use Wemos D1 Mini.
    I am trying the example simulation of the github @Wilberforce, it is working, normally.
    However, if we combine the pid-controller and mqtt modules, when we
    try to connect to mqtt broker, there is an error.

    Execution Interrupted during event processing.
    New interpreter error: LOW_MEMORY,MEMORY
    

    Is there any issue for compatibility of pid-controller and mqtt module ?

    Regards,
    Maman

Actions