Skip to content

Commit 5322b11

Browse files
authored
Merge branch 'launch/portenta-mid-carrier-4G-modules' into mcmchris/portenta-mid-carrier/product-page
2 parents 1848857 + 3ab85c9 commit 5322b11

File tree

762 files changed

+17585
-4293
lines changed

Some content is hidden

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

762 files changed

+17585
-4293
lines changed

.github/actions/cloudflare-upload/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inputs:
44
upload-dir:
55
description: "The name of the app to build and export"
66
required: true
7-
7+
88
project-name:
99
description: "The name of the project to upload to"
1010
required: true
@@ -66,7 +66,7 @@ runs:
6666
### ${{ inputs.project-name }}
6767
🚀 Preview this PR: ${{ steps.deploy-cloudflare.outputs.url }}
6868
📍 Commit SHA: ${{ github.sha }}
69-
69+
7070
7171
- name: Update PR Preview Comment
7272
if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0

.github/workflows/cloudflare.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
1820
- uses: actions/setup-node@v3
1921
with:
2022
node-version: 18

.github/workflows/deploy-prd.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
1921
- uses: actions/setup-node@v3
2022
with:
2123
node-version: 18

.github/workflows/deploy-stg.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515

1616
steps:
1717
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- run: git log -1 --pretty=format:%aI content/learn/04.electronics/05.servo-motors/servo-motors.md
1821
- uses: actions/setup-node@v3
1922
with:
2023
node-version: 18
Loading
Loading

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

Lines changed: 214 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ libraries:
1313

1414
## Introduction
1515

16-
This tutorial guides you on how to use the MicroPython library to connect your Arduino device to the Arduino Cloud.
16+
This tutorial guides you on how to use the MicroPython library to connect your Arduino device to the Arduino Cloud. As a minimal example we will toggle the on-board LED using an Arduino Cloud dashboard widget.
1717

1818
It requires your board to have a version of MicroPython installed, which is covered in [this article](/micropython/basics/board-installation).
1919

@@ -61,7 +61,7 @@ Next step is to create some Cloud variables, which we will later interact with v
6161
1. While in Thing configuration, click on **"Add Variable"** which will open a new window.
6262
2. Name your variable `led` and select it to be of an `boolean` type.
6363
3. Click on **"Add Variable"** at the bottom of the window.
64-
4. Create another variable, name it `ledSwitch` and select it to be `int` type.
64+
4. Create another variable, name it `ledSwitch` and select it to be `boolean` type.
6565

6666
You should now have **two variables**:
6767
- `led` - boolean
@@ -134,7 +134,8 @@ 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 sketch. It connects your device
137+
Here is the example code to copy and paste into your program. It connects your device to Arduino Cloud over Wi-Fi®.
138+
138139

