You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/carriers/portenta-hat-carrier/tutorials/user-manual/content.md
+35-36Lines changed: 35 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -343,7 +343,7 @@ Previously, we manually toggled the LED linked to _GPIO3_ on the Portenta X8 via
343
343
344
344
The script below is compatible with the ADB shell on the Portenta X8:
345
345
346
-
```
346
+
```python
347
347
#!/usr/bin/env python3
348
348
import time
349
349
@@ -519,7 +519,7 @@ This abstraction makes it easier to manipulate the GPIO without having to rewrit
519
519
520
520
The decision to containerize the Python® script using Docker ensures that it runs in a consistent environment and is isolated from other processes. Docker provides a mechanism to create containerized applications that can be executed reliably across various platforms.
521
521
522
-
```
522
+
```bash
523
523
# dockerfile
524
524
525
525
# Use an official Python runtime as the base image
@@ -556,7 +556,7 @@ pyserial==3.4
556
556
557
557
Within the dockerfile, a working directory, `/app`, is defined inside the container. The Python® script is copied into this directory and granted execution permissions, ensuring that it can run without issues. The concluding action sets the default command for the Docker container to initiate the Python® script when the container starts.
@@ -2029,7 +2029,7 @@ If you desire to use Portenta X8 paired to Portenta Hat Carrier, please consider
2029
2029
2030
2030
Below script would be used for __Server side (TCP/IP)__ operations:
2031
2031
2032
-
```
2032
+
```python
2033
2033
#!/usr/bin/env python3
2034
2034
2035
2035
import socket
@@ -2059,7 +2059,7 @@ The Server side script is set to wait for incoming connections on `127.0.0.1` (l
2059
2059
2060
2060
The script below will be used for __Client side (TCP/IP)__ operations:
2061
2061
2062
-
```
2062
+
```python
2063
2063
#!/usr/bin/env python3
2064
2064
2065
2065
import socket
@@ -2083,7 +2083,7 @@ The Client side script connects to the server specified by the `HOST` and `PORT`
2083
2083
2084
2084
If you would like to have a single script running both instances, the following script can perform the task using Python®'s built-in `threading` component.
2085
2085
2086
-
```
2086
+
```python
2087
2087
import socket
2088
2088
import threading
2089
2089
@@ -2259,7 +2259,7 @@ void loop()
2259
2259
2260
2260
Following `Web Client` example can be considered for Portenta C33:
2261
2261
2262
-
```
2262
+
```arduino
2263
2263
#include <EthernetC33.h>
2264
2264
2265
2265
// if you don't want to use DNS (and reduce your sketch size)
@@ -2461,7 +2461,7 @@ Next conditions will help you properly set the hardware to test GPIO controls:
2461
2461
2462
2462
When all conditions are set and in place, use the following script to read all available GPIOs on 40-Pin header:
2463
2463
2464
-
```
2464
+
```python
2465
2465
#!/usr/bin/env python3
2466
2466
2467
2467
# created 12 October 2023
@@ -2538,7 +2538,7 @@ This example uses a designated GPIO pin to set the user-programmable LED on the
2538
2538
2539
2539
Alternatively, the following example controls the user-programmable LED on the Portenta Hat Carrier based on potentiometer input:
2540
2540
2541
-
```
2541
+
```arduino
2542
2542
const int potPin = A0; // the number of the potentiometer pin (16-Pin header)
2543
2543
const int ledPin = <PD_5/30>; // User programmable LED GPIO3 corresponding to paired Portenta board
2544
2544
@@ -2591,7 +2591,7 @@ The following Python® script is designed to control the brightness of a device,
2591
2591
2592
2592
The script sets up the PWM channel, defines its period, and then, within a loop, modulates the brightness by adjusting the duty cycle. Consider the script below as an example:
2593
2593
2594
-
```
2594
+
```python
2595
2595
#!/usr/bin/env python3
2596
2596
2597
2597
import time
@@ -2634,7 +2634,7 @@ if __name__ == "__main__":
2634
2634
#### Using Arduino IDE
2635
2635
<br></br>
2636
2636
2637
-
The [`analogWrite()` function](https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite)] included into the Arduino programming language can be used to access the PWM pins.
2637
+
The [`analogWrite()` function](https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite) included into the Arduino programming language can be used to access the PWM pins.
2638
2638
2639
2639
The example code shown below grabs a pin compatible with PWM functionality to control the brightness of an LED connected to it:
2640
2640
@@ -2759,7 +2759,7 @@ The continuing script offers an interface for interaction with the Seeed Studio
2759
2759
2760
2760
It can interact with up to four relay ports on the board. Among its various features, it can turn a specific relay on or off, toggle all relays simultaneously, toggle a particular relay's state, and retrieve the status of any relay. Furthermore, it has built-in error handling to ensure that a valid integer relay number is specified.
2761
2761
2762
-
```
2762
+
```python
2763
2763
from__future__import print_function
2764
2764
2765
2765
import smbus
@@ -2878,7 +2878,7 @@ Next script showcases the utility of the relay board functions. At the onset, it
2878
2878
2879
2879
Subsequently, it sequentially powers each relay on and off, with a one-second intermission in between. In the event of a keyboard interrupt, the script terminates and ensures all the relays are switched off.
2880
2880
2881
-
```
2881
+
```python
2882
2882
#!/usr/bin/python
2883
2883
2884
2884
from__future__import print_function
@@ -2942,7 +2942,7 @@ To use the drv8825 HAT with Portenta Hat Carrier and Portenta X8, please follow
2942
2942
2943
2943
Once the hardware setup is ready, use the script below to perform a test run of the connected stepper motor:
2944
2944
2945
-
```
2945
+
```python
2946
2946
#!/usr/bin/env python3
2947
2947
2948
2948
# created 12 October 2023
@@ -3001,18 +3001,18 @@ Please, refer to the [board pinout section](#pinout) of the user manual to find
3001
3001
3002
3002
For Portenta X8, it is possible to use following commands:
3003
3003
3004
-
```arduino
3004
+
```
3005
3005
sudo modprobe spidev
3006
3006
```
3007
3007
3008
3008
Present sequence of commands is used to enable the SPI device interface on the Portenta X8. After adding the `spidev` module to the system's configuration, the system is rebooted to apply the changes.
3009
3009
3010
-
```arduino
3010
+
```
3011
3011
echo "spidev" | sudo tee > /etc/modules-load.d/spidev.conf
3012
3012
sudo systemctl reboot
3013
3013
```
3014
3014
3015
-
```arduino
3015
+
```
3016
3016
services:
3017
3017
my_spi_service:
3018
3018
devices:
@@ -3129,20 +3129,20 @@ Please, refer to the [pinout section](#pinout) of the user manual to find them o
3129
3129
3130
3130
For Portenta X8, it is possible to use following commands:
3131
3131
3132
-
```arduino
3132
+
```
3133
3133
sudo modprobe i2c-dev
3134
3134
```
3135
3135
3136
3136
Present sequence of commands is used to enable the I2C device interface on the Portenta X8. After adding the `i2c-dev` module to the system's configuration, the system is rebooted to apply the changes.
3137
3137
3138
-
```arduino
3138
+
```
3139
3139
echo "i2c-dev" | sudo tee > /etc/modules-load.d/i2c-dev.conf
3140
3140
sudo systemctl reboot
3141
3141
```
3142
3142
3143
3143
Following section configures a service named `my_i2c_service` to use the I2C device available at `/dev/i2c-3`.
3144
3144
3145
-
```arduino
3145
+
```
3146
3146
services:
3147
3147
my_i2c_service:
3148
3148
devices:
@@ -3165,7 +3165,7 @@ Below are some brief examples to help you in using I2C with the Portenta X8 and
3165
3165
3166
3166
Here, the SMBus (System Management Bus) communication, with SMBus-compatible [libraries](https://github.com/kplindegaard/smbus2), is established with the device on `/dev/i2c-3`. A byte of data is read from the device at address 80 and offset 0, then printed.
3167
3167
3168
-
```arduino
3168
+
```python
3169
3169
from smbus2 import SMBus
3170
3170
3171
3171
# Connect to /dev/i2c-3
@@ -3176,7 +3176,7 @@ print(b)
3176
3176
3177
3177
The following code initializes the I2C bus using the _smbus2 library_ and reads multiple bytes from the device. The `read_i2c_block_data` function reads a block of bytes from the I2C device at a given address.
3178
3178
3179
-
```
3179
+
```python
3180
3180
from smbus2 import SMBus
3181
3181
3182
3182
# Initialize the I2C bus
@@ -3196,7 +3196,7 @@ for byte in data:
3196
3196
3197
3197
Next code shows how to write data to an I2C device using the _smbus2 library_. A byte of data (`value`) is written to a specific address (`device_address`) with a given instruction.
3198
3198
3199
-
```
3199
+
```python
3200
3200
from smbus2 import SMBus
3201
3201
3202
3202
# Initialize the I2C bus
@@ -3214,7 +3214,7 @@ In the following code, the [python-periphery](https://python-periphery.readthedo
3214
3214
3215
3215
A byte is read from the EEPROM at address `0x50` and offset `0x100`, then printed.
3216
3216
3217
-
```arduino
3217
+
```python
3218
3218
from periphery importI2C
3219
3219
3220
3220
# Open i2c-0 controller
@@ -3321,13 +3321,13 @@ This command sequence activates the CAN transceiver. It does so by exporting _GP
3321
3321
3322
3322
For Portenta X8, it is possible to use following commands:
3323
3323
3324
-
```arduino
3324
+
```
3325
3325
sudo modprobe can-dev
3326
3326
```
3327
3327
3328
3328
The necessary modules for CAN (Controller Area Network) support on the Portenta X8 are loaded. The `can-dev` module is added to the system configuration, after which the system is rebooted to apply the changes.
3329
3329
3330
-
```arduino
3330
+
```
3331
3331
echo "can-dev" | sudo tee > /etc/modules-load.d/can-dev.conf
3332
3332
sudo systemctl reboot
3333
3333
```
@@ -3412,7 +3412,7 @@ Each bustype corresponds to different CAN interfaces or devices, ranging from th
3412
3412
3413
3413
In the following Python® script, `send_standard_can_message` and `send_extended_can_message` functions are defined to send standard and extended CAN messages respectively. The `main()` function creates a CAN bus instance with a 'virtual' bus type for demonstration purposes and sends standard and extended CAN messages in a loop.
3414
3414
3415
-
```
3415
+
```python
3416
3416
import can
3417
3417
import time
3418
3418
@@ -3448,7 +3448,7 @@ if __name__ == "__main__":
3448
3448
3449
3449
Continuing Python® script defines functions to receive and print incoming CAN messages. The receive_can_messages function continuously listens for CAN messages and calls print_received_message to display the details of the received message, such as whether it is an extended message or a remote transmission request (RTR) and its data.
3450
3450
3451
-
```
3451
+
```python
3452
3452
import can
3453
3453
3454
3454
defreceive_can_messages(bus):
@@ -3493,13 +3493,12 @@ if __name__ == "__main__":
3493
3493
The `main()` function initializes the CAN bus with a 'virtual' channel for example demonstration and starts the message listening process.
3494
3494
3495
3495
#### Using Arduino IDE
3496
-
<br></br>
3497
3496
3498
3497
For users working with the Portenta H7 or Portenta C33, following simple examples can be used to test the CAN bus protocol's capabilities.
3499
3498
3500
3499
The _CAN Read_ example for Portenta H7/C33 starts CAN communication at a rate of _250 kbps_ and continuously listens for incoming messages, displaying such information upon receipt.
The _CAN Write_ example, also set at _250 kbps_, builds and sends a specific message format. This message includes a fixed preamble followed by an incrementing counter value that updates with each loop iteration.
@@ -3619,7 +3618,7 @@ The output _/dev/ttymxc1_ is an example of a potential serial device you might f
3619
3618
3620
3619
Following Python® script uses the _pyserial_ library to communicate with devices over UART. It defines the `processData` function which prints the received data. You can modify this function based on your application's needs.
0 commit comments