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
@@ -206,7 +206,13 @@ Please do not turn off your Portenta X8 or disconnect it from the network during
206
206
207
207
Once the update is finished, your Portenta X8 will automatically restart with the new Linux image in place.
208
208
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.
210
216
211
217
In case you try to update the Portenta X8 and it has the latest available image, you will get following message:
212
218
@@ -1116,37 +1122,30 @@ You need to enable SPI support before using SPI devices.
1116
1122
1117
1123
Open Portenta X8 Shell as explained [here](#working-with-linux).
1118
1124
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:
1124
1126
1125
1127
```bash
1126
-
spi-dev
1128
+
sudo modprobe spidev
1127
1129
```
1128
1130
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:
1134
1132
1135
1133
```bash
1134
+
echo"spidev"| sudo tee /etc/modules-load.d/spidev.conf
1136
1135
sudo systemctl reboot
1137
1136
```
1138
1137
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:
1140
1139
1141
-
```
1140
+
```yaml
1142
1141
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"
1148
1145
```
1149
1146
1147
+
This configuration is typically added to a _docker-compose.yml_ file, allowing the service to interact with the specified SPI device.
1148
+
1150
1149
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).
1151
1150
1152
1151
```bash
@@ -1193,39 +1192,36 @@ You need to enable I2C support before using I2C devices.
1193
1192
1194
1193
Open Portenta X8 Shell as explained [here](#working-with-linux).
1195
1194
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:
1197
1196
1198
1197
```bash
1199
1198
sudo modprobe i2c-dev
1200
1199
```
1201
1200
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:
1203
1202
1204
1203
```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
1212
1205
```
1213
1206
1214
1207
```bash
1215
1208
sudo systemctl reboot
1216
1209
```
1217
1210
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:
1219
1212
1220
-
```
1213
+
```yaml
1221
1214
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"
1227
1221
```
1228
1222
1223
+
You can configure I2C services for all available interfaces (from 0 to 3) or specify particular services as needed.
1224
+
1229
1225
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).
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:
# 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
+
1255
1279
Examples of using SMBus-compatible [libraries](https://github.com/kplindegaard/smbus2):
1256
1280
1257
1281
```python
1258
1282
from smbus2 import SMBus
1259
1283
1260
-
# Connect to /dev/i2c-2
1261
-
bus = SMBus(2)
1284
+
# Connect to /dev/i2c-3
1285
+
bus = SMBus(3)
1262
1286
b = bus.read_byte_data(80, 0)
1263
1287
print(b)
1264
1288
```
1265
1289
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.
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.
@@ -1293,12 +1354,62 @@ Since one of the `I2C` pins is GPIO-multiplexed, you need to detach it from the
1293
1354
1294
1355
### UART
1295
1356
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.
1297
1358
1298
1359
#### UART With Linux
1299
1360
1300
1361
A standard UART is available as `/dev/ttymxc1` in Linux and is mapped to the **`UART1`** port on the Portenta Breakout.
1301
1362
1363
+
With root access on the Portenta X8, you can list the available serial ports in Linux using the following command:
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
+
1302
1413
### Bluetooth®
1303
1414
1304
1415
Portenta X8 supports Bluetooth® connectivity just on the Linux side.
0 commit comments