139140
```python
140141
from machine import Pin
@@ -148,11 +149,13 @@ from secrets import WIFI_PASSWORD
148149
from secrets import DEVICE_ID
149150
from secrets import CLOUD_PASSWORD
150151

151-
led = Pin("LEDB", Pin.OUT) # Configure the desired LED pin as an output.
152+
led = Pin("LED_BUILTIN", Pin.OUT) # Configure the desired LED pin as an output.
152153

153154
def on_switch_changed(client, value):
154155
# Toggles the hardware LED on or off.
155156
led.value(not value)
157+
# Depending on the board you use you may need to use "led.value(value)" instead
158+
# so that the LED's state reflects correctly the boolean value.
156159

157160
# Sets the value of the Cloud variable "led" to the current state of the LED
158161
# and thus mirrors the hardware state in the Cloud.
@@ -212,6 +215,212 @@ if __name__ == "__main__":
212215

213216
Open Arduino Lab for MicroPython and connect to your board. Pasting the above code and run the script. Then open your Arduino Cloud dashboard. You should see the registered "ledSwitch" and "led" widgets. Toggle the "ledSwitch", and the LED on your Arduino board should light up accordingly. The state of the "led" variable should also change, mirroring the state of the physical LED.
214217

218+
## Using Advanced Cloud Variables
219+
220+
To use variables in Arduino Cloud that are not of a basic type, you can set them up like you would do with any other variable. For example, to control a colored light such as the on-board RGB led on some Arduino boards, you can create a variable of type `CloudColoredLight`.
221+
222+
![Variable creation in Arduino Cloud](./assets/colored-light-variable.png)
223+
224+
225+
226+
On the programming side, you need to import the corresponding class in MicroPython. For the colored light example, you need to import the `ColoredLight` class:
227+
228+
```python
229+
from arduino_iot_cloud import ColoredLight
230+
```
231+
232+
The cloud variable needs then to be registered with the client using that type and the name that you gave it ("light" in our example):
233+
234+
```python
235+
client.register(ColoredLight("light", swi=True, on_write=on_colored_light_changed))
236+
```
237+
238+
In the callback function for this variable ("on_colored_light_changed") you will receive an object of the same type with populated properties. Those properties depend on the type. For example the `ColoredLight` class has the following properties:
239+
240+
- `swi`: The on-value of the light switch (True/False)
241+
- `hue`: The hue value of the color
242+
- `sat`: The saturation of the color
243+
- `bri`: The brightness of the color
244+
245+
Once you receive these values from the Cloud you will need to convert them to RGB so you can set the RGB LEDs accordingly. For reasons of brevity we won't go into the code for the color conversion, it is provided however in the full example code further down. Also we need to make all three RGB LEDs available in the code so their value can be set:
246+
247+
```python
248+
led_red = Pin("LEDR", Pin.OUT)
249+
led_green = Pin("LEDG", Pin.OUT)
250+
led_blue = Pin("LEDB", Pin.OUT)
251+
```
252+
253+
Then each of the three LEDs' brightness needs to be set so that the resulting color is as desired. This is done using a technique called [PWM](/learn/microcontrollers/analog-output/):
254+
255+
```python
256+
def set_led_brightness(led, brightness):
257+
"""
258+
Sets the brightness (0 - 255) of an LED using PWM.
259+
"""
260+
pwm = PWM(led)
261+
max_brightness = 255
262+
263+
# Ensure brightness is between 0 and max_brightness.
264+
brightness = max(0, min(max_brightness, brightness))
265+
266+
# Map input brightness from 0-max_brightness to 0-65535.
267+
duty_cycle = int(brightness * 65535 / max_brightness)
268+
pwm.duty_u16(duty_cycle)
269+
```
270+
271+
With that defined we can set the corresponding values of the RGBs:
272+
273+
```python
274+
def set_leds_from_rgb(rgb, common_cathode=True):
275+
# For common cathode RGB LEDs, invert the RGB values
276+
# since the LED is on when the pin is low.
277+
if common_cathode:
278+
rgb = (255 - rgb[0], 255 - rgb[1], 255 - rgb[2])
279+
set_led_brightness(led_red, rgb[0])
280+
set_led_brightness(led_green, rgb[1])
281+
set_led_brightness(led_blue, rgb[2])
282+
```
283+
284+
The missing piece is the callback handler for when the cloud variable changes that was defined when registering the variable:
285+
286+
```python
287+
def on_colored_light_changed(client, light):
288+
# Do nothing if the hue, saturation or brightness is None.
289+
if light.hue is None or light.sat is None or light.bri is None:
290+
return
291+
292+
light_enabled = light.swi
293+
294+
if light_enabled:
295+
rgb_value = convert_hs_to_rgb(light.hue, light.sat, light.bri)
296+
set_leds_from_rgb(rgb_value)
297+
else:
298+
set_leds_from_rgb((0, 0, 0)) # Turn LEDs off
299+
```
300+
301+
### Full Code Example
302+
303+
Here is the complete code to try it out:
304+
305+
306+
```python
307+
# This file is part of the Python Arduino Cloud.
308+
309+
# Any copyright is dedicated to the Public Domain.
310+
# https://creativecommons.org/publicdomain/zero/1.0/
311+
from machine import Pin, PWM
312+
import time
313+
import network
314+
import logging
315+
from arduino_iot_cloud import ArduinoCloudClient
316+
from arduino_iot_cloud import ColoredLight
317+
318+
from secrets import *
319+
320+
led_red = Pin("LEDR", Pin.OUT)
321+
led_green = Pin("LEDG", Pin.OUT)
322+
led_blue = Pin("LEDB", Pin.OUT)
323+
324+
def set_led_brightness(led, brightness):
325+
"""
326+
Sets the brightness (0 - 255) of an LED using PWM.
327+
"""
328+
pwm = PWM(led)
329+
max_brightness = 255
330+
331+
# Ensure brightness is between 0 and max_brightness.
332+
brightness = max(0, min(max_brightness, brightness))
333+
334+
# Map input brightness from 0-max_brightness to 0-65535.
335+
duty_cycle = int(brightness * 65535 / max_brightness)
336+
pwm.duty_u16(duty_cycle)
337+
338+
def convert_hs_to_rgb(hue, sat, bri):
339+
# Convert hue, saturation and brightness to RGB.
340+
# This function is based on the algorithm described at
341+
# https://www.developers.meethue.com/documentation/color-conversions-rgb-xy
342+
# and https://gist.github.com/mjackson/5311256
343+
h = hue / 360
344+
s = sat / 100
345+
v = bri / 100
346+
if s == 0.0:
347+
return (int(v * 255), int(v * 255), int(v * 255))
348+
i = int(h * 6)
349+
f = (h * 6) - i
350+
p = v * (1 - s)
351+
q = v * (1 - s * f)
352+
t = v * (1 - s * (1 - f))
353+
if i % 6 == 0:
354+
return (int(v * 255), int(t * 255), int(p * 255))
355+
if i % 6 == 1:
356+
return (int(q * 255), int(v * 255), int(p * 255))
357+
if i % 6 == 2:
358+
return (int(p * 255), int(v * 255), int(t * 255))
359+
if i % 6 == 3:
360+
return (int(p * 255), int(q * 255), int(v * 255))
361+
if i % 6 == 4:
362+
return (int(t * 255), int(p * 255), int(v * 255))
363+
if i % 6 == 5:
364+
return (int(v * 255), int(p * 255), int(q * 255))
365+
366+
def set_leds_from_rgb(rgb, common_cathode=True):
367+
# For common cathode RGB LEDs, invert the RGB values
368+
# since the LED is on when the pin is low.
369+
if common_cathode:
370+
rgb = (255 - rgb[0], 255 - rgb[1], 255 - rgb[2])
371+
set_led_brightness(led_red, rgb[0])
372+
set_led_brightness(led_green, rgb[1])
373+
set_led_brightness(led_blue, rgb[2])
374+
375+
def on_colored_light_changed(client, light):
376+
# Do nothing if the hue, saturation or brightness is None.
377+
if light.hue is None or light.sat is None or light.bri is None:
378+
return
379+
380+
light_enabled = light.swi
381+
382+
if light_enabled:
383+
rgb_value = convert_hs_to_rgb(light.hue, light.sat, light.bri)
384+
set_leds_from_rgb(rgb_value)
385+
else:
386+
set_leds_from_rgb((0, 0, 0))
387+
388+
def wifi_connect():
389+
if not WIFI_SSID or not WIFI_PASSWORD:
390+
raise (Exception("Network is not configured. Set SSID and passwords in secrets.py"))
391+
wlan = network.WLAN(network.STA_IF)
392+
wlan.active(True)
393+
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
394+
while not wlan.isconnected():
395+
logging.info("Trying to connect. Note this may take a while...")
396+
time.sleep_ms(500)
397+
logging.info(f"WiFi Connected {wlan.ifconfig()}")
398+
399+
if __name__ == "__main__":
400+
# Configure the logger.
401+
# All message equal or higher to the logger level are printed.
402+
# To see more debugging messages, set level=logging.DEBUG.
403+
logging.basicConfig(
404+
datefmt="%H:%M:%S",
405+
format="%(asctime)s.%(msecs)03d %(message)s",
406+
level=logging.INFO,
407+
)
408+
409+
# NOTE: Add networking code here or in boot.py
410+
wifi_connect()
411+
412+
# Create a client object to connect to the Arduino Cloud.
413+
414+
# For MicroPython, the key and cert files must be stored in DER format on the filesystem.
415+
# Alternatively, a username and password can be used to authenticate:
416+
client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=CLOUD_PASSWORD)
417+
client.register(ColoredLight("light", swi=True, on_write=on_colored_light_changed))
418+
419+
# Start the Arduino Cloud client.
420+
421+
client.start()
422+
```
423+
215424
## Troubleshoot
216425

217426
If the code is not working, there are some common issues we can troubleshoot:
@@ -223,4 +432,4 @@ If the code is not working, there are some common issues we can troubleshoot:
223432

224433
## Conclusion
225434

226-
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.
435+
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.
Loading
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Cloud Agent
3+
description: The Cloud Agent allows Arduino boards to interface with the Arduino Cloud.
4+
tags: [Arduino Cloud, Cloud Agent, Cloud Editor]
5+
author: Karl Söderby
6+
---
7+
8+
The [Arduino Cloud Agent](https://create.arduino.cc/getting-started/plugin/welcome) is a plugin that you install on your computer, that enables serial communication between your board and the Arduino Cloud. This allows you to upload sketches, and read/write serial data to/from your board, via your web browser.
9+
10+
The Cloud Agent is a requirement to program your devices in the Arduino Cloud, and takes only a minute to install.
11+
12+
## Installation
13+
14+
When you configure a device or use the Cloud Editor, you will automatically receive a prompt to install the Cloud Agent.
15+
16+
You can also access the download page through [this link](https://create.arduino.cc/getting-started/plugin/welcome). It should look like this:
17+
18+
![Download Cloud Agent.](assets/install-agent.png)
19+
20+
Follow the installation guide in the page, where you will download an installation file. To install it, run the file and follow the instructions for your operating system.
21+
22+
Once installed, you can navigate back to the Cloud Editor, and you should be able to recognize the board connected to your computer.
23+
24+
![Board connected to computer.](assets/board-connected.png)
25+
26+
## Source Code
27+
28+
The source code for the Cloud Agent lives [in this GitHub repository](https://github.com/arduino/arduino-create-agent). To report issues or improvements, please do so inside in this repository.
29+
30+
## Troubleshooting
31+
32+
If you are having issues with the Cloud Agent, you can visit the link below:
33+
- [Arduino Help Center - Create Agent](https://support.arduino.cc/hc/en-us/articles/360014869820-Install-the-Arduino-Create-Agent)

0 commit comments

Comments
 (0)