need help converting text to int (CORE2)



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



  • X = int("x")



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



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



  • There's execute code block also