Contents
Quick Start of WiFi for Pico
Asset ‘WiFi for Pico’ is an interface asset between a single Windows PC and plural Pico Ws via WiFi using MQTT communication.
A Unity 3D object ‘ vase’ in the Demo scene moves using the generated data in Pico W. The Pico W generates 3D Object position data ‘x, y, z’. The Pico W sends that data from the Pico W to Unity through Windows PC via WiFi using MQTT communication.
When clicking a Unity 3D object ‘Button’ in the Demo scene, Unity sends the numerical data obtained from the Unity 3D object ‘Inputfield’ and Dropdown to the Pico W. Unity works at Windows PC and sends the numerical data to the Pico W using MQTT communication.
The following shows this asset function structure. Workflow is as follows.
- Unity with this asset on the Windows PC inputs moving data as Subscriber from Unity topic.
- This asset on the Pico W outputs moving data as Publisher to Unity topic.
- Unity with this asset on the Windows PC outputs command data as Publisher to Pico W topic.
- This asset on the Pico W inputs command data as Subscriber from Pico W topic.
- Moving data is for Horizontal or Vertical movement depending on Pico W No.
- Command data is for Pico W No and two input field data.
The following shows the capture screen when the Demo scene runs.
This Quick Start explains how to display the Demo scene on Unity using this asset. This Quick Start also includes some steps for downloading and setting up a package in Unity Project, and writing the Pico W code.
Step-1 Download and set up a package in Unity Project
Step-2 Write Pico W code using Arduino IDE
Step-3 Run Demo scene
Step-1 Download and set up a package in Unity Project
- Download this asset from the Asset Store, and click on the Import button.
- The package is imported under the Assets folder in your Unity project.
- Click the Project tab, choose ‘Assets’ > ‘PicoWiFiInterface’ > ‘Scenes’ folder of the left side menu, double click on the Demo scene ‘PicoWiFiSampleScene’ in the Project window.
- Set Windows PC IP address into label ’pc_ip_addr’ of ‘Scripts/PicoWiFiSampleCode’ as follows.
… public string PC_IP_Addr ; private string pc_ip_addr ="192.168.10.105"; private PicoWiFiLib m_PicoWiFiLib; …
Step-2 Write Pico W code using Arduino IDE
- Connect the Pico W by Micro USB cable to Windows PC, then build a software development environment for this asset with the Arduino IDE according to ‘Arduino IDE v2 for Pico/Pico W’.
- Obtain Pico W code ‘picowifi.ino’ of the folder ‘/Assets / PicoWiFiInterface/ picowifi’and modify the code for adapting your network environment as follows.
- ‘ssid’: ssid for your WiFi
- ‘password’: password for your WiFi
- ‘mqtt_server’: Windows PC IP address
- Compile and write the modified Pico W code ‘picowifi.ino’ into the Pico W using the Arduino IDE.
… const char* ssid = "xxxxxxxx"; const char* password = "xxxxxxxx"; const char* mqtt_server = "xxx.xxx.xxxx.xxx"; …
Step-3 Run Demo scene
- Click the ‘Play’ button on Unity. The Unity 3D object ‘vase’ moves in sync with the received data from the Pico W. The ‘Accelx, Accely, Accelz’ in the ‘Scripts/PicoWiFiSampleCode’ of the ‘Inspector’ tab displays the received data ‘x, y, z’ from the Pico W as follows.
- The ’console’ tab displays the game status as follows.
- The ‘Serial Monitor’ of Arduino IDE displays the data “x, y, z” as follows.
- Select Dropdown and set No0 / No1 into Inputfield ’No0’ / Inputfield ‘No1’ in the game screen, then click the Button ‘On’ to send to the Pico W. Show Dropdown / Inputfield ’No0’ / Inputfield ‘No1’ as follows.
- In the case of the PicoWiFiSampleCode, the Dropdown displays ‘1’ or ’2’ for selecting Pico W No.1 or No.2. When selecting ‘1’, the Unity 3D object ‘ vase’ moves horizontally. When select ’2’, the ‘ vase’ moves vertically.
- The ’console’ tab displays the game status at clicking Button ‘On’ as follows.
- The ‘Serial Monitor’ in Arduino IDE displays the No0/No1 data as follows.