diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef29f39f598f7f8198b0a1f8f2dc411c0bcc8138..e2d0f860ebe33514211cd904387216dc270af28c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ variables: GIT_SUBMODULE_STRATEGY: recursive cache: - key: sphinx-build-env-docs-001 + key: sphinx-build-env-docs-002 paths: - .venv - .cache diff --git a/boards/beaglebone/ai/02-quick-start.rst b/boards/beaglebone/ai/02-quick-start.rst index 83d48f0644f0edce36fa19f1328b557e6c6d4066..956ebce5e94d69399018bd432334e05404e84ba4 100644 --- a/boards/beaglebone/ai/02-quick-start.rst +++ b/boards/beaglebone/ai/02-quick-start.rst @@ -25,7 +25,7 @@ What’s Not in the Box You will need to purchase: -- :ref:`USB C cable or USB C to USB A cable <accessories-cables-usb>`_ +- :ref:`USB C cable or USB C to USB A cable <accessories-cables-usb>` - MicroSD Card (optional) - :ref:`Serial cable <molex-picoblade-serial-cables>` (optional) @@ -205,4 +205,4 @@ Press the small white connector into the 3 PIN debug header. The pinout is: .. image:: images/BB_AI_3pincableattach_500px.jpg :align: center - :alt: BeagleBone AI Overview \ No newline at end of file + :alt: BeagleBone AI Overview diff --git a/boards/beagley/ai/01-introduction.rst b/boards/beagley/ai/01-introduction.rst index af6943ccc2758c3e0896c8f28fdbd2cacd9c06f4..e797a3d2ab60ab35ee06714df3aff43781058429 100644 --- a/boards/beagley/ai/01-introduction.rst +++ b/boards/beagley/ai/01-introduction.rst @@ -18,43 +18,43 @@ I/O and control, a 50 GFlop GPU, video and vision accelerators, and other specia .. table:: BeagleY-AI features - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Feature | Description | - +=======================+==========================================================================================================================================================================+ - | Processor | Texas Instruments AM67A, Quad 64-bit Arm® Cortex®-A53 @1.4 GHz, multiple cores including Arm/GPU processors, DSP, and vision/deep learning accelerators | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | RAM | 4GB LPDDR4 | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Wi-Fi | Beagleboard BM3301, 802.11ax Wi-Fi | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Bluetooth | Bluetooth Low Energy 5.4 (BLE) | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | USB Ports | 4 x USB 3.0 TypeA ports supporting simultaneous 5Gbps operation, 1 x USB 2.0 TypeC, supports USB 2.0 device mode | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Ethernet | Gigabit Ethernet, with PoE+ support (requires separate PoE HAT) | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Camera/Display | 2 x 4-lane MIPI camera connector (one connector muxed with DSI capability) | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Display Output | 1 x HDMI display, 1 x OLDI display, 1 x DSI MIPI Display | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Real-time Clock (RTC) | Supports external coin-cell battery for power failure time retention | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Debug UART | 1 x 3-pin debug UART | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Power | 5V/3A DC power via USB-C | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Power Button | On/Off included | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | PCIe Interface | PCI-Express® Gen3 x 1 interface for fast peripherals (requires separate M.2 HAT or other adapter) | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Expansion Connector | 40-pin header | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Fan connector | 1 x 4-pin fan connector, supports PWM control and fan speed measurement | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Storage | microSD card slot with UHS-1 support | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Tag Connect | 1 x JTAG, 1 x External PMIC programming port | - +-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Feature | Description | + +=======================+=========================================================================================================================================================+ + | Processor | Texas Instruments AM67A, Quad 64-bit Arm® Cortex®-A53 @1.4 GHz, multiple cores including Arm/GPU processors, DSP, and vision/deep learning accelerators | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | RAM | 4GB LPDDR4 | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Wi-Fi | Beagleboard BM3301, 802.11ax Wi-Fi | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Bluetooth | Bluetooth Low Energy 5.4 (BLE) | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | USB Ports | 4 x USB 3.0 TypeA ports supporting simultaneous 5Gbps operation, 1 x USB 2.0 TypeC, supports USB 2.0 device mode | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Ethernet | Gigabit Ethernet, with PoE+ support (requires separate PoE HAT) | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Camera/Display | 2 x 4-lane MIPI camera connector (one connector muxed with DSI capability) | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Display Output | 1 x HDMI display, 1 x OLDI display, 1 x DSI MIPI Display | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Real-time Clock (RTC) | Supports external coin-cell battery for power failure time retention | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Debug UART | 1 x 3-pin debug UART | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Power | 5V/3A DC power via USB-C | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Power Button | On/Off included | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | PCIe Interface | PCI-Express® Gen3 x 1 interface for fast peripherals (requires separate M.2 HAT or other adapter) | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Expansion Connector | 40-pin header | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Fan connector | 1 x 4-pin fan connector, supports PWM control and fan speed measurement | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Storage | microSD card slot with UHS-1 support | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ + | Tag Connect | 1 x JTAG, 1 x External PMIC programming port | + +-----------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ AM67A SoC ========= diff --git a/boards/beagley/ai/02-quick-start.rst b/boards/beagley/ai/02-quick-start.rst index bfd57bdc1ec5e7d1a38f428b9782f0c7f76a700d..e6f6338f4f22baf5f0e104ec48114048510dcab4 100644 --- a/boards/beagley/ai/02-quick-start.rst +++ b/boards/beagley/ai/02-quick-start.rst @@ -165,4 +165,9 @@ After successfully attaching the antenna, power up the board. Once booted you ca .. code:: - ping 8.8.8.8 \ No newline at end of file + ping 8.8.8.8 + +Demos and Tutorials +******************* + +* :ref:`beagley-ai-expansion-nvme` diff --git a/boards/beagley/ai/04-expansion.rst b/boards/beagley/ai/04-expansion.rst index e1a68f483c321372833395cc9d46235a6329ca1e..15155205fef434acc2a6fb79bd77618eca9314fe 100644 --- a/boards/beagley/ai/04-expansion.rst +++ b/boards/beagley/ai/04-expansion.rst @@ -1,4 +1,17 @@ .. _beagley-ai-expansion: Expansion -######### \ No newline at end of file +######### + +.. todo:: + + Describe how to build expansion hardware for BeagleY-AI + +PCIe +**** + +For software reference, you can see how PCIe is used on NVMe HATs. + +* :ref:`beagley-ai-expansion-nvme` +* :ref:`beagley-ai-imx219-csi-cameras` +* :ref:`beagley-ai-rtc` diff --git a/boards/beagley/ai/05-demos.rst b/boards/beagley/ai/05-demos.rst index f31dfd170fb09c3c3df89ef8b6865f3951795b41..7fcf5e2eef2f864e95990d8320ab4ba61c0abc91 100644 --- a/boards/beagley/ai/05-demos.rst +++ b/boards/beagley/ai/05-demos.rst @@ -2,13 +2,17 @@ Demos and tutorials <<<<<<< HEAD +<<<<<<< HEAD #################### ======= +======= +>>>>>>> 4ae108e7e300197de6528dd664413457ae317ede #################### .. toctree:: :maxdepth: 1 +<<<<<<< HEAD demos/using-rtc demos/expansion-nvme demos/pca9685-motor-drivers @@ -16,3 +20,9 @@ Demos and tutorials demos/connecting-imx219-csi-cameras >>>>>>> 8a26010 (Add using-rtc to ToC) +======= + demos/beagley-ai-expansion-nvme + demos/beagley-ai-pca9685-motor-drivers + demos/beagley-ai-arducam-imx219-v3link-dual-camera-kit + +>>>>>>> 4ae108e7e300197de6528dd664413457ae317ede diff --git a/boards/beagley/ai/demos/arducam-imx219-v3link-dual-camera-kit.rst b/boards/beagley/ai/demos/arducam-imx219-v3link-dual-camera-kit.rst new file mode 100644 index 0000000000000000000000000000000000000000..02f2a3e2c4f66a28e0a500852ad91b9e7293d8a6 --- /dev/null +++ b/boards/beagley/ai/demos/arducam-imx219-v3link-dual-camera-kit.rst @@ -0,0 +1,63 @@ +.. _beagley-ai-arducam-imx219-v3link-dual-camera-kit: + +.. note:: This page is a work in progress. Further drive testing and images will be added soon + +Using the Arducam Dual V3Link Camera Kit +############################################ + +`The Arducam Dual V3Link Camera Kit <https://www.arducam.com/product/arducam-imx219-v3link-camera-kit-for-raspberry-pi/>`_ is an IMX219 based kit that leverages Texas Instruments' FPDLink technology to enable using two CSI cameras over a single port up to 15 meters away using twisted pair cables. + +.. image:: ../images/arducam_dual_1.jpg + +.. note:: Unlike the larger quad-camera kit, the dual camera kit aims to simplify the software stack and improve interoperability with the Raspberry Pi and other non-TI SBCs by forgoing the ability to support multi-stream CSI inputs. This means that it is limited to "switching" between the two FPDLink inputs but has the benefit of not requiring additional drivers beyond support for the base CSI camera driver (IMX219 in this case) + +Initial Hardware Connection +***************************** + +Simply plug in the HAT into the BeagleY GPIO header and connect the CSI header as shown below. + +Either CSI header may be connected but make sure you use the corresponding CSI port DTS when enabling your "camera". + +.. todo:: ADD CSI 0/1 Header Location photo. + +Verify that the HAT is connected +************************************ + +The Arducam HAT should present itself as an I2C device on Bus 1. + +To check that the I2C Bus looks like we expect: + +.. code:: console + + sudo i2cdetect -r -y 1 + + +To verify actual communication with the FPDlink device, we issue the following command: + +.. code:: console + + sudo i2ctransfer -f -y 4 w3@0x0c 0xff 0x55 0x01 r1 + + +Switching CSI Channels +************************************ + +The channel numbering for FPDLink goes from 1 to 2 (as opposed to counting from 0 as is the case for CSI) + +Thus, to select video output from channel 1: + +.. code:: console + + sudo i2ctransfer -f -y 4 w3@0x0c 0xff 0x55 0x01 + +To switch to channel 2: + +.. code:: console + + sudo i2ctransfer -f -y 4 w3@0x0c 0xff 0x55 0x02 + + +Troubleshooting +************************************ + +For additional documentation and support, see the `Arducam Docs <https://docs.arducam.com/V3Link-Camera-Solution/V3Link-Camera-Solution-for-Raspberry-Pi/Introduction/>`_. \ No newline at end of file diff --git a/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst b/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst new file mode 100644 index 0000000000000000000000000000000000000000..a69df4d78c6a3e6e0ce41a2f85ce30af68599ecf --- /dev/null +++ b/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst @@ -0,0 +1,164 @@ +.. _beagley-ai-expansion-nvme: + +Booting from NVMe Drives +########################## + +.. todo:: remove notes about work-in-progress. they just make the site more janky. + +.. note:: This page is a work in progress. Further drive testing and images will be added soon + +BeagleY-AI supports a PCI-Express x1 interface which enables data rates of up to 1GB/s for high speed expansion. + +.. note:: While the SoC supports PCI-e Gen 3, the flat-flex connector required by HATs is only rated for PCI-e Gen 2, so, as is the case with other similar boards in this form factor, actual transfer speeds may be limited to Gen 2, depending on a variety of layout and environmental factors + +This enables it to take advantage of standard PC NVMe drives which offer exponentially higher random and sequential read/write speeds as well as improved endurance over SD cards or traditional eMMC storage. + +While the boot-ROM on the AM67 SoC does not support direct boot-to-NVMe, we can use a method where we boot U-Boot from the SD Card and then use it to load the Linux filesystem from external NVMe storage. + +Verified HATs and Drives +*************************** + +Most/All HATs and NVMe drives should work, but the following have been verified to work as part of writing this guide: + +HATs: + +1. `Geekworm X1001 PCIe to M.2 Key-M <https://www.amazon.com/Geekworm-X1001-Key-M-Peripheral-Raspberry/dp/B0CPPGGDQT>`_ +2. `Geekworm X1000 PCIe M.2 Key-M <https://www.amazon.com/gp/product/B0CQ4D2C9S>`_ + +NVMe drives: + +1. `Kingston OM3PDP3512B (512GB 2230) <https://www.amazon.com/Kingston-512GB-3-0x4-Solid-OM3PDP3512B-A01/dp/B0BW7V8ZZ3>`_ +2. `Kingston NV2 (512GB 2280) <https://www.amazon.com/Kingston-500G-2280-Internal-SNV2S/dp/B0BBWJH1P8/>`_ + +Drive Adapters (3D Printable): + +The X1000 above uses the slightly uncommon 2242 drive size, so, an adapter may be required to mount a 2230 drive. + +1. A simple adapter from ``@eliasjonsson`` on Printables works great - https://www.printables.com/model/578236-m2-ssd-2230-to-2242 +2. Similar adapters exist for 2230 to 2280 for example such as this one from ``@nzalog`` - https://www.printables.com/model/217264-2230-to-2280-m2-adapter-ssd + +Step by step +************ + +.. note:: This article was written using the `BeagleY-AI Debian XFCE 12.5 2024-03-25 image <https://www.beagleboard.org/distros/beagley-ai-debian-xfce-12-5-2024-03-25/>`_. + +Step 1. Boot from SD Normally +================================== + +Grab the latest BeagleY-AI SD Image from (`BeagleBoard.org/distros <https://www.beagleboard.org/distros>`_.) + +Once logged in and at the terminal, make sure your system is up to date (a reboot is also recommended after updating) + +.. code:: console + + sudo apt-get update && sudo apt-get full-upgrade -y + sudo reboot + + +Step 2. Verify that your NVMe drive is detected +============================================================ + +The command ``lspci`` will list the attached PCI Express devices on the system: + +.. code:: console + + debian@BeagleY:~$ lspci + +You should see an output similar to the following, where the first entrance is the SoC internal PCI Express bridge device and the second device listed is your NVMe drive, in this case, a Kingston OM3PDP3 drive. + +.. code:: console + + 00:00.0 PCI bridge: Texas Instruments Device b010 + 01:00.0 Non-Volatile memory controller: Kingston Technology Company, Inc. OM3PDP3 NVMe SSD (rev 01) + +Now that we know the PCIe device is detected, let's see if it's recognized as a Storage Device: + +The command ``lsblk`` will list the attached storage devices on the system: + +.. code:: console + + debian@BeagleY:~$ lsblk + NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS + mmcblk0 179:0 0 59.7G 0 disk + ├─mmcblk0p1 179:1 0 256M 0 part /boot/firmware + └─mmcblk0p2 179:2 0 59.4G 0 part / + nvme0n1 259:0 0 476.9G 0 disk + └─nvme0n1p1 259:1 0 476.9G 0 part + +Here we see that two devices are connected, ``mmcblk0`` corresponds to our SD card, and ``nvme0n1`` corresponds to our NVMe drive, so everything is ready to go! + + +If your drives aren't listed as expected, please check the Troubleshooting section at the end of this document. + + +Step 3. Copy your filesystem and modify extlinux.conf for NVMe boot +=========================================================================== + +A variety of useful scripts are available in ``/opt/``, one of them enables us to move our micro-sd contents to NVMe and make BeagleY-AI boot from there directly. + +The following 3 commands will change your U-boot prompt to boot from NVMe by default, but the serial boot menu will still enable you to fall back to SD boot or other modes if something happens. + +.. note:: This will copy the entire contents of your SD card to the NVMe drive, so expect it to take upwards of 15 minutes. This only needs to be run one time + +.. code:: bash + + sudo cp -v /opt/u-boot/bb-u-boot-beagley-ai/beagley-microsd-to-nvme /etc/default/beagle-flasher + sudo beagle-flasher-boot-emmc-rootfs-nvme + sudo reboot + +Enjoy NVMe speeds! +================== + +Now that we've run the scripts above, you should see that lsblk now reports that our ``/`` or root filesystem is on the ``nvme0n1p1`` partition, meaning we are successfully booting from the NVMe drive. + +It's subtle, but the change can be seen by running ``lsblk`` again. + +.. code:: console + + debian@BeagleY:~$ lsblk + NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS + mmcblk0 179:0 0 59.7G 0 disk + ├─mmcblk0p1 179:1 0 256M 0 part /boot/firmware + └─mmcblk0p2 179:2 0 59.4G 0 part + nvme0n1 259:0 0 476.9G 0 disk + └─nvme0n1p1 259:1 0 476.9G 0 part / + +Congratulations! + +Troubleshooting +******************** + +While most setups should work, it is possible that a combination of Software, Hardware or both can result in minor issues. Here are some ideas for troubleshooting on your own: + +Check that your cables are plugged in and oriented correctly +============================================================ + +The flat-flex ribbon cable will only connect correctly one way, so ensure the orientation is correct with your expansion HAT manual and that the ribbon cable is correctly seated. + +A note on power-hungry drives +============================= + +While most drives can be powered as-is with only the ribbon cable, some drives, especially high end full-size 2280 drives may consume more power than normal for an M.2 connector. +For such cases, some HAT expansions will provide a means of providing external supplemental power. If your drive is not detected, it may be worthwhile to try using a drive from a different manufacturer as a troubleshooting step. + +As a side note, since 2230 drives are normally designed to run in Laptops, they tend to also consume less power than their desktop counterparts and as such, are a "safer" option. + +Check the Linux Kernel Logs for PCI: +==================================== + +You should see something similar to below without further errors: + +.. code:: console + + debian@BeagleY:~$ dmesg | grep "PCI" + [ 0.005276] PCI/MSI: /bus@f0000/interrupt-controller@1800000/msi-controller@1820000 domain created + [ 0.158546] PCI: CLS 0 bytes, default 64 + [ 3.674209] j721e-pcie-host f102000.pcie: PCI host bridge to bus 0000:00 + [ 3.742406] pci 0000:01:00.0: 7.876 Gb/s available PCIe bandwidth, limited by 8.0 GT/s PCIe x1 link at 0000:00:00.0 (capable of 31.504 Gb/s with 8.0 GT/s PCIe x4 link) + [ 4.915630] pci 0000:00:00.0: PCI bridge to [bus 01] + + +Still having issues? +==================== + +Post questions on the `forum under the tag "beagley-ai" <https://forum.beagleboard.org/tags/c/general/8/beagley-ai>`_. diff --git a/boards/beagley/ai/demos/pca9685-motor-drivers.rst b/boards/beagley/ai/demos/pca9685-motor-drivers.rst new file mode 100644 index 0000000000000000000000000000000000000000..ee726c61920187ef81654f0d119a892471ed1b30 --- /dev/null +++ b/boards/beagley/ai/demos/pca9685-motor-drivers.rst @@ -0,0 +1,229 @@ +.. _beagley-ai-pca9685-motor-drivers: + +.. note:: This page is a work in progress. Further drive testing and images will be added soon + +Using PCA9685 Motor Drivers +############################# + +There are several such "Motor and Servo Driver HATs" available on Amazon, Adafruit and other marketplaces. While different manufacturers implement them slightly differently, the operating principle remains the same. + +This guide aims to show you examples for two, namely the Xicoolee and Adafruit variants and how you can modify the example Python userspace library for other variations. + +Operating Principle +************************************ + +The `NXP PCA9685 <https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf>`_ is a simple 16-channel, 12-bit PWM controller that communicates over I2C. + +While originally designed as an LED driver, it's ability to output PWM also makes it suitable as a Servo Motor driver. + +In addition, to add the ability to drive DC motors, some board designers add one or two `Toshiba TB6612FNG <https://www.sparkfun.com/datasheets/Robotics/TB6612FNG.pdf>`_ dual motor drivers as shown in the schematic below. + +.. image:: ../images/xicoolee_sch1.png + + +If we look at the Xicoolee board and compare it to the schematic, we see that indeed Servo Channels 3-8 on the PCB Silkscreen match pins 12 through 18 of the PWM Driver, while PWM1, PWM2, INA1/2 and INB1/2 are used in conjunction with the TB6612FNG. + +Looking at the `TB6612FNG Datasheet <https://www.sparkfun.com/datasheets/Robotics/TB6612FNG.pdf>`_, we can see that the IN pins for Channels A and B (INAx, INBx) are used to control the direction or "mode" of the DC motor, while the PWM signal controls the rotation speed for that particular channel. + +.. image:: ../images/tb6612_control_function.png + +Thus, we can use the decoder table above to infer that to drive motor channel A at 50% speed clockwise, we would set the PCA9685 to output INA1 High, INA2 Low and PWM1 at a 50% duty cycle. + +If we wanted to go counter-clockwise, we would simply swap things around so INA1 was Low, INA2 was High and assuming we want to keep the same rotation speed, PWM1 at a 50% duty cycle. + +Lastly, we have the option for a "Short Brake" for the motors but please note that it is not recommended to keep motors in this state as that shorts the coils internally and will cause them to heat up over time. If you want to stop your motor, you should issue a "Short brake" state followed by a short delay to allow the motor to physically stop rotating and then leave the motor in the "Stop" state (which de-energizes the coils) by setting IN1 and IN2 to LOW. + +But enough theory, let's use some actual code to make things spin... + +Using Adafruit ServoKit +************************** + +If you are looking to drive Servo motors accurately and not particularly interested in driving DC motors, you may consider using the Adafruit ServoKit library which simplifies this type of use case. +As with all python modules, make sure you do so inside a virtual environment as shown below! + +.. code:: console + + mkdir project-name && cd project-name + python3 -m venv .venv + source .venv/bin/activate + sudo pip3 install --upgrade setuptools + sudo pip install --upgrade adafruit-python-shell + wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py + sudo python raspi-blinka.py + pip3 install adafruit-circuitpython-servokit adafruit-circuitpython-busdevice adafruit-circuitpython-register + +From here, you should be able to run some example code such as the following: + +.. code:: Python + + import time + from adafruit_servokit import ServoKit + + # Set channels to the number of servo channels on your kit. + # 8 for FeatherWing, 16 for Shield/HAT/Bonnet. + kit = ServoKit(channels=16) + + kit.servo[0].angle = 180 + kit.continuous_servo[1].throttle = 1 + time.sleep(1) + kit.continuous_servo[1].throttle = -1 + time.sleep(1) + kit.servo[0].angle = 0 + kit.continuous_servo[1].throttle = 0 + +To explore ServoKit further, check out the `ServoKit Github Page and Examples <https://github.com/adafruit/Adafruit_CircuitPython_ServoKit/tree/main>`_ + + +Python User-space Driver +************************** + +As mentioned before, the PCA9685 is a rather simple I2C device, so the driver for it is equally simple: +`PCA9685.py <https://gist.github.com/Grippy98/7ef6a75b2dc7a9470bd8c4dfc6b53f0a>`_ + +Simply download this to the root of your project and you are most of the way there. + +From there, you simply need an import statement and to define the driver instance: + +.. code:: Python + + from PCA9685 import PCA9685 + + pwm = PCA9685(0x60, debug=False) #Default I2C Address for the shield is 0x60 + pwm.setPWMFreq(50) #Most Servo Motors use a PWM Frequency of 50Hz + +You can now drive LEDs or servo motors by issuing the following command (replacing pin and dutyCycle with your particular values): + +.. code:: Python + + pwm.setDutycycle(pin, dutyCycle) + +WaveShare Motor and Servo Driver HAT +************************************ + +Waveshare writes some of the better `documentation <https://www.waveshare.com/wiki/Motor_Driver_HAT>`_ for these types of Motor Driver HATs + +.. todo:: Add more information on Waveshare motor & servo driver HAT. + +XICOOLEE Motor and Servo Driver HAT +************************************ + +.. image:: ../images/xicoolee_pca9685_1.jpg + +Photo Credit - Xicoolee + +Looking at the schematic for the Xicoolee HAT, we see that we need to define our DC motor pins as follows: + +.. code:: Python + + #Xicoolee TB6612FNG + + self.PWMA = 0 + self.AIN1 = 2 + self.AIN2 = 1 + self.PWMB = 5 + self.BIN1 = 3 + self.BIN2 = 4 + +We can then run some simple example code as shown below: + +.. code:: Python + + #!/usr/bin/python + + from PCA9685 import PCA9685 + import time + + Dir = [ + 'forward', + 'backward', + ] + pwm = PCA9685(0x40, debug=False) + pwm.setPWMFreq(50) + + class MotorDriver(): + def __init__(self): + # Match these to your particular HAT! + self.PWMA = 0 + self.AIN1 = 2 + self.AIN2 = 1 + self.PWMB = 5 + self.BIN1 = 3 + self.BIN2 = 4 + + def MotorRun(self, motor, index, speed): + if speed > 100: + return + if(motor == 0): + pwm.setDutycycle(self.PWMA, speed) + if(index == Dir[0]): + print ("1") + pwm.setLevel(self.AIN1, 0) + pwm.setLevel(self.AIN2, 1) + else: + print ("2") + pwm.setLevel(self.AIN1, 1) + pwm.setLevel(self.AIN2, 0) + else: + pwm.setDutycycle(self.PWMB, speed) + if(index == Dir[0]): + print ("3") + pwm.setLevel(self.BIN1, 0) + pwm.setLevel(self.BIN2, 1) + else: + print ("4") + pwm.setLevel(self.BIN1, 1) + pwm.setLevel(self.BIN2, 0) + + def MotorStop(self, motor): + if (motor == 0): + pwm.setDutycycle(self.PWMA, 0) + else: + pwm.setDutycycle(self.PWMB, 0) + + print("this is a motor driver test code") + Motor = MotorDriver() + + print("forward 2 s") + Motor.MotorRun(0, 'forward', 100) + Motor.MotorRun(1, 'forward', 100) + time.sleep(2) + + print("backward 2 s") + Motor.MotorRun(0, 'backward', 100) + Motor.MotorRun(1, 'backward', 100) + time.sleep(2) + + print("stop") + Motor.MotorStop(0) + Motor.MotorStop(1) + +Adafruit DC & Stepper Motor HAT +************************************ + +.. image:: ../images/adafruit_pca9685_1.jpg + +Photo Credit - Adafruit + +Looking at the schematic for the Adafruit HAT, we see that we need to define our DC motor pins as follows: + +.. code:: Python + + #Adafruit TB6612FNG #1 + + self.PWMA = 8 + self.AIN1 = 10 + self.AIN2 = 9 + self.PWMB = 13 + self.BIN1 = 11 + self.BIN2 = 12 + + #Adafruit TB6612FNG #2 + + self.PWMA_2 = 2 + self.AIN1_2 = 4 + self.AIN2_2 = 3 + self.PWMB_2 = 7 + self.BIN1_2 = 5 + self.BIN2_2 = 6 + +.. todo:: Expand on running 2 DC motor objects \ No newline at end of file diff --git a/boards/beagley/ai/expansion/Connecting-IMX219-CSI-Cameras.rst b/boards/beagley/ai/expansion/Connecting-IMX219-CSI-Cameras.rst new file mode 100644 index 0000000000000000000000000000000000000000..4aa0de07742db6e0e422d6324addba6efbd08951 --- /dev/null +++ b/boards/beagley/ai/expansion/Connecting-IMX219-CSI-Cameras.rst @@ -0,0 +1,70 @@ +.. _beagley-ai-rtc: + +.. note:: This page is a work in progress. Further drive testing and images will be added soon + + +Using IMX219 CSI Cameras +############################ + +To enable an IMX219 CSI camera, modify the following file: `/boot/firmware/extlinux/extlinux.conf` + +We can check the available list of Device Tree Overlays as such: + +.. code:: console + + debian@BeagleBone:~$ ls /boot/firmware/overlays/ | grep "beagley" + k3-am67a-beagley-ai-csi0-imx219.dtbo + k3-am67a-beagley-ai-csi0-ov5640.dtbo + k3-am67a-beagley-ai-csi1-imx219.dtbo + k3-am67a-beagley-ai-dsi-rpi-7inch-panel.dtbo + k3-am67a-beagley-ai-lincolntech-185lcd-panel.dtbo + +Using CSI Port 0 +************************************** + +Then, add the following line to load the IMX219 CSI0 DTBO: + +.. code:: bash + + fdtoverlays /overlays/k3-am67a-beagley-ai-csi0-imx219.dtbo + +Your /boot/firmware/extlinux/extlinux.conf file should look something like this: + +.. code:: bash + + label microSD (default) + kernel /Image + append console=ttyS2,115200n8 root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait net.ifnames=0 + fdtdir / + fdt /ti/k3-j722s-beagley-ai.dtb + fdtoverlays /overlays/k3-am67a-beagley-ai-csi0-imx219.dtbo + initrd /initrd.img + +Now reboot... + +.. code:: console + debian@BeagleBone:~$ ls /dev/ | grep "video" + video0 + video1 + video2 + +Using CSI Port 1 +******************* + + +Troubleshooting +******************* + +.. code:: console + Found /extlinux/extlinux.conf + Retrieving file: /extlinux/extlinux.conf + beagley-ai microSD (extlinux.conf) + 1: microSD Recovery + 2: microSD (RPI 7inch panel) + 3: microSD (lincolntech-185lcd panel) + 4: microSD (csi0 imx219) + 5: microSD (csi1 imx219) + 6: microSD (csi0 ov5640) + 7: microSD (default) + Enter choice: 4 + 4: microSD (csi0 imx219) \ No newline at end of file diff --git a/boards/beagley/ai/expansion/Using-the-RTC.rst b/boards/beagley/ai/expansion/Using-the-RTC.rst new file mode 100644 index 0000000000000000000000000000000000000000..b4499caab2b2b7fe3f94b03ce53e16dd569f73c0 --- /dev/null +++ b/boards/beagley/ai/expansion/Using-the-RTC.rst @@ -0,0 +1,145 @@ +.. _beagley-ai-rtc: + +.. note:: This page is a work in progress. Further testing and images will be added soon + + +Using the on-board Real Time Clock (RTC) +################################################# + +Real Time Clocks (RTCs) provide precise and reliable timekeeping capabilities, which are beneficial for applications ranging from simple timekeeping to complex scheduling and secure operations. + +Without an RTC, a computer must rely on something called Network Time Protocol (NTP) to obtain the current time from a network source. There are many cases however where an SBC such as BeagleY may not have +a constant or reliable network connection. In situations such as these, an RTC allows the board to keep time even if the network connection is severed or the board loses power for an extended period of time. + +Fortunately, BeagleY-AI comes with a built-in `DS1340 <https://www.analog.com/media/en/technical-documentation/data-sheets/DS1340-DS1340C.pdf>`_ RTC for all your fancy time keeping needs! + +Required Hardware +********************** + +BeagleY provides a **1.25 mm pitch, 2-pin JST GH connector** for a coin cell battery to enable the RTC to keep time even if power is lost to the board. + +These batteries are available from several vendors: + +* Adafruit - `Link <https://www.adafruit.com/product/5817>`_ +* DigiKey - `Link <https://www.digikey.com/en/products/detail/raspberry-pi/SC1163/21658274>`_ +* Amazon (reusable battery holder) - `Link <https://www.amazon.com/KODASW-RTCBattery-Holder-Include-Battery/dp/B0CRKQ2MG1/>`_ + +.. image:: ../images/beagley_rtc.png + +Uses for an RTC +********************** + +1. **Maintaining Accurate Time:** RTCs provide an accurate clock that continues to run even when the SBC is powered down. This is crucial for maintaining the correct time and date across reboots. + +2. **Timestamping:** Many applications need to know the current time for timestamping data, logs, or events. For example, IoT devices may need to log sensor data with precise timestamps. + +3. **Scheduling Tasks:** In some applications, tasks need to be scheduled at specific times. An RTC allows the SBC to keep track of time accurately, ensuring that tasks are performed at the correct times. + +4. **Network Synchronization:** If the SBC is part of a larger network, having an accurate time helps with synchronizing data and events across the network. + +5. **Standby Power Efficiency:** Many RTCs operate with a very low power requirement and can keep time even when the rest of the board is in a low-power or sleep mode. This helps in reducing overall power consumption. + +Reading time +********************** + +.. note:: If you have not connected your BeagleY to a network so it can get time from an NTP server, you must set the time before being able to read it. If you don't do this first, you'll see errors. + +Reading the current time on the RTC is achieved using the **hwclock** command. + +.. code:: console + + debian@BeagleY:~$ sudo hwclock + 2024-05-10 00:00:02.224187-05:00 + +Setting time +********************** + +You can set time manually by running the following command: + +.. code:: console + + hwclock --set --date "10/05/2024 21:01:05" + + +Diving Deeper +********************** + +There are actually two different "times" that your Linux system keeps track of. + +* System time, which can be read using the **date** or **timedatectl** commands +* RTC (hardware) time which can be read using the **hwclock** command shown above. + +Comparing the time, we see something interesting, they're different! + +You can just type "date" but the format will be different, so we add some extra instructions to match the format. + +.. code:: console + + debian@BeagleBone:~$ date +%Y-%m-%d' '%H:%M:%S.%N%:z + 2024-05-10 21:06:50.058595373+00:00 + + debian@BeagleBone:~$ sudo hwclock + 2024-05-10 21:06:56.692874+00:00 + +But why? We see here that our system and hardware clock are over 9 seconds apart! + +Ok, in this particular case we set the HW clock slightly ahead to illustrate the point, but in real life "drift" is a real problem +that has to be dealt with. Environmental conditions like temperature or stray cosmic rays can cause electronics to become ever so slightly out of sync, and these effects only grow over time unless corrected. It's why RTCs and other fancier time keeping instruments implement various methods to help account for this +such as temperature compensated oscillators. + +Let's fix our hardware clock. We assume here that the system clock is freshly synced over NTP so it's going to be our true time "source". + +.. code:: console + + debian@BeagleBone:~$ sudo hwclock --systohc + +Let's write a simple script to get the two times, we'll call it **getTime.sh**: + +.. code:: console + + HWTIME=$(sudo hwclock) + echo "RTC - ${HWTIME} " + + SYSTIME=$(date +%Y-%m-%d' '%H:%M:%S.%N%:z) + echo "SYS - ${SYSTIME} " + +Now let's run it! + +.. code:: console + + debian@BeagleBone:~$ sudo chmod +x getTime.sh + debian@BeagleBone:~$ ./getTime.sh + + RTC - 2024-05-10 21:52:58.374954+00:00 + SYS - 2024-05-10 21:52:59.048442940+00:00 + +As we can see, we're still about a second off, but this is because it takes a bit of time to query the RTC via I2C. + +If you want to learn more, the **Going Further** at the end of this article is a good starting point! + +Troubleshooting +******************* + +The most common error results from not having initialized the RTC at all. +This usually happens if the system is powered on without an RTC battery and without a network connection. + +In such cases, you should be able to read the time after setting the time as follows: + +.. code:: console + + debian@BeagleBone:~$ sudo hwclock --systohc + + debian@BeagleBone:~$ sudo hwclock + 2024-05-10 21:06:56.692874+00:00 + + +Going Further +******************* + +Consider learning about topics such as time keeping over GPS and Atomic Clocks! + +Some good YouTube Videos and sources for inspiration - + +* `Network Time Protocol - Computerphile <https://www.youtube.com/watch?v=BAo5C2qbLq8>`_ +* `Nanosecond Clock Sync - Jeff Geerling <https://www.youtube.com/watch?v=RvnG-ywF6_s>`_ +* `Using GPS with PPS to synchronize clocks over the network <https://www.youtube.com/watch?v=7aTZ66ZL6Dk>`_ \ No newline at end of file diff --git a/boards/beagley/ai/images/adafruit_pca9685_1.jpg b/boards/beagley/ai/images/adafruit_pca9685_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d31c4f0d30be542aff709b834d50e0744886de65 Binary files /dev/null and b/boards/beagley/ai/images/adafruit_pca9685_1.jpg differ diff --git a/boards/beagley/ai/images/arducam_dual_1.jpg b/boards/beagley/ai/images/arducam_dual_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..de83ae491a245ddec615491332c160011f34bcca Binary files /dev/null and b/boards/beagley/ai/images/arducam_dual_1.jpg differ diff --git a/boards/beagley/ai/images/beagley_rtc.png b/boards/beagley/ai/images/beagley_rtc.png new file mode 100644 index 0000000000000000000000000000000000000000..1c3466d774ed54ecf3b29e8222e6a7e9a9bfd2a8 Binary files /dev/null and b/boards/beagley/ai/images/beagley_rtc.png differ diff --git a/boards/beagley/ai/images/tb6612_control_function.png b/boards/beagley/ai/images/tb6612_control_function.png new file mode 100644 index 0000000000000000000000000000000000000000..6cd410b459939868714c615cf1e16e04af705f91 Binary files /dev/null and b/boards/beagley/ai/images/tb6612_control_function.png differ diff --git a/boards/beagley/ai/images/xicoolee_pca9685_1.jpg b/boards/beagley/ai/images/xicoolee_pca9685_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0b3c287552f55351827e63278f2a41d57fc042e2 Binary files /dev/null and b/boards/beagley/ai/images/xicoolee_pca9685_1.jpg differ diff --git a/boards/beagley/ai/images/xicoolee_pca9685_2.jpg b/boards/beagley/ai/images/xicoolee_pca9685_2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8e1db9477cf6478ceccf84fb1fd3cf8734d5f2dd Binary files /dev/null and b/boards/beagley/ai/images/xicoolee_pca9685_2.jpg differ diff --git a/boards/beagley/ai/images/xicoolee_sch1.png b/boards/beagley/ai/images/xicoolee_sch1.png new file mode 100644 index 0000000000000000000000000000000000000000..982e5482c62110347397eb17699af4bb9ac752be Binary files /dev/null and b/boards/beagley/ai/images/xicoolee_sch1.png differ