Skip to content

Commit 730ba7d

Browse files
committed
Merge branch 'main' into content/micropython/micropython-revamp
2 parents b108fa1 + 109c079 commit 730ba7d

File tree

828 files changed

+14072
-5982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

828 files changed

+14072
-5982
lines changed

.github/workflows/deploy-production.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
steps:
4444
- uses: actions/checkout@v4
4545
with:
46-
fetch-depth: 1
46+
fetch-depth: "0"
4747

4848
- name: Cleanup runner disk
4949
uses: ./.github/actions/cleanup-disk # Cleanup machine before starting the build
@@ -66,6 +66,7 @@ jobs:
6666
- name: Copy Static Files
6767
run: |
6868
mkdir -p static/resources/schematics static/resources/pinouts static/resources/models
69+
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
6970
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
7071
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
7172
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;

.github/workflows/deploy-staging.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
steps:
4444
- uses: actions/checkout@v4
4545
with:
46-
fetch-depth: 1
46+
fetch-depth: "0"
4747

4848
- name: Cleanup runner disk
4949
uses: ./.github/actions/cleanup-disk # Cleanup machine before starting the build
@@ -66,6 +66,7 @@ jobs:
6666
- name: Copy Static Files
6767
run: |
6868
mkdir -p static/resources/schematics static/resources/pinouts static/resources/models
69+
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
6970
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
7071
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
7172
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public
88
src
99
.DS_Store
1010
.vscode/settings.json
11+
.vscode/ltex.hiddenFalsePositives.en-US.txt
12+
.vscode/ltex.dictionary.en-US.txt
1113
content/en
1214
content/de
1315
content/pt

.vscode/ltex.dictionary.en-US.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Opta

content/_dev-test/essentials.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
productsLibrariesMap: []
3+
---

content/arduino-cloud/01.guides/04.micropython/content.md

