• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
M5Stack Community
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

need help converting text to int (CORE2)

UIFlow
3
5
8.9k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Arno
    last edited by Feb 28, 2021, 6:13 PM

    how to convert text extracted from a string via ESP NOW.
    0_1614535758163_1a40b9f8-a807-4ef2-ad77-33e8720834cb-image.png

    How to convert X to digital type integer?

    0_1614535888010_825dc2f1-470a-4490-9d1b-a66aa025e815-image.png

    I have error messages !

    I only use Uiflow ! with M5STACK Gray, RED, CORE2, ATOM, ATOM Lite,M5Paper, M5Tough, ATOM Display, M5 Stamp pico and more Unit...

    1 Reply Last reply Reply Quote 0
    • T
      Thrasher
      last edited by Mar 1, 2021, 3:26 PM

      X = int("x")

      1 Reply Last reply Reply Quote 0
      • A
        Arno
        last edited by Mar 14, 2021, 5:36 PM

        @thrasher said in need help converting text to int (CORE2):

        X = int (« x »)

        I have variment of help, voci several attempts with the error messages with UiFlow 1.7.3.

        0_1615742996554_af1d7cc7-db37-4694-8bef-31a105479a0f-image.png Error : can't convert noneType to int

        0_1615743082788_9cd8efde-3ef1-4d06-a2bb-a895cffb1d9b-image.png Error : name 'X' isn't defined

        0_1615743145276_d531ba80-10e2-4344-aa75-383e7304f263-image.png Error : can't convert noneType to int

        How to convert X (ex "7") to 7?

        Lack of documentation is a real problem

        I only use Uiflow ! with M5STACK Gray, RED, CORE2, ATOM, ATOM Lite,M5Paper, M5Tough, ATOM Display, M5 Stamp pico and more Unit...

        W 1 Reply Last reply Mar 15, 2021, 1:55 PM Reply Quote 0
        • W
          world101 @Arno
          last edited by world101 Mar 15, 2021, 9:56 PM Mar 15, 2021, 1:55 PM

          @arno

          I think your issue is because you are using variable X within the ESP Now Receive Callback to hold the string data coming from the ESP Now transmitter device. Then within the Loop, you are trying to convert it to an integer. Upon program execution, the Python code has X=None, and is trying to convert X (which has no data yet) to an integer, thus throwing the error: can't convert noneType to int. So you have a few options. These worked for me.

          1. Define X within the Setup function like this...
            0_1615815666547_Screen Shot 2021-03-15 at 9.39.13 AM.png

          2. Redesign your program to perform all the calculations within the Receive Callback function. I actually prefer this option, because it doesn't require a Loop and is therefore non-blocking (no 1 second delay in the Loop). You're just waiting to receive data from ESP Now and then take action on it. However, I'm not sure what the rest of your program is supposed to achieve, so just take this into consideration.
            0_1615816004028_Screen Shot 2021-03-15 at 9.44.27 AM.png

          For reference, here is my ESP Now transmitter flow. It's an M5StickC with the JoyC Hat. It sends the X position data of the left joystick, mapped from 0 to 180, so it will turn a servo connected to port A on the Core2 (the ESP Now receiver).
          0_1615816326750_Screen Shot 2021-03-15 at 9.49.55 AM.png

          1 Reply Last reply Reply Quote 4
          • T
            Thrasher
            last edited by Mar 15, 2021, 4:30 PM

            There's execute code block also

            1 Reply Last reply Reply Quote 1
            • First post
              Last post