Skip to content

Commit f700f96

Browse files
authored
Merge pull request #1439 from arduino/mcmchris/hat-carrier/usr-manual-fixes
Merged
2 parents 1e2d13e + 4db9c24 commit f700f96

File tree

1 file changed

+35
-36
lines changed
  • content/hardware/04.pro/carriers/portenta-hat-carrier/tutorials/user-manual

1 file changed

+35
-36
lines changed

content/hardware/04.pro/carriers/portenta-hat-carrier/tutorials/user-manual/content.md

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Previously, we manually toggled the LED linked to _GPIO3_ on the Portenta X8 via
343343

344344
The script below is compatible with the ADB shell on the Portenta X8:
345345

346-
```
346+
```python
347347
#!/usr/bin/env python3
348348
import time
349349

@@ -519,7 +519,7 @@ This abstraction makes it easier to manipulate the GPIO without having to rewrit
519519

520520
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.
521521

522-
```
522+
```bash
523523
# dockerfile
524524

525525
# Use an official Python runtime as the base image
@@ -556,7 +556,7 @@ pyserial==3.4
556556

557557
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.
558558

559-
```
559+
```bash
560560
# docker-compose.yaml
561561

562562
version: '3.6'
@@ -1122,7 +1122,7 @@ cat /sys/bus/iio/devices/iio\:device0/in_voltage<adc_pin>_raw
11221122

11231123
If you are working in Python®, the command can be implemented as shown in the script below:
11241124