+92-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,98 @@ For more options on how to install libraries on your board, check out our [Insta
134134

135135
## Programming the Board
136136

137-
Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi®.
137+
### Cloud Connection
138+
There are two main methods to create this connection `async` and `sync`.
139+
140+
#### Async (Default)
141+
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.
142+
143+
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.
144+
145+
146+
**Code example:**
147+
```python
148+
from secrets import DEVICE_ID
149+
from secrets import SECRET_KEY
150+
151+
# Switch callback, toggles the LED.
152+
def on_switch_changed(client, value):
153+
# Note the client object passed to this function can be used to access
154+
# and modify any registered cloud object. The following line updates
155+
# the LED value.
156+
client["led"] = value
157+
158+
# 1. Create a client object, which is used to connect to the IoT cloud and link local
159+
# objects to cloud objects. Note a username and password can be used for basic authentication
160+
# on both CPython and MicroPython. For more advanced authentication methods, please see the examples.
161+
client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
162+
163+
# 2. Register cloud objects.
164+
# Note: The following objects must be created first in the dashboard and linked to the device.
165+
# When the switch is toggled from the dashboard, the on_switch_changed function is called with
166+
# the client object and new value args.
167+
client.register("sw1", value=None, on_write=on_switch_changed)
168+
169+
# The LED object is updated in the switch's on_write callback.
170+
client.register("led", value=None)
171+
172+
# 3. Start the Arduino cloud client.
173+
client.start()
174+
```
175+
176+
Remember that our `secrets.py` file should look like:
177+
```python
178+
WIFI_SSID = "" # WiFi network SSID (for MicroPython)
179+
WIFI_PASS = "" # WiFi network key (for MicroPython)
180+
DEVICE_ID = "" # Provided by Arduino cloud when creating a device.
181+
SECRET_KEY = "" # Provided by Arduino cloud when creating a device.
182+
```
183+
184+
#### Sync
185+
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.
186+
187+
Alternatively, you can select the synchronous method by passing sync_mode=True when creating the client object and calling client.update() periodically after connecting.
188+
189+
Code example:
190+
```python
191+
from secrets import DEVICE_ID
192+
from secrets import SECRET_KEY
193+
194+
# Switch callback, toggles the LED.
195+
def on_switch_changed(client, value):
196+
# Note the client object passed to this function can be used to access
197+
# and modify any registered cloud object. The following line updates
198+
# the LED value.
199+
client["led"] = value
200+
201+
# 1. Create a client object, which is used to connect to the IoT cloud and link local
202+
# objects to cloud objects. Note a username and password can be used for basic authentication
203+
# on both CPython and MicroPython. For more advanced authentication methods, please see the examples.
204+
client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY, sync_mode=True)
205+
206+
# 2. Register cloud objects.
207+
# Note: The following objects must be created first in the dashboard and linked to the device.
208+
# When the switch is toggled from the dashboard, the on_switch_changed function is called with
209+
# the client object and new value args.
210+
client.register("sw1", value=None, on_write=on_switch_changed)
211+
212+
# The LED object is updated in the switch's on_write callback.
213+
client.register("led", value=None)
214+
215+
# In synchronous mode, this function returns immediately after connecting to the cloud.
216+
client.start()
217+
218+
# Update the client periodically.
219+
while True:
220+
client.update()
221+
time.sleep(0.100)
222+
```
223+
224+
`secrets.py` file should look the same on both implementations.
225+
226+
### Project example
227+
228+
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.
138229

139230

140231
```python

content/arduino-cloud/03.cloud-interface/04.triggers/triggers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ tags: [Arduino Cloud, Triggers, Cloud Notification]
77

88
Triggers react to certain conditions inside your Arduino Cloud Thing, such as a boolean being true, or a string being assigned a value. As soon as a set condition is met a notification gets triggered and sent to you. This is useful when you monitor data and you need to know about any change as soon as it happens. This could be anything from different values in environmental monitoring or security-related information such as movement detection.
99

10+
Triggers can also be used to detect **device status**, where you can configure to send an email / push notification whenever a device goes online/offline.
11+
1012
Triggers can be set up for any of your existing projects, and are found in the [cloud home section](https://cloud.arduino.cc/home/).
1113

1214
## Hardware & Software Needed
@@ -16,8 +18,6 @@ Triggers can be set up for any of your existing projects, and are found in the [
1618

1719
***In this tutorial, we use the [Nano 33 IoT](https://store.arduino.cc/products/arduino-nano-33-iot). This is not a requirement, you can use any Arduino Cloud-compatible board for this tutorial.***
1820

19-
## Setup & Configuration
20-
2121
## Limitations
2222

2323
Currently, the only variables supported by the trigger feature are:
Loading
Loading

content/arduino-cloud/04.cloud-editor/embedding-create-iframes/embedding-create-iframes.md

+57-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
---
2-
title: 'Embedding your sketches into an HTML page'
3-
description: 'Learn about different methods when embedding your sketches in a website.'
4-
author: 'Karl Söderby'
2+
title: 'Embed & Share Sketches'
3+
description: 'Learn about sharing your sketches and different methods to embed your sketches in a website.'
4+
author: 'Karl Söderby, Hannes Siebeneicher'
55
---
66

77
The Cloud Editor is a great tool for creating and uploading programs while also collecting all of your sketches in one place. Another great feature is embedding them as iframes, such as articles, blogposts or journals.
88

9-
To embed an iframe is very easy, and we just need to copy and paste a link from our sketch in the Cloud Editor. But we can also do a series of modifications to that iframe, and in this tutorial we will take a look at how to do that.
9+
Embedding an iframe is easy. Simply copy and paste the link from your sketch in the Cloud Editor. But we can also do a series of modifications to that iframe, and in this tutorial we will take a look at how to do that.
1010

1111
## Let's start
1212

13-
First of all, we need to navigate to the [Cloud Editor](https://create.arduino.cc/editor). If we do not have an account, we can register one with just a few simple steps.
13+
First of all, we need to navigate to the [Cloud Editor](https://app.arduino.cc/sketches). If we do not have an account, we can register one with just a few simple steps.
1414

1515
Then, we need to have a code. In this tutorial, we are just going to use the good old **blink** example. When we have our sketch ready, click on the **share** button next to the serial monitor tool. This will open up a new window, that will have two fields: **link** and **embed**. Copy the embed field.
1616

17-
![embed field](assets/iframe-highlight.png)
17+
![Embed in HTML code](./assets/Embed_1.png)
18+
1819

1920
It should look something like this:
2021

2122
```markup
22-
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed" style="height:510px;width:100%;margin:10px 0" frameborder=0></iframe>
23+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
2324
```
2425

2526
This iframe can now simply be embedded in a HTML page, and it will look like this:
@@ -32,44 +33,73 @@ But there are many ways we can modify the iframe to look different. So let's tak
3233

3334
First up is the easiest: making a simple snippet. This removes the other information, such as sketch name and author, and simply presents a good looking snippet!
3435

35-
To do this, we just need to add the following code to the end of the URL:
36+
To do this, we need to change `view-mode=` from `embed` to `snippet` at the end of the URL:
3637

3738
```
38-
&snippet
39+
&view-mode=snippet
3940
```
4041
The result is the following:
4142

42-
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed&snippet" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
43+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
4344

4445
And the full URL should look like this:
4546

4647
```markup
47-
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed&snippet" style="height:510px;width:100%;margin:10px 0" frameborder=0></iframe>
48+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
4849
```
4950

50-
5151
## Highlighting specific lines
5252

5353
Next is the highlighting feature. To use this, simply add the following lines to the end of your URL:
5454

5555
```
56-
&snippet#L3-L4
56+
&highlight=L6,7
5757
```
5858

59-
The result is that line 3 and 4 are highlighted:
59+
The result is that line 6 and 7 are highlighted:
6060

61-
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed&snippet#L3-L4" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
61+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet&highlight=L6,7" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
6262

6363
And the full URL should look like this:
6464

6565
```markup
66-
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed&snippet#L3-L4" style="height:510px;width:100%;margin:10px 0" frameborder=0></iframe>
66+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet&highlight=L6,7" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
6767
```
6868

69-
You can highlight as many lines as you want, and it is easily configurable. For example, if we want to highlight line 1, 3 and 5-8, we simply need to add the following to the URL:
69+
You can highlight as many lines as you want, and it is easily configurable. For example, if we want to highlight line 4 and 6-9, we simply need to add the following to the URL:
7070

7171
```
72-
&snippet#L1,L3,L5-L8
72+
&highlight=L4,L6-L9
73+
```
74+
75+
## Scope
76+
77+
It's also possible to only show specific lines by adding the `scope` parameter, like this:
78+
79+
```markup
80+
&scope=L24-L37
81+
```
82+
83+
The result is that only lines 24 to 37 are shown.
84+
85+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet&scope=L24-L37" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
86+
87+
The full URL should look like this:
88+
```markup
89+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet&scope=24-28" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
90+
```
91+
92+
## Hide Numbers
93+
94+
To hide the line numbers in the embedded snippet, add the `&hide-numbers` parameter, like this:
95+
96+
```markup
97+
&hide-numbers
98+
```
99+
100+
The full URL should look like this:
101+
```markup
102+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet&scope=L3-L30&hide-numbers" style="height:510px;width:100%;margin:10px 0" frameborder="0"></iframe>
73103
```
74104

75105
## Manually changing the size of your widget
@@ -90,7 +120,7 @@ style="height:200px;width:50%;margin:10px 0"
90120

91121
Which will look like this:
92122

93-
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=embed&snippet" style="height:200px;width:50%;margin:10px 0" frameborder="0"></iframe>
123+
<iframe src="https://app.arduino.cc/sketches/examples?eid=01.Basics%2FBlink&view-mode=snippet" style="height:200px;width:50%;margin:10px 0" frameborder="0"></iframe>
94124

95125
## Automatically re-sizing your sketches
96126

@@ -100,13 +130,17 @@ We can also choose to automatically re-size our iframes. This is simply done by
100130
<script src="https://content.arduino.cc/assets/arduinoSketchIframeResizer.js"></script>
101131
```
102132

103-
And then using the class `arduino-sketch-iframe` in your HTML element.
133+
And then using the class `arduino-sketch-iframe` in your `HTML element`.
134+
135+
## Share your Code
136+
137+
If you want to share you're code with others can you do so by following the same steps as above, but instead of clicking on "Embed in HTML code:" you click on "Link to share:"
104138

105-
## Summary
139+
![Share Code](./assets/Share_1.png)
106140

107-
There are several cool ways of working with iframes from the Cloud Editor, and it is a really easy process that requires very little coding.
141+
This link will direct others to a preview of our code where they can copy it or directly add it to their sketchbook.
108142

109-
The Cloud Editor helps you keep track on all of your sketches, and with the iframes, including your projects on other pages has never been easier.
143+
***Note: If you want to learn how to keep sensitive data in your code safe, read [Store Sensitive Data in Sketches](/arduino-cloud/cloud-editor/share-your-sketches/).***
110144

111145
### More tutorials
112146

0 commit comments

Comments
 (0)