Skip to content

Commit e0ee2d4

Browse files
committed
Documentation content update
1 parent 3e2d1af commit e0ee2d4

File tree

3 files changed

+153
-42
lines changed

3 files changed

+153
-42
lines changed

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

Lines changed: 153 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,13 @@ Please do not turn off your Portenta X8 or disconnect it from the network during
206206

207207
Once the update is finished, your Portenta X8 will automatically restart with the new Linux image in place.
208208

209-
At this point, if you want to continue using your Out-of-the-box, you can open a new command line window and launch the command `adb forward tcp:8080 tcp:80` again. Now open your browser, go to [http://localhost:8080](http://localhost:8080), and the same Out-of-the-box dashboard will appear.
209+
At this point, if you want to continue using your Out-of-the-box, you can open a new command line window and launch the following command againg:
210+
211+
```bash
212+
adb forward tcp:8080 tcp:80
213+
```
214+
215+
Now open your browser, go to [**http://localhost:8080**](http://localhost:8080), and the same Out-of-the-box dashboard will appear.
210216

211217
In case you try to update the Portenta X8 and it has the latest available image, you will get following message:
212218

@@ -1116,37 +1122,30 @@ You need to enable SPI support before using SPI devices.
11161122

11171123
Open Portenta X8 Shell as explained [here](#working-with-linux).
11181124

1119-
```bash
1120-
sudo modprobe spi-dev
1121-
```
1122-
1123-
An upcoming image release for the X8 will load the `spi-dev` modules automatically at boot. In the current version, please create a `/etc/modules-load.d/spi-dev.conf` file with the following content:
1125+
With root privileges on the Portenta X8, you can enable the SPI device interface by loading the `spidev` module using the following command:
11241126

11251127
```bash
1126-
spi-dev
1128+
sudo modprobe spidev
11271129
```
11281130

1129-
and restart the board.
1130-
1131-
```bash
1132-
echo "spi-dev" | sudo tee > /etc/modules-load.d/spi-dev.conf
1133-
```
1131+
To ensure the `spidev` module loads automatically at startup, add it to the system's module configuration and reboot:
11341132

11351133
```bash
1134+
echo "spidev" | sudo tee /etc/modules-load.d/spidev.conf
11361135
sudo systemctl reboot
11371136
```
11381137

1139-
Add the device you want to communicate within a container in a `docker-compose.yml` file:
1138+
To set up a service named `my_spi_service` that utilizes the SPI device at `/dev/spidev0.0`, include the following configuration in your service definition:
11401139

1141-
```
1140+
```yaml
11421141
services:
1143-
my_spi_service:
1144-
devices:
1145-
- /dev/spi-1
1146-
- /dev/spi-2
1147-
- /dev/spi-3
1142+
my_spi_service:
1143+
devices:
1144+
- "/dev/spidev0.0"
11481145
```
11491146
1147+
This configuration is typically added to a _docker-compose.yml_ file, allowing the service to interact with the specified SPI device.
1148+
11501149
If the Linux user on which the container is running is not `root`, you need to set up the permissions for the user to access the SPI devices. You might add the required comments to an `entrypoint.sh` shell file (to be added to the `Dockerfile` or the `docker-compose.yml` file).
11511150

11521151
```bash
@@ -1193,39 +1192,36 @@ You need to enable I2C support before using I2C devices.
11931192

11941193
Open Portenta X8 Shell as explained [here](#working-with-linux).
11951194

1196-
Thus, execute the following command:
1195+
With administrative (root) privileges on the Portenta X8, you can enable the I2C device interface using the following command:
11971196

11981197
```bash
11991198
sudo modprobe i2c-dev
12001199
```
12011200

1202-
An upcoming image release for the X8 will load the `i2c-dev` modules automatically at boot. In the current version, please create a `/etc/modules-load.d/i2c-dev.conf` file with the following content:
1201+
Use the following commands to ensure the `i2c-dev` module is automatically loaded at system startup. A system reboot is required for the changes to take effect:
12031202

12041203
```bash
1205-
i2c-dev
1206-
```
1207-
1208-
and restart the board.
1209-
1210-
```bash
1211-
echo "i2c-dev" | sudo tee > /etc/modules-load.d/i2c-dev.conf
1204+
echo "i2c-dev" | sudo tee /etc/modules-load.d/i2c-dev.conf
12121205
```
12131206

12141207
```bash
12151208
sudo systemctl reboot
12161209
```
12171210

1218-
Add the device you want to communicate within a container in a `docker-compose.yml` file:
1211+
These commands activate and configure the I2C device interface on the system. The following section demonstrates how to set up I2C services within a Docker environment by defining them under `my_i2c_service` in a _docker-compose.yml_ file:
12191212

1220-
```
1213+
```yaml
12211214
services:
1222-
my_i2c_service:
1223-
devices:
1224-
- /dev/i2c-1
1225-
- /dev/i2c-2
1226-
- /dev/i2c-3
1215+
my_i2c_service:
1216+
devices:
1217+
- "/dev/i2c-0"
1218+
- "/dev/i2c-1"
1219+
- "/dev/i2c-2"
1220+
- "/dev/i2c-3"
12271221
```
12281222

1223+
You can configure I2C services for all available interfaces (from 0 to 3) or specify particular services as needed.
1224+
12291225
If the Linux user on which the container is running is not `root`, you need to set up the permissions for the user to access the I2C devices. You might add the required comments to an `entrypoint.sh` shell file (to be added to the `Dockerfile` or the `docker-compose.yml` file).
12301226

12311227
```bash
@@ -1248,28 +1244,93 @@ gosu <container user> /usr/bin/python my_i2c_service.py
12481244
|--------------|-------------------------------|-------------|
12491245
| `/dev/i2c-1` | **`I2C1`** | |
12501246
| `/dev/i2c-2` | **`I2C0`** | Recommended |
1251-
| `/dev/i2c-3` | **`I2C1`** | |
1247+
| `/dev/i2c-3` | **`I2C2`** | |
12521248

12531249
#### Examples
12541250

1251+
Within the Portenta X8 shell, you can quickly test I2C communication with compatible devices using specific commands. To list all connected I2C devices, use:
1252+
1253+
```bash
1254+
i2cdetect -y <I2C bus>
1255+
```
1256+
1257+
To interact with a specific I2C device and retrieve data, the command format is:
1258+
1259+
```bash
1260+
i2cget -y <I2C bus> <device address> <register address>
1261+
```
1262+
1263+
For example:
1264+
1265+
```bash
1266+
# List I2C devices on bus 2
1267+
i2cdetect -y 2
1268+
1269+
# Read data from a device at address 0x77 on bus 2, register 0xD0
1270+
i2cget -y 2 0x77 0xD0
1271+
```
1272+
1273+
If a BME280 sensor is connected to *I2C0* and the above commands are used, the Portenta X8 will show **`0x60`** value to tell the sensor is alive.
1274+
1275+
Here are some simple examples of implementing I2C communication on the Portenta X8 with Portenta Mid Carrier using Python.
1276+
1277+
The following code uses the SMBus (System Management Bus) protocol, with SMBus-compatible [libraries](https://github.com/kplindegaard/smbus2), to read a data byte from a device on `/dev/i2c-3`. The byte is read from address 80, offset 0, and then printed.
1278+
12551279
Examples of using SMBus-compatible [libraries](https://github.com/kplindegaard/smbus2):
12561280

12571281
```python
12581282
from smbus2 import SMBus
12591283
1260-
# Connect to /dev/i2c-2
1261-
bus = SMBus(2)
1284+
# Connect to /dev/i2c-3
1285+
bus = SMBus(3)
12621286
b = bus.read_byte_data(80, 0)
12631287
print(b)
12641288
```
12651289

1266-
Example of using [python-periphery](https://python-periphery.readthedocs.io/en/latest/index.html):
1290+
The next example shows how to initialize the I2C bus using the _smbus2_ library and read multiple bytes from a device. The `read_i2c_block_data` function retrieves a block of bytes from the I2C device at the specified address.
1291+
1292+
```python
1293+
from smbus2 import SMBus
1294+
1295+
# Initialize the I2C bus
1296+
bus = SMBus(3) # 3 represents /dev/i2c-3
1297+
1298+
device_address = 0x1
1299+
num_bytes = 2
1300+
1301+
# Read from the I2C device
1302+
data = bus.read_i2c_block_data(device_address, 0, num_bytes) # Starting address is 0 to read from
1303+
1304+
# Data is a list of bytes
1305+
for byte in data:
1306+
print(byte)
1307+
```
1308+
1309+
The following example shows how to write data to an I2C device using the _smbus2_ library. A data byte (`value`) is sent to a specific address (`device_address`) with a given instruction.
1310+
1311+
```python
1312+
from smbus2 import SMBus
1313+
1314+
# Initialize the I2C bus
1315+
bus = SMBus(3) # 3 represents /dev/i2c-3
1316+
1317+
device_address = 0x1
1318+
instruction = 0x00
1319+
value = 0xFF
1320+
1321+
# Write to the I2C device
1322+
bus.write_byte_data(device_address, instruction, value)
1323+
```
1324+
1325+
In the following example, the [python-periphery](https://python-periphery.readthedocs.io/en/latest/index.html) library is used to communicate with the I2C device. This library integrates a broad range of protocols within the same script. The `I2C.transfer()` method performs read and write operations on the I2C bus.
1326+
1327+
The code reads a byte from an EEPROM at address `0x50`, offsets `0x100`, and then prints it.
12671328

12681329
```python
12691330
from periphery import I2C
12701331
1271-
# Open i2c-0 controller
1272-
i2c = I2C("/dev/i2c-2")
1332+
# Open i2c-3 controller
1333+
i2c = I2C("/dev/i2c-3")
12731334
12741335
# Read byte at address 0x100 of EEPROM at 0x50
12751336
msgs = [I2C.Message([0x01, 0x00]), I2C.Message([0x00], read=True)]
@@ -1293,12 +1354,62 @@ Since one of the `I2C` pins is GPIO-multiplexed, you need to detach it from the
12931354
 
12941355
### UART
12951356

1296-
In this case, a Portenta X8 with a Portenta Breakout board is used to explore UART communication.
1357+
In this case, a Portenta X8 with a Portenta Breakout board can be used to explore UART communication. The Portenta Mid Carrier and Portenta Hat Carrier also provides the capability to use the UART communication.
12971358

12981359
#### UART With Linux
12991360

13001361
A standard UART is available as `/dev/ttymxc1` in Linux and is mapped to the **`UART1`** port on the Portenta Breakout.
13011362

1363+
With root access on the Portenta X8, you can list the available serial ports in Linux using the following command:
1364+
1365+
```bash
1366+
ls /dev/ttyUSB* /dev/ttyACM* /dev/ttymxc*
1367+
1368+
// Example output:
1369+
/dev/ttyUSB0 /dev/ttyUSB2 /dev/ttymxc1 /dev/ttymxc3
1370+
/dev/ttyUSB1 /dev/ttyUSB3 /dev/ttymxc2
1371+
```
1372+
1373+
Common serial devices are typically labeled as _/dev/ttyUSBx_, _/dev/ttyACMx_, or _/dev/ttymxcx_. For instance, you might see _/dev/ttymxc1_ listed.
1374+
1375+
The following Python script uses the _pyserial_ library for UART communication. The _processData_ function is defined to handle incoming data, which can be customized according to your needs.
1376+
1377+
```python
1378+
import serial
1379+
import time
1380+
1381+
# Define the processData function (customize based on your requirements)
1382+
def processData(data):
1383+
print("Received:", data) # Currently, it just prints the data. Modify as needed.
1384+
1385+
# Set up the serial port
1386+
ser = serial.Serial('/dev/ttymxc1', 9600) # Replace with the correct port and baud rate for your setup
1387+
1388+
incoming = ""
1389+
1390+
while True:
1391+
# Check for available data and read individual characters
1392+
while ser.in_waiting:
1393+
c = ser.read().decode('utf-8') # Read a single character and decode from bytes to string
1394+
1395+
# Check if the character is a newline (line-ending)
1396+
if c == '\n':
1397+
# Process the received data
1398+
processData(incoming)
1399+
1400+
# Clear the incoming data string for the next message
1401+
incoming = ""
1402+
else:
1403+
# Add the character to the incoming data string
1404+
incoming += c
1405+
1406+
time.sleep(0.002) # Delay for data buffering, similar to Arduino's delay(2);
1407+
```
1408+
1409+
This script maintains a serial connection on _/dev/ttymxc1_ with a baud rate of _9600_. It reads incoming data character by character until it encounters a newline (`\n`), which indicates the end of a data packet.
1410+
1411+
After processing the data, the script resets and is ready for the next message. The `time.sleep(0.002)` introduces a brief delay for data buffering, similar to `delay(2);` in the Arduino environment.
1412+
13021413
### Bluetooth®
13031414

13041415
Portenta X8 supports Bluetooth® connectivity just on the Linux side.

0 commit comments

Comments
 (0)