Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Xio1996
    X
    • Continue chat with Xio1996
    • Start new chat with Xio1996
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    Xio1996

    @Xio1996

    1
    Reputation
    3
    Posts
    1025
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Xio1996 Follow

    Posts made by Xio1996

    • Editing Custom Blocks Problem

      Hi,

      I am working on a set of custom blocks that can be used to control a Robosapien and have come across a problem in editing custom blocks.

      I create my custom blocks in the online block maker and then download the .m5b file. My blocks are all 'Execute' type. When I open the .m5b file in UIFlow the blocks appear and can be used quite happily.

      I wanted to add some more blocks so I went to the Block Maker and loaded in my original .mb5 file. I noticed that the block statements had changed in that the "previousStatement": null, "nextStatement": null was missing from all but one of the blocks. Also the blocks label type had been changed from "field_label" to "label" and a new 'name' attribute had been added in args. Obviously, if you download this file then all your blocks are now broken in UIFlow.

      However, the Block Maker interface appeared to have all the original information for each block. So it I click on each block in turn the code is regenerated correctly. It seems that when reading in the .m5b file into Block Maker something is going wrong.

      As an example here is the original code that works in UIFlow.

      // Block __Robosapien_Forward
      var __Robosapien_Forward_json = {
      "previousStatement": null,
      "nextStatement": null,
      "message0": "%1",
      "args0": [
      {
      "type": "field_label",
      "text": "Forward"
      }
      ],
      "colour": "#eb94e5"
      };

      window['Blockly'].Blocks['__Robosapien_Forward'] = {
      init: function() {
      this.jsonInit(__Robosapien_Forward_json);
      }
      };

      window['Blockly'].Python['__Robosapien_Forward'] = function(block) {
      return espnow.send(id=1, data=str(101)) + "\n";
      };

      Here is the same block's code immediately after the .m5b file is re-opened in Block Maker

      // Block __Robosapien_Forward
      var __Robosapien_Forward_json = {
      "args0": [
      {
      "type": "label",
      "text": "Forward",
      "name": "Forward"
      }
      ],
      "message0": "%1",
      "colour": "#eb94e5"
      };

      window['Blockly'].Blocks['__Robosapien_Forward'] = {
      init: function() {
      this.jsonInit(__Robosapien_Forward_json);
      }
      };

      window['Blockly'].Python['__Robosapien_Forward'] = function(block) {
      return espnow.send(id=1, data=str(101)) + "\n";
      };

      Thank you for all the hard work you put in to developing these tools .

      posted in Custom Blocks
      X
      Xio1996
    • RE: ESP-Now UIFlow to Arduino

      Hi Lukas,

      Thank you for the link. I will see if I can use their method. I did find a solution that works.

      I noticed that the received data starting at index 11 was getting ASCII codes so I modified the Arduino code to construct a String starting from that position. The ESP-Now OnDataRecv callback now looks like this (the string construction is in bold).

      void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len)
      {
      char macStr[18];

      String tData="";
      char Ascii[1];
      for(int i=10;i<data_len;i++)
      {
      tData+=(char)data[i];
      }

      snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
      mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

      Serial.print("Last Packet Recv from: "); Serial.println(macStr);
      Serial.print("Data Length: "); Serial.println(data_len);
      Serial.print("Last Packet Recv Data: '"); Serial.print(tData);
      Serial.println("'");
      }

      Arduino Output

      13:38:11.806 -> Last Packet Recv from: d8:a0:1d:55:4b:38
      13:38:11.806 -> Data Length: 22
      13:38:11.806 -> Last Packet Recv Data: 'Hello World!'

      posted in UIFlow
      X
      Xio1996
    • ESP-Now UIFlow to Arduino

      Dear All,

      I am trying to send a message using the EspNow blocks in UIFlow to an ESP32 running an Arduino program. The message is sent and received but I can't seem to get the data in the Arduino program it just returns '1' even though the length alters as I alter the data being sent. When I look at the Python code it is sending a string, so I think I'm asking how to convert a Python string into an Arduino string/character array. Sorry if this is a real newbie question.

      Blocky - Python code
      def buttonA_wasPressed():
      global iCount
      espnow.send(id=1, data=str('HELLO!'))
      pass
      btnA.wasPressed(buttonA_wasPressed)

      Arduino ESP-Now receive code
      void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len)
      {
      char macStr[18];
      char sData[data_len];

      snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
      mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
      Serial.print("Last Packet Recv from: "); Serial.println(macStr);
      Serial.print("Data Length: "); Serial.println(data_len);
      Serial.print("Last Packet Recv Data: "); Serial.println(*data);
      Serial.println("");
      }

      Arduino Output
      11:39:37.342 -> Last Packet Recv from: d8:a0:1d:55:4b:38
      11:39:37.342 -> Data Length: 16
      11:39:37.342 -> Last Packet Recv Data: 1
      11:39:37.342 ->

      posted in UIFlow
      X
      Xio1996