• # This code is not working for me. I tried below code...and tried many ways but not receiving on RX but TX works fine.
    on Espruino v1.99 on NodeMCU

    var status=0;
    function swap() {
    status = !status;
    digitalWrite(NodeMCU.D0, status);
    }
    function onInit()
    {
    Serial1.setup(9600);
    Serial1.on('data', function (data) { swap(); });
    LoopbackA.setConsole();
    }
    //onInit();

  • This is what I tested:

    connect to device with WEB IDE via TCP/IP

    upload this code for a ESP8266 12F

    var status=0;
    function swap() {
        status = !status;
        digitalWrite(NodeMCU.D4, status);
    }
    Serial1.on('data', function (data) { swap(); });
    

    send data over serial with echo > /dev/cu.usbserial

    result every send toggle the onboard led

    Hope this works for you too.

  • Thanks for response ... I'll try and reply soon

  • Hi @MaBe
    Still not working RX....tested with 2 NodeMCUs
    Sir, please mention which espruino firmware you're using and tested this code... Here mine is v1.99

  • This is the setup I used to test

    • Espruino version is 1v99.

    • ESP8266 12F board connect to access point and serial port /dev/cu-usbserial

    • Connect with WEB IDE over TCP/IP to the ESP8266 board

    Question: Does WEB IDE over serial and TCP/IP work for you?

  • Yes, serial and WEB TCP/IP both are working fine to upload code.

    And one more thing I'm using NodeMCU, which runs on the ESP8266.
    I uploaded firmware in it and everything works fine except RX.

    My Thinking about this issue:
    I'm not sure but may be, RX in standalone ESP8266 is accessible but RX in NodeMCU is not accessible, by some hardware reason or RX is busy for some other task.
    or may be bug in v1.99

    Please provide me your exact firmware. (if possible) becaue I'm using 4mb version that may be differ from yours.

  • Please provide me your exact firmware. (if possible) becaue I'm using 4mb version that may be differ from yours.

    Espruino branch: master

    >process.env
    ={
      VERSION: "1v99.4128",
      GIT_COMMIT: "5b447a61",
      BOARD: "ESP8266_4MB",
      FLASH: 0, RAM: 81920,
      SERIAL: "5ccf7fc1-120b",
      CONSOLE: "Telnet",
      MODULES: "Flash,Storage,net" ... "r,crypto,neopixel",
      EXPTR: 1073643636 }
    > 
    

    try this snippet too:

    var status=0;
    var i=0;
    function swap() {
      i++;
      status = !status;
      console.log(i,"data",Date().toString());­
    }
    
    Serial1.on('data', function (data) { swap(); });
    
    
  • please post output of process.env

  • Thanks for you response
    Here process.env response:

    >process.env
    ={
      "VERSION": "1v99",
      "GIT_COMMIT": "f0d66ba",
      "BOARD": "ESP8266_4MB",
      "FLASH": 0, "RAM": 81920,
      "SERIAL": "dc4f2219-9b31",
      "CONSOLE": "Telnet",
      "MODULES": "Flash,Storage,net" ... "r,crypto,neopixel",
      "EXPTR": 1073643636 }
    > 
    

    and nothing happen in console when I typed and uploaded code which is provided by you.
    Here is my connection to NodeMCU

    TTL 5V-----------------------------------Nod­eMCU 5V (VCC IN)
    TTL RX-----------LEVEL SHIFTER----------NodeMCU TX
    TTL TX-----------LEVEL SHIFTER----------NodeMCU RX
    TTL GND---------------------------------Node­MCU GND

    I found somewhere that NodeMCU works without level shifting on RX/TX. So, I tried without level shifter with another NodeMCU and 2 TTL
    All are components are working fine and I think no component is damaged.
    But can't figured out what is the problem.

  • This is what I use: USB to TTL Serial Cable 3,3V and a D-duino ESP8266 12F device.


    1 Attachment

    • IMG_8451.jpg
  • ...on a beech hardwood floor/table... makes me homesick in a good way... so, more precise: recalls lovely memories.

  • Great ... I think, I should try some other board or standalone ESP8266 first...Thanks for all your response but if you found any other information about this please share....thanks-a-lot :)

  • And since it is not solved so I'm not closing this convo, may be someone else may help

    Thanks @MaBe

  • 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

  • Are you using the latest travis build?

  • 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.

  • Ok, Check the serial snippet in https://github.com/espruino/Espruino/iss­ues/1511

  • 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

  • Ok, what kind of dispay?

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

  • Do you like to Share a link or picture?

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

    Software serial can't handle much above 9600 baud, so this is to be expected. If you want higher then you could use an external SPI to serial bridge chip.

  • @maman Nice, did you buy one?

    I have a 32x32 neopixel display build of 16 times 8x8

  • 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,

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

"Serial1.on('data', function (data) {......" not works for me, is works for any other ??

Posted by Avatar for user94070 @user94070

Actions