I am trying to create an app on a Pico W where core 1 of the Pico runs a loop that controls an ultrasonic sensor. The other core 0 runs code for a web server. I want to be able to control the on / off aspects of the ultrasonic distance detection by clicking on the On / Off buttons on my cell phone.
I believe that any code that I have would just confuse the issue because I have a concept issue not a coding issue. I am under the assumption that both cores run totally independent of each other. I'm trying to control the ultrasonic function by setting global variables from parsing the request coming in from the cell phone on core 0.
Once core 0 calls a function to start the loop that runs the ultrasonic action on core 1, it appears that the web code on core 0 never runs again and never receives the request to quit running from my cell phone. I can start the loop via a web request but once it starts the loop, it appears that core 0 never responds once core 1 goes into its loop.
The following shows what is happening:
- Press the On button on the cell phone web interface.
- The request is received.
- A global "run" variable is set to True.
- A function is called to start the ultrasonic loop on core 1.
- Core 1 checks the global variable "run" and starts if "run" is True.
- The ultrasonic loop begins.
- Press the Off button on the cell phone.
- It appears that the request is never acknowledged because there is no request available on core 0 to print out. Therefore, I can't change the global variable to False to stop the ultrasonic loop.
I can do the following:
- Press the On button on the cell phone web interface that runs the ultrasonic device on core 1 ONCE.
- The request is received on core 0.
- A global "run" variable is set to True.
- A function is called from core 0 to start the ultrasonic loop on core 1 if run is True.
- Core 1 checks the global variable "run" for True.
- The ultrasonic loop runs ONCE.
- The loop runs once on core 1 and a return is sent back to the caller on core 0.
- Any other web request CAN be received and printed out. At this time, core 1 is not running the loop.
Why does it appear that the web server code on core 0 can't run unless core 1 is idle or the call of the function is returned? I can't return the function without stopping the loop which I don't want to do all of the time. Does a webserver request act differently with multiple cores than a hard wired button request? Again, the core 0 webserver request appears to never be acknowledged on core 0 once the core 1 loop begins and before the core 1 function call is returned to core 0. Once core 1 stops the loop and returns the call core 0 will respond.
I want to receive a web request on core 0 and have it run a loop on core 1 and then have a web request on core 0 stop the loop on core 1.
Thank you for your assistance.
Tom