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
@@ -417,228 +417,7 @@ The file is uploaded to `/home/fio` directory. Navigate to the directory using A
417
417
python3 hello_world_python.py
418
418
```
419
419
420
-
Portenta Hat Carrier's user programmable LED will start blinking whenever the script is running. If you wish to upload to a containerized environment, as a Docker container, the following command can be used to do so:
421
-
422
-
```bash
423
-
docker cp hello_world_python.py mycontainer:/app/
424
-
```
425
-
426
-
Then the script can be used by accessing the container with the following command:
427
-
428
-
```bash
429
-
docker exec -it mycontainer sh
430
-
```
431
-
432
-
#### Hello World Using Linux and Docker
433
-
<br></br>
434
-
435
-
We can use the Python® script and create a Docker image as well for containerized applications.
436
-
437
-
For you convenience, the example files can be downloaded [here](assets/hello_world_led.zip) and used as a template for containerizing further examples.
438
-
439
-
The example script to use will be the following sketch:
logging.debug("Configured serial port with:\n\r%s"%str(ser))
490
-
logging.debug("Opening serial port")
491
-
492
-
gpio = GPIOController(163)
493
-
494
-
# Export GPIO
495
-
gpio.export()
496
-
497
-
# Set as output
498
-
gpio.set_direction("out")
499
-
if gpio.read_direction() =="out":
500
-
print("GPIO set as output.")
501
-
502
-
# Turn on (set to 1) and then off (set to 0)
503
-
whileTrue:
504
-
gpio.set_value(1)
505
-
time.sleep(1)
506
-
gpio.set_value(0)
507
-
time.sleep(1)
508
-
509
-
# Unexport
510
-
# gpio.unexport()
511
-
512
-
if__name__=="__main__":
513
-
main()
514
-
```
515
-
516
-
The provided Python® script begins with the import of required modules. The `serial` library, in particular, will help us to communicate over serial ports. This script then defines a `GPIOController` class that packages the functionalities we executed manually in the shell commands.
517
-
518
-
This abstraction makes it easier to manipulate the GPIO without having to rewrite shell commands for every operation. Functions like `export`, `unexport`, `set_direction`, and `set_value` are used to mirror the actions we took in our manual steps.
519
-
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
-
522
-
```bash
523
-
# dockerfile
524
-
525
-
# Use an official Python runtime as the base image
The _dockerfile_ begins by selecting an official Python® runtime as the base image, which ensures Python® is set up and ready to run scripts. Following this, the _`requirements.txt`_ file, which lists the Python® libraries our script depends upon, is copied into the Docker image. The pip command is then used to install these dependencies.
548
-
549
-
The script depends on external libraries for functionality, specifically the `pyserial` library for this instance, which aids in serial communication. This library is defined in the _`requirements.txt`_ file.
550
-
551
-
You must manually create this text file and add the following line to it. In further applications, this file will contain any Python® library that is needed to support your script.
552
-
553
-
```
554
-
pyserial==3.4
555
-
```
556
-
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.
This file tree diagram illustrates how the directory should be structured, containing both the Python® script and the associated Docker components:
583
-
584
-
```
585
-
└── hello_world_led
586
-
├── src
587
-
│ ├── hello_world_led.py
588
-
├── Docker-build.conf
589
-
├── docker-compose.yaml
590
-
├── dockerfile
591
-
└── requirements.txt
592
-
```
593
-
594
-
For the Portenta X8, you will need to upload the Python® script along with the Docker elements. You can set up a directory (with a name of your choosing), in this case `hello_world_led`, within the container resources for dockerization to ease this transfer:
595
-
596
-
```
597
-
adb push <local directory path> /home/fio
598
-
```
599
-
600
-
Once the files are transferred, access the shell of the Portenta X8 with elevated privileges:
601
-
602
-
```
603
-
adb shell
604
-
sudo su -
605
-
```
606
-
607
-
To execute the script, first build the Docker image. Navigate to the directory containing the previously mentioned files and run:
608
-
609
-
```bash
610
-
sudo docker build . -t hello_world_led
611
-
```
612
-
613
-
The commands provided outline the process of starting the container with the necessary permissions, ensuring access to the required components on the Portenta X8.
614
-
615
-
The following commands run the container and ensure that the script inside can interact with the GPIOs, even within the container's environment.
616
-
617
-
Following command uses the _docker-compose.yml_ configuration file to start the services defined within. It is a tool for defining and running multi-container Docker applications.
618
-
619
-
```bash
620
-
docker compose up
621
-
```
622
-
623
-
Then we have the next command allowing us to run the `hello_world_led` container with elevated privileges, giving it almost the same level of access to the host as processes running outside containers.
624
-
625
-
```bash
626
-
docker run --privileged hello_world_led
627
-
```
628
-
629
-
This is useful for certain operations like direct hardware access, which is likely necessary for GPIO interactions.
630
-
631
-
Subsequently, the following command mounts the host's `/sys` directory into the `hello_world_led` container, which is often used for interacting with device drivers and kernel features.
632
-
633
-
```bash
634
-
docker run -v /sys:/sys hello_world_led
635
-
```
636
-
637
-
This allows the container to have direct access to the host's GPIOs and other system attributes. Given its access capabilities, the container can be run; however, always ensure the configuration is set correctly.
638
-
639
-
The Python® scripts found later in the user manual can be used to containerize and leverage benefits of using Docker.
640
-
641
-
***To delve deeper into the use of Docker and custom containers on the Portenta X8, refer to this [tutorial](https://docs.arduino.cc/tutorials/portenta-x8/custom-container).***
420
+
Portenta Hat Carrier's user programmable LED will start blinking whenever the script is running.
642
421
643
422
Please check out the [Portenta X8 user manual](https://docs.arduino.cc/tutorials/portenta-x8/user-manual) to learn how the board operates, and maximize its potential when paired with the Portenta Hat Carrier. The Portenta Hat Carrier supports the Portenta X8 via High-Density connectors.
644
423
@@ -766,24 +545,66 @@ Devices with a USB-A interface, such as storage drives, can be used for logging
766
545
#### Using Linux
767
546
<br></br>
768
547
769
-
As an example, following command on Portenta X8's shell can be used to test write command with a USB memory drive.
548
+
As an example, following command on Portenta X8's shell can be used to test write command with a USB memory drive. To write a file, following sequence of commands can help you accomplish such task.
549
+
550
+
```bash
551
+
dmesg -w
552
+
```
553
+
554
+
The `dmesg -w` command displays kernel messages, helping you monitor system events in real-time. It is particularly useful to see if it has recognized the USB drive when plugged in.
555
+
556
+
```bash
557
+
lsblk
558
+
```
559
+
560
+
The `lsblk` command lists all available block devices, such as hard drives and USB drives. It helps in identifying the device name, like `/dev/sda1` which is the partition designation, of the plugged-in USB drive.
561
+
562
+
```bash
563
+
mkdir -p /mnt/USBmount
564
+
```
565
+
566
+
The `mkdir -p` command creates the directory `/mnt/USBmount`. If the directory already exists, this command won't produce an error. This directory will be used as a mount point for the USB drive.
770
567
771
568
```bash
772
-
dd if=/dev/urandom of=random.bin bs=1M count=128
569
+
mount -t vfat /dev/sda1 /mnt/USBmount
773
570
```
774
571
775
-
This command will create a _random.bin_ file filled with 128 Megabytes of random data. It reads data from the system's pseudo-random number generator `/dev/urandom` and writes it to the file in chunks of 1 Megabyte.
572
+
This mount command mounts the USB drive, assumed to have a FAT filesystem (`vfat`), located at `/dev/sda1` to the directory `/mnt/USBmount`. Once mounted, the content of the USB drive can be accessed from the `/mnt/USBmount` directory.
This command will create a _random.bin_ file filled with 16 Kilobytes of random data. It reads data from the system's pseudo-random number generator `/dev/urandom` and writes it to the file in chunks of 1 Kilobyte.
776
579
777
580
To read the _random.bin_ file with random data, you can use the following command:
This will read the previously generated _random.bin_ file and displays its content in a hexadecimal format on the console. Data is read in chunks of 1 Megabyte up to 128 Megabytes and then processed for display using `hexdump`.
586
+
This will read the previously generated _random.bin_ file and displays its content in a hexadecimal format on the console. Data is read in chunks of 1 Kilobyte up to 16 Kilobytes and then processed for display using `hexdump`.
784
587
785
588
***Reading the entire _random.bin_ file with the `hexdump` command will produce a large output on the console. Use with caution.***
786
589
590
+
n the Portenta X8's shell, if you aim to create a text file containing the message `Hello, World!` on a USB memory drive, you can employ the command:
This command uses the `dd` utility, combined with process substitution. Specifically, it seizes the output of the `echo` command, responsible for generating the `Hello, World!` message, and channels it as an input stream to `dd`.
597
+
598
+
Subsequently, the message gets inscribed into a file named _helloworld.txt_ situated in the `/mnt/USBmount` directory.
599
+
600
+
After creating the file, if you wish to retrieve its contents and display them on the shell, you can use:
601
+
602
+
```bash
603
+
dd if=/mnt/USBmount/helloworld.txt bs=1K count=1
604
+
```
605
+
606
+
This command directs `dd` to peruse the contents of _helloworld.txt_. With a specified block size of 1 Kilobyte, the reading is confined to a single block—adequate given the brevity of the `Hello, World!` message. Upon executing this command, the content of the text file will be displayed on your shell.
607
+
787
608
#### Using Arduino IDE
788
609
<br></br>
789
610
@@ -2762,7 +2583,7 @@ It can interact with up to four relay ports on the board. Among its various feat
0 commit comments