1125-
```
1125+
```python
11261126
def read_adc_value(adc_pin):
11271127
try:
11281128
with open(f'/sys/bus/iio/devices/iio:device0/in_voltage{adc_pin}_raw', 'r') as file:
@@ -1169,7 +1169,7 @@ void loop() {
11691169

11701170
Following example can be considered for Portenta C33:
11711171

1172-
```
1172+
```arduino
11731173
#include "analogWave.h" // Include the library for analog waveform generation
11741174
11751175
analogWave wave(DAC); // Create an instance of the analogWave class, using the DAC pin
@@ -1356,7 +1356,7 @@ cat /sys/devices/virtual/thermal/thermal_zone0/temp
13561356

13571357
It can be translated into a Python® script to automate the command sequence:
13581358

1359-
```
1359+
```python
13601360
def setup_pwm(pwm_chip, pwm_channel, period, duty_cycle):
13611361
base_path = f"/sys/class/pwm/pwmchip{pwm_chip}"
13621362

@@ -1416,7 +1416,7 @@ echo | sudo tee /sys/class/pwm/pwmchip0/pwm9/enable
14161416

14171417
Consider the following Python® script if you would like to automate the command sequence:
14181418

1419-
```
1419+
```python
14201420
import subprocess
14211421

14221422
def setup_pwm(pwm_chip, pwm_channel, period, duty_cycle):
@@ -2029,7 +2029,7 @@ If you desire to use Portenta X8 paired to Portenta Hat Carrier, please consider
20292029

20302030
Below script would be used for __Server side (TCP/IP)__ operations:
20312031

2032-
```
2032+
```python
20332033
#!/usr/bin/env python3
20342034

20352035
import socket
@@ -2059,7 +2059,7 @@ The Server side script is set to wait for incoming connections on `127.0.0.1` (l
20592059

20602060
The script below will be used for __Client side (TCP/IP)__ operations:
20612061

2062-
```
2062+
```python
20632063
#!/usr/bin/env python3
20642064

20652065
import socket
@@ -2083,7 +2083,7 @@ The Client side script connects to the server specified by the `HOST` and `PORT`
20832083

20842084
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.
20852085

2086-
```
2086+
```python
20872087
import socket
20882088
import threading
20892089

@@ -2259,7 +2259,7 @@ void loop()
22592259

22602260
Following `Web Client` example can be considered for Portenta C33:
22612261

2262-
```
2262+
```arduino
22632263
#include <EthernetC33.h>
22642264
22652265
// 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:
24612461

24622462
When all conditions are set and in place, use the following script to read all available GPIOs on 40-Pin header:
24632463

2464-
```
2464+
```python
24652465
#!/usr/bin/env python3
24662466

24672467
# created 12 October 2023
@@ -2538,7 +2538,7 @@ This example uses a designated GPIO pin to set the user-programmable LED on the
25382538

25392539
Alternatively, the following example controls the user-programmable LED on the Portenta Hat Carrier based on potentiometer input:
25402540

2541-
```
2541+
```arduino
25422542
const int potPin = A0; // the number of the potentiometer pin (16-Pin header)
25432543
const int ledPin = <PD_5/30>; // User programmable LED GPIO3 corresponding to paired Portenta board
25442544
@@ -2591,7 +2591,7 @@ The following Python® script is designed to control the brightness of a device,
25912591

25922592
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:
25932593

2594-
```
2594+
```python
25952595
#!/usr/bin/env python3
25962596

25972597
import time
@@ -2634,7 +2634,7 @@ if __name__ == "__main__":
26342634
#### Using Arduino IDE
26352635
<br></br>
26362636

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.
26382638

26392639
The example code shown below grabs a pin compatible with PWM functionality to control the brightness of an LED connected to it:
26402640

@@ -2759,7 +2759,7 @@ The continuing script offers an interface for interaction with the Seeed Studio
27592759

27602760
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.
27612761

2762-
```
2762+
```python
27632763
from __future__ import print_function
27642764

27652765
import smbus
@@ -2878,7 +2878,7 @@ Next script showcases the utility of the relay board functions. At the onset, it
28782878

28792879
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.
28802880

2881-
```
2881+
```python
28822882
#!/usr/bin/python
28832883

28842884
from __future__ import print_function
@@ -2942,7 +2942,7 @@ To use the drv8825 HAT with Portenta Hat Carrier and Portenta X8, please follow
29422942

29432943
Once the hardware setup is ready, use the script below to perform a test run of the connected stepper motor:
29442944

2945-
```
2945+
```python
29462946
#!/usr/bin/env python3
29472947

29482948
# created 12 October 2023
@@ -3001,18 +3001,18 @@ Please, refer to the [board pinout section](#pinout) of the user manual to find
30013001

30023002
For Portenta X8, it is possible to use following commands:
30033003

3004-
```arduino
3004+
```
30053005
sudo modprobe spidev
30063006
```
30073007

30083008
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.
30093009

3010-
```arduino
3010+
```
30113011
echo "spidev" | sudo tee > /etc/modules-load.d/spidev.conf
30123012
sudo systemctl reboot
30133013
```
30143014

3015-
```arduino
3015+
```
30163016
services:
30173017
my_spi_service:
30183018
devices:
@@ -3129,20 +3129,20 @@ Please, refer to the [pinout section](#pinout) of the user manual to find them o
31293129

31303130
For Portenta X8, it is possible to use following commands:
31313131

3132-
```arduino
3132+
```
31333133
sudo modprobe i2c-dev
31343134
```
31353135

31363136
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.
31373137

3138-
```arduino
3138+
```
31393139
echo "i2c-dev" | sudo tee > /etc/modules-load.d/i2c-dev.conf
31403140
sudo systemctl reboot
31413141
```
31423142

31433143
Following section configures a service named `my_i2c_service` to use the I2C device available at `/dev/i2c-3`.
31443144

3145-
```arduino
3145+
```
31463146
services:
31473147
my_i2c_service:
31483148
devices:
@@ -3165,7 +3165,7 @@ Below are some brief examples to help you in using I2C with the Portenta X8 and
31653165

31663166
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.
31673167

3168-
```arduino
3168+
```python
31693169
from smbus2 import SMBus
31703170

31713171
# Connect to /dev/i2c-3
@@ -3176,7 +3176,7 @@ print(b)
31763176

31773177
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.
31783178

3179-
```
3179+
```python
31803180
from smbus2 import SMBus
31813181

31823182
# Initialize the I2C bus
@@ -3196,7 +3196,7 @@ for byte in data:
31963196

31973197
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.
31983198

3199-
```
3199+
```python
32003200
from smbus2 import SMBus
32013201

32023202
# Initialize the I2C bus
@@ -3214,7 +3214,7 @@ In the following code, the [python-periphery](https://python-periphery.readthedo
32143214

32153215
A byte is read from the EEPROM at address `0x50` and offset `0x100`, then printed.
32163216

3217-
```arduino
3217+
```python
32183218
from periphery import I2C
32193219

32203220
# Open i2c-0 controller
@@ -3321,13 +3321,13 @@ This command sequence activates the CAN transceiver. It does so by exporting _GP
33213321

33223322
For Portenta X8, it is possible to use following commands:
33233323

3324-
```arduino
3324+
```
33253325
sudo modprobe can-dev
33263326
```
33273327

33283328
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.
33293329

3330-
```arduino
3330+
```
33313331
echo "can-dev" | sudo tee > /etc/modules-load.d/can-dev.conf
33323332
sudo systemctl reboot
33333333
```
@@ -3412,7 +3412,7 @@ Each bustype corresponds to different CAN interfaces or devices, ranging from th
34123412

34133413
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.
34143414

3415-
```
3415+
```python
34163416
import can
34173417
import time
34183418

@@ -3448,7 +3448,7 @@ if __name__ == "__main__":
34483448

34493449
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.
34503450

3451-
```
3451+
```python
34523452
import can
34533453

34543454
def receive_can_messages(bus):
@@ -3493,13 +3493,12 @@ if __name__ == "__main__":
34933493
The `main()` function initializes the CAN bus with a 'virtual' channel for example demonstration and starts the message listening process.
34943494

34953495
#### Using Arduino IDE
3496-
<br></br>
34973496

34983497
For users working with the Portenta H7 or Portenta C33, following simple examples can be used to test the CAN bus protocol's capabilities.
34993498

35003499
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.
35013500

3502-
```
3501+
```arduino
35033502
#include <Arduino_CAN.h>
35043503
35053504
/**************************************************************************************
@@ -3530,7 +3529,7 @@ void loop()
35303529

35313530
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.
35323531

3533-
```
3532+
```arduino
35343533
/**************************************************************************************
35353534
* INCLUDE
35363535
**************************************************************************************/
@@ -3619,7 +3618,7 @@ The output _/dev/ttymxc1_ is an example of a potential serial device you might f
36193618

36203619
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.
36213620

3622-
```
3621+
```python
36233622
import serial
36243623
import time
36253624

0 commit comments

Comments
 (0)