Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Referenced library wrapper #72

Merged
merged 9 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions content/tutorials/portenta-h7/por-ard-ap/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Begin by plugging in your Portenta board to your computer using a USB-C cable an
## 2. Create the Web Server Sketch
Next we need to create a web server sketch that will handle the HTTP GET requests and provide the client devices with the HTML web page. The [Wifi.h](https://www.arduino.cc/en/Reference/WiFi) library provides all necessary methods that allows Arduino boards to use their WiFi features provided by the on-board WiFi module. To set up the web server copy the following code, paste it into a new sketch file and name it **simpleWebServer.ino**.

**Note:** You can access the final sketch inside the library: *Examples -> Arduino_Pro_Tutorials -> Portenta H7 as a WiFi Access Point -> simpleWebServer*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marqdevx simpleWebServer should be SimpleWebServer because the folder name is camel case too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


```cpp
#include <WiFi.h>
#include "arduino_secrets.h"
Expand Down
2 changes: 1 addition & 1 deletion content/tutorials/portenta-h7/por-ard-ble/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You will need to install the ArduinoBLE library in the Arduino IDE you are using

## 3. Create the BLE Sketch

Let's program the Portenta with the following example sketch. If the BLE module can be initialized correctly, you will see the blue LED lighting up for one second after uploading the sketch. If it fails you will see the red LED lighting up instead. Copy and paste the following code into a new sketch in your IDE.
Let's program the Portenta with the following example sketch. If the BLE module can be initialized correctly, you will see the blue LED lighting up for one second after uploading the sketch. If it fails you will see the red LED lighting up instead. Copy and paste the following code into a new sketch in your IDE or by open it from: *Examples -> Arduino_Pro_Examples -> BLE Connectivity on Portenta H7 -> portentaBLE*

```cpp
#include <ArduinoBLE.h>
Expand Down
20 changes: 11 additions & 9 deletions content/tutorials/portenta-h7/por-ard-dcp/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Processor cores are individual processing units within the board's main processi
![The Architectures of Cortex® M7 and M4 cores.](assets/por_ard_dcp_m4_m7_architectures.svg?sanitize=true)

# Accessing the M7 and M4 Core
To best illustrate the idea of dual core processing, you will be running two separate sketch files. One on each of the cores which blinks the RGB LED in a different colour. The **blink_RedLed_m7.ino** sketch will set the built-in RGB LED on the board to red and blink it with a delay of 500 ms. The **blink_GreenLed_M4.ino** sketch will access the green LED in the RGB led and blink it with a delay of 200 ms. Both the cores will be executing the corresponding sketch file simultaneously and as a result both the green and red LED blink, however, at different intervals.
To best illustrate the idea of dual core processing, you will be running two separate sketch files. One on each of the cores which blinks the RGB LED in a different colour. The **BlinkRedLed_M7.ino** sketch will set the built-in RGB LED on the board to red and blink it with a delay of 500 ms. The **BlinkGreenLed_M4.ino** sketch will access the green LED in the RGB led and blink it with a delay of 200 ms. Both the cores will be executing the corresponding sketch file simultaneously and as a result both the green and red LED blink, however, at different intervals.

![Running two different sketch files on the different cores.](assets/por_ard_dcp_tutorial_overview.svg?sanitize=true)

Expand All @@ -27,12 +27,14 @@ Begin by plugging-in your Portenta board to your computer using an appropriate U

![A Basic setup of the board attached to your computer](../por-ard-gs/assets/por_ard_gs_basic_setup.svg?sanitize=true)

**Note:** Get the examples from the tutorials' library: **Libraries -> Arduino_Pro_Tutorials -> Dual Core Processing**

## 2. Setting the LED Color
In the previous tutorial you learned how to access the built-in RGB LED through the macro definition LED_BUILTIN. You can also control the distinct Red, Green and Blue LED separately through the LEDR, LEDG and LEDB macro definition respectively. 

Please note that, opposed to other Arduino boards, on the Portenta H7 the built-in RGB led pins need to be pulled to ground to make the LED light up. This means that a voltage level of LOW will turn the LED on, a voltage level of HIGH will turn it off.

The following sketch blinks the red LED at an interval of 200ms controlled by the M7 core.Save your sketch as **blink_RedLed_m7** and compile your sketch file.
The following sketch blinks the red LED at an interval of 200ms controlled by the M7 core.Save your sketch as **BlinkRedLed_M7** and compile your sketch file.

```cpp
// the setup function runs once when you press reset or power the board
Expand All @@ -51,12 +53,12 @@ void loop() {
```

## 3. Upload the Sketch to the M7 Core
Select the **Arduino Portenta H7 (M7 core)** from the **Board** menu and the port the Portenta is connected to (e.g. /dev/cu.usbmodem141101). Upload the **blink_RedLed_m7.ino** sketch. Doing so will automatically compile the sketch beforehand. When the sketch is uploaded the RGB LED on the board will start blinking red.
Select the **Arduino Portenta H7 (M7 core)** from the **Board** menu and the port the Portenta is connected to (e.g. /dev/cu.usbmodem141101). Upload the **BlinkRedLed_M7.ino** sketch. Doing so will automatically compile the sketch beforehand. When the sketch is uploaded the RGB LED on the board will start blinking red.

![Uploading the blink_RedLed_m7 sketch to the M7 core](assets/por_ard_dcp_upload_code_m7.png)
![Uploading the BlinkRedLed_M7 sketch to the M7 core](assets/por_ard_dcp_upload_code_m7.png)

## 4. Making the LED Blink Green
Let's write another sketch that makes the RGB LED on the board blink green. Open a new sketch file and call it **blink_GreenLed_M4.ino**. Copy and paste the following program that blinks the LED green, denoted by the variable `LEDG`, with a delay of 500ms. This time the blinking is controlled by the M4 core.
Let's write another sketch that makes the RGB LED on the board blink green. Open a new sketch file and call it **BlinkGreenLed_M4.ino**. Copy and paste the following program that blinks the LED green, denoted by the variable `LEDG`, with a delay of 500ms. This time the blinking is controlled by the M4 core.

```cpp
// the setup function runs once when you press reset or power the board
Expand All @@ -81,7 +83,7 @@ The bootloader of the H7 boards is configured in such a way that only M7 gets bo

![The M7 and the M4 cores share the flash memory where the sketches are stored.](assets/por_ard_dcp_m4_m7_flash_memory.svg?sanitize=true)

Before you can upload the code for the M4 core to the flash memory you need to add the `bootM4()` command in the **blink_RedLed_m7.ino** sketch file that is uploaded and run by the M7 core. Copy and paste the following command `bootM4()` inside the `setup()` function of the **blink_RedLed_m7.ino** sketch and upload the sketch to M7 once again.
Before you can upload the code for the M4 core to the flash memory you need to add the `bootM4()` command in the **BlinkRedLed_M7.ino** sketch file that is uploaded and run by the M7 core. Copy and paste the following command `bootM4()` inside the `setup()` function of the **BlinkRedLed_M7.ino** sketch and upload the sketch to M7 once again.

```cpp
// the setup function runs once when you press reset or power the board
Expand All @@ -103,9 +105,9 @@ void loop() {
Once this sketch runs on the M7 core, it boots the M4 core and allows it to run its corresponding sketch.

## 6. Uploading to the M4 Core
The final step is to upload the sketch that we prepared for the M4. Now open **Tools> Boards** from the IDE menu and select **Arduino Portenta H7 (M4 core)** from the boards. Upload the **blink_GreenLed_M4.ino** to the board. Note that there is no separate serial port listed for the M4 in the port menu as the M7 takes care of the serial communication. The RGB LED blinking in RED currently, starts blinking in green simultaneously at an interval of 500 ms. When the blinking overlaps the mix of red and green light is perceived as yellow.
The final step is to upload the sketch that we prepared for the M4. Now open **Tools> Boards** from the IDE menu and select **Arduino Portenta H7 (M4 core)** from the boards. Upload the **BlinkGreenLed_M4.ino** to the board. Note that there is no separate serial port listed for the M4 in the port menu as the M7 takes care of the serial communication. The RGB LED blinking in RED currently, starts blinking in green simultaneously at an interval of 500 ms. When the blinking overlaps the mix of red and green light is perceived as yellow.

![Uploading the blink_GreenLed_M4 to the M4 core](assets/por_ard_dcp_upload_code_m4.png)
![Uploading the BlinkGreenLed_M4 to the M4 core](assets/por_ard_dcp_upload_code_m4.png)

# Programming both Cores with just one sketch
So far, we used separate sketch files to program the different cores. We can also combine these two sketch files into one by taking advantage the preprocessor directives '#ifdef'. This way you can program different behaviors for both cores by using the same program.
Expand All @@ -115,7 +117,7 @@ So far, we used separate sketch files to program the different cores. We can als
Let's now to create a new sketch to blink both of LEDs with random sequences, this will allow you to clearly see different behaviors for both of the LEDs using a very simple program.

## 1. Programming the M7 Core Set-up
Let's start by opening a new sketch and naming it **blink_2cores.ino**. Then let's add the following lines of code.
Let's start by opening a new sketch and naming it **BlinkBothCores.ino**. Then let's add the following lines of code.

```cpp
int myLED;
Expand Down
4 changes: 3 additions & 1 deletion content/tutorials/portenta-h7/por-ard-gs/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ Now it's time to upload the sketch and see if the LED will start to blink. Make

![Selecting the Arduino Portenta H7 (M7 core)](assets/por_gs_board_selection_pro_ide.png)

# Conclusion
**Optional:** We collect all the sketches from the tutorials in a library wrapper, you can find it at: *Tools -> Library Manager -> Arduino_Pro_Tutorials* or [download them from the repository](https://github.com/arduino-libraries/Arduino_Pro_Tutorials/releases).

# Conclusion
You have now configured your Portenta board to run Arduino sketches. Along with that you gained an understanding of how the Arduino Core runs on top of Mbed OS.

# Next Steps
Expand Down
5 changes: 4 additions & 1 deletion content/tutorials/portenta-h7/por-ard-kvs/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Let's program the Portenta with a sketch. We will also define a few helper funct
* Create a new sketch named `FlashKeyValue.ino`
* Create a new file named `FlashIAPLimits.h` to store the helper functions in a reusable file.

**Note:** Finished sketch its inside the tutorials library wrapper at:
*Examples -> Arduino_Pro_Tutorials -> Storage -> Creating a Flash-Optimised Key-Value Store -> FlashKeyValueStore*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marqdevx Why is this one in a storage folder? It's the only example that cannot be found directly by looking up the tutorial name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## 3. Populate the Helper Functions
First let's add the helper functions to the `FlashIAPLimits.h` header. This will determine the available Flash limits to allocate the custom data.

Expand Down Expand Up @@ -283,4 +286,4 @@ It's not recommended to use the flash of the microcontroller as the primary stor

**Authors:** Giampaolo Mancini
**Reviewed by:** Pablo Marquínez [2.12.2020]
**Last revision:** Sebastian Romero [11.1.2021]
**Last revision:** Sebastian Romero [11.1.2021]
3 changes: 3 additions & 0 deletions content/tutorials/portenta-h7/por-ard-usb/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Then, open: File>Examples>USBHOST>KeyboardController

The **USBHost** library that is used in this example is a revamp of the classic Arduino **USBHost** library. This new version, among adapting the protocol to the newer USB version, allows to connect devices through USB Hubs (USB adapters). For a better understanding about how the USBHost library works, it could be helpful for you to take a look at the Arduino [USBHost](https://www.arduino.cc/en/Reference/USBHost) library.

**Note:** You can get the finished sketch in the library at:
*Examples -> Arduino_Pro_Tutorials -> Portenta H7 as a USB Host -> LEDKeyboardController*

## 3. Detecting the Keys From the Keyboard

The example you opened describes how the board will handle the connection with a keyboard, addressing the functionality of each one of the keys of it. In order to detect which one of the keys from the keyboard is pressed, you will need to modify and add some lines of code to the example.
Expand Down