Skip to content

Commit 20e9867

Browse files
[PC-1771] - Portenta C33 User Manual UART Example Update (#1999)
* Content update (UART section) * Content update (UART section information) * Content update (UART section information) * Update content/hardware/04.pro/boards/portenta-c33/tutorials/user-manual/content.md --------- Co-authored-by: Julián Caro Linares <jcarolinares@gmail.com>
1 parent da0a28d commit 20e9867

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed
Loading
Loading

content/hardware/04.pro/boards/portenta-c33/tutorials/user-manual/content.md

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -702,22 +702,37 @@ The Portenta C33 supports UART communication. The pins used in the Portenta C33
702702
| `92` | `P603` |
703703
| `93` | `P604` |
704704

705-
Please refer to the board pinout section of the user manual to find them on the board. The built-in ([Serial](https://www.arduino.cc/reference/en/language/functions/communication/serial/)) library functions can use the UART pins.
705+
***Please refer to the board pinout section of the user manual to find them on the board. The built-in [Serial](https://www.arduino.cc/reference/en/language/functions/communication/serial/) library functions can use the UART pins.***
706706

707+
The `Arduino Renesas Core` has a built-in library that lets you use the UART communication, the `Serial` library, right out of the box. Let's walk through an example sketch demonstrating some of the module's capabilities.
707708

708-
To begin with UART communication, you'll need to configure it first. In the `setup()` function, set the baud rate (bits per second) for UART communication:
709+
The example sketch below showcases how to configure the UART interface, read incoming data, and transmit data with the Portenta C33 board, which are common tasks for serial communication.
709710

710711
```arduino
711-
// Start UART communication at 9600 baud
712-
Serial.begin(9600);
713-
```
712+
/**
713+
UART Communication
714+
Name: UARTCommunication.ino
715+
Purpose: This sketch demonstrates UART communication on the Portenta C33
714716
715-
To read incoming data, you can use a `while()` loop to continuously check for available data with the `Serial.available()` function and read individual characters with the `Serial.read()` function. The code shown above stores the incoming characters in a String variable and processes the data when a line-ending character is received:
717+
@author Arduino Product Experience Team
718+
@version 1.0 03/06/24
719+
*/
720+
721+
// Include the necessary libraries for UART communication
722+
#include <Arduino.h>
716723
717-
```arduino
718724
// Variable for storing incoming data
719725
String incoming = "";
720726
727+
void setup() {
728+
// Initialize serial communication and wait up to 2.5 seconds for a connection
729+
Serial.begin(115200);
730+
for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500));
731+
732+
// Print a message to the Serial Monitor to indicate setup is complete
733+
Serial.println("- UART communication setup complete!");
734+
}
735+
721736
void loop() {
722737
// Check for available data and read individual characters
723738
while (Serial.available()) {
@@ -737,25 +752,44 @@ void loop() {
737752
incoming += c;
738753
}
739754
}
755+
756+
// Example of transmitting data
757+
// Transmit the string "Hello world!" every second
758+
// Wait for 1 second before sending again
759+
Serial.println("- Hello world!");
760+
delay(1000);
740761
}
741-
```
742762
743-
To transmit data to another device via UART, you can use the `Serial.write()` function:
763+
/**
764+
Processes the received data
765+
This function can be modified to perform different actions based on the received data
744766
745-
```arduino
746-
// Transmit the string "Hello world!
747-
Serial.write("Hello world!");
767+
@param data The received data as a String
768+
@return none
769+
*/
770+
void processData(String data) {
771+
// Print the received data to the Arduino IDE Serial Monitor
772+
Serial.println("- Received: " + data);
773+
}
748774
```
749775

750-
You can also use the `Serial.print()` and `Serial.println()` functions to send a String without a newline character or followed by a newline character:
776+
Let's analyze the example sketch. First, the necessary configurations are made:
751777

752-
```arduino
753-
// Transmit the string "Hello world!"
754-
Serial.print("Hello world!");
778+
- The UART communication is initialized at a baud rate of 115200.
779+
- A loop continuously checks for available data and reads individual characters, storing them in a `String` variable.
780+
- A newline character indicates the end of a message, triggering the processing function.
755781

756-
// Transmit the string "Hello world!" followed by a newline character
757-
Serial.println("Hello world!");
758-
```
782+
The `processData()` function is called to process the received data. This example simply prints the data to the Arduino IDE's Serial Monitor. You can modify this function to perform different actions based on the received data. Finally, the example sketch shows how to send data using the `Serial.println()` function, which transmits the string `Hello world!` every second.
783+
784+
You should see the following output in the Arduino IDE's Serial Monitor:
785+
786+
![Example sketch output in the Arduino IDE's Serial Monitor](assets/user-manual-23.png)
787+
788+
You can also send information to the Portenta C33 using the Arduino IDE's Serial Monitor. In the `Message` box of the IDE's Serial Monitor, write a message (for example, `Portenta C33`) and press Enter; you should see the following output in the Arduino IDE's Serial Monitor:
789+
790+
![Example sketch output in the Arduino IDE's Serial Monitor](assets/user-manual-24.png)
791+
792+
You can download the example sketch [here](assets/UARTCommunication.zip).
759793

760794
### Wi-Fi®
761795

@@ -1053,7 +1087,6 @@ void loop() {
10531087
}
10541088
```
10551089

1056-
10571090
First, the necessary libraries are included:
10581091

10591092
- The `EthernetC33` library which contains the functionality required to communicate via Ethernet is included in the beginning.

0 commit comments

Comments
 (0)