From f4c52382b993ea4d2cc55cff1992ed202590ffd2 Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:25:50 +0200 Subject: [PATCH 1/7] Added reference to ASYNC method on micropython --- .../giga-micropython/giga-micropython.md | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md index 9bf53c0f68..35ecabdc7c 100644 --- a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md +++ b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md @@ -202,6 +202,93 @@ In the table below, you will find the matching between the **STM32H7** and **Ard | PA4 | A12 | | PA5 | A13 | +## Arduino Cloud + +You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. + +### Async (Default) +This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. Asynchronous functions are particularly useful for handling network communication, as they enable the GIGA R1 to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. + +**Code example:** +```python +from secrets import DEVICE_ID +from secrets import SECRET_KEY + +# Switch callback, toggles the LED. +def on_switch_changed(client, value): + # Note the client object passed to this function can be used to access + # and modify any registered cloud object. The following line updates + # the LED value. + client["led"] = value + +# 1. Create a client object, which is used to connect to the IoT cloud and link local +# objects to cloud objects. Note a username and password can be used for basic authentication +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. +client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY) + +# 2. Register cloud objects. +# Note: The following objects must be created first in the dashboard and linked to the device. +# When the switch is toggled from the dashboard, the on_switch_changed function is called with +# the client object and new value args. +client.register("sw1", value=None, on_write=on_switch_changed) + +# The LED object is updated in the switch's on_write callback. +client.register("led", value=None) + +# 3. Start the Arduino cloud client. +client.start() +``` + +Remember that our `secrets.py` file should look like: +```python +WIFI_SSID = "" # WiFi network SSID (for MicroPython) +WIFI_PASS = "" # WiFi network key (for MicroPython) +DEVICE_ID = "" # Provided by Arduino cloud when creating a device. +SECRET_KEY = "" # Provided by Arduino cloud when creating a device. +``` + +### Sync +In synchronous operations, tasks are executed one after another in a sequential manner. Each function call waits for the previous one to complete before starting. This approach is straightforward and easier to implement but can cause delays if a task takes a long time to finish, as it blocks the execution of subsequent code. In the context of network communication with the Arduino Cloud, synchronous functions may lead to unresponsiveness during data transmission or reception. + +Alternatively, you can select the synchronous method by passing sync_mode=True when creating the client object and calling client.update() periodically after connecting. + +Code example: +```python +from secrets import DEVICE_ID +from secrets import SECRET_KEY + +# Switch callback, toggles the LED. +def on_switch_changed(client, value): + # Note the client object passed to this function can be used to access + # and modify any registered cloud object. The following line updates + # the LED value. + client["led"] = value + +# 1. Create a client object, which is used to connect to the IoT cloud and link local +# objects to cloud objects. Note a username and password can be used for basic authentication +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. +client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY, sync_mode=True) + +# 2. Register cloud objects. +# Note: The following objects must be created first in the dashboard and linked to the device. +# When the switch is toggled from the dashboard, the on_switch_changed function is called with +# the client object and new value args. +client.register("sw1", value=None, on_write=on_switch_changed) + +# The LED object is updated in the switch's on_write callback. +client.register("led", value=None) + +# In synchronous mode, this function returns immediately after connecting to the cloud. +client.start() + +# Update the client periodically. +while True: + client.update() + time.sleep(0.100) +``` + +`secrets.py` file should look the same on both implementations. + ## Conclusion In this article, we have learned how to install MicroPython on the GIGA R1, using the `dfu-util` tool. We have also gone through some useful tips and tricks that can help you develop and run MicroPython code on your board. From d66acd6eae393e1b36ec87a718f2690e3c3a4139 Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:13:15 +0200 Subject: [PATCH 2/7] Updated information connection --- .../01.guides/04.micropython/content.md | 90 ++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/content/arduino-cloud/01.guides/04.micropython/content.md b/content/arduino-cloud/01.guides/04.micropython/content.md index 3e3e2ef8f9..208a03e3f5 100644 --- a/content/arduino-cloud/01.guides/04.micropython/content.md +++ b/content/arduino-cloud/01.guides/04.micropython/content.md @@ -134,7 +134,95 @@ For more options on how to install libraries on your board, check out our [Insta ## Programming the Board -Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi®. +### Cloud Connection +You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. + +#### Async (Default) +This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. Asynchronous functions are particularly useful for handling network communication, as they enable the GIGA R1 to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. + +**Code example:** +```python +from secrets import DEVICE_ID +from secrets import SECRET_KEY + +# Switch callback, toggles the LED. +def on_switch_changed(client, value): + # Note the client object passed to this function can be used to access + # and modify any registered cloud object. The following line updates + # the LED value. + client["led"] = value + +# 1. Create a client object, which is used to connect to the IoT cloud and link local +# objects to cloud objects. Note a username and password can be used for basic authentication +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. +client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY) + +# 2. Register cloud objects. +# Note: The following objects must be created first in the dashboard and linked to the device. +# When the switch is toggled from the dashboard, the on_switch_changed function is called with +# the client object and new value args. +client.register("sw1", value=None, on_write=on_switch_changed) + +# The LED object is updated in the switch's on_write callback. +client.register("led", value=None) + +# 3. Start the Arduino cloud client. +client.start() +``` + +Remember that our `secrets.py` file should look like: +```python +WIFI_SSID = "" # WiFi network SSID (for MicroPython) +WIFI_PASS = "" # WiFi network key (for MicroPython) +DEVICE_ID = "" # Provided by Arduino cloud when creating a device. +SECRET_KEY = "" # Provided by Arduino cloud when creating a device. +``` + +#### Sync +In synchronous operations, tasks are executed one after another in a sequential manner. Each function call waits for the previous one to complete before starting. This approach is straightforward and easier to implement but can cause delays if a task takes a long time to finish, as it blocks the execution of subsequent code. In the context of network communication with the Arduino Cloud, synchronous functions may lead to unresponsiveness during data transmission or reception. + +Alternatively, you can select the synchronous method by passing sync_mode=True when creating the client object and calling client.update() periodically after connecting. + +Code example: +```python +from secrets import DEVICE_ID +from secrets import SECRET_KEY + +# Switch callback, toggles the LED. +def on_switch_changed(client, value): + # Note the client object passed to this function can be used to access + # and modify any registered cloud object. The following line updates + # the LED value. + client["led"] = value + +# 1. Create a client object, which is used to connect to the IoT cloud and link local +# objects to cloud objects. Note a username and password can be used for basic authentication +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. +client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY, sync_mode=True) + +# 2. Register cloud objects. +# Note: The following objects must be created first in the dashboard and linked to the device. +# When the switch is toggled from the dashboard, the on_switch_changed function is called with +# the client object and new value args. +client.register("sw1", value=None, on_write=on_switch_changed) + +# The LED object is updated in the switch's on_write callback. +client.register("led", value=None) + +# In synchronous mode, this function returns immediately after connecting to the cloud. +client.start() + +# Update the client periodically. +while True: + client.update() + time.sleep(0.100) +``` + +`secrets.py` file should look the same on both implementations. + +### Project example + +Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi® and toggles the LED of the board using the Arduino Cloud dashboard. ```python From ecb904c72e6c02691c7ca8f5545d439966658c7b Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:48:38 +0200 Subject: [PATCH 3/7] Reverted document --- .../01.guides/04.micropython/content.md | 92 +------------------ 1 file changed, 2 insertions(+), 90 deletions(-) diff --git a/content/arduino-cloud/01.guides/04.micropython/content.md b/content/arduino-cloud/01.guides/04.micropython/content.md index 208a03e3f5..124e2a76a6 100644 --- a/content/arduino-cloud/01.guides/04.micropython/content.md +++ b/content/arduino-cloud/01.guides/04.micropython/content.md @@ -134,95 +134,7 @@ For more options on how to install libraries on your board, check out our [Insta ## Programming the Board -### Cloud Connection -You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. - -#### Async (Default) -This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. Asynchronous functions are particularly useful for handling network communication, as they enable the GIGA R1 to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. - -**Code example:** -```python -from secrets import DEVICE_ID -from secrets import SECRET_KEY - -# Switch callback, toggles the LED. -def on_switch_changed(client, value): - # Note the client object passed to this function can be used to access - # and modify any registered cloud object. The following line updates - # the LED value. - client["led"] = value - -# 1. Create a client object, which is used to connect to the IoT cloud and link local -# objects to cloud objects. Note a username and password can be used for basic authentication -# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. -client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY) - -# 2. Register cloud objects. -# Note: The following objects must be created first in the dashboard and linked to the device. -# When the switch is toggled from the dashboard, the on_switch_changed function is called with -# the client object and new value args. -client.register("sw1", value=None, on_write=on_switch_changed) - -# The LED object is updated in the switch's on_write callback. -client.register("led", value=None) - -# 3. Start the Arduino cloud client. -client.start() -``` - -Remember that our `secrets.py` file should look like: -```python -WIFI_SSID = "" # WiFi network SSID (for MicroPython) -WIFI_PASS = "" # WiFi network key (for MicroPython) -DEVICE_ID = "" # Provided by Arduino cloud when creating a device. -SECRET_KEY = "" # Provided by Arduino cloud when creating a device. -``` - -#### Sync -In synchronous operations, tasks are executed one after another in a sequential manner. Each function call waits for the previous one to complete before starting. This approach is straightforward and easier to implement but can cause delays if a task takes a long time to finish, as it blocks the execution of subsequent code. In the context of network communication with the Arduino Cloud, synchronous functions may lead to unresponsiveness during data transmission or reception. - -Alternatively, you can select the synchronous method by passing sync_mode=True when creating the client object and calling client.update() periodically after connecting. - -Code example: -```python -from secrets import DEVICE_ID -from secrets import SECRET_KEY - -# Switch callback, toggles the LED. -def on_switch_changed(client, value): - # Note the client object passed to this function can be used to access - # and modify any registered cloud object. The following line updates - # the LED value. - client["led"] = value - -# 1. Create a client object, which is used to connect to the IoT cloud and link local -# objects to cloud objects. Note a username and password can be used for basic authentication -# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. -client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY, sync_mode=True) - -# 2. Register cloud objects. -# Note: The following objects must be created first in the dashboard and linked to the device. -# When the switch is toggled from the dashboard, the on_switch_changed function is called with -# the client object and new value args. -client.register("sw1", value=None, on_write=on_switch_changed) - -# The LED object is updated in the switch's on_write callback. -client.register("led", value=None) - -# In synchronous mode, this function returns immediately after connecting to the cloud. -client.start() - -# Update the client periodically. -while True: - client.update() - time.sleep(0.100) -``` - -`secrets.py` file should look the same on both implementations. - -### Project example - -Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi® and toggles the LED of the board using the Arduino Cloud dashboard. +Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi®. ```python @@ -520,4 +432,4 @@ If the code is not working, there are some common issues we can troubleshoot: ## Conclusion -This tutorial has guided you through the process of connecting your Arduino device to the Arduino Cloud using MicroPython. You learned how to install the necessary library, set up your device, and control an LED via the Arduino Cloud. This opens up possibilities for more complex applications, as you can control and monitor your Arduino device remotely. +This tutorial has guided you through the process of connecting your Arduino device to the Arduino Cloud using MicroPython. You learned how to install the necessary library, set up your device, and control an LED via the Arduino Cloud. This opens up possibilities for more complex applications, as you can control and monitor your Arduino device remotely. \ No newline at end of file From 059308014480c1803957720c7de80d7bd6a6fba5 Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:14:57 +0200 Subject: [PATCH 4/7] Updatecloud --- .../01.guides/04.micropython/content.md | 92 ++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/content/arduino-cloud/01.guides/04.micropython/content.md b/content/arduino-cloud/01.guides/04.micropython/content.md index 124e2a76a6..208a03e3f5 100644 --- a/content/arduino-cloud/01.guides/04.micropython/content.md +++ b/content/arduino-cloud/01.guides/04.micropython/content.md @@ -134,7 +134,95 @@ For more options on how to install libraries on your board, check out our [Insta ## Programming the Board -Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi®. +### Cloud Connection +You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. + +#### Async (Default) +This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. Asynchronous functions are particularly useful for handling network communication, as they enable the GIGA R1 to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. + +**Code example:** +```python +from secrets import DEVICE_ID +from secrets import SECRET_KEY + +# Switch callback, toggles the LED. +def on_switch_changed(client, value): + # Note the client object passed to this function can be used to access + # and modify any registered cloud object. The following line updates + # the LED value. + client["led"] = value + +# 1. Create a client object, which is used to connect to the IoT cloud and link local +# objects to cloud objects. Note a username and password can be used for basic authentication +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. +client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY) + +# 2. Register cloud objects. +# Note: The following objects must be created first in the dashboard and linked to the device. +# When the switch is toggled from the dashboard, the on_switch_changed function is called with +# the client object and new value args. +client.register("sw1", value=None, on_write=on_switch_changed) + +# The LED object is updated in the switch's on_write callback. +client.register("led", value=None) + +# 3. Start the Arduino cloud client. +client.start() +``` + +Remember that our `secrets.py` file should look like: +```python +WIFI_SSID = "" # WiFi network SSID (for MicroPython) +WIFI_PASS = "" # WiFi network key (for MicroPython) +DEVICE_ID = "" # Provided by Arduino cloud when creating a device. +SECRET_KEY = "" # Provided by Arduino cloud when creating a device. +``` + +#### Sync +In synchronous operations, tasks are executed one after another in a sequential manner. Each function call waits for the previous one to complete before starting. This approach is straightforward and easier to implement but can cause delays if a task takes a long time to finish, as it blocks the execution of subsequent code. In the context of network communication with the Arduino Cloud, synchronous functions may lead to unresponsiveness during data transmission or reception. + +Alternatively, you can select the synchronous method by passing sync_mode=True when creating the client object and calling client.update() periodically after connecting. + +Code example: +```python +from secrets import DEVICE_ID +from secrets import SECRET_KEY + +# Switch callback, toggles the LED. +def on_switch_changed(client, value): + # Note the client object passed to this function can be used to access + # and modify any registered cloud object. The following line updates + # the LED value. + client["led"] = value + +# 1. Create a client object, which is used to connect to the IoT cloud and link local +# objects to cloud objects. Note a username and password can be used for basic authentication +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. +client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY, sync_mode=True) + +# 2. Register cloud objects. +# Note: The following objects must be created first in the dashboard and linked to the device. +# When the switch is toggled from the dashboard, the on_switch_changed function is called with +# the client object and new value args. +client.register("sw1", value=None, on_write=on_switch_changed) + +# The LED object is updated in the switch's on_write callback. +client.register("led", value=None) + +# In synchronous mode, this function returns immediately after connecting to the cloud. +client.start() + +# Update the client periodically. +while True: + client.update() + time.sleep(0.100) +``` + +`secrets.py` file should look the same on both implementations. + +### Project example + +Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi® and toggles the LED of the board using the Arduino Cloud dashboard. ```python @@ -432,4 +520,4 @@ If the code is not working, there are some common issues we can troubleshoot: ## Conclusion -This tutorial has guided you through the process of connecting your Arduino device to the Arduino Cloud using MicroPython. You learned how to install the necessary library, set up your device, and control an LED via the Arduino Cloud. This opens up possibilities for more complex applications, as you can control and monitor your Arduino device remotely. \ No newline at end of file +This tutorial has guided you through the process of connecting your Arduino device to the Arduino Cloud using MicroPython. You learned how to install the necessary library, set up your device, and control an LED via the Arduino Cloud. This opens up possibilities for more complex applications, as you can control and monitor your Arduino device remotely. From f2c588868403ebdd3c9d52c3f9842986c8236d9c Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:26:13 +0200 Subject: [PATCH 5/7] Update giga-micropython.md --- .../giga-micropython/giga-micropython.md | 89 +------------------ 1 file changed, 1 insertion(+), 88 deletions(-) diff --git a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md index 35ecabdc7c..794a36e2aa 100644 --- a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md +++ b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md @@ -202,95 +202,8 @@ In the table below, you will find the matching between the **STM32H7** and **Ard | PA4 | A12 | | PA5 | A13 | -## Arduino Cloud - -You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. - -### Async (Default) -This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. Asynchronous functions are particularly useful for handling network communication, as they enable the GIGA R1 to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. - -**Code example:** -```python -from secrets import DEVICE_ID -from secrets import SECRET_KEY - -# Switch callback, toggles the LED. -def on_switch_changed(client, value): - # Note the client object passed to this function can be used to access - # and modify any registered cloud object. The following line updates - # the LED value. - client["led"] = value - -# 1. Create a client object, which is used to connect to the IoT cloud and link local -# objects to cloud objects. Note a username and password can be used for basic authentication -# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. -client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY) - -# 2. Register cloud objects. -# Note: The following objects must be created first in the dashboard and linked to the device. -# When the switch is toggled from the dashboard, the on_switch_changed function is called with -# the client object and new value args. -client.register("sw1", value=None, on_write=on_switch_changed) - -# The LED object is updated in the switch's on_write callback. -client.register("led", value=None) - -# 3. Start the Arduino cloud client. -client.start() -``` - -Remember that our `secrets.py` file should look like: -```python -WIFI_SSID = "" # WiFi network SSID (for MicroPython) -WIFI_PASS = "" # WiFi network key (for MicroPython) -DEVICE_ID = "" # Provided by Arduino cloud when creating a device. -SECRET_KEY = "" # Provided by Arduino cloud when creating a device. -``` - -### Sync -In synchronous operations, tasks are executed one after another in a sequential manner. Each function call waits for the previous one to complete before starting. This approach is straightforward and easier to implement but can cause delays if a task takes a long time to finish, as it blocks the execution of subsequent code. In the context of network communication with the Arduino Cloud, synchronous functions may lead to unresponsiveness during data transmission or reception. - -Alternatively, you can select the synchronous method by passing sync_mode=True when creating the client object and calling client.update() periodically after connecting. - -Code example: -```python -from secrets import DEVICE_ID -from secrets import SECRET_KEY - -# Switch callback, toggles the LED. -def on_switch_changed(client, value): - # Note the client object passed to this function can be used to access - # and modify any registered cloud object. The following line updates - # the LED value. - client["led"] = value - -# 1. Create a client object, which is used to connect to the IoT cloud and link local -# objects to cloud objects. Note a username and password can be used for basic authentication -# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. -client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY, sync_mode=True) - -# 2. Register cloud objects. -# Note: The following objects must be created first in the dashboard and linked to the device. -# When the switch is toggled from the dashboard, the on_switch_changed function is called with -# the client object and new value args. -client.register("sw1", value=None, on_write=on_switch_changed) - -# The LED object is updated in the switch's on_write callback. -client.register("led", value=None) - -# In synchronous mode, this function returns immediately after connecting to the cloud. -client.start() - -# Update the client periodically. -while True: - client.update() - time.sleep(0.100) -``` - -`secrets.py` file should look the same on both implementations. - ## Conclusion In this article, we have learned how to install MicroPython on the GIGA R1, using the `dfu-util` tool. We have also gone through some useful tips and tricks that can help you develop and run MicroPython code on your board. -For more information, visit the [MicroPython with Arduino documentation](/micropython). \ No newline at end of file +For more information, visit the [MicroPython with Arduino documentation](/micropython). From 3aac49673f0e8bae1921ce31fad4ab6c2ecb9c70 Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:34:44 +0200 Subject: [PATCH 6/7] Update content/arduino-cloud/01.guides/04.micropython/content.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Karl Söderby <35461661+karlsoderby@users.noreply.github.com> --- content/arduino-cloud/01.guides/04.micropython/content.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/content/arduino-cloud/01.guides/04.micropython/content.md b/content/arduino-cloud/01.guides/04.micropython/content.md index 208a03e3f5..0848f5f573 100644 --- a/content/arduino-cloud/01.guides/04.micropython/content.md +++ b/content/arduino-cloud/01.guides/04.micropython/content.md @@ -138,7 +138,10 @@ For more options on how to install libraries on your board, check out our [Insta You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. #### Async (Default) -This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. Asynchronous functions are particularly useful for handling network communication, as they enable the GIGA R1 to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. +This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython. + +Asynchronous functions are particularly useful for handling network communication, as they enable the boards to perform other operations (like reading sensors or updating outputs) while waiting for data from the Arduino Cloud. + **Code example:** ```python From b64dd916c5827953ad70ba95c85d21ece44b40f8 Mon Sep 17 00:00:00 2001 From: pedromsousalima <32345730+pedromsousalima@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:35:08 +0200 Subject: [PATCH 7/7] Update content/arduino-cloud/01.guides/04.micropython/content.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Karl Söderby <35461661+karlsoderby@users.noreply.github.com> --- content/arduino-cloud/01.guides/04.micropython/content.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/arduino-cloud/01.guides/04.micropython/content.md b/content/arduino-cloud/01.guides/04.micropython/content.md index 0848f5f573..96b85c9c04 100644 --- a/content/arduino-cloud/01.guides/04.micropython/content.md +++ b/content/arduino-cloud/01.guides/04.micropython/content.md @@ -135,7 +135,7 @@ For more options on how to install libraries on your board, check out our [Insta ## Programming the Board ### Cloud Connection -You can connect the GIGA R1 to the Arduino Cloud with MicroPython. There are two main methods to create this connection `async` and `sync`. +There are two main methods to create this connection `async` and `sync`. #### Async (Default) This is the method currently implemented by default with the Cloud. Asynchronous operations allow tasks to run independently of the main program flow. Functions can start and continue without waiting for other tasks to finish. This non-blocking behavior is achieved using techniques like callbacks, coroutines, or the async and await keywords in MicroPython.