diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 66142ecb97fae55857a2d888aeb8eec90fe53b09..7b3d86221f8f1d6288fd1dc8b1b84904b8988288 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,17 +1,23 @@ +# You can override the included template(s) by including variable overrides +# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings +# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings +# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings +# Note that environment variables can be set in several places +# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence image: beagle/sphinx-build-env:latest -stages: - - deploy +variables: + GIT_SUBMODULE_STRATEGY: recursive cache: key: bbdocs paths: - - public + - public pages: stage: deploy script: - - ./gitlab-build.sh + - "./gitlab-build.sh" artifacts: paths: - - public + - public diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..0c170ef15f085e53d111e2b9b65bd7a763ec4456 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "books/beaglebone-cookbook/code"] + path = books/beaglebone-cookbook/code + url = https://git.beagleboard.org/beagleboard/beaglebone-cookbook-code.git diff --git a/Dockerfile b/Dockerfile index 6131d5228d5f8da9f499fa3731b38575cc3c7a92..b0811e854eb9fbb3122269890d9d4ba198c6e880 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,3 +8,4 @@ RUN apk add librsvg RUN pip install sphinx_rtd_theme RUN apk add texlive-full RUN apk add make +RUN apk add rsync diff --git a/_ext/callouts.py b/_ext/callouts.py new file mode 100644 index 0000000000000000000000000000000000000000..8ed544aec52856f305cb501d9bfb2a2006ebb9d5 --- /dev/null +++ b/_ext/callouts.py @@ -0,0 +1,199 @@ +from docutils import nodes + +from sphinx.util.docutils import SphinxDirective +from sphinx.transforms import SphinxTransform +from docutils.nodes import Node + +# BASE_NUM = 2775 # black circles, white numbers +BASE_NUM = 2459 # white circle, black numbers + + +class CalloutIncludePostTransform(SphinxTransform): + """Code block post-processor for `literalinclude` blocks used in callouts.""" + + default_priority = 400 + + def apply(self, **kwargs) -> None: + visitor = LiteralIncludeVisitor(self.document) + self.document.walkabout(visitor) + + +class LiteralIncludeVisitor(nodes.NodeVisitor): + """Change a literal block upon visiting it.""" + + def __init__(self, document: nodes.document) -> None: + super().__init__(document) + + def unknown_visit(self, node: Node) -> None: + pass + + def unknown_departure(self, node: Node) -> None: + pass + + def visit_document(self, node: Node) -> None: + pass + + def depart_document(self, node: Node) -> None: + pass + + def visit_start_of_file(self, node: Node) -> None: + pass + + def depart_start_of_file(self, node: Node) -> None: + pass + + def visit_literal_block(self, node: nodes.literal_block) -> None: + if "<1>" in node.rawsource: + source = str(node.rawsource) + for i in range(1, 20): + source = source.replace( + f"<{i}>", "``" + chr(int(f"0x{BASE_NUM + i}", base=16)) + "``" + ) + node.rawsource = source + node[:] = [nodes.Text(source)] + + +class callout(nodes.General, nodes.Element): + """Sphinx callout node.""" + + pass + + +def visit_callout_node(self, node): + """We pass on node visit to prevent the + callout being treated as admonition.""" + pass + + +def depart_callout_node(self, node): + """Departing a callout node is a no-op, too.""" + pass + + +class annotations(nodes.Element): + """Sphinx annotations node.""" + + pass + + +def _replace_numbers(content: str): + """ + Replaces strings of the form <x> with circled unicode numbers (e.g. â‘ ) as text. + + Args: + content: Python str from a callout or annotations directive. + + Returns: The formatted content string. + """ + for i in range(1, 20): + content.replace(f"<{i}>", chr(int(f"0x{BASE_NUM + i}", base=16))) + return content + + +def _parse_recursively(self, node): + """Utility to recursively parse a node from the Sphinx AST.""" + self.state.nested_parse(self.content, self.content_offset, node) + + +class CalloutDirective(SphinxDirective): + """Code callout directive with annotations for Sphinx. + + Use this `callout` directive by wrapping either `code-block` or `literalinclude` + directives. Each line that's supposed to be equipped with an annotation should + have an inline comment of the form "# <x>" where x is an integer. + + Afterwards use the `annotations` directive to add annotations to the previously + defined code labels ("<x>") by using the syntax "<x> my annotation" to produce an + annotation "my annotation" for x. + Note that annotation lines have to be separated by a new line, i.e. + + .. annotations:: + + <1> First comment followed by a newline, + + <2> second comment after the newline. + + + Usage example: + ------------- + + .. callout:: + + .. code-block:: python + + from ray import tune + from ray.tune.search.hyperopt import HyperOptSearch + import keras + + def objective(config): # <1> + ... + + search_space = {"activation": tune.choice(["relu", "tanh"])} # <2> + algo = HyperOptSearch() + + tuner = tune.Tuner( # <3> + ... + ) + results = tuner.fit() + + .. annotations:: + + <1> Wrap a Keras model in an objective function. + + <2> Define a search space and initialize the search algorithm. + + <3> Start a Tune run that maximizes accuracy. + """ + + has_content = True + + def run(self): + self.assert_has_content() + + content = self.content + content = _replace_numbers(content) + + callout_node = callout("\n".join(content)) + _parse_recursively(self, callout_node) + + return [callout_node] + + +class AnnotationsDirective(SphinxDirective): + """Annotations directive, which is only used nested within a Callout directive.""" + + has_content = True + + def run(self): + content = self.content + content = _replace_numbers(content) + + joined_content = "\n".join(content) + annotations_node = callout(joined_content) + _parse_recursively(self, annotations_node) + + return [annotations_node] + + +def setup(app): + # Add new node types + app.add_node( + callout, + html=(visit_callout_node, depart_callout_node), + latex=(visit_callout_node, depart_callout_node), + text=(visit_callout_node, depart_callout_node), + ) + app.add_node(annotations) + + # Add new directives + app.add_directive("callout", CalloutDirective) + app.add_directive("annotations", AnnotationsDirective) + + # Add post-processor + app.add_post_transform(CalloutIncludePostTransform) + + return { + "version": "0.1", + "parallel_read_safe": True, + "parallel_write_safe": True, + } diff --git a/boards/beaglebone/ai-64/index.rst b/boards/beaglebone/ai-64/index.rst index 598431af47bc2e47f78f72a36a5481c3c54a34e9..691b7213df478e9496d5965524be5b7ea773f9fd 100644 --- a/boards/beaglebone/ai-64/index.rst +++ b/boards/beaglebone/ai-64/index.rst @@ -16,4 +16,5 @@ BeagleBone® AI-64 brings a complete system for developing artificial intelligen /boards/beaglebone/ai-64/ch09.rst /boards/beaglebone/ai-64/ch10.rst /boards/beaglebone/ai-64/ch11.rst + /boards/beaglebone/ai-64/update.rst /boards/beaglebone/ai-64/edge_ai_apps/index.rst diff --git a/boards/beaglebone/ai-64/update.rst b/boards/beaglebone/ai-64/update.rst new file mode 100644 index 0000000000000000000000000000000000000000..576492b5ef0dd259809f15c20c43953e89c17a40 --- /dev/null +++ b/boards/beaglebone/ai-64/update.rst @@ -0,0 +1,60 @@ +.. _bbai64-update: + +Update software on BeagleBone AI-64 +################################### + +Production boards currently ship with the factory-installed 2022-01-14-8GB image. To upgrade from the software image on your BeagleBone AI-64 to the latest, you don't need to completely reflash the board. If you do want to reflash it, visit the flashing instructions on the getting started page. +Factory Image update (without reflashing)… + +.. code-block:: bash + :linenos: + + sudo apt update + sudo apt install --only-upgrade bb-j721e-evm-firmware generic-sys-mods + sudo apt upgrade + +Update U-Boot: +============== + +to ensure only tiboot3.bin is in boot0, the pre-production image we tried to do more in boot0, but failed… + +.. code-block:: bash + :linenos: + + sudo /opt/u-boot/bb-u-boot-beagleboneai64/install-emmc.sh + sudo /opt/u-boot/bb-u-boot-beagleboneai64/install-microsd.sh + sudo reboot + +Update Kernel and SGX modules: +============================== + +.. code-block:: bash + :linenos: + + sudo apt install bbb.io-kernel-5.10-ti-k3-j721e + +Update xfce: +============ + +.. code-block:: bash + :linenos: + + sudo apt install bbb.io-xfce4-desktop + +Update ti-edge-ai 8.2 examples +============================== + +.. code-block:: bash + :linenos: + + sudo apt install ti-edgeai-8.2-base ti-vision-apps-8.2 ti-vision-apps-eaik-firmware-8.2 + +Cleanup: +======== + +.. code-block:: bash + :linenos: + + sudo apt autoremove --purge + + diff --git a/boards/beaglebone/index.rst b/boards/beaglebone/index.rst index a63ca8133ae5c95d6c93b96efc795f41ba904ff4..679d03fa3945679bbe78c1a034cd2969fca30fac 100644 --- a/boards/beaglebone/index.rst +++ b/boards/beaglebone/index.rst @@ -10,7 +10,8 @@ The most popular design is :ref:`beagleboneblack-home`, a staple reference for a embedded Linux single board computer. :ref:`bbai64-home` is our most powerful design with tremendous machine learning inference -performance and +performance, 64-bit processing and a mixture of microcontrollers for various types of +highly-reliable and low-latency control. For simplicity of developing small, mobile robotics, check out :ref:`beaglebone-blue-home`, a highly integrated board with motor drivers, battery support, altimeter, gyroscope, accelerometer, @@ -24,6 +25,6 @@ of your screen. * `BeagleBone (original) <https://git.beagleboard.org/beagleboard/beaglebone/-/blob/master/BeagleBone_SRM_A6_0_1.pdf>`__ * :ref:`beagleboneblack-home` * :ref:`beaglebone-blue-home` -* :ref:`bbai64-home` * :ref:`beaglebone-ai-home` +* :ref:`bbai64-home` diff --git a/boards/beagleconnect/freedom/index.rst b/boards/beagleconnect/freedom/index.rst index 48115ae38a21cd42f60d09c5fe55572fad95e52a..3d1180027569f8b1fbba6fb2470d2dffc20e850b 100644 --- a/boards/beagleconnect/freedom/index.rst +++ b/boards/beagleconnect/freedom/index.rst @@ -1,6 +1,12 @@ +.. _beagleconnect_freedom_home: + BeagleConnect Freedom ###################### +.. important:: + + Currently under development + .. image:: media/image1.jpg :width: 600 :align: center @@ -29,12 +35,12 @@ devices within the first year after the initial release. BeagleConnectâ„¢ Freedom ********************** -BeagleConnectâ„¢ Freedom is based on the `TI CC1352 <https://www.ti.com/product/CC1352P7>`_ +BeagleConnectâ„¢ Freedom is based on a `TI Arm Cortex-M4 wireless-enabled microcontroller <https://www.ti.com/product/CC1352P7>`_ and is the first available BeagleConnectâ„¢ solution. It implements: * BeagleConnectâ„¢ gateway device function for Sub-GHz 802.15.4 long-range wireless -* BeagleConnectâ„¢ node device function for Bluetooth Low-Energe (BLE) and +* BeagleConnectâ„¢ node device function for Bluetooth Low-Energy (BLE) and Sub-GHz 802.15.4 long range wireless * USB-based serial console and firmware updates * 2x `mikroBUS sockets <https://www.mikroe.com/mikrobus>`_ with BeagleConnectâ„¢ @@ -125,7 +131,7 @@ Long-range, low-power wireless ============================== BeagleConnectâ„¢ Freedom wireless hardware is built around a -`TI CC1352 <http://www.ti.com/product/CC1352P7>`_ multiprotocol and multi-band +`TI CC1352P7 <http://www.ti.com/product/CC1352P7>`_ multiprotocol and multi-band Sub-1 GHz and 2.4-GHz wireless microcontroller (MCU). CC1352P7 includes a 48-MHz Arm® Cortex®-M4F processor, 704KB Flash, 256KB ROM, 8KB Cache SRAM, 144KB of ultra-low leakage SRAM, and `Over-the-Air <https://en.wikipedia.org/wiki/Over-the-air_programming>`_ diff --git a/boards/beagleconnect/freedom/zephyr.rst b/boards/beagleconnect/freedom/zephyr.rst index f08d7e4a08da9af999cf54271f5dd8dfc134e928..60ab95732bb0a9ae44b569f602179cf8f82cd386 100644 --- a/boards/beagleconnect/freedom/zephyr.rst +++ b/boards/beagleconnect/freedom/zephyr.rst @@ -73,6 +73,57 @@ BeagleBone® Green Gateway host. #TODO: describe how to know it is working +Other systems +------------- + +.. important:: + + If you are using the image above, none of the instructions in this section are required. + +#. Update the system. + .. code-block:: bash + + sudo apt update + +#. Install all BeagleConnectâ„¢ management software. + .. code-block:: bash + + sudo apt install -y \ + beagleconnect beagleconnect-msp430 \ + git vim \ + build-essential \ + cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler \ + make gcc libsdl2-dev \ + libxml2-dev libxslt-dev libssl-dev libjpeg62-turbo-dev \ + gcc-arm-none-eabi libnewlib-arm-none-eabi \ + libtool-bin pkg-config autoconf automake libusb-1.0-0-dev \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel + + .. code-block:: bash + + echo "export PATH=$PATH:$HOME/.local/bin" >> $HOME/.bashrc + + .. code-block:: bash + + source $HOME/.bashrc + +#. Reboot + .. code-block:: bash + + sudo reboot + +#. Install BeagleConnectâ„¢ flashing software + .. code-block:: bash + + pip3 install -U west + +#. Reboot + .. code-block:: bash + + sudo reboot + + Log into BeagleBone Green Gateway ================================= @@ -86,7 +137,6 @@ computer can be used to connect to your BeagleBone Green Gateway. * To connect you can simply type :code:`$ ssh debian@192.168.7.2` and when asked for password just type :code:`temppwd` * Congratulations, You are now connected to the device! - #. Connect to the `WiFi <https://forum.beagleboard.org/t/debian-11-x-bullseye-monthly-snapshots/31280>`_ * Execute :code:`sudo nano /etc/wpa_supplicant/wpa_supplicant-wlan0.conf` and provide the password :code:`temppwd` to edit the configuration file @@ -94,7 +144,8 @@ computer can be used to connect to your BeagleBone Green Gateway. * Now edit the file (shown below) under the :code:`network={...}` section you can set you :code:`ssid` (WiFi name) and :code:`psk` (Wifi Password). - .. code-block:: + + .. code-block:: ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev update_config=1 @@ -103,10 +154,12 @@ computer can be used to connect to your BeagleBone Green Gateway. ssid="WiFi Name" psk="WiFi Password" } + * Now save the file with :code:`CTRL+O` and exit with :code:`CTRL+X`. * Check if the connection is established by executing :code:`$ ping 8.8.8.8` you should see something like shown below. - .. code-block:: bash + + .. code-block:: bash debian@BeagleBone:~$ ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. @@ -115,62 +168,24 @@ computer can be used to connect to your BeagleBone Green Gateway. 64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=6.13 ms 64 bytes from 8.8.8.8: icmp_seq=4 ttl=118 time=6.11 ms ... + * If everything goes well, you are ready to update your system and install new applications for beagleconnect. -Note: If you are facing some issue during boot then you can try debugging the -boot session with a USB to serial interface cable such as those made by FTDI -plugged into J10 with the black wire of the FTDI cable toward the Ethernet -connector. Application like tio/minicom/putty can be used to make the connection -establishment procedure easy. +.. note: -TODO: Simplify and elaborate on this section, add boot session debugging walkthrough + If you are facing some issue during boot then you can try debugging the + boot session with a USB to serial interface cable such as those made by FTDI + plugged into J10 with the black wire of the FTDI cable toward the Ethernet + connector. Application like tio/minicom/putty can be used to make the connection + establishment procedure easy. -Install Zephyr development tools on BeagleBone Green Gateway -============================================================ +.. note: -#. Update the system. - .. code-block:: bash - - sudo apt update - -#. Install all BeagleConnectâ„¢ management software. - .. code-block:: bash + #TODO#: Simplify and elaborate on this section, add boot session debugging walkthrough - sudo apt install -y \ - beagleconnect beagleconnect-msp430 \ - git vim \ - build-essential \ - cmake ninja-build gperf \ - ccache dfu-util device-tree-compiler \ - make gcc libsdl2-dev \ - libxml2-dev libxslt-dev libssl-dev libjpeg62-turbo-dev \ - gcc-arm-none-eabi libnewlib-arm-none-eabi \ - libtool-bin pkg-config autoconf automake libusb-1.0-0-dev \ - python3-dev python3-pip python3-setuptools python3-tk python3-wheel - - .. code-block:: bash - - echo "export PATH=$PATH:$HOME/.local/bin" >> $HOME/.bashrc - - .. code-block:: bash - - source $HOME/.bashrc - -#. Reboot - .. code-block:: bash - - sudo reboot - -#. Install BeagleConnectâ„¢ flashing software - .. code-block:: bash - - pip3 install -U west - -#. Reboot - .. code-block:: bash - - sudo reboot +Install Zephyr development tools on BeagleBone Green Gateway +============================================================ #. Download and setup Zephyr for BeagleConnectâ„¢ .. code-block:: bash @@ -193,32 +208,37 @@ Build applications for BeagleConnect Freedom on BeagleBone Green Gateway Now you can build various Zephyr applications #. Change directory to BeagleConnect Freedom zephyr repository. + .. code-block:: bash cd $HOME/bcf-zephyr #. Build blinky example - .. code-block:: bash - west build -d build/blinky zephyr/samples/basic/blinky + .. code-block:: bash + west build -d build/blinky zephyr/samples/basic/blinky #. TODO + .. code-block:: bash west build -d build/sensortest zephyr/samples/boards/beagle_bcf/sensortest -- -DOVERLAY_CONFIG=overlay-subghz.conf #. TODO + .. code-block:: bash west build -d build/wpanusb modules/lib/wpanusb_bc -- -DOVERLAY_CONFIG=overlay-subghz.conf #. TODO + .. code-block:: bash west build -d build/bcfserial modules/lib/wpanusb_bc -- -DOVERLAY_CONFIG=overlay-bcfserial.conf -DDTC_OVERLAY_FILE=bcfserial.overlay #. TODO + .. code-block:: bash west build -d build/greybus modules/lib/greybus/samples/subsys/greybus/net -- -DOVERLAY_CONFIG=overlay-802154-subg.conf diff --git a/boards/beagleconnect/index.rst b/boards/beagleconnect/index.rst index 8172f05328e2a4f9d6ef916603b7016028a0e928..d7941e51d1b03c85692afd5b595995766f79f207 100644 --- a/boards/beagleconnect/index.rst +++ b/boards/beagleconnect/index.rst @@ -3,6 +3,10 @@ BeagleConnect ############### +.. important:: + + Currently under development + BeagleConnectâ„¢ is a revolutionary technology virtually eliminating low-level software development for `IoT <https://en.wikipedia.org/wiki/Internet_of_things>`_ and `IIoT <https://en.wikipedia.org/wiki/Industrial_internet_of_things>`_ diff --git a/boards/capes/cape-interface-spec.rst b/boards/capes/cape-interface-spec.rst index a115bad7d0b1a304010785420a446c42ab30647e..9d600bc7cd9b110cc8b626fe0167fea34e9fbfb6 100644 --- a/boards/capes/cape-interface-spec.rst +++ b/boards/capes/cape-interface-spec.rst @@ -3,354 +3,730 @@ BeagleBone cape interface spec ############################### -This page is a replica of `BeagleBone cape interface spec <https://elinux.org/Beagleboard:BeagleBone_cape_interface_spec>`_ page on elinux. - -See `this <https://beagleboard.org/blog/2022-03-31-device-tree-supporting-similar-boards-the-beaglebone-example>`_ blog post on BeagleBoard.org -for an introduction on Device Tree: Supporting Similar Boards - The BeagleBone Example. -`This <https://docs.google.com/spreadsheets/d/1fE-AsDZvJ-bBwzNBj1_sPDrutvEvsmARqFwvbw_HkrE/edit?usp=sharing>`_ -spreadsheet provides a summary of expansion header signals on various BeagleBoard.org board designs. -`This <https://elinux.org/Beagleboard:Cape_Expansion_Headers>`_ provides information on Cape Expansion Headers for BeagleBone designs. - -.. Note:: Below, when mentioning "Black", this is true for all AM3358-based BeagleBone boards. "AI" is AM5729-based. "AI-64" is TDA4VM-based. - +.. |I2C| replace:: I\ :sup:`2`\ C + +This page is a fork of `BeagleBone cape interface spec <https://elinux.org/Beagleboard:BeagleBone_cape_interface_spec>`_ page on elinux. This is the new official home. + +Background and overview +*********************** + +.. important:: + + Resources + + * See `Device Tree: Supporting Similar Boards - The BeagleBone Example blog post <https://beagleboard.org/blog/2022-03-31-device-tree-supporting-similar-boards-the-beaglebone-example>`_ on BeagleBoard.org + * See `spreadsheet with pin header details <https://docs.google.com/spreadsheets/d/1fE-AsDZvJ-bBwzNBj1_sPDrutvEvsmARqFwvbw_HkrE/edit?usp=sharing>`_ + * See `elinux.org Cape Expansion Headers for BeagleBone page <https://elinux.org/Beagleboard:Cape_Expansion_Headers>`_ + * See :ref:`BeagleBone Black System Reference Manual Connectors section <beagleboneblack-connectors>` + * See :ref:`BeagleBone AI System Reference Manual Connectors section <beaglebone-ai-connectors>` + * See :ref:`BeagleBone AI-64 System Reference Manual Connectors section <TODO>` + +.. note:: Below, when mentioning "Black", this is true for all AM3358-based BeagleBone boards. "AI" is AM5729-based. "AI-64" is TDA4VM-based. + +The device tree symbols for the BeagleBone Cape Compatibility Layer are provided in `BeagleBoard-DeviceTrees <https://git.beagleboard.org/beagleboard/BeagleBoard-DeviceTrees>`_ at: + +* Black: `bbb-bone-buses.dtsi <https://git.beagleboard.org/beagleboard/BeagleBoard-DeviceTrees/-/blob/v5.10.x-ti-unified/src/arm/bbb-bone-buses.dtsi>`_ +* AI: `bbai-bone-buses.dtsi <https://git.beagleboard.org/beagleboard/BeagleBoard-DeviceTrees/-/blob/v5.10.x-ti-unified/src/arm/bbai-bone-buses.dtsi>`_ +* AI-64: `k3-j721e-beagleboneai-64-bone-buses.dtsi <https://git.beagleboard.org/beagleboard/BeagleBoard-DeviceTrees/-/blob/v5.10.x-ti-unified/src/arm64/k3-j721e-beagleboneai64-bone-buses.dtsi>`_ + +The udev rules used to create the userspace symlinks for the BeagleBone Cape Compatibility Layer are provided in `usr-customizations <https://git.beagleboard.org/beagleboard/usr-customizations>`_ at: + +More details can be found in :ref:`bone-methodology`. + +.. |A| replace:: :ref:`A <bone-analog>` +.. |B| replace:: :ref:`B <bone-i2s>` +.. |C| replace:: :ref:`C <bone-can>` +.. |D| replace:: :ref:`D <bone-gpio>` +.. |E| replace:: :ref:`E <bone-pwm>` +.. |I| replace:: :ref:`I <bone-i2c>` +.. |L| replace:: :ref:`L <bone-lcd>` +.. |M| replace:: :ref:`M <bone-mmc>` +.. |P| replace:: :ref:`P <bone-pru>` +.. |Q| replace:: :ref:`Q <bone-capture>` +.. |S| replace:: :ref:`S <bone-spi>` +.. |U| replace:: :ref:`U <bone-uart>` +.. |Y| replace:: :ref:`Y <bone-ecap>` + +.. note:: + + Legend + + * |D|: Digital general purpose input and output (GPIO) + * |I|: Inter-integrated circuit bus (|I2C|) ports + * |S|: Serial peripheral interface (SPI) ports + * |U|: Universal asynchronous reciever/transmitter (UART) serial ports + * |C|: CAN + * |A|: Analog inputs + * |E|: PWM + * |Q|: Capture/EQEP + * |M|: MMC/SD/SDIO + * |B|: I2S/audio serial ports + * |L|: LCD + * |P|: PRU + * |Y|: ECAP .. table:: Overall - +-----------------------------------------------+-----+------------------------------------+ - | .. centered:: P8 | | .. centered:: P8 | - +===============+=====+======+==================+=====+===========+=====+======+===========+ - | Functions | odd | even | Functions | | Functions | odd | even | Functions | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | USB D+ | E1 | E2 | USB D- | | - | - | - | - | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | 5V OUT | E3 | E4 | GND | | - | - | - | - | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | 3V3 OUT | 3 | 4 | 3V3 OUT | | D M | 3 | 4 | D M | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | 5V IN | 5 | 6 | 5V IN | | D M | 5 | 6 | D M | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | 5V OUT | 7 | 8 | 5V OUT | | C2r D | 7 | 8 | C2t D | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | PWR BUT | 9 | 10 | RESET | | D | 9 | 10 | D | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D U4r | 11 | 12 | D | | D P0o | 11 | 12 | D Q2a P0o | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D U4t | 13 | 14 | D E1a | | D E2b | 13 | 14 | D | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D | 15 | 16 | D E1b | | D P0i | 15 | 16 | D P0i | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D I1c S00 | 17 | 18 | D I1d S0o | | D | 17 | 18 | D | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | C0r D I2c | 19 | 20 | C0t D I2d | | D E2a | 19 | 20 | D M P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D E0b S0i U2t | 21 | 22 | D E0a S0c U2r | | D M P1 | 21 | 22 | D M Q2b | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D S01 | 23 | 24 | C1r D I3c U1t | | D M | 23 | 24 | D M | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D P0 | 25 | 26 | C1t D I3d U1r | | D M | 25 | 26 | D | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D P0 Q0b | 27 | 28 | D P0 S10 | | D L P1 | 27 | 28 | D L P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D E S1i P0 | 29 | 30 | D P0 S1o | | D L P1 | 29 | 30 | D L P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D E S1c P0 | 31 | 32 | ADC VDD | | D L | 31 | 32 | D L | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | A4 | 33 | 34 | ADC GND | | D L Q1b | 33 | 34 | D E L | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | A6 | 35 | 36 | A5 | | D L Q1a | 35 | 36 | D E L | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | A2 | 37 | 38 | A3 | | D L U5t | 37 | 38 | D L U5r | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | A0 | 39 | 40 | A1 | | D L P1 | 39 | 40 | D L P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | D P0 | 41 | 42 | D Q0a S11 U3t P0 | | D L P1 | 41 | 42 | D L P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | GND | 43 | 44 | GND | | D L P1 | 43 | 44 | D L P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - | GND | 45 | 46 | GND | | D E L P1 | 45 | 46 | D E L P1 | - +---------------+-----+------+------------------+-----+-----------+-----+------+-----------+ - -* A: ADC -* C: CAN -* D: Digital GPIO -* E: EHRPWM -* I: I2C -* L: LCD -* M: MMC/SDIO -* P: PRU -* Q: eQEP -* S: SPI -* U: UART - -LEDs ------- - -The compatibility layer comes with simple reference nodes for attaching LEDs to any gpio pin. The format followed for these nodes is **led_P8_## / led_P9_##**. The **gpio-leds** driver is used by these reference nodes internally and allows users to easily create compatible led nodes in overlays for Black, AI and AI-64. For the definitions, you can see `bbai-bone-buses.dtsi#L16 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbai-bone-buses.dtsi#L16>`_ & `bbb-bone-buses.dtsi#L16 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbb-bone-buses.dtsi#L16>`_. - -Example overlays -***************** - -.. table:: Bone LEDs Overlays - - +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ - | Header | Pin | Overlay | - +=========+======+=======================================================================================================================================================+ - | P8 | 3 | `BONE-LED_P8_03.dts <https://git.beagleboard.org/beagleboard/BeagleBoard-DeviceTrees/blob/v4.19.x-ti-overlays/src/arm/overlays/BONE-LED_P8_03.dts>`_ | - +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ - | P9 | 11 | `BONE-LED_P9_11.dts <https://git.beagleboard.org/beagleboard/BeagleBoard-DeviceTrees/blob/v4.19.x-ti-overlays/src/arm/overlays/BONE-LED_P9_11.dts>`_ | - +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------+ - -Definitions -************ - -.. table:: Bone LEDs - - +----------------------------+-------------+----------+-----------+-----------+ - | LED | Header pin | Black | AI | AI-64 | - +============================+=============+==========+===========+===========+ - | /sys/class/leds/led_P8_03 | P8_03 | gpio1_6 | gpio1_24 | gpio0_20 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_04 | P8_04 | gpio1_7 | gpio1_25 | gpio0_48 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_05 | P8_05 | gpio1_2 | gpio7_1 | gpio0_33 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_06 | P8_06 | gpio1_3 | gpio7_2 | gpio0_34 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_07 | P8_07 | gpio2_2 | gpio6_5 | gpio0_15 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_08 | P8_08 | gpio2_3 | gpio6_6 | gpio0_14 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_09 | P8_09 | gpio2_5 | gpio6_18 | gpio0_17 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_10 | P8_10 | gpio2_4 | gpio6_4 | gpio0_16 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_11 | P8_11 | gpio1_13 | gpio3_11 | gpio0_60 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_12 | P8_12 | gpio1_12 | gpio3_10 | gpio0_59 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_13 | P8_13 | gpio0_23 | gpio4_11 | gpio0_89 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_14 | P8_14 | gpio0_26 | gpio4_13 | gpio0_75 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_15 | P8_15 | gpio1_15 | gpio4_3 | gpio0_61 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_16 | P8_16 | gpio1_14 | gpio4_29 | gpio0_62 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_17 | P8_17 | gpio0_27 | gpio8_18 | gpio0_3 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_18 | P8_18 | gpio2_1 | gpio4_9 | gpio0_4 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_19 | P8_19 | gpio0_22 | gpio4_10 | gpio0_88 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_20 | P8_20 | gpio1_31 | gpio6_30 | gpio0_76 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_21 | P8_21 | gpio1_30 | gpio6_29 | gpio0_30 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_22 | P8_22 | gpio1_5 | gpio1_23 | gpio0_5 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_23 | P8_23 | gpio1_4 | gpio1_22 | gpio0_31 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_24 | P8_24 | gpio1_1 | gpio7_0 | gpio0_6 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_25 | P8_25 | gpio1_0 | gpio6_31 | gpio0_35 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_26 | P8_26 | gpio1_29 | gpio4_28 | gpio0_51 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_27 | P8_27 | gpio2_22 | gpio4_23 | gpio0_71 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_28 | P8_28 | gpio2_24 | gpio4_19 | gpio0_72 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_29 | P8_29 | gpio2_23 | gpio4_22 | gpio0_73 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_30 | P8_30 | gpio2_25 | gpio4_20 | gpio0_74 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_31 | P8_31 | gpio0_10 | gpio8_14 | gpio0_32 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_32 | P8_32 | gpio0_11 | gpio8_15 | gpio0_26 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_33 | P8_33 | gpio0_9 | gpio8_13 | gpio0_25 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_34 | P8_34 | gpio2_17 | gpio8_11 | gpio0_7 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_35 | P8_35 | gpio0_8 | gpio8_12 | gpio0_24 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_36 | P8_36 | gpio2_16 | gpio8_10 | gpio0_8 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_37 | P8_37 | gpio2_14 | gpio8_8 | gpio0_106 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_38 | P8_38 | gpio2_15 | gpio8_9 | gpio0_105 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_39 | P8_39 | gpio2_12 | gpio8_6 | gpio0_69 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_40 | P8_40 | gpio2_13 | gpio8_7 | gpio0_70 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_41 | P8_41 | gpio2_10 | gpio8_4 | gpio0_67 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_42 | P8_42 | gpio2_11 | gpio8_5 | gpio0_68 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_43 | P8_43 | gpio2_8 | gpio8_2 | gpio0_65 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_44 | P8_44 | gpio2_9 | gpio8_3 | gpio0_66 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_45 | P8_45 | gpio2_6 | gpio8_0 | gpio0_79 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P8_46 | P8_46 | gpio2_7 | gpio8_1 | gpio0_80 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_11 | P9_11 | gpio0_30 | gpio8_17 | gpio0_1 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_12 | P9_12 | gpio1_28 | gpio5_0 | gpio0_45 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_13 | P9_13 | gpio0_31 | gpio6_12 | gpio0_2 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_14 | P9_14 | gpio1_18 | gpio4_25 | gpio0_93 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_15 | P9_15 | gpio1_16 | gpio3_12 | gpio0_47 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_16 | P9_16 | gpio1_19 | gpio4_26 | gpio0_94 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_17 | P9_17 | gpio0_5 | gpio7_17 | gpio0_28 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_18 | P9_18 | gpio0_4 | gpio7_16 | gpio0_40 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_19 | P9_19 | gpio0_13 | gpio7_3 | gpio0_78 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_20 | P9_20 | gpio0_12 | gpio7_4 | gpio0_77 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_21 | P9_21 | gpio0_3 | gpio3_3 | gpio0_39 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_22 | P9_22 | gpio0_2 | gpio6_19 | gpio0_38 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_23 | P9_23 | gpio1_17 | gpio7_11 | gpio0_10 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_24 | P9_24 | gpio0_15 | gpio6_15 | gpio0_13 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_25 | P9_25 | gpio3_21 | gpio6_17 | gpio0_127 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_26 | P9_26 | gpio0_14 | gpio6_14 | gpio0_12 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_27 | P9_27 | gpio3_19 | gpio4_15 | gpio0_46 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_28 | P9_28 | gpio3_17 | gpio4_17 | gpio1_11 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_29 | P9_29 | gpio3_15 | gpio5_11 | gpio0_53 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_30 | P9_30 | gpio3_16 | gpio5_12 | gpio0_44 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_31 | P9_31 | gpio3_14 | gpio5_10 | gpio0_52 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_33 | P9_33 | NA | NA | gpio0_50 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_35 | P9_35 | NA | NA | gpio0_55 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_36 | P9_36 | NA | NA | gpio0_56 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_37 | P9_37 | NA | NA | gpio0_57 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_38 | P9_38 | NA | NA | gpio0_58 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_39 | P9_39 | NA | NA | gpio0_54 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_40 | P9_40 | NA | NA | gpio0_81 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_41 | P9_41 | gpio0_20 | gpio6_20 | gpio1_0 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_91 | P9_91 | gpio3_20 | NA | NA | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_42 | P9_42 | gpio0_7 | gpio4_18 | gpio0_123 | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_P9_92 | P9_92 | gpio3_18 | NA | NA | - +----------------------------+-------------+----------+-----------+-----------+ - | /sys/class/leds/led_A15 | A15 | gpio0_19 | NA | NA | - +----------------------------+-------------+----------+-----------+-----------+ - -I2C ----- - -Compatibility layer provides simple I2C bone bus nodes for creating compatible overlays for Black, AI and AI-64. The format followed for these nodes is '''bone_i2c_#'''. For the definitions, you can see `bbai-bone-buses.dtsi#L388 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbai-bone-buses.dtsi#L388>`_ & `bbb-bone-buses.dtsi#L403 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbb-bone-buses.dtsi#L403>`_. - -.. table:: Bone bus I2C - - +------------------+--------------+--------+-------+------------+-----------------+--------+-----------------------------------------------------------------------------------------------------------+ - | SYSFS | DT symbol | Black | AI | AI-64 | SCL | SDA | Overlay | - +==================+==============+========+=======+============+=================+========+===========================================================================================================+ - | /dev/bone/i2c/0 | bone_i2c_0 | I2C0 | I2C1 | TBD | .. centered:: NA (On-board) | - +------------------+--------------+--------+-------+------------+-----------------+--------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/i2c/1 | bone_i2c_1 | I2C1 | I2C5 | MAIN_I2C6 | P9.17 | P9.18 | `BONE-I2C1.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_i2c/src/arm/BONE-I2C1.dts>`_ | - +------------------+--------------+--------+-------+------------+-----------------+--------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/i2c/2 | bone_i2c_2 | I2C2 | I2C4 | MAIN_I2C3 | P9.19 | P9.20 | `BONE-I2C2.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_i2c/src/arm/BONE-I2C2.dts>`_ | - +------------------+--------------+--------+-------+------------+-----------------+--------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/i2c/2a | bone_i2c_2a | I2C2 | N/A | TBD | P9.21 | P9.22 | `BONE-I2C2A.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_i2c/src/arm/BONE-I2C2A.dts>`_ | - +------------------+--------------+--------+-------+------------+-----------------+--------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/i2c/3 | bone_i2c_3 | I2C1 | I2C3 | MAIN_I2C4 | P9.24 | P9.26 | `BONE-I2C3.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_i2c/src/arm/BONE-I2C3.dts>`_ | - +------------------+--------------+--------+-------+------------+-----------------+--------+-----------------------------------------------------------------------------------------------------------+ - + +------------------------------------------------------+---+-------------------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+=====================+===+==================+=====+======+=================+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | USB D+ | E1 | E2 | USB D- | | | | | | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | 5V OUT | E3 | E4 | GND | | | | | | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | 3V3 OUT | 3 | 4 | 3V3 OUT | | |D| |M| | 3 | 4 | |D| |M| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | 5V IN | 5 | 6 | 5V IN | | |D| |M| |C| | 5 | 6 | |D| |M| |C| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | 5V OUT | 7 | 8 | 5V OUT | | |D| |C| | 7 | 8 | |D| |C| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | PWR BUT | 9 | 10 | RESET | | |D| |C| | 9 | 10 | |D| |C| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |U| | 11 | 12 | |D| | | |D| |P| | 11 | 12 | |D| |Q| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |U| | 13 | 14 | |D| |E| | | |D| |E| | 13 | 14 | |D| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| | 15 | 16 | |D| |E| | | |D| |P| | 15 | 16 | |D| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |I| |S| | 17 | 18 | |D| |I| |S| | | |D| | 17 | 18 | |D| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |I| |C| | 19 | 20 | |D| |I| |C| | | |D| |E| | 19 | 20 | |D| |M| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |E| |S| |U| | 21 | 22 | |D| |E| |S| |U| | | |D| |M| |P| | 21 | 22 | |D| |M| |Q| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |S| | 23 | 24 | |D| |I| |U| |C| | | |D| |M| | 23 | 24 | |D| |M| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |P| | 25 | 26 | |D| |I| |U| |C| | | |D| |M| | 25 | 26 | |D| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |P| |Q| | 27 | 28 | |D| |S| |P| | | |D| |L| |P| | 27 | 28 | |D| |L| |P| |U| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |E| |S| |P| | 29 | 30 | |D| |S| |P| | | |D| |L| |P| |U| | 29 | 30 | |D| |L| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |E| |S| |P| | 31 | 32 | ADC VDD REF OUT | | |D| |L| | 31 | 32 | |D| |L| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |A| | 33 | 34 | ADC GND | | |D| |L| |Q| | 33 | 34 | |D| |E| |L| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |A| | 35 | 36 | |A| | | |D| |L| |Q| | 35 | 36 | |D| |E| |L| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |A| | 37 | 38 | |A| | | |D| |L| |U| | 37 | 38 | |D| |L| |U| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |A| | 39 | 40 | |A| | | |D| |L| |P| | 39 | 40 | |D| |L| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | |D| |P| | 41 | 42 | |D| |Q| |S| |U| |P| | | |D| |L| |P| | 41 | 42 | |D| |L| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | GND | 43 | 44 | GND | | |D| |L| |P| | 43 | 44 | |D| |L| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + | GND | 45 | 46 | GND | | |D| |E| |L| |P| | 45 | 46 | |D| |E| |L| |P| | + +-------------------+-----+------+---------------------+---+------------------+-----+------+-----------------+ + +.. _bone-gpio: + +Digital GPIO +************ + +The compatibility layer comes with simple reference nodes for attaching the Linuuux gpio-leds or gpio-keys to any cape header GPIO pin. This provides simple userspace general purpose input or output with various trigger modes. + +The format followed for the gpio-leds nodes is **bone_led_P8_## / bone_led_P9_##**. The **gpio-leds** driver is used by these reference nodes internally and allows users to easily create compatible led nodes in overlays for Black, AI and AI-64. + + +.. code-block:: c + :linenos: + :caption: Example device tree overlay to enable LED driver on header P8 pin 3 + :name: bone_cape_spec_led_example + + /dts-v1/; + /plugin/; + + &bone_led_P8_03 { + status = "okay"; + } + +In :ref:`bone_cape_spec_led_example`, it is possible to redefine the default label +and other properties defined in the +`gpio-leds schema <https://elixir.bootlin.com/linux/v5.10/source/Documentation/devicetree/bindings/leds/leds-gpio.yaml>`_. + +.. table:: GPIO pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 3V3 OUT | 3 | 4 | 3V3 OUT | | D M | 3 | 4 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V IN | 5 | 6 | 5V IN | | D M C4t | 5 | 6 | D M C4r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | 7 | 8 | 5V OUT | | D C2r | 7 | 8 | D C2t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | PWR BUT | 9 | 10 | RESET | | D C3r | 9 | 10 | D C3t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4r | 11 | 12 | D | | D P0o | 11 | 12 | D Q2a P0o | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4t | 13 | 14 | D E1a | | D E2b | 13 | 14 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D | 15 | 16 | D E1b | | D P0i | 15 | 16 | D P0i | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D I1c S00 | 17 | 18 | D I1d S0o | | D | 17 | 18 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | C0r D I2c | 19 | 20 | C0t D I2d | | D E2a | 19 | 20 | D M P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E0b S0i U2t | 21 | 22 | D E0a S0c U2r | | D M P1 | 21 | 22 | D M Q2b | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D S01 | 23 | 24 | C1r D I3c U1t | | D M | 23 | 24 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 25 | 26 | C1t D I3d U1r | | D M | 25 | 26 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 Q0b | 27 | 28 | D P0 S10 | | D L P1 | 27 | 28 | D L P1 U6r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1i P0 | 29 | 30 | D P0 S1o | | D L P1 U6t | 29 | 30 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1c P0 | 31 | 32 | ADC VDD | | D L | 31 | 32 | D L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 4 | 33 | 34 | ADC GND | | D L Q1b | 33 | 34 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 6 | 35 | 36 | |A| 5 | | D L Q1a | 35 | 36 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 2 | 37 | 38 | |A| 3 | | D L U5t | 37 | 38 | D L U5r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 0 | 39 | 40 | |A| 1 | | D L P1 | 39 | 40 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 41 | 42 | D Q0a S11 U3t P0 | | D L P1 | 41 | 42 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 43 | 44 | GND | | D L P1 | 43 | 44 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 45 | 46 | GND | | D E L P1 | 45 | 46 | D E L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + +.. table:: Bone GPIO LEDs interface + + +------------------------+-------------+----------+-----------+-----------+ + | LED SYSFS | Header pin | Black | AI | AI-64 | + +========================+=============+==========+===========+===========+ + | /sys/class/leds/P8_03 | P8_03 | gpio1_6 | gpio1_24 | gpio0_20 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_04 | P8_04 | gpio1_7 | gpio1_25 | gpio0_48 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_05 | P8_05 | gpio1_2 | gpio7_1 | gpio0_33 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_06 | P8_06 | gpio1_3 | gpio7_2 | gpio0_34 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_07 | P8_07 | gpio2_2 | gpio6_5 | gpio0_15 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_08 | P8_08 | gpio2_3 | gpio6_6 | gpio0_14 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_09 | P8_09 | gpio2_5 | gpio6_18 | gpio0_17 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_10 | P8_10 | gpio2_4 | gpio6_4 | gpio0_16 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_11 | P8_11 | gpio1_13 | gpio3_11 | gpio0_60 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_12 | P8_12 | gpio1_12 | gpio3_10 | gpio0_59 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_13 | P8_13 | gpio0_23 | gpio4_11 | gpio0_89 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_14 | P8_14 | gpio0_26 | gpio4_13 | gpio0_75 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_15 | P8_15 | gpio1_15 | gpio4_3 | gpio0_61 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_16 | P8_16 | gpio1_14 | gpio4_29 | gpio0_62 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_17 | P8_17 | gpio0_27 | gpio8_18 | gpio0_3 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_18 | P8_18 | gpio2_1 | gpio4_9 | gpio0_4 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_19 | P8_19 | gpio0_22 | gpio4_10 | gpio0_88 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_20 | P8_20 | gpio1_31 | gpio6_30 | gpio0_76 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_21 | P8_21 | gpio1_30 | gpio6_29 | gpio0_30 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_22 | P8_22 | gpio1_5 | gpio1_23 | gpio0_5 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_23 | P8_23 | gpio1_4 | gpio1_22 | gpio0_31 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_24 | P8_24 | gpio1_1 | gpio7_0 | gpio0_6 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_25 | P8_25 | gpio1_0 | gpio6_31 | gpio0_35 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_26 | P8_26 | gpio1_29 | gpio4_28 | gpio0_51 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_27 | P8_27 | gpio2_22 | gpio4_23 | gpio0_71 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_28 | P8_28 | gpio2_24 | gpio4_19 | gpio0_72 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_29 | P8_29 | gpio2_23 | gpio4_22 | gpio0_73 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_30 | P8_30 | gpio2_25 | gpio4_20 | gpio0_74 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_31 | P8_31 | gpio0_10 | gpio8_14 | gpio0_32 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_32 | P8_32 | gpio0_11 | gpio8_15 | gpio0_26 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_33 | P8_33 | gpio0_9 | gpio8_13 | gpio0_25 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_34 | P8_34 | gpio2_17 | gpio8_11 | gpio0_7 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_35 | P8_35 | gpio0_8 | gpio8_12 | gpio0_24 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_36 | P8_36 | gpio2_16 | gpio8_10 | gpio0_8 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_37 | P8_37 | gpio2_14 | gpio8_8 | gpio0_106 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_38 | P8_38 | gpio2_15 | gpio8_9 | gpio0_105 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_39 | P8_39 | gpio2_12 | gpio8_6 | gpio0_69 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_40 | P8_40 | gpio2_13 | gpio8_7 | gpio0_70 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_41 | P8_41 | gpio2_10 | gpio8_4 | gpio0_67 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_42 | P8_42 | gpio2_11 | gpio8_5 | gpio0_68 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_43 | P8_43 | gpio2_8 | gpio8_2 | gpio0_65 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_44 | P8_44 | gpio2_9 | gpio8_3 | gpio0_66 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_45 | P8_45 | gpio2_6 | gpio8_0 | gpio0_79 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P8_46 | P8_46 | gpio2_7 | gpio8_1 | gpio0_80 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_11 | P9_11 | gpio0_30 | gpio8_17 | gpio0_1 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_12 | P9_12 | gpio1_28 | gpio5_0 | gpio0_45 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_13 | P9_13 | gpio0_31 | gpio6_12 | gpio0_2 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_14 | P9_14 | gpio1_18 | gpio4_25 | gpio0_93 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_15 | P9_15 | gpio1_16 | gpio3_12 | gpio0_47 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_16 | P9_16 | gpio1_19 | gpio4_26 | gpio0_94 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_17 | P9_17 | gpio0_5 | gpio7_17 | gpio0_28 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_18 | P9_18 | gpio0_4 | gpio7_16 | gpio0_40 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_19 | P9_19 | gpio0_13 | gpio7_3 | gpio0_78 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_20 | P9_20 | gpio0_12 | gpio7_4 | gpio0_77 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_21 | P9_21 | gpio0_3 | gpio3_3 | gpio0_39 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_22 | P9_22 | gpio0_2 | gpio6_19 | gpio0_38 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_23 | P9_23 | gpio1_17 | gpio7_11 | gpio0_10 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_24 | P9_24 | gpio0_15 | gpio6_15 | gpio0_13 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_25 | P9_25 | gpio3_21 | gpio6_17 | gpio0_127 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_26 | P9_26 | gpio0_14 | gpio6_14 | gpio0_12 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_27 | P9_27 | gpio3_19 | gpio4_15 | gpio0_46 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_28 | P9_28 | gpio3_17 | gpio4_17 | gpio1_11 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_29 | P9_29 | gpio3_15 | gpio5_11 | gpio0_53 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_30 | P9_30 | gpio3_16 | gpio5_12 | gpio0_44 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_31 | P9_31 | gpio3_14 | gpio5_10 | gpio0_52 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_33 | P9_33 | *n/a* | *n/a* | gpio0_50 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_35 | P9_35 | *n/a* | *n/a* | gpio0_55 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_36 | P9_36 | *n/a* | *n/a* | gpio0_56 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_37 | P9_37 | *n/a* | *n/a* | gpio0_57 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_38 | P9_38 | *n/a* | *n/a* | gpio0_58 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_39 | P9_39 | *n/a* | *n/a* | gpio0_54 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_40 | P9_40 | *n/a* | *n/a* | gpio0_81 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_41 | P9_41 | gpio0_20 | gpio6_20 | gpio1_0 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/P9_42 | P9_42 | gpio0_7 | gpio4_18 | gpio0_123 | + +------------------------+-------------+----------+-----------+-----------+ + | /sys/class/leds/A15 | A15 | gpio0_19 | NA | NA | + +------------------------+-------------+----------+-----------+-----------+ + +.. _bone-i2c: + +|I2C| +***** + +Compatibility layer provides simple I2C bone bus nodes for creating compatible overlays for Black, AI and AI-64. The format followed for these nodes is **bone_i2c_#**. + +.. table:: I2C pins + + +---------------------------------------------------+ + | .. centered:: P9 | + +===================+=====+======+==================+ + | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+ + | 1 SCL | 17 | 18 | 1 SDA | + +-------------------+-----+------+------------------+ + | 2 SCL | 19 | 20 | 2 SDA | + +-------------------+-----+------+------------------+ + | 4 SCL [4]_ [5]_ | 21 | 22 | 4 SDA [4]_ [5]_ | + +-------------------+-----+------+------------------+ + | | 23 | 24 | 3 SCL [3]_ | + +-------------------+-----+------+------------------+ + | | 25 | 26 | 3 SDA [3]_ | + +-------------------+-----+------+------------------+ + +.. [3] Mutually exclusive with port 1 on Black + +.. [4] Mutually exclusive with port 2 on Black + +.. [5] On Black and AI-64 only + +.. table:: I2C port mapping + + +-----------------+--------------+-------+-------+-----------+-------+--------+-----------+ + | SYSFS | DT symbol | Black | AI | AI-64 | SCL | SDA | Overlay | + +=================+==============+=======+=======+===========+=======+========+===========+ + | /dev/bone/i2c/0 | bone_i2c_0 | I2C0 | I2C1 | TBD | On-board | + +-----------------+--------------+-------+-------+-----------+-------+--------+-----------+ + | /dev/bone/i2c/1 | bone_i2c_1 | I2C1 | I2C5 | MAIN_I2C6 | P9.17 | P9.18 | BONE-I2C1 | + +-----------------+--------------+-------+-------+-----------+-------+--------+-----------+ + | /dev/bone/i2c/2 | bone_i2c_2 | I2C2 | I2C4 | MAIN_I2C3 | P9.19 | P9.20 | BONE-I2C2 | + +-----------------+--------------+-------+-------+-----------+-------+--------+-----------+ + | /dev/bone/i2c/3 | bone_i2c_3 | I2C1 | I2C3 | MAIN_I2C4 | P9.24 | P9.26 | BONE-I2C3 | + +-----------------+--------------+-------+-------+-----------+-------+--------+-----------+ + | /dev/bone/i2c/4 | bone_i2c_4 | I2C2 | *n/a* | MAIN_I2C3 | P9.21 | P9.22 | BONE-I2C4 | + +-----------------+--------------+-------+-------+-----------+-------+--------+-----------+ + +.. important:: + + In the case the same controller is used for 2 different bone bus nodes, usage of those nodes is mutually-exclusive. + +.. note:: + + The provided pre-compiled overlays enable the |I2C| bus driver only, not a specific device driver. Either a custom + overlay is required to load the device driver or usermode device driver loading can be performed, depending on + the driver. See :ref:`bone101_i2c` for information on loading |I2C| drivers from userspace. + +.. code-block:: c + :linenos: + :caption: Example device tree overlay to enable I2C driver + :name: bone_cape_spec_i2c_example + + /dts-v1/; + /plugin/; + + &bone_i2c_1 { + status = "okay"; + accel@1c { + compatible = "fsl,mma8453"; + reg = <0x1c>; + }; + } + +In :ref:`bone_cape_spec_i2c_example`, you can specify what driver you want to load and provide any properties it might need. + +* https://www.kernel.org/doc/html/v5.10/i2c/summary.html +* https://www.kernel.org/doc/html/v5.10/i2c/instantiating-devices.html#method-1-declare-the-i2c-devices-statically +* https://www.kernel.org/doc/Documentation/devicetree/bindings/i2c/ + +.. _bone-spi: SPI ------ - -SPI bone bus nodes allow creating compatible overlays for Black, AI and AI-64. For the definitions, you can see `bbai-bone-buses.dtsi#L406 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbai-bone-buses.dtsi#L406>`_ & `bbb-bone-buses.dtsi#L423 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbb-bone-buses.dtsi#L423>`_. - -.. table:: Bone bus SPI - - +--------------------+------------+--------+-------+------------+--------+--------+--------+---------------------------------------+--------------------------------------------------------------------------------------------------------------+ - | Bone bus | DT symbol | Black | AI | AI-64 | SDO | SDI | CLK | CS | Overlay | - +====================+============+========+=======+============+========+========+========+=======================================+==============================================================================================================+ - | /dev/bone/spi/0.x | bone_spi_0 | SPI0 | SPI2 | MAIN_SPI6 | P9.18 | P9.21 | P9.22 | - P9.17 (CS0) | - `BONE-SPI0_0.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_spi/src/arm/BONE-SPI0_0.dts>`_ | - | | | | | | | | | - P9.23 (CS1 - BBAI and BBAI64 only) | - `BONE-SPI0_0.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_spi/src/arm/BONE-SPI0_1.dts>`_ | - +--------------------+------------+--------+-------+------------+--------+--------+--------+---------------------------------------+--------------------------------------------------------------------------------------------------------------+ - | /dev/bone/spi/1.x | bone_spi_1 | SPI1 | SPI3 | MAIN_SPI7 | P9.30 | P9.29 | P9.31 | - P9.28 (CS0) | - `BONE-SPI0_0.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_spi/src/arm/BONE-SPI1_0.dts>`_ | - | | | | | | | | | - P9.42 (CS1) | - `BONE-SPI0_0.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_spi/src/arm/BONE-SPI1_1.dts>`_ | - +--------------------+------------+--------+-------+------------+--------+--------+--------+---------------------------------------+--------------------------------------------------------------------------------------------------------------+ +*** + +SPI bone bus nodes allow creating compatible overlays for Black, AI and AI-64. + +.. table:: SPI pins + + +---------------------------------------------------+ + | .. centered:: P9 | + +===================+=====+======+==================+ + | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+ + | 0 CS0 | 17 | 18 | 0 SDO | + +-------------------+-----+------+------------------+ + | | 19 | 20 | | + +-------------------+-----+------+------------------+ + | 0 SDI | 21 | 22 | 0 CLK | + +-------------------+-----+------+------------------+ + | 0 CS1 | 23 | 24 | | + +-------------------+-----+------+------------------+ + | | 25 | 26 | | + +-------------------+-----+------+------------------+ + | | 27 | 28 | 1 CS0 | + +-------------------+-----+------+------------------+ + | 1 SDI | 29 | 30 | 1 SDO | + +-------------------+-----+------+------------------+ + | 1 CLK | 31 | 32 | | + +-------------------+-----+------+------------------+ + | | 33 | 34 | | + +-------------------+-----+------+------------------+ + | | 35 | 36 | | + +-------------------+-----+------+------------------+ + | | 37 | 38 | | + +-------------------+-----+------+------------------+ + | | 39 | 40 | | + +-------------------+-----+------+------------------+ + | | 41 | 42 | 1 CS1 [2]_ | + +-------------------+-----+------+------------------+ + +.. table:: SPI port mapping + + +--------------------+------------+-------+------+-----------+-------+-------+-------+------------------+-------------+ + | Bone bus | DT symbol | Black | AI | AI-64 | SDO | SDI | CLK | CS | Overlay | + +====================+============+=======+======+===========+=======+=======+=======+==================+=============+ + | /dev/bone/spi/0.0 | bone_spi_0 | SPI0 | SPI2 | MAIN_SPI6 | P9.18 | P9.21 | P9.22 | P9.17 (CS0) | BONE-SPI0_0 | + +--------------------+ + + + + + + +------------------+-------------+ + | /dev/bone/spi/0.1 | | | | | | | | P9.23 (CS1) [2]_ | BONE-SPI0_1 | + +--------------------+------------+-------+------+-----------+-------+-------+-------+------------------+-------------+ + | /dev/bone/spi/1.0 | bone_spi_1 | SPI1 | SPI3 | MAIN_SPI7 | P9.30 | P9.29 | P9.31 | P9.28 (CS0) | BONE-SPI1_0 | + +--------------------+ + + + + + + +------------------+-------------+ + | /dev/bone/spi/1.1 | | | | | | | | P9.42 (CS1) | BONE-SPI1_1 | + +--------------------+------------+-------+------+-----------+-------+-------+-------+------------------+-------------+ + +.. [2] Only available on AI and AI-64 + +.. note:: + + The provided pre-compiled overlays enable the "spidev" driver using the "rohm,dh2228fv" compatible string. + See https://stackoverflow.com/questions/53634892/linux-spidev-why-it-shouldnt-be-directly-in-devicetree for + more background. A custom overlay is required to overload the compatible string to load a non-spidev driver. + +.. note:: #TODO# figure out if BONE-SPI0_0 and BONE-SPI0_1 can be loaded at the same time + +.. code-block:: c + :linenos: + :caption: Example device tree overlay to enable SPI driver + :name: bone_cape_spec_spi_example + + /dts-v1/; + /plugin/; + + &bone_spi_0 { + status = "okay"; + pressure@0 { + compatible = "bosch,bmp280"; + reg = <0>; /* CS0 */ + spi-max-frequency = <5000000>; + }; + } + +In :ref:`bone_cape_spec_spi_example`, you can specify what driver you want to load and provide any properties it might need. + +* https://www.kernel.org/doc/html/v5.10/spi/spi-summary.html +* https://www.kernel.org/doc/Documentation/devicetree/bindings/spi/ + +.. _bone-uart: UART ------ - -UART bone bus nodes allow creating compatible overlays for Black, AI and AI-64. For the definitions, you can see `bbai-bone-buses.dtsi#L367 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbai-bone-buses.dtsi#L367>`_ & `bbb-bone-buses.dtsi#L382 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbb-bone-buses.dtsi#L382>`_ - -.. table:: Bone bus UART - - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - | Bone bus | Black | AI | AI-64 | TX | RX | RTSn | CTSn | Overlays | - +===================+========+========+=======================+==================================+========+=============================================+=============================================+===========================================================================================================+ - | /dev/bone/uart/0 | UART0 | UART1 | MAIN_UART0 | .. centered:: NA (console debug header pins) | - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/uart/1 | UART1 | UART10 | MAIN_UART2 | P9.24 | P9.26 | P9.19 P8.4 (N/A on AM3358) | P9.20 P8.3 (N/A on AM3358) | `BONE-UART1.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_uart/src/arm/BONE-UART1.dts>`_ | - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/uart/2 | UART2 | UART3 | - | P9.21 | P9.22 | P8.38 (N/A on AM5729) | P8.37 (N/A on AM5729) | `BONE-UART2.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_uart/src/arm/BONE-UART2.dts>`_ | - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/uart/3 | UART3 | - | - | P9.42 | NA | - | - | `BONE-UART3.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_uart/src/arm/BONE-UART3.dts>`_ | - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/uart/4 | UART4 | UART5 | MAIN_UART0 (console) | P9.13 | P9.11 | P8.33 (N/A on AM5729) P8.6 (N/A on AM3358) | P8.35 (N/A on AM5729) P8.5 (N/A on AM3358) | `BONE-UART4.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_uart/src/arm/BONE-UART4.dts>`_ | - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - | /dev/bone/uart/5 | UART5 | UART8 | MAIN_UART5 | P8.37 | P8.38 | P8.32 | P8.31 | `BONE-UART5.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_uart/src/arm/BONE-UART5.dts>`_ | - +-------------------+--------+--------+-----------------------+----------------------------------+--------+---------------------------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------------------+ - +***** + +UART bone bus nodes allow creating compatible overlays for Black, AI and AI-64. + +.. table:: UART pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 4 RX [6]_ | 11 | 12 | | | | 11 | 12 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 4 TX [6]_ | 13 | 14 | | | | 13 | 14 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 15 | 16 | | | | 15 | 16 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 17 | 18 | | | | 17 | 18 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 19 | 20 | | | | 19 | 20 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 2 TX | 21 | 22 | 2 RX | | | 21 | 22 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 23 | 24 | 1 TX | | | 23 | 24 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 25 | 26 | 1 RX | | | 25 | 26 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 27 | 28 | | | | 27 | 28 | 6 RX | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 29 | 30 | | | 6 TX | 29 | 30 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 31 | 32 | | | | 31 | 32 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 33 | 34 | | | | 33 | 34 | 7 TX | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 35 | 36 | | | | 35 | 36 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 37 | 38 | | | 5 TX | 37 | 38 | 5 RX | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 39 | 40 | | | | 39 | 40 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 41 | 42 | 3 TX | | | 41 | 42 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + +.. important:: + + RTSn and CTSn mappings are not compatible across boards in the family and are therefore not part of the + cape specification. + +.. table:: UART port mapping + + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | Bone bus | DT symbol | Black | AI | AI-64 | TX | RX | Overlay | + +===================+==============+========+========+=================+========+========+============+ + | /dev/bone/uart/0 | bone_uart_0 | UART0 | UART1 | MAIN_UART0 | Console debug header pins | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/1 | bone_uart_1 | UART1 | UART10 | MAIN_UART2 | P9.24 | P9.26 | BONE-UART1 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/2 | bone_uart_2 | UART2 | UART3 | *n/a* | P9.21 | P9.22 | BONE-UART2 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/3 | bone_uart_3 | UART3 | *n/a* | *n/a* | P9.42 | *n/a* | BONE-UART3 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/4 | bone_uart_4 | UART4 | UART5 | MAIN_UART0 [6]_ | P9.13 | P9.11 | BONE-UART4 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/5 | bone_uart_5 | UART5 | UART8 | MAIN_UART5 | P8.37 | P8.38 | BONE-UART5 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/6 | bone_uart_6 | *n/a* | *n/a* | MAIN_UART8 | P8.29 | P8.28 | BONE-UART6 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + | /dev/bone/uart/7 | bone_uart_7 | *n/a* | *n/a* | MAIN_UART2 | P8.34 | P8.22 | BONE-UART7 | + +-------------------+--------------+--------+--------+-----------------+--------+--------+------------+ + +.. [6] This port is shared with the console UART on AI-64 + +.. important:: + + In the case the same controller is used for 2 different bone bus nodes, usage of those nodes is mutually-exclusive. + +.. _bone-can: CAN ------ - -CAN bone bus nodes allow creating compatible overlays for Black, AI and AI-64. For the definitions, you can see `bbai-bone-buses.dtsi#L440 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbai-bone-buses.dtsi#L440>`_ & `bbb-bone-buses.dtsi#L457 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbb-bone-buses.dtsi#L457>`_. - -.. table:: Bone bus CAN - - +------------------+--------+--------------------------+------------+--------+--------+--------------------------------------------------------------------------------------------------------+ - | Bone bus | Black | AI | AI-64 | TX | RX | Overlays | - +==================+========+==========================+============+========+========+========================================================================================================+ - | /dev/bone/can/0 | CAN0 | - | MAIN_MCAN0 | P9.20 | P9.19 | `BONE-CAN0.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_can/src/arm/BONE-CAN0.dts>`_ | - +------------------+--------+--------------------------+------------+--------+--------+--------------------------------------------------------------------------------------------------------+ - | /dev/bone/can/1 | CAN1 | CAN2 | MAIN_MCAN4 | P9.26 | P9.24 | `BONE-CAN1.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_can/src/arm/BONE-CAN1.dts>`_ | - +------------------+--------+--------------------------+------------+--------+--------+--------------------------------------------------------------------------------------------------------+ - | /dev/bone/can/2 | - | CAN1 (rev A2 and later) | TBD | P8.8 | P8.7 | | - +------------------+--------+--------------------------+------------+--------+--------+--------------------------------------------------------------------------------------------------------+ +***** + +CAN bone bus nodes allow creating compatible overlays for Black, AI and AI-64. + +.. table:: CAN pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 5 | 6 | | | 4 TX | 5 | 6 | 4 RX | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 7 | 8 | | | 2 RX | 7 | 8 | 2 TX | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 9 | 10 | | | 3 RX | 9 | 10 | 3 TX | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 11 | 12 | | | | 11 | 12 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 13 | 14 | | | | 13 | 14 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 15 | 16 | | | | 15 | 16 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 17 | 18 | | | | 17 | 18 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 0 RX | 19 | 20 | 0 TX | | | 19 | 20 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 21 | 22 | | | | 21 | 22 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 23 | 24 | 1 RX | | | 23 | 24 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | | 25 | 26 | 1 TX | | | 25 | 26 | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + +.. table:: CAN port mapping + + +------------------+--------+-----------+------------+--------+--------+-----------+ + | Bone bus | Black | AI | AI-64 | TX | RX | Overlays | + +==================+========+===========+============+========+========+===========+ + | /dev/bone/can/0 | CAN0 | *n/a* | MAIN_MCAN0 | P9.20 | P9.19 | BONE-CAN0 | + +------------------+--------+-----------+------------+--------+--------+-----------+ + | /dev/bone/can/1 | CAN1 | CAN2 | MAIN_MCAN4 | P9.26 | P9.24 | BONE-CAN1 | + +------------------+--------+-----------+------------+--------+--------+-----------+ + | /dev/bone/can/2 | *n/a* | CAN1 [1]_ | MAIN_MCAN5 | P8.08 | P8.07 | BONE-CAN2 | + +------------------+--------+-----------+------------+--------+--------+-----------+ + | /dev/bone/can/3 | *n/a* | *n/a* | MAIN_MCAN6 | P8.10 | P8.09 | BONE-CAN3 | + +------------------+--------+-----------+------------+--------+--------+-----------+ + | /dev/bone/can/4 | *n/a* | *n/a* | MAIN_MCAN7 | P8.05 | P8.06 | BONE-CAN4 | + +------------------+--------+-----------+------------+--------+--------+-----------+ + +.. [1] BeagleBone AI rev A2 and later only + + +.. _bone-analog: ADC -------- +******* * TODO: We need a udev rule to make sure the ADC shows up at /dev/bone/adc! There's nothing for sure that IIO devices will show up in the same place. * TODO: I think we can also create symlinks for each channel based on which device is there, such that we can do /dev/bone/adc/Px_y +.. table:: ADC pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | USB D+ | E1 | E2 | USB D- | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | E3 | E4 | GND | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 3V3 OUT | 3 | 4 | 3V3 OUT | | D M | 3 | 4 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V IN | 5 | 6 | 5V IN | | D M C4t | 5 | 6 | D M C4r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | 7 | 8 | 5V OUT | | D C2r | 7 | 8 | D C2t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | PWR BUT | 9 | 10 | RESET | | D C3r | 9 | 10 | D C3t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4r | 11 | 12 | D | | D P0o | 11 | 12 | D Q2a P0o | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4t | 13 | 14 | D E1a | | D E2b | 13 | 14 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D | 15 | 16 | D E1b | | D P0i | 15 | 16 | D P0i | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D I1c S00 | 17 | 18 | D I1d S0o | | D | 17 | 18 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | C0r D I2c | 19 | 20 | C0t D I2d | | D E2a | 19 | 20 | D M P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E0b S0i U2t | 21 | 22 | D E0a S0c U2r | | D M P1 | 21 | 22 | D M Q2b | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D S01 | 23 | 24 | C1r D I3c U1t | | D M | 23 | 24 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 25 | 26 | C1t D I3d U1r | | D M | 25 | 26 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 Q0b | 27 | 28 | D P0 S10 | | D L P1 | 27 | 28 | D L P1 U6r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1i P0 | 29 | 30 | D P0 S1o | | D L P1 U6t | 29 | 30 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1c P0 | 31 | 32 | ADC VDD | | D L | 31 | 32 | D L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 4 | 33 | 34 | ADC GND | | D L Q1b | 33 | 34 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 6 | 35 | 36 | |A| 5 | | D L Q1a | 35 | 36 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 2 | 37 | 38 | |A| 3 | | D L U5t | 37 | 38 | D L U5r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 0 | 39 | 40 | |A| 1 | | D L P1 | 39 | 40 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 41 | 42 | D Q0a S11 U3t P0 | | D L P1 | 41 | 42 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 43 | 44 | GND | | D L P1 | 43 | 44 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 45 | 46 | GND | | D E L P1 | 45 | 46 | D E L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + .. table:: Bone ADC +--------+-------------+------------------+------------------+ @@ -386,6 +762,64 @@ PWM PWM bone bus nodes allow creating compatible overlays for Black, AI and AI-64. For the definitions, you can see `bbai-bone-buses.dtsi#L415 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbai-bone-buses.dtsi#L415>`_ & `bbb-bone-buses.dtsi#L432 <https://github.com/lorforlinux/BeagleBoard-DeviceTrees/blob/97a6f0daa9eab09633a2064f68a53b107d6e3968/src/arm/bbb-bone-buses.dtsi#L432>`_ +.. table:: PWM pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | USB D+ | E1 | E2 | USB D- | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | E3 | E4 | GND | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 3V3 OUT | 3 | 4 | 3V3 OUT | | D M | 3 | 4 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V IN | 5 | 6 | 5V IN | | D M C4t | 5 | 6 | D M C4r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | 7 | 8 | 5V OUT | | D C2r | 7 | 8 | D C2t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | PWR BUT | 9 | 10 | RESET | | D C3r | 9 | 10 | D C3t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4r | 11 | 12 | D | | D P0o | 11 | 12 | D Q2a P0o | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4t | 13 | 14 | D E1a | | D E2b | 13 | 14 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D | 15 | 16 | D E1b | | D P0i | 15 | 16 | D P0i | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D I1c S00 | 17 | 18 | D I1d S0o | | D | 17 | 18 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | C0r D I2c | 19 | 20 | C0t D I2d | | D E2a | 19 | 20 | D M P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E0b S0i U2t | 21 | 22 | D E0a S0c U2r | | D M P1 | 21 | 22 | D M Q2b | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D S01 | 23 | 24 | C1r D I3c U1t | | D M | 23 | 24 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 25 | 26 | C1t D I3d U1r | | D M | 25 | 26 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 Q0b | 27 | 28 | D P0 S10 | | D L P1 | 27 | 28 | D L P1 U6r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1i P0 | 29 | 30 | D P0 S1o | | D L P1 U6t | 29 | 30 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1c P0 | 31 | 32 | ADC VDD | | D L | 31 | 32 | D L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 4 | 33 | 34 | ADC GND | | D L Q1b | 33 | 34 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 6 | 35 | 36 | |A| 5 | | D L Q1a | 35 | 36 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 2 | 37 | 38 | |A| 3 | | D L U5t | 37 | 38 | D L U5r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 0 | 39 | 40 | |A| 1 | | D L P1 | 39 | 40 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 41 | 42 | D Q0a S11 U3t P0 | | D L P1 | 41 | 42 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 43 | 44 | GND | | D L P1 | 43 | 44 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 45 | 46 | GND | | D E L P1 | 45 | 46 | D E L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + .. table:: Bone bus PWM +------------------+--------+-------+--------+--------+--------+--------------------------------------------------------------------------------------------------------+ @@ -421,12 +855,151 @@ TIMER PWM bone bus uses ti,omap-dmtimer-pwm driver, and timer nodes that allow c | /sys/bus/platform/devices/bone_timer_pwm_5/ | P9.22 | - | timer15 | `BONE-TIMER_PWM_5.dts <https://github.com/lorforlinux/bb.org-overlays/blob/bone_timer/src/arm/BONE-TIMER_PWM_5.dts>`_ | +----------------------------------------------+-------------+--------+----------+-------------------------------------------------------------------------------------------------------------------------+ +.. _bone-capture: + +eQEP +******** + +.. table:: eQEP pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | USB D+ | E1 | E2 | USB D- | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | E3 | E4 | GND | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 3V3 OUT | 3 | 4 | 3V3 OUT | | D M | 3 | 4 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V IN | 5 | 6 | 5V IN | | D M C4t | 5 | 6 | D M C4r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | 7 | 8 | 5V OUT | | D C2r | 7 | 8 | D C2t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | PWR BUT | 9 | 10 | RESET | | D C3r | 9 | 10 | D C3t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4r | 11 | 12 | D | | D P0o | 11 | 12 | D Q2a P0o | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4t | 13 | 14 | D E1a | | D E2b | 13 | 14 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D | 15 | 16 | D E1b | | D P0i | 15 | 16 | D P0i | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D I1c S00 | 17 | 18 | D I1d S0o | | D | 17 | 18 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | C0r D I2c | 19 | 20 | C0t D I2d | | D E2a | 19 | 20 | D M P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E0b S0i U2t | 21 | 22 | D E0a S0c U2r | | D M P1 | 21 | 22 | D M Q2b | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D S01 | 23 | 24 | C1r D I3c U1t | | D M | 23 | 24 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 25 | 26 | C1t D I3d U1r | | D M | 25 | 26 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 Q0b | 27 | 28 | D P0 S10 | | D L P1 | 27 | 28 | D L P1 U6r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1i P0 | 29 | 30 | D P0 S1o | | D L P1 U6t | 29 | 30 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1c P0 | 31 | 32 | ADC VDD | | D L | 31 | 32 | D L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 4 | 33 | 34 | ADC GND | | D L Q1b | 33 | 34 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 6 | 35 | 36 | |A| 5 | | D L Q1a | 35 | 36 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 2 | 37 | 38 | |A| 3 | | D L U5t | 37 | 38 | D L U5r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 0 | 39 | 40 | |A| 1 | | D L P1 | 39 | 40 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 41 | 42 | D Q0a S11 U3t P0 | | D L P1 | 41 | 42 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 43 | 44 | GND | | D L P1 | 43 | 44 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 45 | 46 | GND | | D E L P1 | 45 | 46 | D E L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + +On BeagleBone's without an eQEP on specific pins, consider using the PRU to perform a software counter function. + +.. table:: Bone eQEP + + +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ + | Bone bus | Black | AI | AI-64 | A | B | strobe | index | overlay | + +======================+========+========+========+========+========+===============================+===============================+==========+ + | /dev/bone/counter/0 | eQEP0 | eQEP2 | eQEP0 | P9.42 | P9.27 | - Black/AI-64: P9.25 | - Black/AI-64: P9.41 | | + | | | | | | | - AI: P8.06 | - AI: P8.05 | | + +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ + | /dev/bone/counter/1 | eQEP1 | eQEP0 | eQEP1 | P8.35 | P8.33 | - Black/AI-64: P8.32 | - Black/AI-64: P8.31 | | + | | | | | | | - AI: P9.21 | - AI: ‒ | | + +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ + | /dev/bone/counter/2 | eQEP2 | eQEP1 | ‒ | P8.12 | P8.22 | - Black: P8.15 | - Black: P8.16 | | + | | | | | | | - AI: P8.18 | - AI: P9.15 | | + +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ + + eCAP ------- #TODO: This doesn't include any abstraction yet. +.. table:: ECAP pins + + +---------------------------------------------------+-----+--------------------------------------+ + | .. centered:: P9 | | .. centered:: P8 | + +===================+=====+======+==================+=====+============+=====+======+============+ + | Functions | odd | even | Functions | | Functions | odd | even | Functions | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | USB D+ | E1 | E2 | USB D- | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | E3 | E4 | GND | | | | | | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 1 | 2 | GND | | GND | 1 | 2 | GND | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 3V3 OUT | 3 | 4 | 3V3 OUT | | D M | 3 | 4 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V IN | 5 | 6 | 5V IN | | D M C4t | 5 | 6 | D M C4r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | 5V OUT | 7 | 8 | 5V OUT | | D C2r | 7 | 8 | D C2t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | PWR BUT | 9 | 10 | RESET | | D C3r | 9 | 10 | D C3t | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4r | 11 | 12 | D | | D P0o | 11 | 12 | D Q2a P0o | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D U4t | 13 | 14 | D E1a | | D E2b | 13 | 14 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D | 15 | 16 | D E1b | | D P0i | 15 | 16 | D P0i | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D I1c S00 | 17 | 18 | D I1d S0o | | D | 17 | 18 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | C0r D I2c | 19 | 20 | C0t D I2d | | D E2a | 19 | 20 | D M P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E0b S0i U2t | 21 | 22 | D E0a S0c U2r | | D M P1 | 21 | 22 | D M Q2b | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D S01 | 23 | 24 | C1r D I3c U1t | | D M | 23 | 24 | D M | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 25 | 26 | C1t D I3d U1r | | D M | 25 | 26 | D | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 Q0b | 27 | 28 | D P0 S10 | | D L P1 | 27 | 28 | D L P1 U6r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1i P0 | 29 | 30 | D P0 S1o | | D L P1 U6t | 29 | 30 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D E S1c P0 | 31 | 32 | ADC VDD | | D L | 31 | 32 | D L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 4 | 33 | 34 | ADC GND | | D L Q1b | 33 | 34 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 6 | 35 | 36 | |A| 5 | | D L Q1a | 35 | 36 | D E L | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 2 | 37 | 38 | |A| 3 | | D L U5t | 37 | 38 | D L U5r | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | |A| 0 | 39 | 40 | |A| 1 | | D L P1 | 39 | 40 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | D P0 | 41 | 42 | D Q0a S11 U3t P0 | | D L P1 | 41 | 42 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 43 | 44 | GND | | D L P1 | 43 | 44 | D L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + | GND | 45 | 46 | GND | | D E L P1 | 45 | 46 | D E L P1 | + +-------------------+-----+------+------------------+-----+------------+-----+------+------------+ + .. table:: Black eCAP PWMs +-----------------------------------------------+-------------+--------------------+---------------------------------------------------------------------------------------------------------------------------------------------+ @@ -550,27 +1123,6 @@ LCD +--------+-----+----------+ -eQEP --------- - -On BeagleBone's without an eQEP on specific pins, consider using the PRU to perform a software counter function. - -.. table:: Bone eQEP - - +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ - | Bone bus | Black | AI | AI-64 | A | B | strobe | index | overlay | - +======================+========+========+========+========+========+===============================+===============================+==========+ - | /dev/bone/counter/0 | eQEP0 | eQEP2 | eQEP0 | P9.42 | P9.27 | - Black/AI-64: P9.25 | - Black/AI-64: P9.41 | | - | | | | | | | - AI: P8.06 | - AI: P8.05 | | - +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ - | /dev/bone/counter/1 | eQEP1 | eQEP0 | eQEP1 | P8.35 | P8.33 | - Black/AI-64: P8.32 | - Black/AI-64: P8.31 | | - | | | | | | | - AI: P9.21 | - AI: ‒ | | - +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ - | /dev/bone/counter/2 | eQEP2 | eQEP1 | ‒ | P8.12 | P8.22 | - Black: P8.15 | - Black: P8.16 | | - | | | | | | | - AI: P8.18 | - AI: P9.15 | | - +----------------------+--------+--------+--------+--------+--------+-------------------------------+-------------------------------+----------+ - - McASP --------- @@ -770,19 +1322,22 @@ TODO<br> For each of the pins with a GPIO, there should be a symlink that comes from the names * + +.. _bone-methodology: + Methodology ---------------- +*************** The methodology for applied in the kernel and software images to expose the software interfaces is to be documented here. The most fundamental elements are the device tree entries, including overlays, and udev rules. Device Trees -------------- +============= udev rules --------------- +========================= 10-of-symlink.rules -********************** +------------------------ .. code-block:: diff --git a/boards/images/beaglebone-ai-64-400x.webp b/boards/images/beaglebone-ai-64-400x.webp new file mode 100644 index 0000000000000000000000000000000000000000..d8b892ca8b97c91249a3540afa285d805d3ba311 Binary files /dev/null and b/boards/images/beaglebone-ai-64-400x.webp differ diff --git a/boards/index.rst b/boards/index.rst index 519d98e15e842634334989616ca0b7e6e3abae9b..26ab4b70e0db9259e636161fc1817a95d90a98bd 100644 --- a/boards/index.rst +++ b/boards/index.rst @@ -22,8 +22,13 @@ started. .. toctree:: :maxdepth: 1 + :hidden: /boards/beaglebone/index + /boards/beaglebone/black/index + /boards/beaglebone/blue/index + /boards/beaglebone/ai/index + /boards/beaglebone/ai-64/index /boards/pocketbeagle/original/index /boards/capes/index /boards/beagleconnect/index diff --git a/books/beaglebone-cookbook/01basics/basics.rst b/books/beaglebone-cookbook/01basics/basics.rst index 8ff3dddcc33c0c2d5b115ae55c5c7b99a5b02a4e..892733833516e138e21689c3c4f956cb3082e710 100644 --- a/books/beaglebone-cookbook/01basics/basics.rst +++ b/books/beaglebone-cookbook/01basics/basics.rst @@ -170,15 +170,13 @@ Connect your Bone to the Internet and log into it. From the command line run: .. code-block:: - bone$ git clone git@github.com:MarkAYoder/BoneCookbook.git - bone$ cd BoneCookbook/docs + bone$ git clone https://git.beagleboard.org/beagleboard/beaglebone-cookbook-code + bone$ cd beaglebone-cookbook-code bone$ ls You can look around from the command line, or explore from Visual Sudio Code. If you ar using VSC, go to the *File* menu and select *Open Folder ...* and -select BoneCookbook/docs. Then explore. You'll find there is a directory -for each chapter and most chapters have a *code* directory for the sample -scripts and a *figures* directory for the figures. +select beaglebone-cookbook-code. Then explore. .. _basics_wire_breadboard: diff --git a/books/beaglebone-cookbook/02sensors/code/GPS.js b/books/beaglebone-cookbook/02sensors/code/GPS.js deleted file mode 100755 index fd81970d017f8f6ce1f6bf7c6943a9f8ce4a02fb..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/GPS.js +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env node -// Install with: npm install nmea - -// Need to add exports.serialParsers = m.module.parsers; -// to the end of /usr/local/lib/node_modules/bonescript/serial.js - -var b = require('bonescript'); -var nmea = require('nmea'); - -var port = '/dev/ttyO4'; -var options = { - baudrate: 9600, - parser: b.serialParsers.readline("\n") -}; - -b.serialOpen(port, options, onSerial); - -function onSerial(x) { - if (x.err) { - console.log('***ERROR*** ' + JSON.stringify(x)); - } - if (x.event == 'open') { - console.log('***OPENED***'); - } - if (x.event == 'data') { - console.log(String(x.data)); - console.log(nmea.parse(x.data)); - } -} diff --git a/books/beaglebone-cookbook/02sensors/code/analogIn.js b/books/beaglebone-cookbook/02sensors/code/analogIn.js deleted file mode 100755 index 62136407952ab7a0aab8ec7ad935d62170f18506..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/analogIn.js +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env node -////////////////////////////////////// -// analogin.js -// Reads the analog value of the light sensor. -////////////////////////////////////// -const fs = require("fs"); -const ms = 500; // Time in milliseconds - -const pin = "2"; // light sensor, A2, P9_37 - -const IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw'; - -console.log('Hit ^C to stop'); - -// Read every 500ms -setInterval(readPin, ms); - -function readPin() { - var data = fs.readFileSync(IIOPATH).slice(0, -1); - console.log('data = ' + data); - } -// Bone | Pocket | AIN -// ----- | ------ | --- -// P9_39 | P1_19 | 0 -// P9_40 | P1_21 | 1 -// P9_37 | P1_23 | 2 -// P9_38 | P1_25 | 3 -// P9_33 | P1_27 | 4 -// P9_36 | P2_35 | 5 -// P9_35 | P1_02 | 6 diff --git a/books/beaglebone-cookbook/02sensors/code/analogIn.py b/books/beaglebone-cookbook/02sensors/code/analogIn.py deleted file mode 100644 index c62abd1b71e7f29cc986667382f255d7703a810a..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/analogIn.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 -#////////////////////////////////////// -# analogin.py -# Reads the analog value of the light sensor. -#////////////////////////////////////// -import time -import os - -pin = "2" # light sensor, A2, P9_37 - -IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw' - -print('Hit ^C to stop') - -f = open(IIOPATH, "r") - -while True: - f.seek(0) - x = float(f.read())/4096 - print('{}: {:.1f}%, {:.3f} V'.format(pin, 100*x, 1.8*x), end = '\r') - time.sleep(0.1) - -# // Bone | Pocket | AIN -# // ----- | ------ | --- -# // P9_39 | P1_19 | 0 -# // P9_40 | P1_21 | 1 -# // P9_37 | P1_23 | 2 -# // P9_38 | P1_25 | 3 -# // P9_33 | P1_27 | 4 -# // P9_36 | P2_35 | 5 -# // P9_35 | P1_02 | 6 diff --git a/books/beaglebone-cookbook/02sensors/code/audio.asoundrc b/books/beaglebone-cookbook/02sensors/code/audio.asoundrc deleted file mode 100644 index 8fcc9b97184440ddfa39d75341e1bf4ae7ec80c2..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/audio.asoundrc +++ /dev/null @@ -1,10 +0,0 @@ -pcm.!default { - type plug - slave { - pcm "hw:1,0" - } -} -ctl.!default { - type hw - card 1 -} diff --git a/books/beaglebone-cookbook/02sensors/code/audio.js b/books/beaglebone-cookbook/02sensors/code/audio.js deleted file mode 100755 index eeca6ca30c36dd904a5c0d1742e4fba284646400..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/audio.js +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/node -// 'childprocess' help at: -// http://nodejs.org/api/child_process.html\ -// #child_process_child_process_spawn_command_args_options -"use strict"; - -var b = require('bonescript'), - spawn = require('child_process').spawn; - -var audioRate = 48000, - bufferSize = 4800, - format = "S16_LE"; // 16-bit signed, little endian - -var audioIn = spawn( - "/usr/bin/arecord", - [ - "-c2", "-r"+audioRate, "-f"+format, "-traw", - "--buffer-size="+bufferSize, "--period-size="+bufferSize, "-N" - ] - ); - - var audioOut = spawn( - "/usr/bin/aplay", - [ - "-c2", "-r"+audioRate, "-f"+format, "-traw", - "--buffer-size="+bufferSize, "--period-size="+bufferSize, "-N" - ] - ); - - audioIn.stdout.on('data', function(data) { - audioOut.stdin.write(data); - }); - - audioIn.on('close', function(code) { - if(code !== 0) { - console.log('arecord process exited with code: ' + code); - audioOut.stdin.end(); - } - }) - - audioOut.on('close', function(code) { - if(code !== 0) { - console.log('aplay process exited with code: ' + code); - } - }) - \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/bone_eqep2b.dts b/books/beaglebone-cookbook/02sensors/code/bone_eqep2b.dts deleted file mode 100644 index 036cdcd3204cc182309060d40560daae2db2be0f..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/bone_eqep2b.dts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2013 Nathaniel R. Lewis - http://nathanielrlewis.com/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Enable eQEP2 on the Beaglebone White and Black - * These pins don't conflict with the HDMI - */ -/dts-v1/; -/plugin/; - -/ { - compatible = "ti,beaglebone", "ti,beaglebone-black"; - - /* identification */ - part-number = "bone_eqep2"; - version = "00A0"; - - fragment@0 { - target = <&am33xx_pinmux>; - __overlay__ { - pinctrl_eqep2: pinctrl_eqep2_pins { - pinctrl-single,pins = < - 0x038 0x24 /* P8_16 = GPIO2_12 = EQEP2_index, MODE4 */ - 0x03C 0x24 /* P8_15 = GPIO2_13 = EQEP2_strobe, MODE4 */ - 0x030 0x34 /* P8_12 = GPIO2_10 = EQEP2A_in, MODE4 */ - 0x034 0x34 /* P8_11 = GPIO2_11 = EQEP2B_in, MODE4 */ - >; - }; - }; - }; - - fragment@1 { - target = <&epwmss2>; - __overlay__ { - status = "okay"; - }; - }; - - fragment@2 { - target = <&eqep2>; - __overlay__ { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_eqep2>; - count_mode = < 0 >; - /* 0 - Quadrature mode, normal 90 phase offset cha & chb. - 1 - Direction mode. cha input = clock, chb input = direction */ - swap_inputs = < 0 >; /* Are chan A & chan B swapped? (0-no,1-yes) */ - invert_qa = < 1 >; /* Should we invert the channel A input? */ - invert_qb = < 1 >; /* Should we invert the channel B input? - These are inverted because my encoder outputs drive transistors - that pull down the pins */ - invert_qi = < 0 >; /* Should we invert the index input? */ - invert_qs = < 0 >; /* Should we invert the strobe input? */ - - status = "okay"; - }; - }; -}; diff --git a/books/beaglebone-cookbook/02sensors/code/encoder.js b/books/beaglebone-cookbook/02sensors/code/encoder.js deleted file mode 100644 index 7ad2f4d4b12beab7812a1e62b6f70c3836226d82..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/encoder.js +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env node -// Test this -var b = require('bonescript'); -var encoder = ''; - -function printStatus(x) { - console.log('x.value = ' + x.value); - console.log('x.err = ' + x.err); -} - -function onEncoderReady(e) { - if(e.event == 'return') { - b.encoderRead(encoder, printStatus); - } -} - -b.encoderOpen(encoder, {}, onEncoderReady); diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/.gitignore b/books/beaglebone-cookbook/02sensors/code/gpiod/.gitignore deleted file mode 100644 index fecb0575772aafdbd64d7b707fd034a19a7a56e8..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -toggle1 -toggle2 -get -getset -getsetEvent -toggleLED diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/Makefile b/books/beaglebone-cookbook/02sensors/code/gpiod/Makefile deleted file mode 100644 index b5267491fc4e67162a3dd81626851c5cd7badf6a..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# -# Programs -# -all: toggle1 toggle2 get getset getsetEvent toggleLED - -toggle1: toggle1.c - $(CC) $(LDFLAGS) -o $@ $^ -lgpiod - -toggle2: toggle2.c - $(CC) $(LDFLAGS) -o $@ $^ -lgpiod - -get: get.c - $(CC) $(LDFLAGS) -o $@ $^ -lgpiod - -getset: getset.c - $(CC) $(LDFLAGS) -o $@ $^ -lgpiod - -getsetEvent: getsetEvent.c - $(CC) $(LDFLAGS) -o $@ $^ -lgpiod - -toggleLED: toggleLED.c - $(CC) $(LDFLAGS) -o $@ $^ -lgpiod - -# -# Objects -# - -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - rm toggle1 toggle2 get getset getsetEvent toggleLED diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/ReadMe.md b/books/beaglebone-cookbook/02sensors/code/gpiod/ReadMe.md deleted file mode 100644 index 4a8d2212ebb69178a26786709c41ea4a1cb5c25d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/ReadMe.md +++ /dev/null @@ -1,23 +0,0 @@ -libgpiod is a new C library and tools for interacting with the linux GPIO -character device. -Detailed information is -[here](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README) -and [Adafruit](https://blog.adafruit.com/2018/11/26/sysfs-is-dead-long-live-libgpiod-libgpiod-for-linux-circuitpython/) -also has information. - -One of the advantages of gpiod is that it can toggle multiple bits on the same -gpio chip at the same time. The toggle2 examples show how it's done. - -The directory contains examples of using gpiod with **C** and **python** to read/write -a gpio pin. - -File | Description ----- | ----------- -[toggle1](toggle1.c) | Toggles one pin as fast as possible. (300KHz in C, 57KHz in python) -[toggle2](toggle2.c) | Toggles two pins as fast as possible. (280KHz in C, 55KHz in python) -[get](get.c) | Reads an input pin and prints its value. -[getset](getset.c) | Reads an input pin and writes its value to an output pin. (5us delay in C, 20 us Delay in python) -[getsetEvent](getset.c) | Like **getset**, but uses events. (40 us delay in C, 75 us delay in python) -[toggleLED](toggleLED.c) | Toggles the four built in USR LEDs. - -> Tip: Use **gpioinfo** to lookup chip and line numbers for various pins. diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/aggregatorSetup.sh b/books/beaglebone-cookbook/02sensors/code/gpiod/aggregatorSetup.sh deleted file mode 100644 index edc4d387417a72741922ddf2daa48d44fcb25163..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/aggregatorSetup.sh +++ /dev/null @@ -1,47 +0,0 @@ -# See: https://elinux.org/EBC_Exercise_51_GPIO_aggregator - -# Insert the module -sudo modprobe gpio-aggregator -# Go to the aggregator -cd /sys/bus/platform/drivers/gpio-aggregator -# Fix the modes -sudo chgrp gpio * -sudo chmod g+w * -# See what's there before adding a new chip -gpiodetect -# gpiochip0 [gpio-0-31] (32 lines) -# gpiochip1 [gpio-32-63] (32 lines) -# gpiochip2 [gpio-64-95] (32 lines) -# gpiochip3 [gpio-96-127] (32 lines) - -# Add a new chip mapping P9_14, P9_16, P9_18 and P9_22 -gpioinfo | grep -e chip -e P9_1[468] -e P9_22 -# gpiochip0 - 32 lines: -# line 2: "P9_22 [spi0_sclk]" "gpio-aggregator.0" input active-high [used] -# line 4: "P9_18 [spi0_d1]" "gpio-aggregator.0" output active-high [used] -# gpiochip1 - 32 lines: -# line 18: "P9_14 [ehrpwm1a]" "gpio-aggregator.0" output active-high [used] -# line 19: "P9_16 [ehrpwm1b]" "gpio-aggregator.0" input active-high [used] -# gpiochip2 - 32 lines: -# gpiochip3 - 32 lines: - -echo "gpio-32-63 18,19 gpio-0-31 4,2" > new_device -# Check to see if they are there -gpiodetect -# gpiochip0 [gpio-0-31] (32 lines) -# gpiochip1 [gpio-32-63] (32 lines) -# gpiochip2 [gpio-64-95] (32 lines) -# gpiochip3 [gpio-96-127] (32 lines) -# gpiochip4 [gpio-aggregator.0] (4 lines) - -gpioinfo | tail -6 -# line 31: "NC" unused input active-high -# gpiochip4 - 4 lines: -# line 0: unnamed unused output active-high -# line 1: unnamed unused input active-high -# line 2: unnamed unused input active-high -# line 3: unnamed unused output active-high - -# Turn them all on, then off -gpioset gpiochip4 0=1 1=1 2=1 3=1 -gpioset gpiochip4 0=0 1=0 2=0 3=0 diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/bulk_blink.py b/books/beaglebone-cookbook/02sensors/code/gpiod/bulk_blink.py deleted file mode 100755 index 7599325cf76c02fd1debb7541e4e6e2ecea1fecf..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/bulk_blink.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# bulk_blink.py -# Toggles given pins as fast as it can. -# Given pins must be on the same gpiochip -# P9_14 is line 18 P9_16 is line 19. -# Run gpioinfo to see which pins are where. -# Wiring: Attach an oscilloscope to P9_14 and P9_16 to see the squarewave or -# uncomment the sleep and attach an LED. -# Setup: sudo apt update; pip install gpiod -# See: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/examples -# ////////////////////////////////////// -import sys -import time -import gpiod - -try: - if len(sys.argv) > 2: - LED_CHIP = sys.argv[1] - LED_LINE_OFFSETS = [] - for i in range(len(sys.argv) - 2): - LED_LINE_OFFSETS.append(int(sys.argv[i + 2])) - else: - raise Exception() -# pylint: disable=broad-except -except Exception: - print( - "Usage:" - + " python3 -m gpiod.test.bulk_blink <chip> <line offset1>" - + " [<line offset2> ...]" - ) - sys.exit() - -chip = gpiod.Chip(LED_CHIP) -lines = chip.get_lines(LED_LINE_OFFSETS) - -lines.request(consumer='Bulk Blink', type=gpiod.LINE_REQ_DIR_OUT) - -off = [0] * len(LED_LINE_OFFSETS) -on = [1] * len(LED_LINE_OFFSETS) - -while True: - lines.set_values(off) - time.sleep(0.25) - lines.set_values(on) - time.sleep(0.25) diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/get.c b/books/beaglebone-cookbook/02sensors/code/gpiod/get.c deleted file mode 100644 index 4aeefe0435631e6c2c863216fef11f1870a69f56..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/get.c +++ /dev/null @@ -1,52 +0,0 @@ -// ////////////////////////////////////// -// get.c -// Get the value of P8_13. P8_13 is line 23 on chip 0. -// Wiring: Attach a switch to P8_13 and 3.3V -// Setup: sudo apt update; sudo apt install libgpiod-dev -// See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -// ////////////////////////////////////// -#include <gpiod.h> -#include <stdio.h> -#include <unistd.h> - -#define CONSUMER "Consumer" - -int main(int argc, char **argv) -{ - int chipnumber = 0; - unsigned int line_num = 23; // GPIO Pin P8_13 - struct gpiod_chip *chip; - struct gpiod_line *line; - int i, ret; - - chip = gpiod_chip_open_by_number(chipnumber); - if (!chip) { - perror("Open chip failed\n"); - goto end; - } - - line = gpiod_chip_get_line(chip, line_num); - if (!line) { - perror("Get line failed\n"); - goto close_chip; - } - - ret = gpiod_line_request_input(line, CONSUMER); - if (ret < 0) { - perror("Request line as intput failed\n"); - goto release_line; - } - - /* Get */ - while(1) { - printf("%d\r", gpiod_line_get_value(line)); - usleep(1000); - } - -release_line: - gpiod_line_release(line); -close_chip: - gpiod_chip_close(chip); -end: - return 0; -} diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/get.py b/books/beaglebone-cookbook/02sensors/code/gpiod/get.py deleted file mode 100755 index 05820068f6cbc9e2cf504063ddf19f0da11fe163..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/get.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# get.py -# Get the value of P8_13. P8_13 is line 23 on chip 0. -# Wiring: Attach a switch to P8_13 and 3.3V -# Setup: sudo apt uupdate; sudo apt install libgpiod-dev -# See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -# ////////////////////////////////////// - -import gpiod -import sys - -if len(sys.argv) < 3: # Use P8_13 if not given - CHIP='0' - offsets=[13] -else: - CHIP=sys.argv[1] - offsets = [] - for off in sys.argv[2:]: - offsets.append(int(off)) - -chip = gpiod.Chip(CHIP) - -lines = chip.get_lines(offsets) -lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_DIR_IN) - -print("Hit ^C to stop") - -while True: - vals = lines.get_values() - - for val in vals: - print(val, end=' ') - print('\r', end='') diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/get.sh b/books/beaglebone-cookbook/02sensors/code/gpiod/get.sh deleted file mode 100755 index 54cc18ba6de10b802529c8e4ddb9c2f8bb05f573..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/get.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# Reads P8_13 via gpiod. P8_13 is chip 0 line 23 - -echo Hit ^c to stop - -while true; do - gpioget 0 23 | tr \\n \\r -done \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/getset.c b/books/beaglebone-cookbook/02sensors/code/gpiod/getset.c deleted file mode 100644 index 207c7689db6140c5edab7695daa011f266573ac4..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/getset.c +++ /dev/null @@ -1,70 +0,0 @@ -// ////////////////////////////////////// -// getset.c -// Get the value of P8_16 and write it to P9_14. -// P8_16 is line 14 on chip 1. P9_14 is line 18 of chip 1. -// Wiring: Attach a switch to P8_16 and 3.3V and an LED to P9_14. -// Setup: sudo apt uupdate; sudo apt install libgpiod-dev -// See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -// ////////////////////////////////////// -#include <gpiod.h> -#include <stdio.h> -#include <unistd.h> - -#define CONSUMER "Consumer" - -int main(int argc, char **argv) -{ - int chipnumber = 1; - unsigned int getline_num = 14; // GPIO Pin P8_16 - unsigned int setline_num = 18; // GPIO Pin P9_14 - unsigned int val; - struct gpiod_chip *chip; - struct gpiod_line *getline, *setline; - int i, ret; - - chip = gpiod_chip_open_by_number(chipnumber); - if (!chip) { - perror("Open chip failed\n"); - goto end; - } - - getline = gpiod_chip_get_line(chip, getline_num); - if (!getline) { - perror("Get line failed\n"); - goto close_chip; - } - - setline = gpiod_chip_get_line(chip, setline_num); - if (!setline) { - perror("Set line failed\n"); - goto close_chip; - } - - ret = gpiod_line_request_input(getline, CONSUMER); - if (ret < 0) { - perror("Request line as input failed\n"); - goto release_line; - } - - ret = gpiod_line_request_output(setline, CONSUMER, 0); - if (ret < 0) { - perror("Request line as output failed\n"); - goto release_line; - } - - /* Get */ - while(1) { - val = gpiod_line_get_value(getline); - gpiod_line_set_value(setline, val); - // printf("%d\r", val); - // usleep(1000); - } - -release_line: - gpiod_line_release(getline); - gpiod_line_release(setline); -close_chip: - gpiod_chip_close(chip); -end: - return 0; -} diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/getset.py b/books/beaglebone-cookbook/02sensors/code/gpiod/getset.py deleted file mode 100755 index 335807a91aaf8e611254886617834ffb920115e0..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/getset.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# getset.py -# Get the value of P8_16 and write it to P9_14. -# P8_16 is line 14 on chip 1. P9_14 is line 18 of chip 1. -# Wiring: Attach a switch to P8_16 and 3.3V and an LED to P9_14. -# Setup: sudo apt uupdate; sudo apt install libgpiod-dev -# See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -# ////////////////////////////////////// -# Based on https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/examples - -import gpiod -import sys - -CONSUMER='getset' -CHIP='1' -getoffsets=[14] # P8_16 -setoffests=[18] # P9_14 - -chip = gpiod.Chip(CHIP) - -getlines = chip.get_lines(getoffsets) -getlines.request(consumer=CONSUMER, type=gpiod.LINE_REQ_DIR_IN) - -setlines = chip.get_lines(setoffests) -setlines.request(consumer=CONSUMER, type=gpiod.LINE_REQ_DIR_OUT) - -print("Hit ^C to stop") - -while True: - vals = getlines.get_values() - - # for val in vals: - # print(val, end=' ') - # print('\r', end='') - - setlines.set_values(vals) diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/getsetEvent.c b/books/beaglebone-cookbook/02sensors/code/gpiod/getsetEvent.c deleted file mode 100644 index b49ab2dfea3e7b723ded6461aa65f22a5ebabcf0..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/getsetEvent.c +++ /dev/null @@ -1,85 +0,0 @@ -// ////////////////////////////////////// -// getsetEvent.c -// Like setset.c, but uses events -// Get the value of P8_16 and write it to P9_14. -// P8_16 is line 14 on chip 1. P9_14 is line 18 of chip 1. -// Wiring: Attach a switch to P8_16 and 3.3V and an LED to P9_14. -// Setup: sudo apt uupdate; sudo apt install libgpiod-dev -// See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -// ////////////////////////////////////// -#include <gpiod.h> -#include <stdio.h> -#include <unistd.h> - -#define CONSUMER "Consumer" - -int main(int argc, char **argv) -{ - int chipnumber = 1; - struct timespec ts = { 0, 1000000 }; // 1s Timeout for event - struct gpiod_line_event event; - unsigned int getline_num = 14; // GPIO Pin P8_16 - unsigned int setline_num = 18; // GPIO Pin P9_14 - unsigned int val; - struct gpiod_chip *chip; - struct gpiod_line *getline, *setline; - int i, ret; - - chip = gpiod_chip_open_by_number(chipnumber); - if (!chip) { - perror("Open chip failed\n"); - goto end; - } - - getline = gpiod_chip_get_line(chip, getline_num); - if (!getline) { - perror("Get line failed\n"); - goto close_chip; - } - - setline = gpiod_chip_get_line(chip, setline_num); - if (!setline) { - perror("Set line failed\n"); - goto close_chip; - } - - ret = gpiod_line_request_both_edges_events(getline, CONSUMER); - if (ret < 0) { - perror("Request line as input failed\n"); - goto release_line; - } - - ret = gpiod_line_request_output(setline, CONSUMER, 0); - if (ret < 0) { - perror("Request line as output failed\n"); - goto release_line; - } - - /* Get */ - while(1) { - do { - // printf("waiting...\n"); - ret = gpiod_line_event_wait(getline, &ts); - } while (ret <= 0); - - // I'm getting a Segment failt. event isn't correct. - // ret = gpiod_line_event_read(getline, &event); - // printf("ret: %d, event: %d\n", ret, event); - // if (!ret) - // printf("event: %s timestamp: [%8ld.%09ld]\n", - // event.event_type, event.ts.tv_sec, event.ts.tv_nsec); - - val = gpiod_line_get_value(getline); - gpiod_line_set_value(setline, val); - // printf("%d\n", val); - // usleep(1000); - } - -release_line: - gpiod_line_release(getline); - gpiod_line_release(setline); -close_chip: - gpiod_chip_close(chip); -end: - return 0; -} diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/getsetEvent.py b/books/beaglebone-cookbook/02sensors/code/gpiod/getsetEvent.py deleted file mode 100755 index 9240220fd5b4ab6bda1cb172c7ad0c6dc6bdc8d0..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/getsetEvent.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# getsetEvent.py -# Like getset.py but uses events. -# Get the value of P8_16 and write it to P9_14. -# P8_16 is line 14 on chip 1. P9_14 is line 18 of chip 1. -# Wiring: Attach a switch to P8_16 and 3.3V and an LED to P9_14. -# Setup: sudo apt uupdate; sudo apt install libgpiod-dev -# See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -# ////////////////////////////////////// -# Based on https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/examples - -import gpiod -import sys - -CONSUMER='getset' -CHIP='1' -getoffsets=[14] # P8_16 -setoffests=[18] # P9_14 - -def print_event(event): - if event.type == gpiod.LineEvent.RISING_EDGE: - evstr = ' RISING EDGE' - elif event.type == gpiod.LineEvent.FALLING_EDGE: - evstr = 'FALLING EDGE' - else: - raise TypeError('Invalid event type') - - print('event: {} offset: {} timestamp: [{}.{}]'.format(evstr, - event.source.offset(), - event.sec, event.nsec)) - -chip = gpiod.Chip(CHIP) - -getlines = chip.get_lines(getoffsets) -getlines.request(consumer=CONSUMER, type=gpiod.LINE_REQ_EV_BOTH_EDGES) - -setlines = chip.get_lines(setoffests) -setlines.request(consumer=CONSUMER, type=gpiod.LINE_REQ_DIR_OUT) - -print("Hit ^C to stop") - -while True: - ev_lines = getlines.event_wait(sec=1) - if ev_lines: - for line in ev_lines: - event = line.event_read() - print_event(event) - vals = getlines.get_values() - - # for val in vals: - # print(val, end=' ') - # print('\r', end='') - - setlines.set_values(vals) diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.c b/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.c deleted file mode 100644 index 1ff8c1cb7cac717f0f094fa2ae481a0291492fde..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.c +++ /dev/null @@ -1,61 +0,0 @@ -// ////////////////////////////////////// -// toggle1.c -// Toggles the P9_14 pin as fast as it can. P9_14 is line 18 on chip 1. -// Wiring: Attach an oscilloscope to P9_14 to see the squarewave or -// uncomment the usleep and attach an LED. -// Setup: sudo apt update; sudo apt install libgpiod-dev -// See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -// ////////////////////////////////////// -#include <gpiod.h> -#include <stdio.h> -#include <unistd.h> - -#define CONSUMER "Consumer" - -int main(int argc, char **argv) -{ - int chipnumber = 1; - unsigned int line_num = 18; // GPIO Pin P9_14 - unsigned int val; - struct gpiod_chip *chip; - struct gpiod_line *line; - int i, ret; - - chip = gpiod_chip_open_by_number(chipnumber); - if (!chip) { - perror("Open chip failed\n"); - goto end; - } - - line = gpiod_chip_get_line(chip, line_num); - if (!line) { - perror("Get line failed\n"); - goto close_chip; - } - - ret = gpiod_line_request_output(line, CONSUMER, 0); - if (ret < 0) { - perror("Request line as output failed\n"); - goto release_line; - } - - /* Blink */ - val = 0; - while(1) { - ret = gpiod_line_set_value(line, val); - if (ret < 0) { - perror("Set line output failed\n"); - goto release_line; - } - // printf("Output %u on line #%u\n", val, line_num); - usleep(100000); // Number of microseconds to sleep - val = !val; - } - -release_line: - gpiod_line_release(line); -close_chip: - gpiod_chip_close(chip); -end: - return 0; -} diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.py b/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.py deleted file mode 100755 index d8b6d5d4edef7531771c3ab947a5766fd9c608f0..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# toggle1.py -# Toggles the P9_14 pin as fast as it can. P9_14 is line 18 on chip 1. -# Wiring: Attach an oscilloscope to P9_14 to see the squarewave or -# uncomment the sleep and attach an LED. -# Setup: sudo apt update; pip install gpiod -# See: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/examples -# ////////////////////////////////////// - -import gpiod -import time - -LED_CHIP = 'gpiochip1' -LED_LINE_OFFSET = [18] # P9_14 - -chip = gpiod.Chip(LED_CHIP) - -lines = chip.get_lines(LED_LINE_OFFSET) -lines.request(consumer='blink', type=gpiod.LINE_REQ_DIR_OUT) - -while True: - lines.set_values([0]) - time.sleep(0.1) - lines.set_values([1]) - time.sleep(0.1) - \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.sh b/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.sh deleted file mode 100755 index b27f9824818f1f17446b7a1512b9cd99fb93ddbd..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle1.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# gpio chip=1 line 18=P9_14 line19=P9_16 - -while true; do - gpioset 1 18=0 19=0 - gpioset 1 18=1 19=1 -done \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle2.c b/books/beaglebone-cookbook/02sensors/code/gpiod/toggle2.c deleted file mode 100644 index ad6b77f05e4a00cea320324465a3dc2c6e944c56..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle2.c +++ /dev/null @@ -1,66 +0,0 @@ -// ////////////////////////////////////// -// toggle2.c -// Toggles P9_14 and P9_16 pins as fast as it can. -// P9_14 and P9_16 are both on chip 1 so they can be toggled together. -// P9_14 is line 18 P9_16 is line 18. -// Wiring: Attach an oscilloscope to P9_14 and P9_16 to see the squarewave or -// uncomment the usleep and attach an LED. -// Setup: sudo apt uupdate; sudo apt install libgpiod-dev -// See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -// ////////////////////////////////////// -#include <gpiod.h> -#include <stdio.h> -#include <unistd.h> - -#define CONSUMER "Consumer" -#define NUMLINES 2 - -int main(int argc, char **argv) -{ - int chipnumber = 1; - unsigned int line_num[NUMLINES] = {18, 19}; // GPIO Pins P9_14 and P9_16 - unsigned int val; - struct gpiod_chip *chip; - struct gpiod_line_bulk line[NUMLINES]; - int i, ret; - - chip = gpiod_chip_open_by_number(chipnumber); - if (!chip) { - perror("Open chip failed\n"); - goto end; - } - - int err = gpiod_chip_get_lines(chip, line_num, NUMLINES, line); - if (err) { - perror("Get line failed\n"); - goto close_chip; - } - - int off_values[NUMLINES] = {0, 0}; - int on_values[NUMLINES] = {1, 1}; - ret = gpiod_line_request_bulk_output(line, CONSUMER, off_values); - if (ret < 0) { - perror("Request line as output failed\n"); - goto release_line; - } - - /* Blink */ - val = 0; - while(1) { - ret = gpiod_line_set_value_bulk(line, val ? on_values : off_values); - if (ret < 0) { - perror("Set line output failed\n"); - goto release_line; - } - // printf("Output %u on line #%u\n", val, line_num); - usleep(100000); - val = !val; - } - -release_line: - gpiod_line_release_bulk(line); -close_chip: - gpiod_chip_close(chip); -end: - return 0; -} diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle2.py b/books/beaglebone-cookbook/02sensors/code/gpiod/toggle2.py deleted file mode 100755 index 1e7badc26164badc1a2a9c86bfc1dd91e447aa53..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggle2.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# toggle2.py -# Toggles P9_14 and P9_16 pins as fast as it can. -# P9_14 and P9_16 are both on chip 1 so they can be toggled together. -# P9_14 is line 18 P9_16 is line 19. -# Wiring: Attach an oscilloscope to P9_14 and P9_16 to see the squarewave or -# uncomment the sleep and attach an LED. -# Setup: sudo apt update; pip install gpiod -# See: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/examples -# ////////////////////////////////////// - -import gpiod -import time - -LED_CHIP = 'gpiochip1' -LED_LINE_OFFSET = [18, 19] # P9_14 and P9_16 - -chip = gpiod.Chip(LED_CHIP) - -lines = chip.get_lines(LED_LINE_OFFSET) -lines.request(consumer='blink', type=gpiod.LINE_REQ_DIR_OUT) - -while True: - lines.set_values([0, 0]) - time.sleep(0.1) - lines.set_values([1, 1]) - time.sleep(0.1) diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggleLED.c b/books/beaglebone-cookbook/02sensors/code/gpiod/toggleLED.c deleted file mode 100644 index cc79b49ba5867ef6601bb4ef6775bc0d3dafb532..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggleLED.c +++ /dev/null @@ -1,66 +0,0 @@ -// ////////////////////////////////////// -// toggle2.c -// Toggles P9_14 and P9_16 pins as fast as it can. -// P9_14 and P9_16 are both on chip 1 so they can be toggled together. -// P9_14 is line 18 P9_16 is line 18. -// Wiring: Attach an oscilloscope to P9_14 and P9_16 to see the squarewave or -// uncomment the usleep and attach an LED. -// Setup: sudo apt uupdate; sudo apt install libgpiod-dev -// See: https://github.com/starnight/libgpiod-example/blob/master/libgpiod-led/main.c -// ////////////////////////////////////// -#include <gpiod.h> -#include <stdio.h> -#include <unistd.h> - -#define CONSUMER "Consumer" -#define NUMLINES 4 - -int main(int argc, char **argv) -{ - int chipnumber = 1; - unsigned int line_num[NUMLINES] = {21, 22, 23, 24}; // USR LEDS 1-4 - unsigned int val; - struct gpiod_chip *chip; - struct gpiod_line_bulk line[NUMLINES]; - int i, ret; - - chip = gpiod_chip_open_by_number(chipnumber); - if (!chip) { - perror("Open chip failed\n"); - goto end; - } - - int err = gpiod_chip_get_lines(chip, line_num, NUMLINES, line); - if (err) { - perror("Get line failed\n"); - goto close_chip; - } - - int off_values[NUMLINES] = {0, 0, 0, 0}; - int on_values[NUMLINES] = {1, 1, 1 ,1} ; - ret = gpiod_line_request_bulk_output(line, CONSUMER, off_values); - if (ret < 0) { - perror("Request line as output failed\n"); - goto release_line; - } - - /* Blink */ - val = 0; - while(1) { - ret = gpiod_line_set_value_bulk(line, val ? on_values : off_values); - if (ret < 0) { - perror("Set line output failed\n"); - goto release_line; - } - // printf("Output %u on line #%u\n", val, line_num); - usleep(100000); - val = !val; - } - -release_line: - gpiod_line_release_bulk(line); -close_chip: - gpiod_chip_close(chip); -end: - return 0; -} diff --git a/books/beaglebone-cookbook/02sensors/code/gpiod/toggleLED.py b/books/beaglebone-cookbook/02sensors/code/gpiod/toggleLED.py deleted file mode 100755 index ffca05a5d7129633a9a34b9a9b705d4dbb119827..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/gpiod/toggleLED.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 -# ////////////////////////////////////// -# toggleLED.py -# Toggles the four built in USR LEDs -# They are all on chip 1 so they can be toggled together. -# Setup: sudo apt uupdate; pip3 install gpiod -# See: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/examples -# ////////////////////////////////////// -import gpiod -import time - -LED_CHIP = 'gpiochip1' -LED_LINE_OFFSET = [21, 22, 23, 24] # USR LEDS 1-4 - -chip = gpiod.Chip(LED_CHIP) - -lines = chip.get_lines(LED_LINE_OFFSET) -lines.request(consumer='blink LEDs', type=gpiod.LINE_REQ_DIR_OUT) - -while True: - lines.set_values([0, 0, 0, 0]) - time.sleep(0.25) - lines.set_values([1, 1, 1, 1]) - time.sleep(0.25) diff --git a/books/beaglebone-cookbook/02sensors/code/hc-sr04-ultraSonic.js b/books/beaglebone-cookbook/02sensors/code/hc-sr04-ultraSonic.js deleted file mode 100755 index 8d1592e5a2c7905fa13333d9ad0e3b529e2f3fdd..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/hc-sr04-ultraSonic.js +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env node - -// This is an example of reading HC-SR04 Ultrasonic Range Finder -// This version measures from the fall of the Trigger pulse -// to the end of the Echo pulse - -var b = require('bonescript'); - -var trigger = 'P9_16', // Pin to trigger the ultrasonic pulse - echo = 'P9_41', // Pin to measure to pulse width related to the distance - ms = 250; // Trigger period in ms - -var startTime, pulseTime; - -b.pinMode(echo, b.INPUT, 7, 'pulldown', 'fast', doAttach); -function doAttach(x) { - if(x.err) { - console.log('x.err = ' + x.err); - return; - } - // Call pingEnd when the pulse ends - b.attachInterrupt(echo, true, b.FALLING, pingEnd); -} - -b.pinMode(trigger, b.OUTPUT); - -b.digitalWrite(trigger, 1); // Unit triggers on a falling edge. - // Set trigger to high so we call pull it low later - -// Pull the trigger low at a regular interval. -setInterval(ping, ms); - -// Pull trigger low and start timing. -function ping() { - // console.log('ping'); - b.digitalWrite(trigger, 0); - startTime = process.hrtime(); -} - -// Compute the total time and get ready to trigger again. -function pingEnd(x) { - if(x.attached) { - console.log("Interrupt handler attached"); - return; - } - if(startTime) { - pulseTime = process.hrtime(startTime); - b.digitalWrite(trigger, 1); - console.log('pulseTime = ' + (pulseTime[1]/1000000-0.8).toFixed(3)); - } -} diff --git a/books/beaglebone-cookbook/02sensors/code/i2c-scan.js b/books/beaglebone-cookbook/02sensors/code/i2c-scan.js deleted file mode 100755 index 245a8386be63e6714db9c5232d42d69a9f44c88c..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/i2c-scan.js +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env node -// Not working as for 28-Mar-2014 -var b = require('bonescript'); -var port = '/dev/i2c-2' - -b.i2cOpen(port, null, {}, onI2C); - -function onI2C(x) { - console.log('onI2C: ' + JSON.stringify(x)); - if (x.event == 'return') { - b.i2cScan(port, onScan); - } -} - -function onScan(x) { - if (x.event == 'callback') { - console.log('scan data: ' + JSON.stringify(x)); - } -} diff --git a/books/beaglebone-cookbook/02sensors/code/i2c-test.js b/books/beaglebone-cookbook/02sensors/code/i2c-test.js deleted file mode 100755 index 183e1f5a5978cb0908385c629566390c4f0de7f1..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/i2c-test.js +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env node -# This uses the i2c method from npm what bonescript builds on -var i2c = require('i2c'); -var address = 0x49; -var wire = new i2c(address, {device: '/dev/i2c-1', debug: false}); // point to your i2c address, debug provides REPL interface - -wire.scan(function(err, data) { - // result contains an array of addresses - console.log(data); -}); - -// wire.writeByte(byte, function(err) {}); - -// wire.writeBytes(command, [byte0, byte1], function(err) {}); - -wire.readByte(function(err, res) { // result is single byte }) - console.log(err); - console.log(res); -}); - -// wire.readBytes(command, length, function(err, res) { -// // result contains a buffer of bytes -// }); - -// wire.on('data', function(data) { -// // result for continuous stream contains data buffer, address, length, timestamp -// }); - -// wire.stream(command, length, delay); // continuous stream, delay in ms diff --git a/books/beaglebone-cookbook/02sensors/code/i2cTemp.js b/books/beaglebone-cookbook/02sensors/code/i2cTemp.js deleted file mode 100755 index 9839340c84fa64b9c7717074b0dc238fb7828163..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/i2cTemp.js +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// i2cTemp.js -// Read at TMP101 sensor on i2c bus 2, address 0x49 -// Wiring: Attach to i2c as shown in text. -// Setup: echo tmp101 0x49 > /sys/class/i2c-adapter/i2c-2/new_device -// See: -//////////////////////////////////////// -const fs = require("fs"); - -const ms = 1000; // Read time in ms -const bus = '2'; -const addr = '49'; -I2CPATH='/sys/class/i2c-adapter/i2c-'+bus+'/'+bus+'-00'+addr+'/hwmon/hwmon0'; - -// Read every ms -setInterval(readTMP, ms); - -function readTMP() { - var data = fs.readFileSync(I2CPATH+"/temp1_input").slice(0, -1); - console.log('data (C) = ' + data/1000); - } diff --git a/books/beaglebone-cookbook/02sensors/code/i2cTemp.py b/books/beaglebone-cookbook/02sensors/code/i2cTemp.py deleted file mode 100755 index 2649262fbe7fff0942c442dc0bb58798a2015083..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/i2cTemp.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // i2cTemp.py -# // Read a TMP101 sensor on i2c bus 2, address 0x49 -# // Wiring: Attach to i2c as shown in text. -# // Setup: echo tmp101 0x49 > /sys/class/i2c-adapter/i2c-2/new_device -# // See: -# //////////////////////////////////////// -import time - -ms = 1000 # Read time in ms -bus = '2' -addr = '49' -I2CPATH='/sys/class/i2c-adapter/i2c-'+bus+'/'+bus+'-00'+addr+'/hwmon/hwmon0'; - -f = open(I2CPATH+"/temp1_input", "r") - -while True: - f.seek(0) - data = f.read()[:-1] # returns mili-degrees C - print("data (C) = " + str(int(data)/1000)) - time.sleep(ms/1000) \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/i2ctmp101.py b/books/beaglebone-cookbook/02sensors/code/i2ctmp101.py deleted file mode 100755 index 21b29fceb6c70f0935b9401376a9f78afa838c48..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/i2ctmp101.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // i2ctmp101.py -# // Read at TMP101 sensor on i2c bus 2, address 0x49 -# // Wiring: Attach to i2c as shown in text. -# // Setup: pip install smbus -# // See: -# //////////////////////////////////////// -import smbus -import time - -ms = 1000 # Read time in ms -bus = smbus.SMBus(2) # Using i2c bus 2 -addr = 0x49 # TMP101 is at address 0x49 - -while True: - data = bus.read_byte_data(addr, 0) - print("temp (C) = " + str(data)) - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/02sensors/code/pushbutton.js b/books/beaglebone-cookbook/02sensors/code/pushbutton.js deleted file mode 100755 index 4c852c27680d956c93fe19add576a9ad7321be85..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/pushbutton.js +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// pushbutton.js -// Reads P9_42 and prints its value. -// Wiring: Connect a switch between P9_42 and 3.3V -// Setup: -// See: -//////////////////////////////////////// -const fs = require("fs"); - -const ms = 500 // Read time in ms -const pin = '7'; // P9_42 is gpio 7 -const GPIOPATH="/sys/class/gpio/"; - -// Make sure pin is exported -if(!fs.existsSync(GPIOPATH+"gpio"+pin)) { - fs.writeFileSync(GPIOPATH+"export", pin); -} -// Make it an input pin -fs.writeFileSync(GPIOPATH+"gpio"+pin+"/direction", "in"); - -// Read every ms -setInterval(readPin, ms); - -function readPin() { - var data = fs.readFileSync(GPIOPATH+"gpio"+pin+"/value").slice(0, -1); - console.log('data = ' + data); - } diff --git a/books/beaglebone-cookbook/02sensors/code/pushbutton.py b/books/beaglebone-cookbook/02sensors/code/pushbutton.py deleted file mode 100755 index 2bb133858d5ef8d15f58e002048af10b4a154ab1..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/pushbutton.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // pushbutton.py -# // Reads P9_42 and prints its value. -# // Wiring: Connect a switch between P9_42 and 3.3V -# // Setup: -# // See: -# //////////////////////////////////////// -import time -import os - -ms = 500 # Read time in ms -pin = '7' # P9_42 is gpio 7 -GPIOPATH="/sys/class/gpio" - -# Make sure pin is exported -if (not os.path.exists(GPIOPATH+"/gpio"+pin)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() - -# Make it an input pin -f = open(GPIOPATH+"/gpio"+pin+"/direction", "w") -f.write("in") -f.close() - -f = open(GPIOPATH+"/gpio"+pin+"/value", "r") - -while True: - f.seek(0) - data = f.read()[:-1] - print("data = " + data) - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/02sensors/code/pushbutton2.js b/books/beaglebone-cookbook/02sensors/code/pushbutton2.js deleted file mode 100755 index f54307a594701eb709edaa80581c33ee4380f2f8..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/pushbutton2.js +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env node -var b = require('bonescript'); -var button = 'P9_42'; -var state; // State of pushbutton - -b.pinMode(button, b.INPUT, 7, 'pulldown'); - -state = b.digitalRead(button); -console.log('button state = ' + state); - diff --git a/books/beaglebone-cookbook/02sensors/code/pushbuttonPullup.js b/books/beaglebone-cookbook/02sensors/code/pushbuttonPullup.js deleted file mode 100755 index bee1ce82391cd73156f19d1122e1245f412b86a6..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/pushbuttonPullup.js +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env node -var b = require('bonescript'); -var buttonTop = 'P9_26'; - -b.pinMode(buttonTop, b.INPUT, 7, 'pullup', 'fast', doAttachTop); - -function doAttachTop(x) { - if(x.err) { - console.log('x.err = ' + x.err); - return; - } - b.attachInterrupt(buttonTop, true, b.CHANGE, printStatus); -} - -var buttonBot = 'P9_42'; -b.pinMode(buttonBot, b.INPUT, 7, 'pulldown', 'fast', doAttachBot); - -function doAttachBot(x) { - if(x.err) { - console.log('x.err = ' + x.err); - return; - } - b.attachInterrupt(buttonBot, true, b.CHANGE, printStatus); -} - -function printStatus(x) { - if(x.attached) { - console.log("Interrupt handler attached"); - return; - } - - console.log('x.value = ' + x.value); - console.log('x.err = ' + x.err); -} diff --git a/books/beaglebone-cookbook/02sensors/code/pushbutton_digitalRead.js b/books/beaglebone-cookbook/02sensors/code/pushbutton_digitalRead.js deleted file mode 100755 index 59f1f14df2c652f8b62c6721b9ab2b1a6eb2a4c5..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/pushbutton_digitalRead.js +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env node -var b = require('bonescript'); -var button = 'P9_42'; - -b.pinMode(button, b.INPUT, 7, 'pulldown'); -b.digitalRead(button, printStatus); - -function printStatus(x) { - console.log('x.value = ' + x.value); - console.log('x.err = ' + x.err); -} diff --git a/books/beaglebone-cookbook/02sensors/code/rotaryEncoder.js b/books/beaglebone-cookbook/02sensors/code/rotaryEncoder.js deleted file mode 100755 index 3390a817d41ff4f12a182ca5aaf326f3b11f11fd..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/rotaryEncoder.js +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env node -// This uses the eQEP hardware to read a rotary encoder -// bone$ config-pin P8_11 eqep -// bone$ config-pin P8_12 eqep -const fs = require("fs"); - -const eQEP = "2"; -const COUNTERPATH = '/dev/bone/counter/counter'+eQEP+'/count0'; - -const ms = 100; // Time between samples in ms -const maxCount = '1000000'; - -// Set the eEQP maximum count -fs.writeFileSync(COUNTERPATH+'/ceiling', maxCount); - -// Enable -fs.writeFileSync(COUNTERPATH+'/enable', '1'); - -setInterval(readEncoder, ms); // Check state every ms - -var olddata = -1; -function readEncoder() { - var data = parseInt(fs.readFileSync(COUNTERPATH+'/count')); - if(data != olddata) { - // Print only if data changes - console.log('data = ' + data); - olddata = data; - } -} - -// Black OR Pocket -// eQEP0: P9.27 and P9.42 OR P1_33 and P2_34 -// eQEP1: P9.33 and P9.35 -// eQEP2: P8.11 and P8.12 OR P2_24 and P2_33 - -// AI -// eQEP1: P8.33 and P8.35 -// eQEP2: P8.11 and P8.12 or P9.19 and P9.41 -// eQEP3: P8.24 abd P8.25 or P9.27 and P9.42 \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/rotaryEncoder.py b/books/beaglebone-cookbook/02sensors/code/rotaryEncoder.py deleted file mode 100755 index 04eb3735f2b02769cc526d562bbb725f0dced64a..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/rotaryEncoder.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python -# // This uses the eQEP hardware to read a rotary encoder -# // bone$ config-pin P8_11 eqep -# // bone$ config-pin P8_12 eqep -import time - -eQEP = '2' -COUNTERPATH = '/dev/bone/counter/counter'+eQEP+'/count0' - -ms = 100 # Time between samples in ms -maxCount = '1000000' - -# Set the eEQP maximum count -f = open(COUNTERPATH+'/ceiling', 'w') -f.write(maxCount) -f.close() - -# Enable -f = open(COUNTERPATH+'/enable', 'w') -f.write('1') -f.close() - -f = open(COUNTERPATH+'/count', 'r') - -olddata = -1 -while True: - f.seek(0) - data = f.read()[:-1] - # Print only if data changes - if data != olddata: - olddata = data - print("data = " + data) - time.sleep(ms/1000) - -# Black OR Pocket -# eQEP0: P9.27 and P9.42 OR P1_33 and P2_34 -# eQEP1: P9.33 and P9.35 -# eQEP2: P8.11 and P8.12 OR P2_24 and P2_33 - -# AI -# eQEP1: P8.33 and P8.35 -# eQEP2: P8.11 and P8.12 or P9.19 and P9.41 -# eQEP3: P8.24 abd P8.25 or P9.27 and P9.42 \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/sensorTag.js b/books/beaglebone-cookbook/02sensors/code/sensorTag.js deleted file mode 100755 index 9b3eed155098927949592b29e2852712bc65af03..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/sensorTag.js +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env node -// From: https://github.com/sandeepmistry/node-sensortag - -// Reads temperature - -var util = require('util'); // <1> -var async = require('async'); -var SensorTag = require('sensortag'); -var fs = require('fs'); - -console.log("Be sure sensorTag is on"); - -SensorTag.discover(function(sensorTag) { // <2> - console.log('sensorTag = ' + sensorTag); - sensorTag.on('disconnect', function() { // <3> - console.log('disconnected!'); - process.exit(0); - }); - - async.series([ // <4> - function(callback) { - console.log('connect'); // <5> - sensorTag.connect(callback); - }, - function(callback) { // <6> - console.log('discoverServicesAndCharacteristics'); - sensorTag.discoverServicesAndCharacteristics(callback); - }, - function(callback) { - console.log('enableIrTemperature'); // <7> - sensorTag.enableIrTemperature(callback); - }, - function(callback) { - setTimeout(callback, 100); // <8> - }, - function(callback) { - console.log('readIrTemperature'); // <9> - sensorTag.readIrTemperature( - function(objectTemperature, ambientTemperature) { - console.log('\tobject temperature = %d °C', - objectTemperature.toFixed(1)); - console.log('\tambient temperature = %d °C', - ambientTemperature.toFixed(1)); - callback(); - }); - - sensorTag.on('irTemperatureChange', // <10> - function(objectTemperature, ambientTemperature) { - console.log('\tobject temperature = %d °C', - objectTemperature.toFixed(1)); - console.log('\tambient temperature = %d °C\n', - ambientTemperature.toFixed(1)); - }); - - sensorTag.notifyIrTemperature(function() { - console.log('notifyIrTemperature'); - }); - }, - // function(callback) { - // console.log('disableIrTemperature'); // <11> - // sensorTag.disableIrTemperature(callback); - // }, - - function(callback) { - console.log('readSimpleRead'); // <12> - sensorTag.on('simpleKeyChange', function(left, right) { - console.log('left: ' + left + ' right: ' + right); - if (left && right) { - sensorTag.notifySimpleKey(callback); // <13> - } - }); - - sensorTag.notifySimpleKey(function() { // <14> - }); - }, - function(callback) { - console.log('disconnect'); - sensorTag.disconnect(callback); // <15> - } - ] - ); -}); - -// The MIT License (MIT) - -// Copyright (c) 2013 Sandeep Mistry - -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/books/beaglebone-cookbook/02sensors/code/stop.js b/books/beaglebone-cookbook/02sensors/code/stop.js deleted file mode 100755 index 0c3ec1b622d17e45abf9aedbd8734ecf70093872..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/stop.js +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env node -// Used for turning everything off. -var b = require('bonescript'); -var gpio = ['P9_11', 'P9_13', 'P9_15', 'P9_16', 'P9_21']; -var i; - -for(i=0; i<gpio.length; i++) { - b.pinMode(gpio[i], b.OUTPUT); - b.digitalWrite(gpio[i], b.LOW); -} diff --git a/books/beaglebone-cookbook/02sensors/code/testHC-SR04.js b/books/beaglebone-cookbook/02sensors/code/testHC-SR04.js deleted file mode 100755 index 452fd8afb66386b5e817b0517dff710173a201e8..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/testHC-SR04.js +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env node - -// This is an example of reading HC-SR04 Ultrasonic Range Finder - -var b = require('bonescript'); - -var motor = 'P9_16',// Pin to drive transistor - range = 'P9_41', - min = 0.05, // Slowest speed (duty cycle) - max = 1, // Fastest (always on) - ms = 100, // How often to change speed, in ms - width = 10, // Pulse width in us - freq = 100, // Frequency in Hz - step = 0.05; // Change in speed - -b.pinMode(range, b.INPUT); // Make sure there is on pull-up/down -b.pinMode(motor, b.ANALOG_OUTPUT); -var dutyCycle = width/1000000*freq; -b.analogWrite(motor, dutyCycle, freq); - - -// var timer = setInterval(sweep, ms); - -// function sweep() { -// speed += step; -// if(speed > max || speed < min) { -// step *= -1; -// } -// b.analogWrite(motor, speed); -// console.log('speed = ' + speed); -// } - -process.on('SIGINT', function() { - console.log('Got SIGINT, turning motor off'); - clearInterval(timer); // Stop the timer - b.analogWrite(motor, 0); // Turn motor off -}); \ No newline at end of file diff --git a/books/beaglebone-cookbook/02sensors/code/ultrasonicRange.js b/books/beaglebone-cookbook/02sensors/code/ultrasonicRange.js deleted file mode 100755 index 0d00de89a29e80613085e4a135da7a5b973c7cda..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/ultrasonicRange.js +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env node -////////////////////////////////////// -// ultrasonicRange.js -// Reads the analog value of the sensor. -////////////////////////////////////// -const fs = require("fs"); -const ms = 250; // Time in milliseconds - -const pin = "0"; // sensor, A0, P9_39 - -const IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw'; - -console.log('Hit ^C to stop'); - -// Read every ms -setInterval(readPin, ms); - -function readPin() { - var data = fs.readFileSync(IIOPATH); - console.log('data= ' + data); - } -// Bone | Pocket | AIN -// ----- | ------ | --- -// P9_39 | P1_19 | 0 -// P9_40 | P1_21 | 1 -// P9_37 | P1_23 | 2 -// P9_38 | P1_25 | 3 -// P9_33 | P1_27 | 4 -// P9_36 | P2_35 | 5 -// P9_35 | P1_02 | 6 diff --git a/books/beaglebone-cookbook/02sensors/code/ultrasonicRange.py b/books/beaglebone-cookbook/02sensors/code/ultrasonicRange.py deleted file mode 100755 index d02bf7511d8be90833b7b26c94d176496cfe6685..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/ultrasonicRange.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# ////////////////////////////////////// -# // ultrasonicRange.js -# // Reads the analog value of the sensor. -# ////////////////////////////////////// -import time -ms = 250; # Time in milliseconds - -pin = "0" # sensor, A0, P9_39 - -IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw' - -print('Hit ^C to stop'); - -f = open(IIOPATH, "r") -while True: - f.seek(0) - data = f.read()[:-1] - print('data= ' + data) - time.sleep(ms/1000) - -# // Bone | Pocket | AIN -# // ----- | ------ | --- -# // P9_39 | P1_19 | 0 -# // P9_40 | P1_21 | 1 -# // P9_37 | P1_23 | 2 -# // P9_38 | P1_25 | 3 -# // P9_33 | P1_27 | 4 -# // P9_36 | P2_35 | 5 -# // P9_35 | P1_02 | 6 diff --git a/books/beaglebone-cookbook/02sensors/code/w1.js b/books/beaglebone-cookbook/02sensors/code/w1.js deleted file mode 100755 index 187023af3c0430a2d825be6193cfce0fc58f06a7..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/w1.js +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// w1.js -// Read a Dallas 1-wire device on P9_12 -// Wiring: Attach gnd and 3.3V and data to P9_12 -// Setup: Edit /boot/uEnv.txt to include: -// uboot_overlay_addr4=BB-W1-P9.12-00A0.dtbo -// See: -//////////////////////////////////////// -const fs = require("fs"); - -const ms = 500 // Read time in ms -// Do ls /sys/bus/w1/devices and find the address of your device -const addr = '28-00000d459c2c'; // Must be changed for your device. -const W1PATH ='/sys/bus/w1/devices/' + addr; - -// Read every ms -setInterval(readW1, ms); - -function readW1() { - var data = fs.readFileSync(W1PATH+'/temperature').slice(0, -1); - console.log('temp (C) = ' + data/1000); - } diff --git a/books/beaglebone-cookbook/02sensors/code/w1.py b/books/beaglebone-cookbook/02sensors/code/w1.py deleted file mode 100755 index 8a0a62f6deae22059e26f9770dce3dd6348bb794..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/02sensors/code/w1.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // w1.js -# // Read a Dallas 1-wire device on P9_12 -# // Wiring: Attach gnd and 3.3V and data to P9_12 -# // Setup: Edit /boot/uEnv.txt to include: -# // uboot_overlay_addr4=BB-W1-P9.12-00A0.dtbo -# // See: -# //////////////////////////////////////// -import time - -ms = 500 # Read time in ms -# Do ls /sys/bus/w1/devices and find the address of your device -addr = '28-00000d459c2c' # Must be changed for your device. -W1PATH ='/sys/bus/w1/devices/' + addr - -f = open(W1PATH+'/temperature') - -while True: - f.seek(0) - data = f.read()[:-1] - print("temp (C) = " + str(int(data)/1000)) - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/02sensors/sensors.rst b/books/beaglebone-cookbook/02sensors/sensors.rst index 6f15d0adf0c28d3db2271194a7b51c1b3a786cdc..d5e6400db18980febaa6fb0b9149e99b1ebd56aa 100644 --- a/books/beaglebone-cookbook/02sensors/sensors.rst +++ b/books/beaglebone-cookbook/02sensors/sensors.rst @@ -91,7 +91,7 @@ You are just a few simple steps from running any of the recipes in this book. .. code-block:: bash bone$ cd - bone$ cd BoneCookbook/docs/02sensors/code + bone$ cd beaglebone-cookbook-code/02sensors .. _sensors_vsc_bash: @@ -168,19 +168,19 @@ reads GPIO port *P9_42*, which is attached to the pushbutton. .. _py_pushbutton_code: -.. literalinclude:: code/pushbutton.py +.. literalinclude:: ../code/02sensors/pushbutton.py :caption: Monitoring a pushbutton (pushbutton.py) :linenos: -:download:`pushbutton.py <code/pushbutton.py>` +:download:`pushbutton.py <../code/02sensors/pushbutton.py>` .. _js_pushbutton_code: -.. literalinclude:: code/pushbutton.js +.. literalinclude:: ../code/02sensors/pushbutton.js :caption: Monitoring a pushbutton (pushbutton.js) :linenos: -:download:`pushbutton.js <code/pushbutton.js>` +:download:`pushbutton.js <../code/02sensors/pushbutton.js>` Put this code in a file called *pushbutton.js* following the steps in :ref:`sensors_getting_started`. In the VSC *bash* tab, run it by using the following commands: @@ -294,19 +294,19 @@ Add the code to a file called _analogIn.js_ and run it; then change the resistor .. _py_analogIn_code: -.. literalinclude:: code/analogIn.py +.. literalinclude:: ../code/02sensors/analogIn.py :caption: Reading an analog voltage (analogIn.py) :linenos: -:download:`analogIn.py <code/analogIn.py>` +:download:`analogIn.py <../code/02sensors/analogIn.py>` .. _sensors_analogIn_code: -.. literalinclude:: code/analogIn.js +.. literalinclude:: ../code/02sensors/analogIn.js :caption: Reading an analog voltage (analogIn.js) :linenos: -:download:`analogIn.js <code/analogIn.js>` +:download:`analogIn.js <../code/02sensors/analogIn.js>` .. note:: @@ -370,20 +370,20 @@ shows the code that reads the sensor at a fixed interval. .. _py_ultrasonicRange_code: -.. literalinclude:: code/ultrasonicRange.py +.. literalinclude:: ../code/02sensors/ultrasonicRange.py :caption: Reading an analog voltage (ultrasonicRange.py) :linenos: -:download:`ultrasonicRange.py <code/ultrasonicRange.py>` +:download:`ultrasonicRange.py <../code/02sensors/ultrasonicRange.py>` .. _sensors_ultrasonicRange_code: -.. literalinclude:: code/ultrasonicRange.js +.. literalinclude:: ../code/02sensors/ultrasonicRange.js :caption: Reading an analog voltage (ultrasonicRange.js) :linenos: -:download:`ultrasonicRange.js <code/ultrasonicRange.js>` +:download:`ultrasonicRange.js <../code/02sensors/ultrasonicRange.js>` .. _sensors_hc-sr04: @@ -433,11 +433,11 @@ HC-SR04 to the Bone's 5 V power supply. .. _sensors_hc-sr04_code: -.. literalinclude:: code/hc-sr04-ultraSonic.js +.. literalinclude:: ../code/02sensors/hc-sr04-ultraSonic.js :caption: Driving a HC-SR04 ultrasound sensor (hc-sr04-ultraSonic.js) :linenos: -:download:`hc-sr04-ultraSonic.js <code/hc-sr04-ultraSonic.js>` +:download:`hc-sr04-ultraSonic.js <../code/02sensors/hc-sr04-ultraSonic.js>` This code is more complex than others in this chapter, because we have to tell the device when to start @@ -520,19 +520,19 @@ to a file named *rotaryEncoder.js* and run it. .. _digital_rotaryEncoder_py: -.. literalinclude:: code/rotaryEncoder.py +.. literalinclude:: ../code/02sensors/rotaryEncoder.py :caption: Reading a rotary encoder (rotaryEncoder.py) :linenos: -:download:`rotaryEncoder.py <code/rotaryEncoder.py>` +:download:`rotaryEncoder.py <../code/02sensors/rotaryEncoder.py>` .. _digital_rotaryEncoder_js: -.. literalinclude:: code/rotaryEncoder.js +.. literalinclude:: ../code/02sensors/rotaryEncoder.js :caption: Reading a rotary encoder (rotaryEncoder.js) :linenos: -:download:`rotaryEncoder.js <code/rotaryEncoder.js>` +:download:`rotaryEncoder.js <../code/02sensors/rotaryEncoder.js>` Try rotating the encoder clockwise and counter-clockwise. You'll see an output like this: @@ -608,11 +608,11 @@ will print the current location every time the GPS outputs it. .. _digital_GPS_code: -.. literalinclude:: code/GPS.js +.. literalinclude:: ../code/02sensors/GPS.js :caption: Talking to a GPS with UART 4 (GPS.js) :linenos: -:download:`GPS.js <code/GPS.js>` +:download:`GPS.js <../code/02sensors/GPS.js>` If you don't need the NMEA formatting, you can skip the *npm* part and remove the lines in the code that refer to it. @@ -786,19 +786,19 @@ Once the driver is in place, you can read it via code. .. _py_i2cTemp_code: -.. literalinclude:: code/i2cTemp.py +.. literalinclude:: ../code/02sensors/i2cTemp.py :caption: Reading an |I2C| device (i2cTemp.py) :linenos: -:download:`i2cTemp.py <code/i2cTemp.py>` +:download:`i2cTemp.py <../code/02sensors/i2cTemp.py>` .. _js_i2cTemp_code: -.. literalinclude:: code/i2cTemp.js +.. literalinclude:: ../code/02sensors/i2cTemp.js :caption: Reading an |I2C| device (i2cTemp.js) :linenos: -:download:`i2cTemp.js <code/i2cTemp.js>` +:download:`i2cTemp.js <../code/02sensors/i2cTemp.js>` Run the code by using the following command: @@ -827,11 +827,11 @@ using the kernel driver. First you need to install the i2c module. .. _js_i2ctmp101_code: -.. literalinclude:: code/i2ctmp101.py +.. literalinclude:: ../code/02sensors/i2ctmp101.py :caption: Reading an |I2C| device (i2cTemp.py) :linenos: -:download:`i2ctmp101.py <code/i2ctmp101.py>` +:download:`i2ctmp101.py <../code/02sensors/i2ctmp101.py>` This gets only 8 bits for the temperature. See the TMP101 datasheet for details on how to get up to 12 bits. @@ -914,19 +914,19 @@ that the path points to your device, and then run it. .. _py_onewire__code: -.. literalinclude:: code/w1.py +.. literalinclude:: ../code/02sensors/w1.py :caption: Reading a temperature with a DS18B20 (w1.py) :linenos: -:download:`w1.py <code/w1.py>` +:download:`w1.py <../code/02sensors/w1.py>` .. _sensors_onewire__code: -.. literalinclude:: code/w1.js +.. literalinclude:: ../code/02sensors/w1.js :caption: Reading a temperature with a DS18B20 (w1.js) :linenos: -:download:`w1.js <code/w1.js>` +:download:`w1.js <../code/02sensors/w1.js>` .. code-block:: bash @@ -983,7 +983,7 @@ Each temperature sensor has a unique serial number, so you can have several all .. // [source, js] .. // ---- -.. // include::code/sensorTag.js[sensorTag.js] +.. // include::../code/02sensors/sensorTag.js[sensorTag.js] .. // ---- .. // ==== @@ -1120,11 +1120,11 @@ can change that default by creating a file in your home directory called .. _sensors_asoundrc: -.. literalinclude:: code/audio.asoundrc +.. literalinclude:: ../code/02sensors/audio.asoundrc :caption: Change the default audio out by putting this in ~/.asoundrc (audio.asoundrc) :linenos: -:download:`audio.asoundrc <code/audio.asoundrc>` +:download:`audio.asoundrc <../code/02sensors/audio.asoundrc>` You can easily play ``.wav`` files with *aplay*: diff --git a/books/beaglebone-cookbook/03displays/code/externLED.js b/books/beaglebone-cookbook/03displays/code/externLED.js deleted file mode 100755 index 40ad5dabb9bd79d2b43c29c29e4c021f06b3e842..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/externLED.js +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// externalLED.js -// Blinks the P9_14 pin -// Wiring: -// Setup: -// See: -//////////////////////////////////////// -const fs = require("fs"); - -// Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 -pin="50"; - -GPIOPATH="/sys/class/gpio/"; -// Make sure pin is exported -if(!fs.existsSync(GPIOPATH+"gpio"+pin)) { - fs.writeFileSync(GPIOPATH+"export", pin); -} -// Make it an output pin -fs.writeFileSync(GPIOPATH+"gpio"+pin+"/direction", "out"); - -// Blink every 500ms -setInterval(toggle, 500); - -state="1"; -function toggle() { - fs.writeFileSync(GPIOPATH+"gpio"+pin+"/value", state); - if(state == "0") { - state = "1"; - } else { - state = "0"; - } -} diff --git a/books/beaglebone-cookbook/03displays/code/externLED.py b/books/beaglebone-cookbook/03displays/code/externLED.py deleted file mode 100755 index 786d3217dbd0c53dccc668d215c0442a69feb860..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/externLED.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // externalLED.py -# // Blinks an external LED wired to P9_14. -# // Wiring: P9_14 connects to the plus lead of an LED. The negative lead of the -# LED goes to a 220 Ohm resistor. The other lead of the resistor goes -# to ground. -# // Setup: -# // See: -# //////////////////////////////////////// -import time -import os - -ms = 250 # Time to blink in ms -# Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 -pin = '50' - -GPIOPATH='/sys/class/gpio/' -# Make sure pin is exported -if (not os.path.exists(GPIOPATH+"gpio"+pin)): - f = open(GPIOPATH+"export", "w") - f.write(pin) - f.close() - -# Make it an output pin -f = open(GPIOPATH+"gpio"+pin+"/direction", "w") -f.write("out") -f.close() - -f = open(GPIOPATH+"gpio"+pin+"/value", "w") -# Blink -while True: - f.seek(0) - f.write("1") - time.sleep(ms/1000) - - f.seek(0) - f.write("0") - time.sleep(ms/1000) -f.close() diff --git a/books/beaglebone-cookbook/03displays/code/fadeLED.js b/books/beaglebone-cookbook/03displays/code/fadeLED.js deleted file mode 100755 index 49db7ecd7a6839f3952e9090af1572cf0346b22d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/fadeLED.js +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// fadeLED.js -// Blinks the P9_14 pin -// Wiring: -// Setup: config-pin P9_14 pwm -// See: -//////////////////////////////////////// -const fs = require("fs"); -const ms = '20'; // Fade time in ms - -const pwmPeriod = '1000000'; // Period in ns -const pwm = '1'; // pwm to use -const channel = 'a'; // channel to use -const PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel; -var step = 0.02; // Step size -const min = 0.02, // dimmest value - max = 1; // brightest value -var brightness = min; // Current brightness; - - -// Set the period in ns -fs.writeFileSync(PWMPATH+'/period', pwmPeriod); -fs.writeFileSync(PWMPATH+'/duty_cycle', pwmPeriod/2); -fs.writeFileSync(PWMPATH+'/enable', '1'); - -setInterval(fade, ms); // Step every ms - -function fade() { - fs.writeFileSync(PWMPATH+'/duty_cycle', - parseInt(pwmPeriod*brightness)); - brightness += step; - if(brightness >= max || brightness <= min) { - step = -1 * step; - } -} - -// | Pin | pwm | channel -// | P9_31 | 0 | a -// | P9_29 | 0 | b -// | P9_14 | 1 | a -// | P9_16 | 1 | b -// | P8_19 | 2 | a -// | P8_13 | 2 | b \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/code/fadeLED.py b/books/beaglebone-cookbook/03displays/code/fadeLED.py deleted file mode 100755 index bd2016d1f80a8fc21f02387909824236fd16a9d7..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/fadeLED.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // fadeLED.py -# // Blinks the P9_14 pin -# // Wiring: -# // Setup: config-pin P9_14 pwm -# // See: -# //////////////////////////////////////// -import time -ms = 20; # Fade time in ms - -pwmPeriod = 1000000 # Period in ns -pwm = '1' # pwm to use -channel = 'a' # channel to use -PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel -step = 0.02 # Step size -min = 0.02 # dimmest value -max = 1 # brightest value -brightness = min # Current brightness - -f = open(PWMPATH+'/period', 'w') -f.write(str(pwmPeriod)) -f.close() - -f = open(PWMPATH+'/enable', 'w') -f.write('1') -f.close() - -f = open(PWMPATH+'/duty_cycle', 'w') -while True: - f.seek(0) - f.write(str(round(pwmPeriod*brightness))) - brightness += step - if(brightness >= max or brightness <= min): - step = -1 * step - time.sleep(ms/1000) - -# | Pin | pwm | channel -# | P9_31 | 0 | a -# | P9_29 | 0 | b -# | P9_14 | 1 | a -# | P9_16 | 1 | b -# | P8_19 | 2 | a -# | P8_13 | 2 | b \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/code/internLED.js b/books/beaglebone-cookbook/03displays/code/internLED.js deleted file mode 100755 index b6545f219cedf856089757c75cee29675792692f..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/internLED.js +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env node -// ////////////////////////////////////// -// internalLED.js -// Blinks the USR LEDs. -// Wiring: -// Setup: -// See: -// ////////////////////////////////////// -const fs = require('fs'); -const ms = 250; // Blink time in ms -const LED = 'usr0'; // LED to blink -const LEDPATH = '/sys/class/leds/beaglebone:green:'+LED+'/brightness'; - -var state = '1'; // Initial state - -setInterval(flash, ms); // Change state every ms - -function flash() { - fs.writeFileSync(LEDPATH, state) - if(state === '1') { - state = '0'; - } else { - state = '1'; - } -} diff --git a/books/beaglebone-cookbook/03displays/code/internLED.py b/books/beaglebone-cookbook/03displays/code/internLED.py deleted file mode 100755 index 11db5efcfa129cc05a7b8871ce9fc32489dedcb6..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/internLED.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# ////////////////////////////////////// -# internalLED.py -# Blinks A USR LED. -# Wiring: -# Setup: -# See: -# ////////////////////////////////////// -import time - -ms = 250 # Blink time in ms -LED = 'usr0'; # LED to blink -LEDPATH = '/sys/class/leds/beaglebone:green:'+LED+'/brightness' - -state = '1' # Initial state - -f = open(LEDPATH, "w") - -while True: - f.seek(0) - f.write(state) - if (state == '1'): - state = '0' - else: - state = '1' - time.sleep(ms/1000) \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/code/matrixLEDi2c.js b/books/beaglebone-cookbook/03displays/code/matrixLEDi2c.js deleted file mode 100755 index 405419b7b0d1339af1ebae20b02d3f663677d4cf..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/matrixLEDi2c.js +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env node -// npm install -g sleep - -var b = require('bonescript'); -var sleep = require('sleep'); -var port = '/dev/i2c-2' // <1> -var matrix = 0x70; // <2> -var time = 1000000; // Delay between images in us - -// The first btye is GREEN, the second is RED. <3> -var smile = - [0x00, 0x3c, 0x00, 0x42, 0x28, 0x89, 0x04, 0x85, - 0x04, 0x85, 0x28, 0x89, 0x00, 0x42, 0x00, 0x3c]; -var frown = - [0x3c, 0x00, 0x42, 0x00, 0x85, 0x20, 0x89, 0x00, - 0x89, 0x00, 0x85, 0x20, 0x42, 0x00, 0x3c, 0x00]; -var neutral = - [0x3c, 0x3c, 0x42, 0x42, 0xa9, 0xa9, 0x89, 0x89, - 0x89, 0x89, 0xa9, 0xa9, 0x42, 0x42, 0x3c, 0x3c]; -var blank = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - -b.i2cOpen(port, matrix); // <4> - -b.i2cWriteByte(port, 0x21); // Start oscillator (p10) <5> -b.i2cWriteByte(port, 0x81); // Disp on, blink off (p11) -b.i2cWriteByte(port, 0xe7); // Full brightness (page 15) - -b.i2cWriteBytes(port, 0x00, frown); // <6> -sleep.usleep(time); - -b.i2cWriteBytes(port, 0x00, neutral); -sleep.usleep(time); - -b.i2cWriteBytes(port, 0x00, smile); -// Fade the display -var fade; -for(fade = 0xef; fade >= 0xe0; fade--) { // <7> - b.i2cWriteByte(port, fade); - sleep.usleep(time/10); -} -for(fade = 0xe1; fade <= 0xef; fade++) { - b.i2cWriteByte(port, fade); - sleep.usleep(time/10); -} -b.i2cWriteBytes(port, 0x04, [0xff]); \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/code/matrixLEDi2c.py b/books/beaglebone-cookbook/03displays/code/matrixLEDi2c.py deleted file mode 100755 index 311714c04bcfc5f25ab140d1bd928c1153ae4238..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/matrixLEDi2c.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // i2cTemp.py -# // Write an 8x8 Red/Green LED matrix. -# // Wiring: Attach to i2c as shown in text. -# // Setup: echo tmp101 0x49 > /sys/class/i2c-adapter/i2c-2/new_device -# // See: https://www.adafruit.com/product/902 -# //////////////////////////////////////// -import smbus -import time - -bus = smbus.SMBus(2) # Use i2c bus 2 <1> -matrix = 0x70 # Use address 0x70 <2> -ms = 1; # Delay between images in ms - -# The first byte is GREEN, the second is RED. <3> -smile = [0x00, 0x3c, 0x00, 0x42, 0x28, 0x89, 0x04, 0x85, - 0x04, 0x85, 0x28, 0x89, 0x00, 0x42, 0x00, 0x3c -] -frown = [0x3c, 0x00, 0x42, 0x00, 0x85, 0x20, 0x89, 0x00, - 0x89, 0x00, 0x85, 0x20, 0x42, 0x00, 0x3c, 0x00 -] -neutral = [0x3c, 0x3c, 0x42, 0x42, 0xa9, 0xa9, 0x89, 0x89, - 0x89, 0x89, 0xa9, 0xa9, 0x42, 0x42, 0x3c, 0x3c -] - -bus.write_byte_data(matrix, 0x21, 0) # Start oscillator (p10) <4> -bus.write_byte_data(matrix, 0x81, 0) # Disp on, blink off (p11) -bus.write_byte_data(matrix, 0xe7, 0) # Full brightness (page 15) - -bus.write_i2c_block_data(matrix, 0, frown) # <5> -for fade in range(0xef, 0xe0, -1): # <6> - bus.write_byte_data(matrix, fade, 0) - time.sleep(ms/10) - -bus.write_i2c_block_data(matrix, 0, neutral) -for fade in range(0xe0, 0xef, 1): - bus.write_byte_data(matrix, fade, 0) - time.sleep(ms/10) - -bus.write_i2c_block_data(matrix, 0, smile) diff --git a/books/beaglebone-cookbook/03displays/code/neoPixel.sh b/books/beaglebone-cookbook/03displays/code/neoPixel.sh deleted file mode 100755 index 0e213f4b4fc8dddaf5001536e3073513a7b41564..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/neoPixel.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# Here's what you do to install the neoPixel driver -# Disable the HDMI to gain access to the PRU pins -sed -i '/cape_disable=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN$/ \ - s/^#//' /boot/uEnv.txt -reboot -# Clone and build the code -cd -git clone -b opc-server https://github.com/jadonk/LEDscape.git -cd LEDscape -make -cd -git clone https://github.com/jadonk/openpixelcontrol.git -# Load and configure the kernel module, pins and LEDscape daemon -config-pin overlay BB-OPC-EX -modprobe uio_pruss -./LEDscape/run-ledscape & -# Run an example Python script -./openpixelcontrol/python_clients/example.py diff --git a/books/beaglebone-cookbook/03displays/code/nokia5110.js b/books/beaglebone-cookbook/03displays/code/nokia5110.js deleted file mode 100644 index 9a43c98bd1f8093b00268d84e768b9398a1c9874..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/nokia5110.js +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env node -// -// Copyright (C) 2012 - Cabin Programs, Ken Keller -// - -var lcd = require('nokia5110'); -var b = require('bonescript'); -var timeout = 0; -var inverseIndex; - -// -// Must define the following outputs -// -lcd.PIN_SDIN = "P9_17"; -lcd.PIN_SCLK = "P9_21"; -lcd.PIN_SCE = "P9_11"; -lcd.PIN_DC = "P9_15"; -lcd.PIN_RESET= "P9_13"; \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/code/nokia5110Test.js b/books/beaglebone-cookbook/03displays/code/nokia5110Test.js deleted file mode 100755 index a823f8193780b615cb73f9c475a19ef6df74686d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/nokia5110Test.js +++ /dev/null @@ -1,231 +0,0 @@ -#!/usr/bin/env node -// -// Copyright (C) 2012 - Cabin Programs, Ken Keller -// - -var lcd = require('nokia5110'); -var b = require('bonescript'); -var timeout = 0; -var inverseIndex; - -// -// Must define the following outputs to use LCD_5110.js -// -lcd.PIN_SDIN = "P9_17"; -lcd.PIN_SCLK = "P9_21"; -lcd.PIN_SCE = "P9_11"; -lcd.PIN_DC = "P9_15"; -lcd.PIN_RESET= "P9_13"; - -lcd.setup(); -setTimeout(loop, 0); -// loop(); - -function loop() { -// test bitmap write - console.log("test bitmap write"); -// lcd.clear(); - lcd.gotoXY(0, 0); - lcd.bitmap(beagle); - - inverseIndex = 0; - setTimeout(loop0, 1000*timeout); -} - -function loop0() { -// test inverse video - console.log("test inverse video"); - if(inverseIndex % 2) { - lcd.inverse(lcd.LCD_INVERSE); - } else { - lcd.inverse(lcd.LCD_NORMAL); - } - - inverseIndex++; - - if(inverseIndex < 19) { - setTimeout(loop0, 50*timeout); - } else { - setTimeout(loop1, 50*timeout); - } -} - -function loop1() { -// test normal character write - console.log("test normal character write"); - // lcd.clear(); - lcd.gotoXY(0, 0); - for ( index = 0x41 ; index < 0x7b ; index++) - lcd.character(String.fromCharCode(index)); - - setTimeout(loop2, 2000*timeout); -} - -function loop2() { -// test bitmap and string write - console.log("test bitmap and string write"); - // lcd.clear(); - lcd.gotoXY(0, 0); - lcd.bitmap(world_map); - - setTimeout(loop3, 1000*timeout); -} - -function loop3() { - var index; - - for (index=0; index<5; index++) - { - lcd.gotoXY(0, 3); - lcd.string('HELLO WORLD!'); - lcd.gotoXY(0, 3); - lcd.string('hello world!'); - } - - setTimeout(loop4, 0); -} - -function loop4() { - var index; - -// test solid block character - console.log("test solid block character"); - // lcd.clear(); - lcd.gotoXY(0, 0); - for ( index = 0 ; index < 72 ; index++) - lcd.character(String.fromCharCode(0x7f)); - -// Scrolling text test - console.log("Scrolling text test"); - // lcd.clear(); - var theTEXT = "Scroll text..."; - var numScrolls = lcd.scrollLength(theTEXT) * 2; - - lcd.scrollInit(3); - for (index=0; index<numScrolls; index++) - { - lcd.scroll(3,theTEXT); - } - lcd.scrollInit(3); // used to clear row - - setTimeout(loop5, 2000*timeout); -} - -function loop5() { - var index; - -// Progress Bar test - console.log("Progress Bar test"); - lcd.gotoXY(0,0); - lcd.string("Progress Bar"); - - lcd.progressInit(2); - for (index=0; index<101; index+=2) - lcd.progressBar(2,index); - - for (index=100; index>=0; index-=2) - lcd.progressBar(2,index); - - lcd.progressInit(2); - for (index=100; index>=0; index-=6) - lcd.progressBar(2,index); - - if(timeout) setTimeout(loop, 2000); -} - -var beagle = [ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0xF8, 0xFC, -0x9C, 0x0C, 0x07, 0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 0x06, 0x0C, -0x1C, 0x18, 0x30, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x03, 0x7F, 0xF8, 0xE0, 0x00, 0x00, 0xE0, 0xB0, 0x90, 0xF0, 0xE0, 0xE0, -0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6D, 0x6D, 0x77, 0xFF, 0xEE, 0xF8, 0xC0, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x38, 0x1E, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3F, 0xFF, 0xF8, 0x81, 0x02, -0x02, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x03, 0x03, 0x02, 0x02, 0x06, 0x06, 0x84, 0xCC, 0x9C, 0xF8, 0x70, 0x70, 0x60, 0xC0, 0xC0, -0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0, 0xFE, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x07, 0x1F, 0xFC, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x1F, 0x7F, 0x78, 0xF8, 0xFC, 0xFC, -0xFE, 0xFE, 0x7E, 0x7F, 0x7F, 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x3F, 0xFF, 0xC0, -0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0x60, -0x20, 0x30, 0x30, 0xD0, 0x98, 0x08, 0x1C, 0x3E, 0x63, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0xE0, 0x30, 0x31, 0x33, 0xF7, 0xEF, 0x0E, 0x0C, 0x1C, 0x38, 0xF8, 0xF8, 0x18, 0x18, 0x18, -0x18, 0x18, 0x18, 0x18, 0x1C, 0x1C, 0x0E, 0x0E, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10, 0x10, -0x30, 0x30, 0x60, 0x60, 0x60, 0x60, 0x40, 0x45, 0x43, 0x43, 0x47, 0x47, 0x7F, 0x7F, 0xFF, 0xFF, -0x0F, 0x0F, 0x0F, 0x0E, 0x1D, 0x38, 0x30, 0x30, 0x21, 0x23, 0x24, 0x24, 0x38, 0x0F, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFA, 0xF0, 0xE0, 0x8F, 0x3F, 0x7E, 0xD8, 0x30, 0xF0, 0xFF, -0xFF, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, -0x00, 0x02, 0x06, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0x3F, 0xFC, 0xF0, -0xE0, 0x01, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, -0xF0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0x00, 0x00, 0x00, 0x00, -0x70, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x01, 0x03, 0x87, 0xFE, 0x7C, 0x60, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x3F, 0x00, -0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x0F, -0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x3F, 0xFE, 0x00, 0x00, 0x3C, 0x7F, 0xFF, 0xE0, 0xC0, 0x80, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x3F, 0xFF, 0xE1, 0xC0, 0xC0, 0x80, 0xE0, 0x78, 0x0E, -0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xDF, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x70, 0xF1, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0D, 0x30, 0xE0, 0x80, 0x80, -0x80, 0x81, 0xFF, 0xFF, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, -0x20, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0xC0, 0x20, 0x20, 0x00, -0xF7, 0x5E, 0x5E, 0x0C, 0xEC, 0x8C, 0x84, 0x0E, 0xBE, 0x9E, 0x9F, 0x0F, 0x87, 0x91, 0x80, 0x00, -0x90, 0x90 ]; - -var world_map = [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x00, 0x60, 0xC0, 0xF0, 0xDC, 0x7C, 0X3C, 0x1C, 0xF0, 0xF8, 0xF0, 0xF0, - 0xF8, 0xF8, 0xFE, 0xFE, 0xE6, 0xD4, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, - 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0xB0, 0x70, - 0xC0, 0x60, 0x00, 0xB0, 0x90, 0x28, 0xE3, 0x41, 0xC0, 0x81, 0x01, 0x03, 0x0F, 0x3F, 0xFF, - 0xFF, 0xFF, 0xFF, 0xBF, 0x0F, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, - 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x84, 0x40, 0x00, 0xE0, 0x80, 0xF0, 0xF8, - 0xF8, 0xFC, 0xFC, 0xEC, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xC0, 0xC0, 0x80, 0x00, - 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x0B, 0x3F, 0x0F, 0x0F, 0x0F, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFF, - 0xFE, 0xFF, 0xFE, 0xFE, 0xE7, 0xC1, 0xC1, 0x00, 0xF8, 0xF7, 0xE5, 0xC0, 0x00, 0x03, 0x0F, - 0x07, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x80, 0x00, 0x98, 0xBC, 0xD7, 0xE9, - 0xEF, 0xFF, 0xFD, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0x0F, 0x0F, 0x0F, 0x0F, 0x3F, - 0x0F, 0x0F, 0x07, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, - 0x3F, 0x7F, 0xFF, 0x7F, 0x3F, 0x3E, 0x3D, 0x1B, 0x07, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xEC, 0xED, 0xF3, 0xF3, 0xE5, 0xC3, 0xEF, - 0xE7, 0xE9, 0x29, 0xFB, 0xFF, 0xB1, 0xBD, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, - 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x67, 0x07, 0x07, 0x13, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x02, 0x30, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xE0, 0xE0, - 0xE0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x07, 0x07, 0x07, 0xBF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0x1E, 0x0F, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x00, 0x00, - 0x01, 0x11, 0x23, 0x10, 0x10, 0x00, 0x00, 0x00, 0x80, 0x20, 0xA0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x7F, 0x3F, 0x0F, 0x0F, 0x03, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, - 0x0F, 0x07, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x1F, 0x5E, 0x0C, 0x00, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; - diff --git a/books/beaglebone-cookbook/03displays/code/pwmTest.sh b/books/beaglebone-cookbook/03displays/code/pwmTest.sh deleted file mode 100755 index 188ef6ffc665d6f2561667af8ce9bbcc57277bc3..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/pwmTest.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -# config-pin P9_14 pwm - -PWMPATH=/sys/class/pwm - -echo Testing pwmchip$1 pwm$2 in -echo $PWMPATH/pwmchip$1 - - -cd $PWMPATH/pwmchip$1 -sudo chgrp gpio * -sudo chmod g+w * -echo $2 > export - -cd pwm$2 -sudo chgrp gpio * -sudo chmod g+w * -ls -ls -echo 1000000000 > period -echo 500000000 > duty_cycle -echo 1 > enable \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/code/speak.js b/books/beaglebone-cookbook/03displays/code/speak.js deleted file mode 100755 index 9ee797de6499cd8495a8f1ac33bd621e6ba1598d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/03displays/code/speak.js +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env node - -var exec = require('child_process').exec; - -function speakForSelf(phrase) { -{ - exec('flite -t "' + phrase + '"', function (error, stdout, stderr) { - console.log(stdout); - if(error) { - console.log('error: ' + error); - } - if(stderr) { - console.log('stderr: ' + stderr); - } - }); -} - -speakForSelf("Hello, My name is Borris. " + - "I am a BeagleBone Black, " + - "a true open hardware, " + - "community-supported embedded computer for developers and hobbyists. " + - "I am powered by a 1 Giga Hertz Sitaraâ„¢ ARM® Cortex-A8 processor. " + - "I boot Linux in under 10 seconds. " + - "You can get started on development in " + - "less than 5 minutes with just a single USB cable." + - "Bark, bark!" - ); \ No newline at end of file diff --git a/books/beaglebone-cookbook/03displays/displays.rst b/books/beaglebone-cookbook/03displays/displays.rst index 3abec72fb8617a9342206634bbd2ab4061737c1f..dcd7c689e60c1af0f47748dd2a4e88f3aeda78bf 100644 --- a/books/beaglebone-cookbook/03displays/displays.rst +++ b/books/beaglebone-cookbook/03displays/displays.rst @@ -57,25 +57,25 @@ a more traditional editor (as shown in :ref:`tips_editing_files`). .. _py_internLED_code: -.. literalinclude:: code/internLED.py +.. literalinclude:: ../code/03displays/internLED.py :caption: Using an internal LED (internLED.py) :linenos: -:download:`internLED.py <code/internLED.py>` +:download:`internLED.py <../code/03displays/internLED.py>` .. _js_internLED_code: -.. literalinclude:: code/internLED.js +.. literalinclude:: ../code/03displays/internLED.js :caption: Using an internal LED (internLED.js) :linenos: -:download:`internLED.js <code/internLED.js>` +:download:`internLED.js <../code/03displays/internLED.js>` In the *bash* command window, enter the following commands: .. code-block:: bash - bone$ cd ~/BoneCookbook/docs/03displays/code + bone$ cd ~/beaglebone-cookbook-code/03displays bone$ ./internLED.js @@ -126,19 +126,19 @@ and find the code shown in :ref:`py_externLED_code`. .. _py_externLED_code: -.. literalinclude:: code/externLED.py +.. literalinclude:: ../code/03displays/externLED.py :caption: Code for using an external LED (externLED.py) :linenos: -:download:`externLED.py <code/externLED.py>` +:download:`externLED.py <../code/03displays/externLED.py>` .. _js_externLED_code: -.. literalinclude:: code/externLED.js +.. literalinclude:: ../code/03displays/externLED.js :caption: Code for using an external LED (externLED.js) :linenos: -:download:`externLED.js <code/externLED.js>` +:download:`externLED.js <../code/03displays/externLED.js>` Save your file and run the code as before (:ref:`displays_onboardLED`). @@ -201,19 +201,19 @@ Then run it as before. .. _py_fadeLED_code: -.. literalinclude:: code/fadeLED.py +.. literalinclude:: ../code/03displays/fadeLED.py :caption: Code for using an external LED (fadeLED.py) :linenos: -:download:`fadeLED.py <code/fadeLED.py>` +:download:`fadeLED.py <../code/03displays/fadeLED.py>` .. _js_fadeLED_code: -.. literalinclude:: code/fadeLED.js +.. literalinclude:: ../code/03displays/fadeLED.js :caption: Code for using an external LED (fadeLED.js) :linenos: -:download:`fadeLED.js <code/fadeLED.js>` +:download:`fadeLED.js <../code/03displays/fadeLED.js>` The Bone has several outputs that can be use as pwm's as shown in :ref:`cape-headers-pwm_fig`. There are three *EHRPWM's* which each has a pair of pwm channels. Each pair must have the same period. @@ -354,7 +354,7 @@ LED matrix display (matrixLEDi2c.py) .. code-block:: C - include::code/matrixLEDi2c.py + include::../code/03displays/matrixLEDi2c.py 1. This line states which bus to use. The last digit gives the BoneScript bus number. @@ -461,7 +461,7 @@ Writing to a NeoPixel LED String Using LEDscape .. // [source, bash] .. // ---- -.. // include::code/neoPixel.sh +.. // include::../code/03displays/neoPixel.sh .. // ---- .. // ==== @@ -490,10 +490,10 @@ Then add the code from :ref:`speak_code` in a file called ``speak.js`` and run. .. _speak_code: -.. literalinclude:: code/speak.js +.. literalinclude:: ../code/03displays/speak.js :caption: A program that talks (speak.js) :linenos: -:download:`speak.js <code/speak.js>` +:download:`speak.js <../code/03displays/speak.js>` See :ref:`sensors_audio` to see how to use a USB audio dongle and set your default audio out. diff --git a/books/beaglebone-cookbook/04motors/code/bipolarStepperMotor.py b/books/beaglebone-cookbook/04motors/code/bipolarStepperMotor.py deleted file mode 100755 index 2b0b2cafd00d3621f67f52a67902d1fb02093bf7..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/bipolarStepperMotor.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -import time -import os -import signal -import sys - -# Motor is attached here -# controller = ["P9_11", "P9_13", "P9_15", "P9_17"]; -# controller = ["30", "31", "48", "5"] -# controller = ["P9_14", "P9_16", "P9_18", "P9_22"]; -controller = ["50", "51", "4", "2"] -states = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]] -statesHiTorque = [[1,1,0,0], [0,1,1,0], [0,0,1,1], [1,0,0,1]] -statesHalfStep = [[1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0], - [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1]] - -curState = 0 # Current state -ms = 100 # Time between steps, in ms -maxStep = 22 # Number of steps to turn before turning around -minStep = 0 # minimum step to turn back around on - -CW = 1 # Clockwise -CCW = -1 -pos = 0 # current position and direction -direction = CW -GPIOPATH="/sys/class/gpio" - -def signal_handler(sig, frame): - print('Got SIGINT, turning motor off') - for i in range(len(controller)) : - f = open(GPIOPATH+"/gpio"+controller[i]+"/value", "w") - f.write('0') - f.close() - sys.exit(0) -signal.signal(signal.SIGINT, signal_handler) -print('Hit ^C to stop') - -def move(): - global pos - global direction - global minStep - global maxStep - pos += direction - print("pos: " + str(pos)) - # Switch directions if at end. - if (pos >= maxStep or pos <= minStep) : - direction *= -1 - rotate(direction) - -# This is the general rotate -def rotate(direction) : - global curState - global states - # print("rotate(%d)", direction); - # Rotate the state acording to the direction of rotation - curState += direction - if(curState >= len(states)) : - curState = 0; - elif(curState<0) : - curState = len(states)-1 - updateState(states[curState]) - -# Write the current input state to the controller -def updateState(state) : - global controller - print(state) - for i in range(len(controller)) : - f = open(GPIOPATH+"/gpio"+controller[i]+"/value", "w") - f.write(str(state[i])) - f.close() - -# Initialize motor control pins to be OUTPUTs -for i in range(len(controller)) : - # Make sure pin is exported - if (not os.path.exists(GPIOPATH+"/gpio"+controller[i])): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() - # Make it an output pin - f = open(GPIOPATH+"/gpio"+controller[i]+"/direction", "w") - f.write("out") - f.close() - -# Put the motor into a known state -updateState(states[0]) -rotate(direction) - -# Rotate -while True: - move() - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/04motors/code/dcMotor.js b/books/beaglebone-cookbook/04motors/code/dcMotor.js deleted file mode 100755 index 09c798c94a8a6d497373db17f34201b9125c44bf..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/dcMotor.js +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// dcMotor.js -// This is an example of driving a DC motor -// Wiring: -// Setup: config-pin P9_16 pwm -// See: -//////////////////////////////////////// -const fs = require("fs"); - -const pwmPeriod = '1000000'; // Period in ns -const pwm = '1'; // pwm to use -const channel = 'b'; // channel to use -const PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel; - -const low = 0.05, // Slowest speed (duty cycle) - hi = 1, // Fastest (always on) - ms = 100; // How often to change speed, in ms -var speed = 0.5, // Current speed; - step = 0.05; // Change in speed - -// fs.writeFileSync(PWMPATH+'/export', pwm); // Export the pwm channel -// Set the period in ns, first 0 duty_cycle, -fs.writeFileSync(PWMPATH+'/duty_cycle', '0'); -fs.writeFileSync(PWMPATH+'/period', pwmPeriod); -fs.writeFileSync(PWMPATH+'/duty_cycle', pwmPeriod/2); -fs.writeFileSync(PWMPATH+'/enable', '1'); - -timer = setInterval(sweep, ms); - -function sweep() { - speed += step; - if(speed > hi || speed < low) { - step *= -1; - } - fs.writeFileSync(PWMPATH+'/duty_cycle', parseInt(pwmPeriod*speed)); - // console.log('speed = ' + speed); -} - -process.on('SIGINT', function() { - console.log('Got SIGINT, turning motor off'); - clearInterval(timer); // Stop the timer - fs.writeFileSync(PWMPATH+'/enable', '0'); -}); \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/dcMotor.py b/books/beaglebone-cookbook/04motors/code/dcMotor.py deleted file mode 100755 index 755eaf8481c6d35a523ed5ecd20ec40ceed16a10..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/dcMotor.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // dcMotor.js -# // This is an example of driving a DC motor -# // Wiring: -# // Setup: config-pin P9_16 pwm -# // See: -# //////////////////////////////////////// -import time -import signal -import sys - -def signal_handler(sig, frame): - print('Got SIGINT, turning motor off') - f = open(PWMPATH+'/enable', 'w') - f.write('0') - f.close() - sys.exit(0) -signal.signal(signal.SIGINT, signal_handler) - -pwmPeriod = '1000000' # Period in ns -pwm = '1' # pwm to use -channel = 'b' # channel to use -PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel - -low = 0.05 # Slowest speed (duty cycle) -hi = 1 # Fastest (always on) -ms = 100 # How often to change speed, in ms -speed = 0.5 # Current speed -step = 0.05 # Change in speed - -f = open(PWMPATH+'/duty_cycle', 'w') -f.write('0') -f.close() -f = open(PWMPATH+'/period', 'w') -f.write(pwmPeriod) -f.close() -f = open(PWMPATH+'/enable', 'w') -f.write('1') -f.close() - -f = open(PWMPATH+'/duty_cycle', 'w') -while True: - speed += step - if(speed > hi or speed < low): - step *= -1 - duty_cycle = str(round(speed*1000000)) # Convert ms to ns - f.seek(0) - f.write(duty_cycle) - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/04motors/code/h-bridgeMotor.js b/books/beaglebone-cookbook/04motors/code/h-bridgeMotor.js deleted file mode 100755 index 239418dd7237b6483231fd5944f237bc5f38e1da..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/h-bridgeMotor.js +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env node - -// This example uses an H-bridge to drive a DC motor in two directions - -var b = require('bonescript'); - -var enable = 'P9_21'; // Pin to use for PWM speed control - in1 = 'P9_15', - in2 = 'P9_16', - step = 0.05, // Change in speed - min = 0.05, // Min duty cycle - max = 1.0, // Max duty cycle - ms = 100, // Update time, in ms - speed = min; // Current speed; - -b.pinMode(enable, b.ANALOG_OUTPUT, 6, 0, 0, doInterval); -b.pinMode(in1, b.OUTPUT); -b.pinMode(in2, b.OUTPUT); - -function doInterval(x) { - if(x.err) { - console.log('x.err = ' + x.err); - return; - } - timer = setInterval(sweep, ms); -} - -clockwise(); // Start by going clockwise - -function sweep() { - speed += step; - if(speed > max || speed < min) { - step *= -1; - step>0 ? clockwise() : counterClockwise(); - } - b.analogWrite(enable, speed); - console.log('speed = ' + speed); -} - -function clockwise() { - b.digitalWrite(in1, b.HIGH); - b.digitalWrite(in2, b.LOW); -} - -function counterClockwise() { - b.digitalWrite(in1, b.LOW); - b.digitalWrite(in2, b.HIGH); -} - -process.on('SIGINT', function() { - console.log('Got SIGINT, turning motor off'); - clearInterval(timer); // Stop the timer - b.analogWrite(enable, 0); // Turn motor off -}); \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/ring.js b/books/beaglebone-cookbook/04motors/code/ring.js deleted file mode 100755 index a383eae4dc7d5639da22ea7623fb5f0927ae1c38..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/ring.js +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env node - -// Drive a simple servo motor back and forth - -var b = require('bonescript'); - -var motor = 'P9_21', // Pin to control servo - freq = 50, // Servo frequency (20 ms) - min = 0.8, // Smallest angle (in ms) - max = 2.5, // Largest angle (in ms) - ms = 500, // How often to change position, in ms - pos = 1.5, // Current position, about middle - step = 0.1; // Step size to next position -var timer; - -console.log('Hit ^C to stop'); -b.pinMode(motor, b.ANALOG_OUTPUT); - -pos1(); - -function pos1() { - move(0.9); - timer = setTimeout(pos2, ms); -} -function pos2() { - move(2.1); // Start in the middle - timer = setTimeout(pos1, ms); -} - -function move(pos) { - var dutyCycle = pos/1000*freq; - b.analogWrite(motor, dutyCycle, freq); - console.log('pos = ' + pos.toFixed(3) + ' duty cycle = ' + dutyCycle.toFixed(3)); -} - -process.on('SIGINT', function() { - console.log('Got SIGINT, turning motor off'); - clearTimeout(timer); // Stop the timer - b.analogWrite(motor, 0, 0); // Turn motor off -}); \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/servoBird.js b/books/beaglebone-cookbook/04motors/code/servoBird.js deleted file mode 100755 index 29466b949aac459f027b5466a8a9cc4700d6f23e..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/servoBird.js +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env node -var b = require('bonescript'); -var motor = 'P9_14'; // Pin to use -var freq = 80; // Servo frequency -var dir = 0.001, // Direction - min = 0.05, - max = 0.15, - ms = 50, - pos = min; // Current position; - -b.pinMode(motor, b.ANALOG_OUTPUT); - -setInterval(move, ms); - -function move() { - pos += dir; - if(pos > max || pos < min) { - dir = -1 * dir; - } - b.analogWrite(motor, pos, freq); - console.log('pos = ' + pos); -} diff --git a/books/beaglebone-cookbook/04motors/code/servoEncoder.py b/books/beaglebone-cookbook/04motors/code/servoEncoder.py deleted file mode 100755 index 70724954dbd51f50483a5a225834ebe84f3f6d1f..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/servoEncoder.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // servoEncoder.py -# // Drive a simple servo motor using rotary encoder viq eQEP -# // Wiring: Servo on P9_16, rotary encoder on P8_11 and P8_12 -# // Setup: config-pin P9_16 pwm -# // config-pin P8_11 eqep -# // config-pin P8_12 eqep -# // See: -# //////////////////////////////////////// -import time -import signal -import sys - -# Set up encoder -eQEP = '2' -COUNTERPATH = '/dev/bone/counter/counter'+eQEP+'/count0' -maxCount = '180' - -ms = 100 # Time between samples in ms - -# Set the eEQP maximum count -fQEP = open(COUNTERPATH+'/ceiling', 'w') -fQEP.write(maxCount) -fQEP.close() - -# Enable -fQEP = open(COUNTERPATH+'/enable', 'w') -fQEP.write('1') -fQEP.close() - -fQEP = open(COUNTERPATH+'/count', 'r') - -# Set up servo -pwmPeriod = '20000000' # Period in ns, (20 ms) -pwm = '1' # pwm to use -channel = 'b' # channel to use -PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel -low = 0.6 # Smallest angle (in ms) -hi = 2.5 # Largest angle (in ms) -ms = 250 # How often to change position, in ms -pos = 1.5 # Current position, about middle ms) -step = 0.1 # Step size to next position - -def signal_handler(sig, frame): - print('Got SIGINT, turning motor off') - f = open(PWMPATH+'/enable', 'w') - f.write('0') - f.close() - sys.exit(0) -signal.signal(signal.SIGINT, signal_handler) - -f = open(PWMPATH+'/period', 'w') -f.write(pwmPeriod) -f.close() -f = open(PWMPATH+'/duty_cycle', 'w') -f.write(str(round(int(pwmPeriod)/2))) -f.close() -f = open(PWMPATH+'/enable', 'w') -f.write('1') -f.close() - -print('Hit ^C to stop') - -olddata = -1 -while True: - fQEP.seek(0) - data = fQEP.read()[:-1] - # Print only if data changes - if data != olddata: - olddata = data - # print("data = " + data) - # # map 0-180 to low-hi - duty_cycle = -1*int(data)*(hi-low)/180.0 + hi - duty_cycle = str(int(duty_cycle*1000000)) # Convert from ms to ns - # print('duty_cycle = ' + duty_cycle) - f = open(PWMPATH+'/duty_cycle', 'w') - f.write(duty_cycle) - f.close() - time.sleep(ms/1000) - -# Black OR Pocket -# eQEP0: P9.27 and P9.42 OR P1_33 and P2_34 -# eQEP1: P9.33 and P9.35 -# eQEP2: P8.11 and P8.12 OR P2_24 and P2_33 - -# AI -# eQEP1: P8.33 and P8.35 -# eQEP2: P8.11 and P8.12 or P9.19 and P9.41 -# eQEP3: P8.24 abd P8.25 or P9.27 and P9.42 - -# | Pin | pwm | channel -# | P9_31 | 0 | a -# | P9_29 | 0 | b -# | P9_14 | 1 | a -# | P9_16 | 1 | b -# | P8_19 | 2 | a -# | P8_13 | 2 | b diff --git a/books/beaglebone-cookbook/04motors/code/servoMotor.js b/books/beaglebone-cookbook/04motors/code/servoMotor.js deleted file mode 100755 index efe028801d442bd273f65fddf04d14daa4ab6c2d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/servoMotor.js +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// servoMotor.js -// Drive a simple servo motor back and forth on P9_16 pin -// Wiring: -// Setup: config-pin P9_16 pwm -// See: -//////////////////////////////////////// -const fs = require("fs"); - -const pwmPeriod = '20000000'; // Period in ns, (20 ms) -const pwm = '1'; // pwm to use -const channel = 'b'; // channel to use -const PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel; -const low = 0.8, // Smallest angle (in ms) - hi = 2.4, // Largest angle (in ms) - ms = 250; // How often to change position, in ms -var pos = 1.5, // Current position, about middle ms) - step = 0.1; // Step size to next position - -console.log('Hit ^C to stop'); -fs.writeFileSync(PWMPATH+'/period', pwmPeriod); -fs.writeFileSync(PWMPATH+'/enable', '1'); - -var timer = setInterval(sweep, ms); - -// Sweep from low to hi position and back again -function sweep() { - pos += step; // Take a step - if(pos > hi || pos < low) { - step *= -1; - } - var dutyCycle = parseInt(pos*1000000); // Convert ms to ns - // console.log('pos = ' + pos + ' duty cycle = ' + dutyCycle); - fs.writeFileSync(PWMPATH+'/duty_cycle', dutyCycle); -} - -process.on('SIGINT', function() { - console.log('Got SIGINT, turning motor off'); - clearInterval(timer); // Stop the timer - fs.writeFileSync(PWMPATH+'/enable', '0'); -}); - -// | Pin | pwm | channel -// | P9_31 | 0 | a -// | P9_29 | 0 | b -// | P9_14 | 1 | a -// | P9_16 | 1 | b -// | P8_19 | 2 | a -// | P8_13 | 2 | b \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/servoMotor.py b/books/beaglebone-cookbook/04motors/code/servoMotor.py deleted file mode 100755 index 324bc7be5570eb30b29592cd3813f5cd270889c3..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/servoMotor.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // servoMotor.py -# // Drive a simple servo motor back and forth on P9_16 pin -# // Wiring: -# // Setup: config-pin P9_16 pwm -# // See: -# //////////////////////////////////////// -import time -import signal -import sys - -pwmPeriod = '20000000' # Period in ns, (20 ms) -pwm = '1' # pwm to use -channel = 'b' # channel to use -PWMPATH='/dev/bone/pwm/'+pwm+'/'+channel -low = 0.8 # Smallest angle (in ms) -hi = 2.4 # Largest angle (in ms) -ms = 250 # How often to change position, in ms -pos = 1.5 # Current position, about middle ms) -step = 0.1 # Step size to next position - -def signal_handler(sig, frame): - print('Got SIGINT, turning motor off') - f = open(PWMPATH+'/enable', 'w') - f.write('0') - f.close() - sys.exit(0) -signal.signal(signal.SIGINT, signal_handler) -print('Hit ^C to stop') - -f = open(PWMPATH+'/period', 'w') -f.write(pwmPeriod) -f.close() -f = open(PWMPATH+'/enable', 'w') -f.write('1') -f.close() - -f = open(PWMPATH+'/duty_cycle', 'w') -while True: - pos += step # Take a step - if(pos > hi or pos < low): - step *= -1 - duty_cycle = str(round(pos*1000000)) # Convert ms to ns - # print('pos = ' + str(pos) + ' duty_cycle = ' + duty_cycle) - f.seek(0) - f.write(duty_cycle) - time.sleep(ms/1000) - -# | Pin | pwm | channel -# | P9_31 | 0 | a -# | P9_29 | 0 | b -# | P9_14 | 1 | a -# | P9_16 | 1 | b -# | P8_19 | 2 | a -# | P8_13 | 2 | b \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/servoSense.js b/books/beaglebone-cookbook/04motors/code/servoSense.js deleted file mode 100755 index 3dfe2f1fbdf8195bc5929616e430c7a3a5b31bbf..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/servoSense.js +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env node - -// Bird will bow when there is a change in the sersor distance. - -var b = require('bonescript'); -var motor = 'P9_14'; // Pin to use -var freq = 50; // Servo frequency (20 ms) -var up = 0.6, // Smallest angle (in ms) - down = 2.0, // Largest angle (in ms) - dutyCycle, - ms = 250, // How often to change position, in ms - oldPos = 0; - -b.pinMode(motor, b.ANALOG_OUTPUT, 6, 0, 0, doInterval); - -function doInterval(x) { - if(x.err) { - console.log('x.err = ' + x.err); - return; - } - setInterval(readRange, ms); -} - -move(2.0); - -function readRange() { - b.analogRead('P9_37', printStatus); -} -function printStatus(x) { - var pos = x.value; - console.log('pos = ' + pos); - if (pos-oldPos>0.5) { - move(up); - } - if (oldPos-pos>0.5) { - move(down); - } - oldPos = pos; -} - -function move(pos) { - - dutyCycle = pos/1000*freq - b.analogWrite(motor, dutyCycle, freq); - console.log('pos = ' + pos + ' duty cycle = ' + dutyCycle); -} diff --git a/books/beaglebone-cookbook/04motors/code/stop.js b/books/beaglebone-cookbook/04motors/code/stop.js deleted file mode 100755 index ff06655adfa9123a032b114742cbd5ad280b6314..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/stop.js +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env node -// Used for turning everything off. -var b = require('bonescript'); -var gpio = ['P9_11', 'P9_13', 'P9_14', 'P9_15', 'P9_16']; -var i; - -for(i=0; i<gpio.length; i++) { - b.pinMode(gpio[i], b.OUTPUT); - b.digitalWrite(gpio[i], b.LOW); -} diff --git a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.js b/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.js deleted file mode 100755 index 26032442241ed60c973a6e126a78df2078c42a68..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.js +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env node -var fs = require('fs'); - -// Motor is attached here -// var controller = ["P9_11", "P9_13", "P9_15", "P9_17"]; -// var controller = ["P9_14", "P9_16", "P9_18", "P9_22"]; -var controller = ["50", "51", "4", "2"]; -var states = [[1,1,0,0], [0,1,1,0], [0,0,1,1], [1,0,0,1]]; - -var curState = 0; // Current state -var ms = 100, // Time between steps, in ms - max = 22, // Number of steps to turn before turning around - min = 0; // Minimum step to turn back around on - -var CW = 1, // Clockwise - CCW = -1, - pos = 0, // current position and direction - direction = CW; -const GPIOPATH="/sys/class/gpio"; - -// Initialize motor control pins to be OUTPUTs -var i; -for(i=0; i<controller.length; i++) { - // Make sure pins are exported - if(!fs.existsSync(GPIOPATH+"/gpio"+controller[i])) { - fs.writeFileSync(GPIOPATH+"/export", controller[i]); - // Make it an output pin - fs.writeFileSync(GPIOPATH+"/gpio"+controller[i]+"/direction", "in"); - } -} - -// Put the motor into a known state -updateState(states[0]); -rotate(direction); - -var timer = setInterval(move, ms); - -// Rotate back and forth once -function move() { - pos += direction; - console.log("pos: " + pos); - // Switch directions if at end. - if (pos >= max || pos <= min) { - direction *= -1; - } - rotate(direction); -} - -// This is the general rotate -function rotate(direction) { - // console.log("rotate(%d)", direction); - // Rotate the state acording to the direction of rotation - curState += direction; - if(curState >= states.length) { - curState = 0; - } else if(curState<0) { - curState = states.length-1; - } - updateState(states[curState]); -} - -// Write the current input state to the controller -function updateState(state) { - console.log("state: " + state); - for (i=0; i<controller.length; i++) { - fs.writeFileSync(GPIOPATH+"/gpio"+controller[i]+"/value", state[i]) - } -} - -process.on('exit', function() { - updateState([0,0,0,0]); // Turn motor off -}); \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.js.diff b/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.js.diff deleted file mode 100644 index 4a34a7768fec3f608bd6cfe0ee6bd6a77118a90e..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.js.diff +++ /dev/null @@ -1,6 +0,0 @@ -# var controller = ["P9_11", "P9_13", "P9_15", "P9_17"]; -controller = ["30", "31", "48", "5"] -var states = [[1,1,0,0], [0,1,1,0], [0,0,1,1], [1,0,0,1]]; -var curState = 0; // Current state -var ms = 100, // Time between steps, in ms - max = 200, // Number of steps to turn before turning around \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.py b/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.py deleted file mode 100755 index 1d13e416a39279865195067ada3840a887854373..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -import time -import os -import signal -import sys - -# Motor is attached here -# controller = ["P9_11", "P9_13", "P9_15", "P9_17"]; -# controller = ["30", "31", "48", "5"] -# controller = ["P9_14", "P9_16", "P9_18", "P9_22"]; -controller = ["50", "51", "4", "2"] -states = [[1,1,0,0], [0,1,1,0], [0,0,1,1], [1,0,0,1]] -statesHiTorque = [[1,1,0,0], [0,1,1,0], [0,0,1,1], [1,0,0,1]] -statesHalfStep = [[1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0], - [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1]] - -curState = 0 # Current state -ms = 250 # Time between steps, in ms -maxStep = 22 # Number of steps to turn before turning around -minStep = 0 # minimum step to turn back around on - -CW = 1 # Clockwise -CCW = -1 -pos = 0 # current position and direction -direction = CW -GPIOPATH="/sys/class/gpio" - -def signal_handler(sig, frame): - print('Got SIGINT, turning motor off') - for i in range(len(controller)) : - f = open(GPIOPATH+"/gpio"+controller[i]+"/value", "w") - f.write('0') - f.close() - sys.exit(0) -signal.signal(signal.SIGINT, signal_handler) -print('Hit ^C to stop') - -def move(): - global pos - global direction - global minStep - global maxStep - pos += direction - print("pos: " + str(pos)) - # Switch directions if at end. - if (pos >= maxStep or pos <= minStep) : - direction *= -1 - rotate(direction) - -# This is the general rotate -def rotate(direction) : - global curState - global states - # print("rotate(%d)", direction); - # Rotate the state acording to the direction of rotation - curState += direction - if(curState >= len(states)) : - curState = 0; - elif(curState<0) : - curState = len(states)-1 - updateState(states[curState]) - -# Write the current input state to the controller -def updateState(state) : - global controller - print(state) - for i in range(len(controller)) : - f = open(GPIOPATH+"/gpio"+controller[i]+"/value", "w") - f.write(str(state[i])) - f.close() - -# Initialize motor control pins to be OUTPUTs -for i in range(len(controller)) : - # Make sure pin is exported - if (not os.path.exists(GPIOPATH+"/gpio"+controller[i])): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() - # Make it an output pin - f = open(GPIOPATH+"/gpio"+controller[i]+"/direction", "w") - f.write("out") - f.close() - -# Put the motor into a known state -updateState(states[0]) -rotate(direction) - -# Rotate -while True: - move() - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.py.diff b/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.py.diff deleted file mode 100644 index af91b7cd35747a466a872de88c04b32ea78c03fd..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/04motors/code/unipolarStepperMotor.py.diff +++ /dev/null @@ -1,6 +0,0 @@ -# controller = ["P9_11", "P9_13", "P9_15", "P9_17"] -controller = ["30", "31", "48", "5"] -states = [[1,1,0,0], [0,1,1,0], [0,0,1,1], [1,0,0,1]] -curState = 0 // Current state -ms = 100 // Time between steps, in ms -max = 200 // Number of steps to turn before turning around \ No newline at end of file diff --git a/books/beaglebone-cookbook/04motors/motors.rst b/books/beaglebone-cookbook/04motors/motors.rst index 481a684f6c1fab1c40f7a63430a780803ccb0e19..a159a8db3024e4195e52d0369c646539b67a4f9d 100644 --- a/books/beaglebone-cookbook/04motors/motors.rst +++ b/books/beaglebone-cookbook/04motors/motors.rst @@ -3,6 +3,10 @@ Motors ######## +.. |kohm| replace:: kΩ + +.. |ohm| replace:: Ω + One of the many fun things about embedded computers is that you can move physical things with motors. But there are so many different kinds of motors (``servo``, ``stepper``, ``DC``), so how do you select the right one? @@ -52,10 +56,10 @@ To make the recipe, you will need: * Servo motor. * Breadboard and jumper wires. -* 1 kΩ resistor (optional) +* 1 |kohm| resistor (optional) * 5 V power supply (optional) -The 1 kΩ resistor isn't required, but it provides some protection to the general-purpose +The 1 |kohm| resistor isn't required, but it provides some protection to the general-purpose input/output (GPIO) pin in case the servo fails and draws a large current. Wire up your servo, as shown in :ref:`motors_servoMotor`. @@ -79,25 +83,25 @@ in :ref:`py_servoMotor_code`. You need to configure the pin for PWM. .. code-block:: bash - bone$ <strong>cd ~/BoneCookbook/docs/04motors/code</strong> + bone$ <strong>cd ~/beaglebone-cookbook-code/04motors</strong> bone$ <strong>config-pin P9_16 pwm</strong> bone$ <strong>./servoMotor.py</strong> .. _py_servoMotor_code: -.. literalinclude:: code/servoMotor.py +.. literalinclude:: ../code/04motors/servoMotor.py :caption: Code for driving a servo motor (servoMotor.py) :linenos: -:download:`servoMotor.py <code/servoMotor.py>` +:download:`servoMotor.py <../code/04motors/servoMotor.py>` .. _motors_servoMotor_code: -.. literalinclude:: code/servoMotor.js +.. literalinclude:: ../code/04motors/servoMotor.js :caption: Code for driving a servo motor (servoMotor.js) :linenos: -:download:`servoMotor.js <code/servoMotor.js>` +:download:`servoMotor.js <../code/04motors/servoMotor.js>` Running the code causes the motor to move back and forth, progressing to successive @@ -126,11 +130,11 @@ Combine the code from :ref:`digital_rotaryEncoder_js` and :ref:`motors_servo`. .. _py_servoEncoder_code: -.. literalinclude:: code/servoEncoder.py +.. literalinclude:: ../code/04motors/servoEncoder.py :caption: Code for driving a servo motor with a rotary encorder(servoEncoder.py) :linenos: -:download:`servoEncoder.py <code/servoEncoder.py>` +:download:`servoEncoder.py <../code/04motors/servoEncoder.py>` .. _motors_dcSpeed: @@ -158,7 +162,7 @@ Here's what you will need: * 3 V to 5 V DC motor * Breadboard and jumper wires. -* 1 kΩ resistor. +* 1 |kohm| resistor. * Transistor 2N3904. * Diode 1N4001. * Power supply for the motor (optional) @@ -180,19 +184,19 @@ Use the code in :ref:`motors_dcMotor_code` (``dcMotor.js``) to run the motor. .. _py_dcMotor_code: -.. literalinclude:: code/dcMotor.py +.. literalinclude:: ../code/04motors/dcMotor.py :caption: Driving a DC motor in one direction (dcMotor.py) :linenos: -:download:`dcMotor.py <code/dcMotor.py>` +:download:`dcMotor.py <../code/04motors/dcMotor.py>` .. _motors_dcMotor_code: -.. literalinclude:: code/dcMotor.js +.. literalinclude:: ../code/04motors/dcMotor.js :caption: Driving a DC motor in one direction (dcMotor.js) :linenos: -:download:`dcMotor.js <code/dcMotor.js>` +:download:`dcMotor.js <../code/04motors/dcMotor.js>` See Also ========= @@ -238,11 +242,11 @@ motor with a transistor (:ref:`motors_dcMotor_code`). The additional code specif .. _motors_h-bridge_code: -.. literalinclude:: code/h-bridgeMotor.js +.. literalinclude:: ../code/04motors/h-bridgeMotor.js :caption: Code for driving a DC motor with an H-bridge (h-bridgeMotor.js) :linenos: -:download:`h-bridgeMotor.js <code/h-bridgeMotor.js>` +:download:`h-bridgeMotor.js <../code/04motors/h-bridgeMotor.js>` Driving a Bipolar Stepper Motor =============================== @@ -278,11 +282,11 @@ Use the code in :ref:`motors_stepperMotor_code_py` to drive the motor. .. _motors_stepperMotor_code_py: -.. literalinclude:: code/bipolarStepperMotor.py +.. literalinclude:: ../code/04motors/bipolarStepperMotor.py :caption: Driving a bipolar stepper motor (bipolarStepperMotor.py) :linenos: -:download:`bipolarStepperMotor.py <code/bipolarStepperMotor.py>` +:download:`bipolarStepperMotor.py <../code/04motors/bipolarStepperMotor.py>` When you run the code, the stepper motor will rotate back and forth. @@ -335,19 +339,19 @@ so :ref:`motors_unistepperMotor_code` shows only the lines that you need to chan .. _motors_unistepperMotor_js_code: -.. literalinclude:: code/unipolarStepperMotor.py.diff +.. literalinclude:: ../code/04motors/unipolarStepperMotor.py.diff :caption: Changes to bipolar code to drive a unipolar stepper motor (unipolarStepperMotor.py.diff) :linenos: -:download:`unipolarStepperMotor.py.diff <code/unipolarStepperMotor.py.diff>` +:download:`unipolarStepperMotor.py.diff <../code/04motors/unipolarStepperMotor.py.diff>` .. _motors_unistepperMotor_code: -.. literalinclude:: code/unipolarStepperMotor.js.diff +.. literalinclude:: ../code/04motors/unipolarStepperMotor.js.diff :caption: Changes to bipolar code to drive a unipolar stepper motor (unipolarStepperMotor.js.diff) :linenos: -:download:`unipolarStepperMotor.js.diff <code/unipolarStepperMotor.js.diff>` +:download:`unipolarStepperMotor.js.diff <../code/04motors/unipolarStepperMotor.js.diff>` The code in this example makes the following changes: diff --git a/books/beaglebone-cookbook/05tips/code/blinkLED.c b/books/beaglebone-cookbook/05tips/code/blinkLED.c deleted file mode 100755 index 1863c1ef9a8637f1e46d06fafcaf848324ef1e26..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/05tips/code/blinkLED.c +++ /dev/null @@ -1,48 +0,0 @@ -//////////////////////////////////////// -// blinkLED.c -// Blinks the P9_14 pin -// Wiring: -// Setup: -// See: -//////////////////////////////////////// -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#define MAXSTR 100 -// Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 -int main() { - FILE *fp; - char pin[] = "50"; - char GPIOPATH[] = "/sys/class/gpio"; - char path[MAXSTR] = ""; - - // Make sure pin is exported - snprintf(path, MAXSTR, "%s%s%s", GPIOPATH, "/gpio", pin); - if (!access(path, F_OK) == 0) { - snprintf(path, MAXSTR, "%s%s", GPIOPATH, "/export"); - fp = fopen(path, "w"); - fprintf(fp, "%s", pin); - fclose(fp); - } - - // Make it an output pin - snprintf(path, MAXSTR, "%s%s%s%s", GPIOPATH, "/gpio", pin, "/direction"); - fp = fopen(path, "w"); - fprintf(fp, "out"); - fclose(fp); - - // Blink every .25 sec - int state = 0; - snprintf(path, MAXSTR, "%s%s%s%s", GPIOPATH, "/gpio", pin, "/value"); - fp = fopen(path, "w"); - while (1) { - fseek(fp, 0, SEEK_SET); - if (state) { - fprintf(fp, "1"); - } else { - fprintf(fp, "0"); - } - state = ~state; - usleep(250000); // sleep time in microseconds - } -} \ No newline at end of file diff --git a/books/beaglebone-cookbook/05tips/code/blinkLED.py b/books/beaglebone-cookbook/05tips/code/blinkLED.py deleted file mode 100755 index 2b15ebd35f2dfcaffdf06c50791961dac06e5d03..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/05tips/code/blinkLED.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python -import Adafruit_BBIO.GPIO as GPIO -import time - -pin = "P9_14" - -GPIO.setup(pin, GPIO.OUT) - -while True: - GPIO.output(pin, GPIO.HIGH) - time.sleep(0.5) - GPIO.output(pin, GPIO.LOW) - time.sleep(0.5) diff --git a/books/beaglebone-cookbook/05tips/code/ipMasquerade.sh b/books/beaglebone-cookbook/05tips/code/ipMasquerade.sh deleted file mode 100755 index 524fb338a895212bcace7d5e116bab90b9ef1d11..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/05tips/code/ipMasquerade.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# These are the commands to run on the host to set up IP -# masquerading so the Bone can access the Internet through -# the USB connection. -# This configures the host, run ./setDNS.sh to configure the Bone. -# Inspired by http://thoughtshubham.blogspot.com/2010/03/ -# internet-over-usb-otg-on-beagleboard.html - -if [ $# -eq 0 ] ; then -echo "Usage: $0 interface (such as eth0 or wlan0)" -exit 1 -fi - -interface=$1 -hostAddr=192.168.7.1 -beagleAddr=192.168.7.2 -ip_forward=/proc/sys/net/ipv4/ip_forward - -if [ `cat $ip_forward` == 0 ] - then - echo "You need to set IP forwarding. Edit /etc/sysctl.conf using:" - echo "$ sudo nano /etc/sysctl.conf" - echo "and uncomment the line \"net.ipv4.ip_forward=1\"" - echo "to enable forwarding of packets. Then run the following:" - echo "$ sudo sysctl -p" - exit 1 - else - echo "IP forwarding is set on host." -fi -# Set up IP masquerading on the host so the bone can reach the outside world -sudo iptables -t nat -A POSTROUTING -s $beagleAddr -o $interface -j MASQUERADE diff --git a/books/beaglebone-cookbook/05tips/code/setDNS.sh b/books/beaglebone-cookbook/05tips/code/setDNS.sh deleted file mode 100755 index a73f1b51b881f3753c5b15af290a322ea49e5a26..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/05tips/code/setDNS.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# These are the commands to run on the host so the Bone -# can access the Internet through the USB connection. -# Run ./ipMasquerade.sh the first time. It will set up the host. -# Run this script if the host is already set up. -# Inspired by http://thoughtshubham.blogspot.com/2010/03/internet-over-usb-otg-on-beagleboard.html - -hostAddr=192.168.7.1 -beagleAddr=${1:-192.168.7.2} - -# Save the /etc/resolv.conf on the Beagle in case we mess things up. -ssh root@$beagleAddr "mv -n /etc/resolv.conf /etc/resolv.conf.orig" -# Create our own resolv.conf -cat - << EOF > /tmp/resolv.conf -# This is installed by ./setDNS.sh on the host - -EOF - -TMP=/tmp/nmcli -# Look up the nameserver of the host and add it to our resolv.conf -# From: http://askubuntu.com/questions/197036/how-to-know-what-dns-am-i-using-in-ubuntu-12-04 -# Use nmcli dev list for older version nmcli -# Use nmcli dev show for newer version nmcli -nmcli dev show > $TMP -if [ $? -ne 0 ]; then # $? is the return code, if not 0 something bad happened. - echo "nmcli failed, trying older 'list' instead of 'show'" - nmcli dev list > $TMP - if [ $? -ne 0 ]; then - echo "nmcli failed again, giving up..." - exit 1 - fi -fi - -grep IP4.DNS $TMP | sed 's/IP4.DNS\[.\]:/nameserver/' >> /tmp/resolv.conf - -scp /tmp/resolv.conf root@$beagleAddr:/etc - -# Tell the beagle to use the host as the gateway. -ssh root@$beagleAddr "/sbin/route add default gw $hostAddr" || true - diff --git a/books/beaglebone-cookbook/05tips/tips.rst b/books/beaglebone-cookbook/05tips/tips.rst index 1e3e0b27cf2a704fc7caeaa4cfd27cab372925cc..24d03aaee03bcba50be4473d92be2cca6977c05b 100644 --- a/books/beaglebone-cookbook/05tips/tips.rst +++ b/books/beaglebone-cookbook/05tips/tips.rst @@ -528,8 +528,8 @@ Just enter the following command: You are now in nano (:ref:`tips_nano_fig`). You can't move around the screen using the mouse, so use the arrow keys. The bottom two lines of the screen -list some useful commands. Pressing ˄G (Ctrl-G) will display more useful -commands. ˄X (Ctrl-X) exits nano and gives you the option of saving the file. +list some useful commands. Pressing ^G (Ctrl-G) will display more useful +commands. ^X (Ctrl-X) exits nano and gives you the option of saving the file. .. _tips_nano_fig: @@ -814,11 +814,11 @@ file called ``ipMasquerade.sh`` on your host computer. .. _tips_ipmasq_code: -.. literalinclude:: code/ipMasquerade.sh +.. literalinclude:: ../code/05tips/ipMasquerade.sh :caption: Code for IP Masquerading (ipMasquerade.sh) :linenos: -:download:`ipMasquerade.sh <code/ipMasquerade.sh>` +:download:`ipMasquerade.sh <../code/05tips/ipMasquerade.sh>` Then, on your host, run the following commands: @@ -836,11 +836,11 @@ in :ref:`tips_setDNS` to ``setDNS.sh`` on your host computer. .. _tips_setDNS: -.. literalinclude:: code/setDNS.sh +.. literalinclude:: ../code/05tips/setDNS.sh :caption: Code for setting the DNS on the Bone (setDNS.sh) :linenos: -:download:`setDNS.sh <code/setDNS.sh>` +:download:`setDNS.sh <../code/05tips/setDNS.sh>` Then, on your host, run the following commands: @@ -1320,11 +1320,11 @@ and is much faster. The approach is the same, write to the */sys/class/gpio* fi .. _misc_c_blink: -.. literalinclude:: code/blinkLED.c +.. literalinclude:: ../code/05tips/blinkLED.c :caption: Use C to blink an LED (blinkLED.c) :linenos: -:download:`blinkLED.c <code/blinkLED.c>` +:download:`blinkLED.c <../code/05tips/blinkLED.c>` Here, as with JavaScript and Python, the gpio pins are refered to by the Linux gpio number. :ref:`tips_cape_headers_digital` shows how the P8 and P9 Headers numbers map to the gpio number. diff --git a/books/beaglebone-cookbook/06iot/code/GPIOserver.js b/books/beaglebone-cookbook/06iot/code/GPIOserver.js deleted file mode 100755 index 00c28d9b2fc9f04739d03c213aa29ba44d18c1cc..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/GPIOserver.js +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env node -// Initial idea from Getting Started With node.js and socket.io -// http://codehenge.net/blog/2011/12/getting-started-with-node-js-and-socket-io- -// v0-7-part-2/ -// This is a simple server for the various web frontends -// Display status of P9_42 -"use strict"; - -var port = 9090, // Port on which to listen - http = require('http'), - url = require('url'), - fs = require('fs'), - b = require('bonescript'), - gpio = 'P9_42'; // gpio port to read - - // <1> -var htmlStart = "\ -<!DOCTYPE html>\ -<html>\ -<body>\ -\ -<h1>" + gpio + "</h1>\ -data = "; - - // <2> -var htmlEnd = "\ -</body>\ -</html>"; - -var server = http.createServer(servePage); - -b.pinMode(gpio, b.INPUT, 7, 'pulldown'); - -server.listen(port); -console.log("Listening on " + port); - -function servePage(req, res) { - var path = url.parse(req.url).pathname; - console.log("path: " + path); - if (path === '/gpio') { // <3> - var data = b.digitalRead(gpio); // <4> - res.write(htmlStart + data + htmlEnd, 'utf8'); // <5> - res.end(); - } else { - fs.readFile(__dirname + path, function (err, data) { - if (err) { - return send404(res); - } - res.write(data, 'utf8'); - res.end(); - }); - } -} - -function send404(res) { - res.writeHead(404); - res.write('404 - page not found'); - res.end(); -} diff --git a/books/beaglebone-cookbook/06iot/code/analogInContinuous.py b/books/beaglebone-cookbook/06iot/code/analogInContinuous.py deleted file mode 100755 index f026aa92c085aeebfdb662c623bdfdb8244de2fa..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/analogInContinuous.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/python -#////////////////////////////////////// -# analogInContinuous.py -# Read analog data via IIO continous mode and plots it. -#////////////////////////////////////// -# From: https://stackoverflow.com/questions/20295646/python-ascii-plots-in-terminal -# https://github.com/dkogan/gnuplotlib -# https://github.com/dkogan/gnuplotlib/blob/master/guide/guide.org -# sudo apt install gnuplot (10 minute to install) -# sudo apt install libatlas-base-dev -# pip3 install gnuplotlib -# This uses X11, so when connecting to the bone from the host use: ssh -X bone - -# See https://elinux.org/index.php?title=EBC_Exercise_10a_Analog_In#Analog_in_-_Continuous.2C_Change_the_sample_rate -# for instructions on changing the sampling rate. Can go up to 200KHz. - -fd = open(IIODEV, "r") -import numpy as np -import gnuplotlib as gp -import time -# import struct - -IIOPATH='/sys/bus/iio/devices/iio:device0' -IIODEV='/dev/iio:device0' -LEN = 100 -SAMPLERATE=8000 -AIN='2' - -# Setup IIO for Continous reading -# Enable AIN -try: - file1 = open(IIOPATH+'/scan_elements/in_voltage'+AIN+'_en', 'w') - file1.write('1') - file1.close() -except: # carry on if it's already enabled - pass -# Set buffer length -file1 = open(IIOPATH+'/buffer/length', 'w') -file1.write(str(2*LEN)) # I think LEN is in 16-bit values, but here we pass bytes -file1.close() -# Enable continous -file1 = open(IIOPATH+'/buffer/enable', 'w') -file1.write('1') -file1.close() - -x = np.linspace(0, 1000*LEN/SAMPLERATE, LEN) -# Do a dummy plot to give time of the fonts to load. -gp.plot(x, x) -print("Waiting for fonts to load") -time.sleep(10) - -print('Hit ^C to stop') - -fd = open(IIODEV, "r") - -try: - while True: - y = np.fromfile(fd, dtype='uint16', count=LEN)*1.8/4096 - # print(y) - gp.plot(x, y, - xlabel = 't (ms)', - ylabel = 'volts', - _yrange = [0, 2], - title = 'analogInContinuous', - legend = np.array( ("P9.39", ), ), - # ascii=1, - # terminal="xterm", - # legend = np.array( ("P9.40", "P9.38"), ), - # _with = 'lines' - ) - -except KeyboardInterrupt: - print("Turning off input.") - # Disable continous - file1 = open(IIOPATH+'/buffer/enable', 'w') - file1.write('0') - file1.close() - - file1 = open(IIOPATH+'/scan_elements/in_voltage'+AIN+'_en', 'w') - file1.write('0') - file1.close() - -# // Bone | Pocket | AIN -# // ----- | ------ | --- -# // P9_39 | P1_19 | 0 -# // P9_40 | P1_21 | 1 -# // P9_37 | P1_23 | 2 -# // P9_38 | P1_25 | 3 -# // P9_33 | P1_27 | 4 -# // P9_36 | P2_35 | 5 -# // P9_35 | P1_02 | 6 diff --git a/books/beaglebone-cookbook/06iot/code/emailTest.py b/books/beaglebone-cookbook/06iot/code/emailTest.py deleted file mode 100755 index 4c696b7c0553193d9fc8bb6321f5a864d989c8f7..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/emailTest.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python -# From: https://realpython.com/python-send-email/ -import smtplib, ssl - -port = 587 # For starttls -smtp_server = "smtp.gmail.com" -sender_email = "from_account@gmail.com" -receiver_email = "to_account@gmail.com" -# Go to: https://myaccount.google.com/security -# Select App password -# Generate your own 16 char password, copy here -# Delete password when done -password = "cftqhcejjdjfdwjh" -message = """\ -Subject: Testing email - -This message is sent from Python. - -""" -context = ssl.create_default_context() -with smtplib.SMTP(smtp_server, port) as server: - server.starttls(context=context) - server.login(sender_email, password) - server.sendmail(sender_email, receiver_email, message) diff --git a/books/beaglebone-cookbook/06iot/code/flask/app1.py b/books/beaglebone-cookbook/06iot/code/flask/app1.py deleted file mode 100755 index 7a0597c5a2b83598f4722faf1eae6a0945d4f149..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/app1.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -# From: https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d - -''' -Code created by Matt Richardson -for details, visit: http://mattrichardson.com/Raspberry-Pi-Flask/inde... -''' -from flask import Flask, render_template -import datetime -app = Flask(__name__) -@app.route("/") -def hello(): - now = datetime.datetime.now() - timeString = now.strftime("%Y-%m-%d %H:%M") - templateData = { - 'title' : 'HELLO!', - 'time': timeString - } - return render_template('index1.html', **templateData) -if __name__ == "__main__": - app.run(host='0.0.0.0', port=8080, debug=True) - \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/app2.py b/books/beaglebone-cookbook/06iot/code/flask/app2.py deleted file mode 100755 index a6f026cdcd327e63e9d8ea7586cf612fa142854e..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/app2.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python -# From: https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d -import os -from flask import Flask, render_template -app = Flask(__name__) - -pin = '30' # P9_11 is gpio 30 -GPIOPATH="/sys/class/gpio" -buttonSts = 0 - -# Make sure pin is exported -if (not os.path.exists(GPIOPATH+"/gpio"+pin)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() - -# Make it an input pin -f = open(GPIOPATH+"/gpio"+pin+"/direction", "w") -f.write("in") -f.close() - -@app.route("/") -def index(): - # Read Button Status - f = open(GPIOPATH+"/gpio"+pin+"/value", "r") - buttonSts = f.read()[:-1] - f.close() - - # buttonSts = GPIO.input(button) - templateData = { - 'title' : 'GPIO input Status!', - 'button' : buttonSts, - } - return render_template('index2.html', **templateData) -if __name__ == "__main__": - app.run(host='0.0.0.0', port=8080, debug=True) \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/app3.py b/books/beaglebone-cookbook/06iot/code/flask/app3.py deleted file mode 100755 index 388206d5dab5d0d5e0bfb035c04e860991208ffd..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/app3.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# From: https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d -# import Adafruit_BBIO.GPIO as GPIO -import os -from flask import Flask, render_template, request -app = Flask(__name__) -#define LED GPIO -ledRed = "P9_14" -pin = '50' # P9_14 is gpio 50 -GPIOPATH="/sys/class/gpio" - -#initialize GPIO status variable -ledRedSts = 0 -# Make sure pin is exported -if (not os.path.exists(GPIOPATH+"/gpio"+pin)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() -# Define led pin as output -f = open(GPIOPATH+"/gpio"+pin+"/direction", "w") -f.write("out") -f.close() -# turn led OFF -f = open(GPIOPATH+"/gpio"+pin+"/value", "w") -f.write("0") -f.close() - -@app.route("/") -def index(): - # Read Sensors Status - f = open(GPIOPATH+"/gpio"+pin+"/value", "r") - ledRedSts = f.read() - f.close() - templateData = { - 'title' : 'GPIO output Status!', - 'ledRed' : ledRedSts, - } - return render_template('index3.html', **templateData) - -@app.route("/<deviceName>/<action>") -def action(deviceName, action): - if deviceName == 'ledRed': - actuator = ledRed - f = open(GPIOPATH+"/gpio"+pin+"/value", "w") - if action == "on": - f.write("1") - if action == "off": - f.write("0") - f.close() - - f = open(GPIOPATH+"/gpio"+pin+"/value", "r") - ledRedSts = f.read() - f.close() - - templateData = { - 'ledRed' : ledRedSts, - } - return render_template('index3.html', **templateData) -if __name__ == "__main__": - app.run(host='0.0.0.0', port=8080, debug=True) \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/app4.py b/books/beaglebone-cookbook/06iot/code/flask/app4.py deleted file mode 100755 index 9799ff3d50c6158d237721473b5e0e754a0227b9..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/app4.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# From: https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d -import os -# import Adafruit_BBIO.GPIO as GPIO -from flask import Flask, render_template, request -app = Flask(__name__) -GPIOPATH="/sys/class/gpio" -#define sensors GPIOs -button = "30" # "P9_11" -#define actuators GPIOs -ledRed = "50" # "P9_14" - -# Make sure pin is exported -if (not os.path.exists(GPIOPATH+"/gpio"+button)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() -if (not os.path.exists(GPIOPATH+"/gpio"+ledRed)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() -#initialize GPIO status variables -buttonSts = 0 -ledRedSts = 0 -# Define button and PIR sensor pins as an input -f = open(GPIOPATH+"/gpio"+button+"/direction", "w") -f.write("in") -f.close() -# Define led pins as output -f = open(GPIOPATH+"/gpio"+ledRed+"/direction", "w") -f.write("out") -f.close() -# turn leds OFF -f = open(GPIOPATH+"/gpio"+ledRed+"/value", "w") -f.write("0") -f.close() - -@app.route("/") -def index(): - # Read GPIO Status - f = open(GPIOPATH+"/gpio"+button+"/value", "r") - buttonSts = f.read()[:-1] - f.close() - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "r") - ledRedSts = f.read()[:-1] - f.close() - - templateData = { - 'button' : buttonSts, - 'ledRed' : ledRedSts, - } - return render_template('index4.html', **templateData) - -@app.route("/<deviceName>/<action>") -def action(deviceName, action): - if deviceName == 'ledRed': - actuator = ledRed - - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "w") - if action == "on": - f.write("1") - if action == "off": - f.write("0") - f.close() - - f = open(GPIOPATH+"/gpio"+button+"/value", "r") - buttonSts = f.read()[:-1] - f.close() - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "r") - ledRedSts = int(f.read()[:-1]) - f.close() - - templateData = { - 'button' : buttonSts, - 'ledRed' : ledRedSts, - } - return render_template('index4.html', **templateData) -if __name__ == "__main__": - app.run(host='0.0.0.0', port=8080, debug=True) \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/app5.py b/books/beaglebone-cookbook/06iot/code/flask/app5.py deleted file mode 100755 index d92a2583af3eb4d9a6438fb8eaa4d051197b38e2..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/app5.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python -# From: https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d -import os -# import Adafruit_BBIO.GPIO as GPIO -from flask import Flask, render_template, request -app = Flask(__name__) -GPIOPATH="/sys/class/gpio" -#define sensors GPIOs -button = "30" # "P9_11" -#define actuators GPIOs -ledRed = "50" # "P9_14" - -# Make sure pin is exported -if (not os.path.exists(GPIOPATH+"/gpio"+button)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() -if (not os.path.exists(GPIOPATH+"/gpio"+ledRed)): - f = open(GPIOPATH+"/export", "w") - f.write(pin) - f.close() -#initialize GPIO status variables -buttonSts = 0 -ledRedSts = 0 -# Define button and PIR sensor pins as an input -f = open(GPIOPATH+"/gpio"+button+"/direction", "w") -f.write("in") -f.close() -# Define led pins as output -f = open(GPIOPATH+"/gpio"+ledRed+"/direction", "w") -f.write("out") -f.close() -# turn leds OFF -f = open(GPIOPATH+"/gpio"+ledRed+"/value", "w") -f.write("0") -f.close() - -@app.route("/") -def index(): - # Read GPIO Status - f = open(GPIOPATH+"/gpio"+button+"/value", "r") - buttonSts = f.read()[:-1] - f.close() - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "r") - ledRedSts = f.read()[:-1] - f.close() - - templateData = { - 'button' : buttonSts, - 'ledRed' : ledRedSts, - } - return render_template('index5.html', **templateData) - -@app.route("/<deviceName>/<action>") -def action(deviceName, action): - if deviceName == 'ledRed': - actuator = ledRed - - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "w") - if action == "on": - f.write("1") - if action == "off": - f.write("0") - if action == "toggle": - f.close() - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "r") - ledRedSts = int(f.read()[:-1]) - ledRedSts = str(int(not ledRedSts)) - f.close() - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "w") - f.write(ledRedSts) - f.close() - - f = open(GPIOPATH+"/gpio"+button+"/value", "r") - buttonSts = f.read()[:-1] - f.close() - f = open(GPIOPATH+"/gpio"+ledRed+"/value", "r") - ledRedSts = int(f.read()[:-1]) - f.close() - - templateData = { - 'button' : buttonSts, - 'ledRed' : ledRedSts, - } - return render_template('index5.html', **templateData) -if __name__ == "__main__": - app.run(host='0.0.0.0', port=8080, debug=True) \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/flask.service b/books/beaglebone-cookbook/06iot/code/flask/flask.service deleted file mode 100644 index 1b577785a2314fc7b4d559cd89283630dfb7eba7..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/flask.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=flask server - -[Service] -WorkingDirectory=/home/debian/exercises/flask/server -ExecStart=/home/debian/exercises/flask/server/app5.py -SyslogIdentifier=flask - -[Install] -WantedBy=multi-user.target diff --git a/books/beaglebone-cookbook/06iot/code/flask/helloWorld.py b/books/beaglebone-cookbook/06iot/code/flask/helloWorld.py deleted file mode 100755 index 176350b065475774e1ff6ba56d8043498a49a6e0..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/helloWorld.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -# From: https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d - -from flask import Flask -app = Flask(__name__) -@app.route('/') -def index(): - return 'hello, world' -if __name__ == '__main__': - app.run(debug=True, port=8080, host='0.0.0.0') \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/install.sh b/books/beaglebone-cookbook/06iot/code/flask/install.sh deleted file mode 100644 index 332244695a5fed8aaa447c60b5364b3120271c86..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/install.sh +++ /dev/null @@ -1,7 +0,0 @@ -# From: https://www.cloudsavvyit.com/903/debug-your-local-applications-over-the-internet-with-ngrok-tunnels/ -wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip -unzip ngrok-stable-linux-arm.zip -sudo mv ngrok ~/.local/bin - -mkdir -p ~/.ngrok2 -cp ngrok.yml ~/.ngrok2 \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/ngrok.yml b/books/beaglebone-cookbook/06iot/code/flask/ngrok.yml deleted file mode 100644 index 5074663e9d79da704834075c14e009103945e992..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/ngrok.yml +++ /dev/null @@ -1,4 +0,0 @@ -tunnels: - flask: - proto: http - addr: 8081 diff --git a/books/beaglebone-cookbook/06iot/code/flask/setup.sh b/books/beaglebone-cookbook/06iot/code/flask/setup.sh deleted file mode 100644 index 410868a7afbc15e04da4a51738065a9b1e38128c..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/setup.sh +++ /dev/null @@ -1,2 +0,0 @@ -# Start ngrok -ngrok start flask diff --git a/books/beaglebone-cookbook/06iot/code/flask/static/favicon.ico b/books/beaglebone-cookbook/06iot/code/flask/static/favicon.ico deleted file mode 100644 index e96154d507400f4d1ad0c844a47f9d3455af3917..0000000000000000000000000000000000000000 Binary files a/books/beaglebone-cookbook/06iot/code/flask/static/favicon.ico and /dev/null differ diff --git a/books/beaglebone-cookbook/06iot/code/flask/static/style.css b/books/beaglebone-cookbook/06iot/code/flask/static/style.css deleted file mode 100644 index f05f2cc82abb471035a46bf8b6e37a638f6a6bb5..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/static/style.css +++ /dev/null @@ -1,15 +0,0 @@ -/*body {*/ -/* background: blue;*/ -/* color: yellow;*/ -/*}*/ -.button { - font: bold 15px Arial; - text-decoration: none; - background-color: #EEEEEE; - color: #333333; - padding: 2px 6px 2px 6px; - border-top: 1px solid #CCCCCC; - border-right: 1px solid #333333; - border-bottom: 1px solid #333333; - border-left: 1px solid #CCCCCC; -} \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/templates/index1.html b/books/beaglebone-cookbook/06iot/code/flask/templates/index1.html deleted file mode 100644 index 067d7eff0a86544a2b81846f8c9cedf856e24167..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/templates/index1.html +++ /dev/null @@ -1,9 +0,0 @@ -<!DOCTYPE html> - <head> - <title>{{ title }}</title> - </head> - <body> - <h1>Hello, World!</h1> - <h2>The date and time on the server is: {{ time }}</h2> - </body> -</html> diff --git a/books/beaglebone-cookbook/06iot/code/flask/templates/index2.html b/books/beaglebone-cookbook/06iot/code/flask/templates/index2.html deleted file mode 100644 index be37dfc44c5f1e6f4a647ad8f2d1378bb7ab9bbc..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/templates/index2.html +++ /dev/null @@ -1,10 +0,0 @@ -<!DOCTYPE html> - <head> - <title>{{ title }}</title> - <link rel="stylesheet" href='../static/style.css'/> - </head> - <body> - <h1>{{ title }}</h1> - <h2>Button pressed: {{ button }}</h1> - </body> -</html> diff --git a/books/beaglebone-cookbook/06iot/code/flask/templates/index3.html b/books/beaglebone-cookbook/06iot/code/flask/templates/index3.html deleted file mode 100644 index ef95fca7d25f8e8cfc2287773149dd301c57e580..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/templates/index3.html +++ /dev/null @@ -1,17 +0,0 @@ -<!DOCTYPE html> - <head> - <title>GPIO Control</title> - <link rel="stylesheet" href='../static/style.css'/> - </head> - <body> - <h2>Actuators</h2> - <h3> Status </h3> - RED LED ==> {{ ledRed }} - <br> - <h3> Commands </h3> - RED LED Ctrl ==> - <a href="/ledRed/on" class="button">TURN ON</a> - <a href="/ledRed/off"class="button">TURN OFF</a> - </body> -</html> - diff --git a/books/beaglebone-cookbook/06iot/code/flask/templates/index4.html b/books/beaglebone-cookbook/06iot/code/flask/templates/index4.html deleted file mode 100644 index ea85a3f3af71baf7003d1d51e2b4ef92900522ad..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/templates/index4.html +++ /dev/null @@ -1,20 +0,0 @@ -<!DOCTYPE html> - <head> - <title>GPIO Control</title> - <link rel="stylesheet" href='../static/style.css'/> - </head> - <body> - <h1>GPIO Control</h1> - <h2> Sensor Status </h2> - <h3> BUTTON ==> {{ button }}</h3> - <h2> Actuator Status & Control </h2> - <h3> RED LED ==> {{ ledRed }} ==> - {% if ledRed == 1 %} - <a href="/ledRed/off"class="button">TURN OFF</a> - {% else %} - <a href="/ledRed/on" class="button">TURN ON</a> - {% endif %} - </h3> - </h3> - </body> -</html> \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flask/templates/index5.html b/books/beaglebone-cookbook/06iot/code/flask/templates/index5.html deleted file mode 100644 index cff4bffb06a8b08702b13a9b7fbafc75d93ba611..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flask/templates/index5.html +++ /dev/null @@ -1,21 +0,0 @@ -<!DOCTYPE html> - <head> - <title>GPIO Control</title> - <link rel="stylesheet" href='../static/style.css'/> - </head> - <body> - <h1>GPIO Control</h1> - <h2> Sensor Status </h2> - <h3> BUTTON ==> {{ button }}</h3> - <h2> Actuator Status & Control </h2> - <h3> RED LED ==> {{ ledRed }} ==> - <a href="/ledRed/toggle" class="button">TOGGLE</a> - {% if ledRed == 1 %} - <a href="/ledRed/off"class="button">TURN OFF</a> - {% else %} - <a href="/ledRed/on" class="button">TURN ON</a> - {% endif %} - </h3> - </h3> - </body> -</html> \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/flotDemo.html b/books/beaglebone-cookbook/06iot/code/flotDemo.html deleted file mode 100644 index 8bf03881537f86c2b48f5e4e72cd0ff23cedb05e..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flotDemo.html +++ /dev/null @@ -1,15 +0,0 @@ -<html> - <head> - <title>BoneScript Flot Demo</title> - <script src="/static/flot/jquery.min.js"></script> - <script src="/static/flot/jquery.flot.min.js"></script> - <script src="/static/bonescript.js"></script> - <script src="flotDemo.js"></script> - </head> -<body> - -<h1>BoneScript Flot Demo</h1> -<div id="myplot" style="width:500px;height:300px;"></div> - -</body> -</html> diff --git a/books/beaglebone-cookbook/06iot/code/flotDemo.js b/books/beaglebone-cookbook/06iot/code/flotDemo.js deleted file mode 100644 index 5bf690c27287c42db2f5ea395908bda85e83f0a6..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/flotDemo.js +++ /dev/null @@ -1,66 +0,0 @@ -setTargetAddress('192.168.7.2', { // <1> - initialized: run -}); - -function run() { - var b = require('bonescript'); // <2> - var POT = 'P9_36'; // <3> - - var container = $("#myplot"); // <4> - var totalPoints = container.outerWidth() / 2 || 250; // <5> - var data = []; - var plotOptions = { // <6> - series: { - shadowSize: 0 - }, - yaxis: { - min: 0, - max: 1 - }, - xaxis: { - min: 0, - max: totalPoints, - show: false - } - }; - var plot = $.plot(container, getData(), plotOptions); // <7> - - drawGraph(); // <8> - - function drawGraph() { // <9> - plot.setData(getData()); - plot.draw(); - b.analogRead(POT, onAnalogRead); - } - - // Handle data back from potentiometer - function onAnalogRead(x) { - if (!x.err && typeof x.value == 'number') { - pushData(x.value); // <10> - } - setTimeout(drawGraph, 20); // <11> - } - - function pushData(y) { - if (data.length && (data.length + 1) > totalPoints) { - data = data.slice(1); - } - if (data.length < totalPoints) { - data.push(y); - } - } - - function getData() { - var res = []; - for (var i = 0; i < data.length; ++i) { - res.push([i, data[i]]); - } - var series = [{ - data: res, - lines: { - fill: true - } - }]; - return series; - } -} \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/jQueryDemo.js b/books/beaglebone-cookbook/06iot/code/jQueryDemo.js deleted file mode 100644 index 9581030e2857ce5210071c88f883b1169cf95add..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/jQueryDemo.js +++ /dev/null @@ -1,34 +0,0 @@ -setTargetAddress('192.168.7.2', { // <1> - initialized: run -}); - -function run() { - var b = require('bonescript'); // <2> - var SLIDER = 'P9_36'; // <3> - var BUTTON = 'P8_19'; - b.pinMode(BUTTON, b.INPUT); - - getSliderStatus(); // <4> - - function getSliderStatus() { - b.analogRead(SLIDER, onSliderRead); // <5> - } - - function onSliderRead(x) { - if (!x.err) { // <6> - $('#sliderStatus').html(x.value.toFixed(3)); - } - getButtonStatus() // <7> - } - - function getButtonStatus() { - b.digitalRead(BUTTON, onButtonRead); // <8> - } - - function onButtonRead(x) { - if (!x.err) { // <9> - $('#buttonStatus').html(x.value); - } - setTimeout(getSliderStatus, 20); // <10> - } -} diff --git a/books/beaglebone-cookbook/06iot/code/jQueryInstall.sh b/books/beaglebone-cookbook/06iot/code/jQueryInstall.sh deleted file mode 100644 index 8f5e8b1eac152607257b583e90d12ab781f2ac7d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/jQueryInstall.sh +++ /dev/null @@ -1,2 +0,0 @@ -# This gives easy acces to the bonscript and jquery libraries -ln -s /var/lib/cloud9/static/ . diff --git a/books/beaglebone-cookbook/06iot/code/launchPad.js b/books/beaglebone-cookbook/06iot/code/launchPad.js deleted file mode 100755 index f81591dd336e39a66fc083cd2471ef273acec95b..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/launchPad.js +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env node -// Need to add exports.serialParsers = m.module.parsers; -// to /usr/local/lib/node_modules/bonescript/serial.js -var b = require('bonescript'); - -var port = '/dev/ttyO1'; // <1> -var options = { - baudrate: 9600, // <2> - parser: b.serialParsers.readline("\n") // <3> -}; - -b.serialOpen(port, options, onSerial); // <4> - -function onSerial(x) { // <5> - console.log(x.event); - if (x.err) { - console.log('***ERROR*** ' + JSON.stringify(x)); - } - if (x.event == 'open') { - console.log('***OPENED***'); - setInterval(sendCommand, 1000); // <6> - } - if (x.event == 'data') { - console.log(String(x.data)); - } -} - -var command = ['r', 'g']; // <7> -var commIdx = 1; - -function sendCommand() { - // console.log('Command: ' + command[commIdx]); - b.serialWrite(port, command[commIdx++]); // <8> - if(commIdx >= command.length) { // <9> - commIdx = 0; - } -} diff --git a/books/beaglebone-cookbook/06iot/code/launchPad/launchPad.ino b/books/beaglebone-cookbook/06iot/code/launchPad/launchPad.ino deleted file mode 100644 index 12e3cd7dd7b759feda60e852e0882e88cc80d3de..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/launchPad/launchPad.ino +++ /dev/null @@ -1,44 +0,0 @@ -/* - Tests connection to a BeagleBone - Mark A. Yoder - Waits for input on Serial Port - g - Green toggle - r - Red toggle -*/ -char inChar = 0; // incoming serial byte -int red = 0; -int green = 0; - -void setup() -{ - // initialize the digital pin as an output. - pinMode(RED_LED, OUTPUT); // <1> - pinMode(GREEN_LED, OUTPUT); - // start serial port at 9600 bps: - Serial.begin(9600); // <2> - Serial.print("Command (r, g): "); // <3> - - digitalWrite(GREEN_LED, green); // <4> - digitalWrite( RED_LED, red); -} - -void loop() -{ - if(Serial.available() > 0 ) { // <5> - inChar = Serial.read(); - switch(inChar) { // <6> - case 'g': - green = ~green; - digitalWrite(GREEN_LED, green); - Serial.println("Green"); - break; - case 'r': - red = ~red; - digitalWrite(RED_LED, red); - Serial.println("Red"); - break; - } - Serial.print("Command (r, g): "); - } -} - diff --git a/books/beaglebone-cookbook/06iot/code/nodemailer-install.sh b/books/beaglebone-cookbook/06iot/code/nodemailer-install.sh deleted file mode 100755 index 856fc7c3c0a1e0703b4351b4dc6c574c0cd0ddb9..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/nodemailer-install.sh +++ /dev/null @@ -1 +0,0 @@ -npm install -g nodemailer diff --git a/books/beaglebone-cookbook/06iot/code/nodemailer-test.js b/books/beaglebone-cookbook/06iot/code/nodemailer-test.js deleted file mode 100755 index e5b99f6db79cca22f933ba0d5ba9af1cee09538e..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/nodemailer-test.js +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env node -// From: https://github.com/andris9/Nodemailer - -var nodemailer = require('nodemailer'); - -// create reusable transporter object using SMTP transport -var transporter = nodemailer.createTransport({ - service: 'gmail', - auth: { - user: 'yourUser@gmail.com', - pass: 'yourPass' - } -}); - -// NB! No need to re-create the transporter object. You can use -// the same transporter object for all e-mails - -// set up e-mail data with unicode symbols -var mailOptions = { - from: 'Your User <yourUser@gmail.edu>', // sender address - to: 'anotherUser@gmail.edu', // list of receivers - subject: 'Test of nodemail', // Subject line - text: 'Hello world from modemailer', // plaintext body - html: '<b>Hello world</b><p>Way to go!</p>' // html body -}; - -// send mail with defined transport object -transporter.sendMail(mailOptions, function(error, info){ - if(error){ - console.log(error); - }else{ - console.log('Message sent: ' + info.response); - } -}); - -// Nodemailer is licensed under MIT license -// (https://github.com/andris9/Nodemailer/blob/master/LICENSE). -// Basically you can do whatever you want to with it diff --git a/books/beaglebone-cookbook/06iot/code/noderedExample.json b/books/beaglebone-cookbook/06iot/code/noderedExample.json deleted file mode 100644 index 06b306df51787ae3096298bd08b289436045bcd1..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/noderedExample.json +++ /dev/null @@ -1,164 +0,0 @@ -[ - { - "id": "70fd05e2.f03d0c", - "type": "tab", - "label": "Flow 1", - "disabled": false, - "info": "" - }, - { - "id": "b1dc9221.09e41", - "type": "gpio out", - "z": "70fd05e2.f03d0c", - "name": "", - "state": "OUTPUT", - "pin": "P9_14", - "i2cDelay": "0", - "i2cAddress": "", - "i2cRegister": "", - "outputs": 0, - "board": "14fb0dec.376712", - "x": 610, - "y": 180, - "wires": [] - }, - { - "id": "acb4df30.72216", - "type": "inject", - "z": "70fd05e2.f03d0c", - "name": "", - "props": [ - { - "p": "payload" - } - ], - "repeat": "", - "crontab": "", - "once": false, - "onceDelay": 0.1, - "topic": "", - "payload": "1", - "payloadType": "num", - "x": 370, - "y": 180, - "wires": [ - [ - "b1dc9221.09e41" - ] - ] - }, - { - "id": "35e9479e.0e2428", - "type": "inject", - "z": "70fd05e2.f03d0c", - "name": "", - "props": [ - { - "p": "payload" - } - ], - "repeat": "", - "crontab": "", - "once": false, - "onceDelay": 0.1, - "topic": "", - "payload": "0", - "payloadType": "str", - "x": 370, - "y": 220, - "wires": [ - [ - "b1dc9221.09e41" - ] - ] - }, - { - "id": "cca6a964.c0e978", - "type": "gpio out", - "z": "70fd05e2.f03d0c", - "name": "", - "state": "OUTPUT", - "pin": "USR3", - "i2cDelay": "0", - "i2cAddress": "", - "i2cRegister": "", - "outputs": 0, - "board": "14fb0dec.376712", - "x": 610, - "y": 280, - "wires": [] - }, - { - "id": "b9def222.f9a97", - "type": "inject", - "z": "70fd05e2.f03d0c", - "name": "", - "props": [ - { - "p": "payload" - } - ], - "repeat": "", - "crontab": "", - "once": false, - "onceDelay": 0.1, - "topic": "", - "payload": "1", - "payloadType": "num", - "x": 370, - "y": 280, - "wires": [ - [ - "cca6a964.c0e978" - ] - ] - }, - { - "id": "230706ad.dbc7ea", - "type": "inject", - "z": "70fd05e2.f03d0c", - "name": "", - "props": [ - { - "p": "payload" - } - ], - "repeat": "", - "crontab": "", - "once": false, - "onceDelay": 0.1, - "topic": "", - "payload": "0", - "payloadType": "str", - "x": 370, - "y": 320, - "wires": [ - [ - "cca6a964.c0e978" - ] - ] - }, - { - "id": "14fb0dec.376712", - "type": "ioplugin", - "name": "", - "username": "", - "password": "", - "boardType": "beaglebone-io", - "serialportName": "", - "connectionType": "local", - "mqttServer": "", - "pubTopic": "", - "subTopic": "", - "tcpHost": "", - "tcpPort": "", - "sparkId": "", - "sparkToken": "", - "beanId": "", - "impId": "", - "uuid": "", - "token": "", - "sendUuid": "", - "samplingInterval": "500" - } -] \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/processingDemo.js b/books/beaglebone-cookbook/06iot/code/processingDemo.js deleted file mode 100644 index 3356cc00ef9cad6ca1900f488cc3210f41304224..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/processingDemo.js +++ /dev/null @@ -1,89 +0,0 @@ -var canvas = document.getElementById("mysketch"); -var p = new Processing(canvas, sketchProc); - -function sketchProc(pjs) { - // Sketch global variables - var radius = 50.0; - var X, Y; - var nX, nY; - var delay = 16; - var brightness = 0; - var buttonStatus = 0; - var sliderStatus = 0; - var lastSliderValue = 0; - var BUTTON = 'P8_19'; - var POT = 'P9_36'; - - // Get the BoneScript library and begin updating the canvas - setTargetAddress('beaglebone.local', { - initialized: run - }); - setTargetAddress('192.168.7.2', { - initialized: run - }); - - function run() { - var b = require('bonescript'); - b.pinMode(BUTTON, b.INPUT); - - // Setup the Processing Canvas - pjs.setup = function () { - pjs.size(256, 256); - pjs.strokeWeight(10); - pjs.frameRate(15); - X = pjs.width / 2; - Y = pjs.height / 2; - nX = X; - nY = Y; - } - - // Main draw loop - pjs.draw = function () { - // Calculate some fading values based on the frame count - radius = 50.0 + (15 - sliderStatus) * pjs.sin(pjs.frameCount / 4); - brightness = (radius - 40.0) / 20.0; - - // Track circle to new destination - X += (nX - X) / delay; - Y += (nY - Y) / delay; - - // Fill canvas grey - pjs.background(100); - - // Set fill-color to blue or red, based on button status - if (buttonStatus) pjs.fill(200, 30, 20) - else pjs.fill(0, 121, 184); - - // Set stroke-color white - pjs.stroke(255); - - // Draw circle - pjs.ellipse(X, Y, radius, radius); - - // Fetch slider location for next time - b.analogRead(POT, onAnalogRead); - - // Fetch button status - b.digitalRead(BUTTON, onDigitalRead); - } - - // Get things started - pjs.setup(); - - // Handle data back from potentiometer - function onAnalogRead(x) { - if (!x.err && (x.value >= 0) && (x.value <= 1)) { - if (Math.abs(x.value - lastSliderValue) > 0.05) { - lastSliderValue = x.value; - nY = x.value * 255; - sliderStatus = parseInt(x.value * 10, 10); - } - } - } - - // Handle data back from button - function onDigitalRead(x) { - buttonStatus = (x.value == b.LOW) ? 1 : 0; - } - } -} \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/server.js b/books/beaglebone-cookbook/06iot/code/server.js deleted file mode 100755 index c827116c40ee32b679786f7aa0cb316d2e37d1ba..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/server.js +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env node -// Initial idea from Getting Started With node.js and socket.io -// by Constantine Aaron Cois, Ph.D. (www.codehenge.net) -// http://codehenge.net/blog/2011/12/getting-started-with-node-js-and-socket-io- -// v0-7-part-2/ -// This is a simple server for the various web frontends -"use strict"; - -var port = 9090, // Port on which to listen - http = require('http'), - url = require('url'), - fs = require('fs'), - b = require('bonescript'); - -var server = http.createServer(servePage); // <1> - -server.listen(port); // <2> -console.log("Listening on " + port); - -function servePage(req, res) { - var path = url.parse(req.url).pathname; // <3> - console.log("path: " + path); - - fs.readFile(__dirname + path, function (err, data) {// <4> - if (err) { // <5> - return send404(res); - } - res.write(data, 'utf8'); // <6> - res.end(); - }); -} - -function send404(res) { - res.writeHead(404); - res.write('404 - page not found'); - res.end(); -} diff --git a/books/beaglebone-cookbook/06iot/code/test.html b/books/beaglebone-cookbook/06iot/code/test.html deleted file mode 100644 index ddb20a32d654f50858e09c38e8ed33ee6b8162a2..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/test.html +++ /dev/null @@ -1,10 +0,0 @@ -<!DOCTYPE html> -<html> -<body> - -<h1>My First Heading</h1> - -<p>My first paragraph.</p> - -</body> -</html> diff --git a/books/beaglebone-cookbook/06iot/code/twilio-test.js b/books/beaglebone-cookbook/06iot/code/twilio-test.js deleted file mode 100755 index 49ef9b585955256450bb7407d5517e8d706aed25..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twilio-test.js +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env node -// From: http://twilio.github.io/twilio-node/ -// Twilio Credentials -var accountSid = ''; -var authToken = ''; - -//require the Twilio module and create a REST client -var client = require('twilio')(accountSid, authToken); - -client.messages.create({ - to: "812555121", - from: "+2605551212", - body: "This is a test", -}, function(err, message) { - console.log(message.sid); -}); - -// https://github.com/twilio/twilio-node/blob/master/LICENSE -// The MIT License (MIT) -// Copyright (c) 2010 Stephen Walters -// Copyright (c) 2012 Twilio Inc. - -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twilioSetup.sh b/books/beaglebone-cookbook/06iot/code/twilioSetup.sh deleted file mode 100755 index c9a033885ba0344f752b27f0e119ae58c2129d8a..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twilioSetup.sh +++ /dev/null @@ -1,2 +0,0 @@ -export TWILIO_ACCOUNT_SID="AC407ab27aab63fa995dbc24c43a18d204" -export TWILIO_AUTH_TOKEN="71fe036081445dd693ed80c3ebf0f9b1" \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twilioTest.py b/books/beaglebone-cookbook/06iot/code/twilioTest.py deleted file mode 100755 index 356cb03b6ac60e6ed2d632897f0bd879717084b6..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twilioTest.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# Download the helper library from https://www.twilio.com/docs/python/install -import os -from twilio.rest import Client - - -# Find your Account SID and Auth Token at twilio.com/console -# and set the environment variables. See http://twil.io/secure -account_sid = os.environ['TWILIO_ACCOUNT_SID'] -auth_token = os.environ['TWILIO_AUTH_TOKEN'] -client = Client(account_sid, auth_token) - -message = client.messages \ - .create( - body="Join Earth's mightiest heroes. Like Kevin Bacon.", - from_='+18122333219', - to='+18122333219' - ) - -print(message.sid) diff --git a/books/beaglebone-cookbook/06iot/code/twitterInstall.sh b/books/beaglebone-cookbook/06iot/code/twitterInstall.sh deleted file mode 100644 index 6cb7b7c0adf99821894da38fc781c9721d733196..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterInstall.sh +++ /dev/null @@ -1,4 +0,0 @@ -npm install -g node-twitter -# Go to https://apps.twitter.com/ -# "Create New App" -# Copy API and TOKEN to twitterKeys.js \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitterKeys.sh b/books/beaglebone-cookbook/06iot/code/twitterKeys.sh deleted file mode 100755 index 9e5e9db37b3876e4744124b4e344cbc1dcb5c18c..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterKeys.sh +++ /dev/null @@ -1,10 +0,0 @@ -# My Twitter keys -# From https://apps.twitter.com/app/5771872/keys -export API_KEY='RKH9Bi6QDo8LIUydJN5ubBH7r' -export API_SECRET_KEY='DwyL7V4Q7O5ochI0PNlDsd00tA2lcSnEaxQSavSW4Jy86GKoxd' -export TOKEN='48435578-W5fX8R7k93gbwptwpmnp5FgRbsG2Hos8M20iV6140' -export TOKEN_SECRET='SOFLoyuBBkEsdvBKXh4CLBfQTiO2OiNtx3FQqnjYsHlRM' -export BEARER_TOKEN='AAAAAAAAAAAAAAAAAAAAAGASWAAAAAAAx3tNEacg9qMqvGRJsmc5ivTuuO0%3Dyu1wzpaLMQDsTgGrh21jAacNRNsnEYKLIuePlJy4kX7DnBeHNj' - -# Client ID dmNxcDVPencxT2l3Ry12OWFSdEc6MTpjaQ -# Client Secret 16tjW8lITIMH0ETUcmCvT1bpUvebCzsWQF3yVLv329rjynRSvT \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitterPushbutton.js b/books/beaglebone-cookbook/06iot/code/twitterPushbutton.js deleted file mode 100755 index e3fe0c376885391b3657725df1d6b252474d48d5..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterPushbutton.js +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env node -// From: https://www.npmjs.org/package/node-twitter -// Tweets with attached image media (JPG, PNG or GIF) can be posted -// using the upload API endpoint. -var Twitter = require('node-twitter'); -var b = require('bonescript'); -var key = require('./twitterKeys'); -var gpio = "P9_42"; -var count = 0; - -b.pinMode(gpio, b.INPUT); -b.attachInterrupt(gpio, sendTweet, b.FALLING); - -var twitterRestClient = new Twitter.RestClient( - key.API_KEY, key.API_SECRET, - key.TOKEN, key.TOKEN_SECRET -); - -function sendTweet() { - console.log("Sending..."); - count++; - - twitterRestClient.statusesUpdate( - {'status': 'Posting tweet ' + count + ' via my BeagleBone Black', }, - function(error, result) { - if (error) { - console.log('Error: ' + - (error.code ? error.code + ' ' + error.message : error.message)); - } - - if (result) { - console.log(result); - } - } - ); -} - -// node-twitter is made available under terms of the BSD 3-Clause License. -// http://www.opensource.org/licenses/BSD-3-Clause \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitterSearch.js b/books/beaglebone-cookbook/06iot/code/twitterSearch.js deleted file mode 100755 index bb1d3edcc64b92407495397f692ad3fc89217566..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterSearch.js +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env node -// From: https://www.npmjs.org/package/node-twitter -// The Twitter Search API can be accessed using Twitter.SearchClient. The following -// code example shows how to search for tweets containing the keyword "node.js".var Twitter = require('node-twitter'); -var key = require('./twitterKeys'); - -var twitterSearchClient = new Twitter.SearchClient( - key.API_KEY, key.API_SECRET, - key.TOKEN, key.TOKEN_SECRET -); - -twitterSearchClient.search({'q': 'rosehulman'}, function(error, result) { - if (error) { - console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message)); - } - - if (result) { - console.log(result); - } -}); \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitterStream.js b/books/beaglebone-cookbook/06iot/code/twitterStream.js deleted file mode 100755 index 35e2068a3c6cdff5a41b1f5c04b02b958d161d28..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterStream.js +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env node -// From: https://www.npmjs.org/package/node-twitter -// The Twitter Streaming API can be accessed using Twitter.StreamClient. -// The following code example shows how to catch all tweets containing keywords. -var Twitter = require('node-twitter'); -var b = require('bonescript'); -var key = require('./twitterKeys'); -var gpio = "P9_14"; -var count = 0; -var timeOn = 5000; // Turn LED off after this amount of time (in ms) - -b.pinMode(gpio, b.OUTPUT); - -b.digitalWrite(gpio, 1); // Toggle LED -setTimeout(ledOff, timeOn); - -var twitterStreamClient = new Twitter.StreamClient( - key.API_KEY, key.API_SECRET, - key.TOKEN, key.TOKEN_SECRET -); - -twitterStreamClient.on('close', function() { - console.log('Connection closed.'); -}); -twitterStreamClient.on('end', function() { - console.log('End of Line.'); -}); -twitterStreamClient.on('error', function(error) { - console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message)); -}); -twitterStreamClient.on('tweet', function(tweet) { - console.log(tweet); - b.digitalWrite(gpio, 1); // Turn LED on - console.log(count++ + " =====\ - tweet\ - ====="); - setTimeout(ledOff, timeOn); -}); - -twitterStreamClient.start(['beagleboard', 'beaglebone', 'cookbook', 'rosehulman']); - -function ledOff() { - b.digitalWrite(gpio, 0); -} \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitterTimeLine.js b/books/beaglebone-cookbook/06iot/code/twitterTimeLine.js deleted file mode 100755 index dca85d32b93b60b7b82e967ebacca14cb4cfe266..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterTimeLine.js +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env node -// From: https://www.npmjs.org/package/node-twitter -// The Twitter REST API can be accessed using Twitter.RestClient. The following -// code example shows how to retrieve tweets from the authenticated user's timeline. -var Twitter = require('node-twitter'); -var key = require('./twitterKeys'); - -var twitterRestClient = new Twitter.RestClient( - key.API_KEY, key.API_SECRET, - key.TOKEN, key.TOKEN_SECRET -); - -twitterRestClient.statusesHomeTimeline({}, function(error, result) { - if (error) { - console.log('Error: ' + - (error.code ? error.code + ' ' + error.message : error.message)); - } - - if (result) { - console.log(result); - } -}); - -// node-twitter is made available under terms of the BSD 3-Clause License. -// http://www.opensource.org/licenses/BSD-3-Clause \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitterUpload.js b/books/beaglebone-cookbook/06iot/code/twitterUpload.js deleted file mode 100755 index e09a900a09b80abbe0fa734663549572630ebb96..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitterUpload.js +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env node -// From: https://www.npmjs.org/package/node-twitter -// Tweets with attached image media (JPG, PNG or GIF) can be posted -// using the upload API endpoint. -var Twitter = require('node-twitter'); -var b = require('bonescript'); -var key = require('./twitterKeys'); - -var twitterRestClient = new Twitter.RestClient( - key.API_KEY, key.API_SECRET, - key.TOKEN, key.TOKEN_SECRET -); - -twitterRestClient.statusesUpdateWithMedia( - { - 'status': 'Posting a tweet w/ attached media.', - 'media[]': '/root/cookbook-atlas/images/cover.png' - }, - function(error, result) { - if (error) { - console.log('Error: ' + - (error.code ? error.code + ' ' + error.message : error.message)); - } - - if (result) { - console.log(result); - } - } -); - -// node-twitter is made available under terms of the BSD 3-Clause License. -// http://www.opensource.org/licenses/BSD-3-Clause \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/twitter_create_tweet.py b/books/beaglebone-cookbook/06iot/code/twitter_create_tweet.py deleted file mode 100755 index fc7829bc8d4963ca55253a2e7d43631dc5358b53..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitter_create_tweet.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -# From: https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/main/Manage-Tweets/create_tweet.py -from requests_oauthlib import OAuth1Session -import os -import json - -# In your terminal please set your environment variables by running the following lines of code. -# export 'API_KEY'='<your_consumer_key>' -# export 'API_SECRET_KEY'='<your_consumer_secret>' - -consumer_key = os.environ.get("API_KEY") -consumer_secret = os.environ.get("API_SECRET_KEY") - -# Be sure to add replace the text of the with the text you wish to Tweet. You can also add parameters to post polls, quote Tweets, Tweet with reply settings, and Tweet to Super Followers in addition to other features. -payload = {"text": "Hello world!"} - -# Get request token -request_token_url = "https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write" -oauth = OAuth1Session(consumer_key, client_secret=consumer_secret) - -try: - fetch_response = oauth.fetch_request_token(request_token_url) -except ValueError: - print( - "There may have been an issue with the consumer_key or consumer_secret you entered." - ) - -resource_owner_key = fetch_response.get("oauth_token") -resource_owner_secret = fetch_response.get("oauth_token_secret") -print("Got OAuth token: %s" % resource_owner_key) - -# Get authorization -base_authorization_url = "https://api.twitter.com/oauth/authorize" -authorization_url = oauth.authorization_url(base_authorization_url) -print("Please go here and authorize: %s" % authorization_url) -verifier = input("Paste the PIN here: ") - -# Get the access token -access_token_url = "https://api.twitter.com/oauth/access_token" -oauth = OAuth1Session( - consumer_key, - client_secret=consumer_secret, - resource_owner_key=resource_owner_key, - resource_owner_secret=resource_owner_secret, - verifier=verifier, -) -oauth_tokens = oauth.fetch_access_token(access_token_url) - -access_token = oauth_tokens["oauth_token"] -access_token_secret = oauth_tokens["oauth_token_secret"] - -# Make the request -oauth = OAuth1Session( - consumer_key, - client_secret=consumer_secret, - resource_owner_key=access_token, - resource_owner_secret=access_token_secret, -) - -# Making the request -response = oauth.post( - "https://api.twitter.com/2/tweets", - json=payload, -) - -if response.status_code != 201: - raise Exception( - "Request returned an error: {} {}".format(response.status_code, response.text) - ) - -print("Response code: {}".format(response.status_code)) - -# Saving the response as JSON -json_response = response.json() -print(json.dumps(json_response, indent=4, sort_keys=True)) diff --git a/books/beaglebone-cookbook/06iot/code/twitter_delete_tweet.py b/books/beaglebone-cookbook/06iot/code/twitter_delete_tweet.py deleted file mode 100755 index d35a11928d153f3f58f3d92d3034df5fd39cb27e..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitter_delete_tweet.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# From: https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/main/Manage-Tweets/delete_tweet.py -from requests_oauthlib import OAuth1Session -import os -import json - -# In your terminal please set your environment variables by running the following lines of code. -# export 'API_KEY'='<your_consumer_key>' -# export 'API_SECRET_KEY'='<your_consumer_secret>' - -consumer_key = os.environ.get("API_KEY") -consumer_secret = os.environ.get("API_SECRET_KEY") - -# Be sure to replace tweet-id-to-delete with the id of the Tweet you wish to delete. The authenticated user must own the list in order to delete -id = "1547963178700533760" - -# Get request token -request_token_url = "https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write" -oauth = OAuth1Session(consumer_key, client_secret=consumer_secret) - -try: - fetch_response = oauth.fetch_request_token(request_token_url) -except ValueError: - print( - "There may have been an issue with the consumer_key or consumer_secret you entered." - ) - -resource_owner_key = fetch_response.get("oauth_token") -resource_owner_secret = fetch_response.get("oauth_token_secret") -print("Got OAuth token: %s" % resource_owner_key) - -# Get authorization -base_authorization_url = "https://api.twitter.com/oauth/authorize" -authorization_url = oauth.authorization_url(base_authorization_url) -print("Please go here and authorize: %s" % authorization_url) -verifier = input("Paste the PIN here: ") - -# Get the access token -access_token_url = "https://api.twitter.com/oauth/access_token" -oauth = OAuth1Session( - consumer_key, - client_secret=consumer_secret, - resource_owner_key=resource_owner_key, - resource_owner_secret=resource_owner_secret, - verifier=verifier, -) -oauth_tokens = oauth.fetch_access_token(access_token_url) - -access_token = oauth_tokens["oauth_token"] -access_token_secret = oauth_tokens["oauth_token_secret"] - -# Make the request -oauth = OAuth1Session( - consumer_key, - client_secret=consumer_secret, - resource_owner_key=access_token, - resource_owner_secret=access_token_secret, -) - -# Making the request -response = oauth.delete("https://api.twitter.com/2/tweets/{}".format(id)) - -if response.status_code != 200: - raise Exception( - "Request returned an error: {} {}".format(response.status_code, response.text) - ) - -print("Response code: {}".format(response.status_code)) - -# Saving the response as JSON -json_response = response.json() -print(json_response) diff --git a/books/beaglebone-cookbook/06iot/code/twitter_recent_search.py b/books/beaglebone-cookbook/06iot/code/twitter_recent_search.py deleted file mode 100755 index 0569385763c904059cf3155d8a10e385ccaeea37..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitter_recent_search.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# From: https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/main/Recent-Search/recent_search.py -import requests -import os -import json - -# To set your environment variables in your terminal run the following line: -# export 'BEARER_TOKEN'='<your_bearer_token>' -bearer_token = os.environ.get("BEARER_TOKEN") - -search_url = "https://api.twitter.com/2/tweets/search/recent" - -# Optional params: start_time,end_time,since_id,until_id,max_results,next_token, -# expansions,tweet.fields,media.fields,poll.fields,place.fields,user.fields -query_params = {'query': '(from:MarkAYoder) OR #MarkAYoder','tweet.fields': 'author_id'} -# query_params = {'query': '(from:twitterdev -is:retweet) OR #twitterdev','tweet.fields': 'author_id'} - - -def bearer_oauth(r): - """ - Method required by bearer token authentication. - """ - - r.headers["Authorization"] = f"Bearer {bearer_token}" - r.headers["User-Agent"] = "v2RecentSearchPython" - return r - -def connect_to_endpoint(url, params): - response = requests.get(url, auth=bearer_oauth, params=params) - print(response.status_code) - if response.status_code != 200: - raise Exception(response.status_code, response.text) - return response.json() - - -def main(): - json_response = connect_to_endpoint(search_url, query_params) - print(json.dumps(json_response, indent=4, sort_keys=True)) - - -if __name__ == "__main__": - main() diff --git a/books/beaglebone-cookbook/06iot/code/twitter_user_tweets.py b/books/beaglebone-cookbook/06iot/code/twitter_user_tweets.py deleted file mode 100755 index 19dac531a57a239b87b08705a81178038f50754d..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/twitter_user_tweets.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# From: https://github.com/twitterdev/Twitter-API-v2-sample-code/blob/main/User-Tweet-Timeline/user_tweets.py -import requests -import os -import json - -# To set your environment variables in your terminal run the following line: -# export 'BEARER_TOKEN'='<your_bearer_token>' -bearer_token = os.environ.get("BEARER_TOKEN") - -def create_url(): - # Replace with user ID below - user_id = 48435578 - # return "https://api.twitter.com/2/users/{}/followers".format(user_id) - return "https://api.twitter.com/2/users/{}/tweets".format(user_id) - - -def get_params(): - # Tweet fields are adjustable. - # Options include: - # attachments, author_id, context_annotations, - # conversation_id, created_at, entities, geo, id, - # in_reply_to_user_id, lang, non_ai_64_lic_metrics, organic_metrics, - # possibly_sensitive, promoted_metrics, public_metrics, referenced_tweets, - # source, text, and withheld - return {"tweet.fields": "created_at"} - # return {} - - -def bearer_oauth(r): - """ - Method required by bearer token authentication. - """ - - r.headers["Authorization"] = f"Bearer {bearer_token}" - r.headers["User-Agent"] = "v2UserTweetsPython" - return r - - -def connect_to_endpoint(url, params): - response = requests.request("GET", url, auth=bearer_oauth, params=params) - print(response.status_code) - if response.status_code != 200: - raise Exception( - "Request returned an error: {} {}".format( - response.status_code, response.text - ) - ) - return response.json() - - -def main(): - url = create_url() - params = get_params() - json_response = connect_to_endpoint(url, params) - print(json.dumps(json_response, indent=4, sort_keys=True)) - - -if __name__ == "__main__": - main() diff --git a/books/beaglebone-cookbook/06iot/code/weather.py b/books/beaglebone-cookbook/06iot/code/weather.py deleted file mode 100755 index 1b165eb3284b0c87c653539a46985d047d03e641..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/weather.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -# Displays current weather and forcast -import os -import sys -from datetime import datetime -import requests # For getting weather - -# http://api.openweathermap.org/data/2.5/onecall -params = { - 'appid': os.environ['APPID'], - # 'city': 'brazil,indiana', - 'exclude': "minutely,hourly", - 'lat': '39.52', - 'lon': '-87.12', - 'units': 'imperial' - } -urlWeather = "http://api.openweathermap.org/data/2.5/onecall" - -print("Getting weather") - -try: - r = requests.get(urlWeather, params=params) - if(r.status_code==200): - # print("headers: ", r.headers) - # print("text: ", r.text) - # print("json: ", r.json()) - weather = r.json() - print("Temp: ", weather['current']['temp']) # <1> - print("Humid:", weather['current']['humidity']) - print("Low: ", weather['daily'][1]['temp']['min']) - print("High: ", weather['daily'][0]['temp']['max']) - day = weather['daily'][0]['sunrise']-weather['timezone_offset'] - print("sunrise: " + datetime.utcfromtimestamp(day).strftime('%Y-%m-%d %H:%M:%S')) - # print("Day: " + datetime.utcfromtimestamp(day).strftime('%a')) - # print("weather: ", weather['daily'][1]) # <2> - # print("weather: ", weather) # <3> - # print("icon: ", weather['current']['weather'][0]['icon']) - # print() - - else: - print("status_code: ", r.status_code) -except IOError: - print("File not found: " + tmp101) - print("Have you run setup.sh?") -except: - print("Unexpected error:", sys.exc_info()) diff --git a/books/beaglebone-cookbook/06iot/code/weatherSetup.sh b/books/beaglebone-cookbook/06iot/code/weatherSetup.sh deleted file mode 100755 index e2840d08ab0cc26640edf5df40da9f99c21d261f..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/weatherSetup.sh +++ /dev/null @@ -1,2 +0,0 @@ -# From:https://home.openweathermap.org/api_keys -export APPID="6a2db5c8171494bce131dc69af6f34b9" \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/code/xbee.js b/books/beaglebone-cookbook/06iot/code/xbee.js deleted file mode 100644 index 40b184d21f1dfa38d018cfed18c9a507c18a4d3f..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/06iot/code/xbee.js +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -// This isn't working yet \ No newline at end of file diff --git a/books/beaglebone-cookbook/06iot/iot.rst b/books/beaglebone-cookbook/06iot/iot.rst index 4886a0e826684b383e0d63f4e440c9a4a154acbb..427682621c0b3be720e4615cfa46ff0f258bf4fc 100644 --- a/books/beaglebone-cookbook/06iot/iot.rst +++ b/books/beaglebone-cookbook/06iot/iot.rst @@ -95,11 +95,11 @@ to a file called */var/www/html/test.html*, and then point your browser to *192. .. _networking_index_html: -.. literalinclude:: code/test.html +.. literalinclude:: ../code/06iot/test.html :caption: A sample web page (test.html) :linenos: -:download:`test.html <code/test.html>` +:download:`test.html <../code/06iot/test.html>` You will see the web page shown in :ref:`networking_node_page`. @@ -142,8 +142,8 @@ All the code in is the Cookbook repo: .. code-block:: bash - bone$ git clone https://github.com/MarkAYoder/BoneCookbook - bone$ cd BoneCookbook/doc/06iod/code/flash + bone$ git clone https://git.beagleboard.org/beagleboard/beaglebone-cookbook-code + bone$ cd beaglebone-cookbook-code/06iot/flask First Flask - hello, world ============================ @@ -152,11 +152,11 @@ Our first example is *helloWorld.py* .. _flask_hello_world: -.. literalinclude:: code/flask/helloWorld.py +.. literalinclude:: ../code/06iot/flask/helloWorld.py :caption: Python code for flask hello world (helloWorld.py) :linenos: -:download:`helloWorld.py <code/flask/helloWorld.py>` +:download:`helloWorld.py <../code/06iot/flask/helloWorld.py>` 1. The first line loads the Flask module into your Python script. @@ -188,11 +188,11 @@ Here's what's in *templates/index1.html*: .. _flask_index1: -.. literalinclude:: code/flask/templates/index1.html +.. literalinclude:: ../code/06iot/flask/templates/index1.html :caption: index1.html :linenos: -:download:`index1.html <code/flask/templates/index1.html>` +:download:`index1.html <../code/06iot/flask/templates/index1.html>` Note: a style sheet (style.css) is also included. This will be populated later. @@ -203,11 +203,11 @@ function. Now, let’s create a new Python script. We will name it app1.py: .. _flask_app1: -.. literalinclude:: code/flask/app1.py +.. literalinclude:: ../code/06iot/flask/app1.py :caption: app1.py :linenos: -:download:`app1.py <code/flask/app1.py>` +:download:`app1.py <../code/06iot/flask/app1.py>` Note that we create a formatted string("timeString") using the date and time from the "now" object, that has the current time stored on it. @@ -260,11 +260,11 @@ Let’s use a new Python script named *app2.py*. .. _flask_app2: -.. literalinclude:: code/flask/app2.py +.. literalinclude:: ../code/06iot/flask/app2.py :caption: A simple Flask-based web server to read a GPIO (app2.py) :linenos: -:download:`app2.py <code/flask/app2.py>` +:download:`app2.py <../code/06iot/flask/app2.py>` Look that what we are doing is defining the button on *P9_11* as input, reading its value and storing it in *buttonSts*. Inside the function *index()*, we will pass that value to our web @@ -274,11 +274,11 @@ Let’s also see the new *index2.html* to show the GPIO status: .. _flask_index2: -.. literalinclude:: code/flask/templates/index2.html +.. literalinclude:: ../code/06iot/flask/templates/index2.html :caption: A simple Flask-based web server to read a GPIO (index2.html) :linenos: -:download:`index2.html <code/flask/templates/index2.html>` +:download:`index2.html <../code/06iot/flask/templates/index2.html>` Now, run the following command: @@ -326,7 +326,7 @@ A simple Flask-based web server to read a GPIO (app3.py) .. code-block:: python - include::code/flask/app3.py + include::../code/06iot/flask/app3.py @@ -359,11 +359,11 @@ actuator and more important, create “buttons†to send the commands: .. _flask_index3: -.. literalinclude:: code/flask/templates/index3.html +.. literalinclude:: ../code/06iot/flask/templates/index3.html :caption: A simple Flask-based web server to write a GPIO (index3.html) :linenos: -:download:`index3.html <code/flask/templates/index3.html>` +:download:`index3.html <../code/06iot/flask/templates/index3.html>` .. code-block:: bash @@ -457,11 +457,11 @@ plot the buffer is here: analogInContinuous.py .. _analog_code: -.. literalinclude:: code/analogInContinuous.py +.. literalinclude:: ../code/06iot/analogInContinuous.py :caption: Code to read and plot a continuous analog input(analogInContinuous.py) :linenos: -:download:`analogInContinuous.py <code/analogInContinuous.py>` +:download:`analogInContinuous.py <../code/06iot/analogInContinuous.py>` Be sure to read the instillation instructions in the comments. Also note this uses X windows and you need to *ssh -X 192.168.7.2* for X to know where the display is. @@ -472,7 +472,7 @@ Run it: host$ ssh -X bone - bone$ cd <Cookbook repo>/doc/06iot/code>/strong> + bone$ cd beaglebone-cookbook-code/06iot bone$ ./analogInContinuous.py Hit ^C to stop @@ -562,7 +562,7 @@ A number of files get installed, including the ADC file. Now try rerunning. .. code-block:: bash - bone$ cd <Cookbook repo>/docs/06iot/code> + bone$ cd beaglebone-cookbook-code/06iot bone$ ./analogInContinuous.py Hit ^C to stop @@ -609,11 +609,11 @@ Then add the code in :ref:`networking_nodemailer_code` to a file named ``emailTe .. _networking_nodemailer_code: -.. literalinclude:: code/emailTest.py +.. literalinclude:: ../code/06iot/emailTest.py :caption: Sending email using nodemailer (emailtTest.py) :linenos: -:download:`emailTest.py <code/emailTest.py>` +:download:`emailTest.py <../code/06iot/emailTest.py>` Then run the script to send the email: @@ -665,12 +665,12 @@ Finally, add the code in :ref:`networking_twilio_code` to a file named ``twilio- .. _networking_twilio_code: -.. literalinclude:: code/twilio-test.js +.. literalinclude:: ../code/06iot/twilio-test.js :caption: Sending SMS messages using Twilio (``twilio-test.js``) :linenos: -:download:`twilio-test.js <code/twilio-test.js>` -:download:`nodemailer-test.js <code/nodemailer-test.js>` +:download:`twilio-test.js <../code/06iot/twilio-test.js>` +:download:`nodemailer-test.js <../code/06iot/nodemailer-test.js>` Twilio allows a small number of free text messages, enough to test your code and to play around some. @@ -701,11 +701,11 @@ Because your Bone is on the network, it's not hard to access the current weather .. _networking_weather_code: -.. literalinclude:: code/weather.py +.. literalinclude:: ../code/06iot/weather.py :caption: Code for getting current weather conditions (``weather.py``) :linenos: -:download:`weather.py <code/weather.py>` +:download:`weather.py <../code/06iot/weather.py>` 1. Prints current conditions. 2. Prints the forecast for the next day. @@ -776,11 +776,11 @@ Add the code in :ref:`twitter_create_code` to a file called .. _twitter_create_code: -.. literalinclude:: code/twitter_create_tweet.py +.. literalinclude:: ../code/06iot/twitter_create_tweet.py :caption: Create a Tweet (``twitter_create_tweet.py``) :linenos: -:download:`twitter_create_tweet.py <code/twitter_create_tweet.py>` +:download:`twitter_create_tweet.py <../code/06iot/twitter_create_tweet.py>` Run the code and you'll have to authorize. @@ -809,11 +809,11 @@ Around line 15 is the *id* number. Paste in the value returned above. .. _twitter_delete_code: -.. literalinclude:: code/twitter_delete_tweet.py +.. literalinclude:: ../code/06iot/twitter_delete_tweet.py :caption: Code to delete a tweet (``twitter_delete_tweet.py``) :linenos: -:download:`twitter_delete_tweet.py <code/twitter_delete_tweet.py>` +:download:`twitter_delete_tweet.py <../code/06iot/twitter_delete_tweet.py>` .. TODO Start Here @@ -822,11 +822,11 @@ The code in :ref:`networking_pushbutton_code` snds a tweet whenever a button is .. _networking_pushbutton_code: -.. literalinclude:: code/twitterPushbutton.js +.. literalinclude:: ../code/06iot/twitterPushbutton.js :caption: Tweet when a button is pushed (twitterPushbutton.js) :linenos: -:download:`twitterPushbutton.js <code/twitterPushbutton.js>` +:download:`twitterPushbutton.js <../code/06iot/twitterPushbutton.js>` To see many other examples, go to `iStrategyLabs node-twitter GitHub page <http://bit.ly/18AvST>`_. @@ -1042,11 +1042,11 @@ to a file called ``launchPad.ino`` and run it on your LaunchPad. .. _js_launchPad_code: -.. literalinclude:: code/launchPad/launchPad.ino +.. literalinclude:: ../code/06iot/launchPad/launchPad.ino :caption: LaunchPad code for communicating via the UART (launchPad.ino) :linenos: -:download:`launchPad.ino <code/launchPad/launchPad.ino>` +:download:`launchPad.ino <../code/06iot/launchPad/launchPad.ino>` 1. Set the mode for the built-in red and green LEDs. @@ -1064,11 +1064,11 @@ On the Bone, add the script in :ref:`js_launchPadBeagle_code` to a file called ` .. _js_launchPadBeagle_code: -.. literalinclude:: code/launchPad.js +.. literalinclude:: ../code/06iot/launchPad.js :caption: Code for communicating via the UART (launchPad.js) :linenos: -:download:`launchPad.js <code/launchPad.js>` +:download:`launchPad.js <../code/06iot/launchPad.js>` 1. Select which serial port to use. :ref:`networking_cape-headers-serial_fig` sows what's available. We've wired *P9_24* and *P9_26*, so we are using serial port */dev/ttyO1*. (Note that's the letter ``O`` and not the number ``zero``.) diff --git a/books/beaglebone-cookbook/07kernel/code/Makefile b/books/beaglebone-cookbook/07kernel/code/Makefile deleted file mode 100644 index c151dc6d41e8906b57b297c3e2a496d200bed690..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/07kernel/code/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -obj-m := hello.o -KDIR := /lib/modules/$(shell uname -r)/build - -all: - make -C $(KDIR) M=$$PWD - -clean: - rm hello.mod.c hello.o modules.order hello.mod.o Module.symvers diff --git a/books/beaglebone-cookbook/07kernel/code/Makefile.display b/books/beaglebone-cookbook/07kernel/code/Makefile.display deleted file mode 100644 index a7f5a1fc7280dd7981fb76f1cdfa4ec208d7de40..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/07kernel/code/Makefile.display +++ /dev/null @@ -1,8 +0,0 @@ -obj-m := hello.o -KDIR := /lib/modules/$(shell uname -r)/build - -all: -<TAB>make -C $(KDIR) M=$$PWD - -clean: -<TAB>rm hello.mod.c hello.o modules.order hello.mod.o Module.symvers diff --git a/books/beaglebone-cookbook/07kernel/code/hello.c b/books/beaglebone-cookbook/07kernel/code/hello.c deleted file mode 100644 index b3392a72b167b13ff4db6bd116732a2094da8e19..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/07kernel/code/hello.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <linux/module.h> /* Needed by all modules */ -#include <linux/kernel.h> /* Needed for KERN_INFO */ -#include <linux/init.h> /* Needed for the macros */ - -static int __init hello_start(void) -{ - printk(KERN_INFO "Loading hello module...\n"); - printk(KERN_INFO "Hello, World!\n"); - return 0; -} - -static void __exit hello_end(void) -{ - printk(KERN_INFO "Goodbye Boris\n"); -} - -module_init(hello_start); -module_exit(hello_end); - -MODULE_AUTHOR("Boris Houndleroy"); -MODULE_DESCRIPTION("Hello World Example"); -MODULE_LICENSE("GPL"); diff --git a/books/beaglebone-cookbook/07kernel/code/hello.patch b/books/beaglebone-cookbook/07kernel/code/hello.patch deleted file mode 100644 index deb5c615560465760fb6ec770525db26d3fd7226..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/07kernel/code/hello.patch +++ /dev/null @@ -1,53 +0,0 @@ -From eaf4f7ea7d540bc8bb57283a8f68321ddb4401f4 Mon Sep 17 00:00:00 2001 -From: Jason Kridner <jdk@ti.com> -Date: Tue, 12 Feb 2013 02:18:03 +0000 -Subject: [PATCH] hello: example kernel modules - ---- - hello/Makefile | 7 +++++++ - hello/hello.c | 18 ++++++++++++++++++ - 2 files changed, 25 insertions(+), 0 deletions(-) - create mode 100644 hello/Makefile - create mode 100644 hello/hello.c - -diff --git a/hello/Makefile b/hello/Makefile -new file mode 100644 -index 0000000..4b23da7 ---- /dev/null -+++ b/hello/Makefile -@@ -0,0 +1,7 @@ -+obj-m := hello.o -+ -+PWD := $(shell pwd) -+KDIR := ${PWD}/.. -+ -+default: -+ make -C $(KDIR) SUBDIRS=$(PWD) modules -diff --git a/hello/hello.c b/hello/hello.c -new file mode 100644 -index 0000000..157d490 ---- /dev/null -+++ b/hello/hello.c -@@ -0,0 +1,22 @@ -+#include <linux/module.h> /* Needed by all modules */ -+#include <linux/kernel.h> /* Needed for KERN_INFO */ -+#include <linux/init.h> /* Needed for the macros */ -+ -+static int __init hello_start(void) -+{ -+ printk(KERN_INFO "Loading hello module...\n"); -+ printk(KERN_INFO "Hello, World!\n"); -+ return 0; -+} -+ -+static void __exit hello_end(void) -+{ -+ printk(KERN_INFO "Goodbye Boris\n"); -+} -+ -+module_init(hello_start); -+module_exit(hello_end); -+ -+MODULE_AUTHOR("Boris Houndleroy"); -+MODULE_DESCRIPTION("Hello World Example"); -+MODULE_LICENSE("GPL"); diff --git a/books/beaglebone-cookbook/07kernel/code/helloWorld.c b/books/beaglebone-cookbook/07kernel/code/helloWorld.c deleted file mode 100644 index 0fd542de11f94a460882ea93ad7b9faf32068831..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/07kernel/code/helloWorld.c +++ /dev/null @@ -1,5 +0,0 @@ -#include <stdio.h> - -int main(int argc, char **argv) { - printf("Hello, World! \n"); -} diff --git a/books/beaglebone-cookbook/07kernel/kernel.rst b/books/beaglebone-cookbook/07kernel/kernel.rst index c18a91ef28016dbd0f71fbf806812508e689c327..b57809bb6eccaa7189be53a671394add104b8d8d 100644 --- a/books/beaglebone-cookbook/07kernel/kernel.rst +++ b/books/beaglebone-cookbook/07kernel/kernel.rst @@ -94,11 +94,11 @@ For our example module, add the code in :ref:`kernel_simple_module` to a file ca .. _kernel_simple_module: -.. literalinclude:: code/hello.c +.. literalinclude:: ../code/07kernel/hello.c :caption: Simple Kernel Module (hello.c) :linenos: -:download:`hello.c <code/hello.c>` +:download:`hello.c <../code/07kernel/hello.c>` When compiling on the Bone, all you need to do is load the Kernel Headers for the version of the kernel you're running: @@ -120,11 +120,11 @@ Next, add the code in :ref:`kernel_Makefle` to a file called ``Makefile``. .. _kernel_Makefle: -.. literalinclude:: code/Makefile.display +.. literalinclude:: ../code/07kernel/Makefile.display :caption: Simple Kernel Module (``Makefile``) :linenos: -:download:`Makefile.display <code/Makefile.display>` +:download:`Makefile.display <../code/07kernel/Makefile.display>` .. note:: Replace the two instances of *<TAB>* with a tab character (the key left of the Q key on a United States keyboard). @@ -137,13 +137,13 @@ Now, compile the kernel module by using the *make* command: bone$ make make -C /lib/modules/3.8.13-bone67/build \ - SUBDIRS=/root/cookbook-atlas/code/hello modules + SUBDIRS=/home/debian/beaglebone-cookbook-code/07kernel/hello modules make[1]: Entering directory `/usr/src/linux-headers-3.8.13-bone67' - CC [M] /root/cookbook-atlas/code/hello/hello.o + CC [M] /home/debian/beaglebone-cookbook-code/07kernel/hello/hello.o Building modules, stage 2. MODPOST 1 modules - CC /root/cookbook-atlas/code/hello/hello.mod.o - LD [M] /root/cookbook-atlas/code/hello/hello.ko + CC /home/debian/beaglebone-cookbook-code/07kernel/hello/hello.mod.o + LD [M] /home/debian/beaglebone-cookbook-code/07kernel/hello/hello.ko make[1]: Leaving directory `/usr/src/linux-headers-3.8.13-bone67' bone$ ls Makefile hello.c hello.mod.c hello.o @@ -156,7 +156,7 @@ Notice that several files have been created. .. code-block:: bash bone$ modinfo hello.ko - filename: /root/hello/hello.ko + filename: /home/debian/beaglebone-cookbook-code/07kernel/hello/hello.ko srcversion: 87C6AEED7791B4B90C3B50C depends: vermagic: 3.8.13-bone67 SMP mod_unload modversions ARMv7 thumb2 p2v8 @@ -581,11 +581,11 @@ tools to use. Test the cross compiler by adding :ref:`kernel_helloWorld` to a fi .. _kernel_helloWorld: -.. literalinclude:: code/helloWorld.c +.. literalinclude:: ../code/07kernel/helloWorld.c :caption: Simple helloWorld.c to test cross compiling (helloWorld.c) :linenos: -:download:`helloWorld.c <code/helloWorld.c>` +:download:`helloWorld.c <../code/07kernel/helloWorld.c>` You can then cross-compile by using the following commands: @@ -617,11 +617,11 @@ Solution .. _kernel_hello_patch: -.. literalinclude:: code/hello.patch +.. literalinclude:: ../code/07kernel/hello.patch :caption: Simple kernel patch file (hello.patch) :linenos: -:download:`hello.patch <code/hello.patch>` +:download:`hello.patch <../code/07kernel/hello.patch>` Here's how to use it: diff --git a/books/beaglebone-cookbook/08realtime/code/pushLED.c b/books/beaglebone-cookbook/08realtime/code/pushLED.c deleted file mode 100755 index 118210df3d93882406021436cf3110f6b0331294..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/pushLED.c +++ /dev/null @@ -1,68 +0,0 @@ -//////////////////////////////////////// -// blinkLED.c -// Blinks the P9_14 pin based on the P9_42 pin -// Wiring: -// Setup: -// See: -//////////////////////////////////////// -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#define MAXSTR 100 - -int main() { - FILE *fpbutton, *fpLED; - char LED[] = "50"; // Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 - char button[] = "7"; // Look up P9.42 using gpioinfo | grep -e chip -e P9.42. chip 0, line 7 maps to 7 - char GPIOPATH[] = "/sys/class/gpio"; - char path[MAXSTR] = ""; - - // Make sure LED is exported - snprintf(path, MAXSTR, "%s%s%s", GPIOPATH, "/gpio", LED); - if (!access(path, F_OK) == 0) { - snprintf(path, MAXSTR, "%s%s", GPIOPATH, "/export"); - fpLED = fopen(path, "w"); - fprintf(fpLED, "%s", LED); - fclose(fpLED); - } - - // Make it an output LED - snprintf(path, MAXSTR, "%s%s%s%s", GPIOPATH, "/gpio", LED, "/direction"); - fpLED = fopen(path, "w"); - fprintf(fpLED, "out"); - fclose(fpLED); - - // Make sure bbuttonutton is exported - snprintf(path, MAXSTR, "%s%s%s", GPIOPATH, "/gpio", button); - if (!access(path, F_OK) == 0) { - snprintf(path, MAXSTR, "%s%s", GPIOPATH, "/export"); - fpbutton = fopen(path, "w"); - fprintf(fpbutton, "%s", button); - fclose(fpbutton); - } - - // Make it an input button - snprintf(path, MAXSTR, "%s%s%s%s", GPIOPATH, "/gpio", button, "/direction"); - fpbutton = fopen(path, "w"); - fprintf(fpbutton, "in"); - fclose(fpbutton); - - // I don't know why I can open the LED outside the loop and use fseek before - // each read, but I can't do the same for the button. It appears it needs - // to be opened every time. - snprintf(path, MAXSTR, "%s%s%s%s", GPIOPATH, "/gpio", LED, "/value"); - fpLED = fopen(path, "w"); - - char state = '0'; - - while (1) { - snprintf(path, MAXSTR, "%s%s%s%s", GPIOPATH, "/gpio", button, "/value"); - fpbutton = fopen(path, "r"); - fseek(fpLED, 0L, SEEK_SET); - fscanf(fpbutton, "%c", &state); - printf("state: %c\n", state); - fprintf(fpLED, "%c", state); - fclose(fpbutton); - usleep(250000); // sleep time in microseconds - } -} \ No newline at end of file diff --git a/books/beaglebone-cookbook/08realtime/code/pushLED.js b/books/beaglebone-cookbook/08realtime/code/pushLED.js deleted file mode 100755 index 485a2bbf9537c885f8acc07911716aecfb549dfc..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/pushLED.js +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env node -//////////////////////////////////////// -// pushLED.js -// Blinks an LED attached to P9_12 when the button at P9_42 is pressed -// Wiring: -// Setup: -// See: -//////////////////////////////////////// -const fs = require("fs"); - -const ms = 500 // Read time in ms - -const LED="50"; // Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 -const button="7"; // P9_42 mapps to 7 - -GPIOPATH="/sys/class/gpio/"; - -// Make sure LED is exported -if(!fs.existsSync(GPIOPATH+"gpio"+LED)) { - fs.writeFileSync(GPIOPATH+"export", LED); -} -// Make it an output pin -fs.writeFileSync(GPIOPATH+"gpio"+LED+"/direction", "out"); - -// Make sure button is exported -if(!fs.existsSync(GPIOPATH+"gpio"+button)) { - fs.writeFileSync(GPIOPATH+"export", button); -} -// Make it an input pin -fs.writeFileSync(GPIOPATH+"gpio"+button+"/direction", "in"); - -// Read every ms -setInterval(flashLED, ms); - -function flashLED() { - var data = fs.readFileSync(GPIOPATH+"gpio"+button+"/value").slice(0, -1); - console.log('data = ' + data); - fs.writeFileSync(GPIOPATH+"gpio"+LED+"/value", data); - } diff --git a/books/beaglebone-cookbook/08realtime/code/pushLED.py b/books/beaglebone-cookbook/08realtime/code/pushLED.py deleted file mode 100755 index 7606e090ae9418ce8ab233f2083d1b28650d805c..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/pushLED.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python -# //////////////////////////////////////// -# // pushLED.py -# // Blinks an LED attached to P9_12 when the button at P9_42 is pressed -# // Wiring: -# // Setup: -# // See: -# //////////////////////////////////////// -import time -import os - -ms = 50 # Read time in ms - -LED="50" # Look up P9.14 using gpioinfo | grep -e chip -e P9.14. chip 1, line 18 maps to 50 -button="7" # P9_42 mapps to 7 - -GPIOPATH="/sys/class/gpio/" - -# Make sure LED is exported -if (not os.path.exists(GPIOPATH+"gpio"+LED)): - f = open(GPIOPATH+"export", "w") - f.write(LED) - f.close() - -# Make it an output pin -f = open(GPIOPATH+"gpio"+LED+"/direction", "w") -f.write("out") -f.close() - -# Make sure button is exported -if (not os.path.exists(GPIOPATH+"gpio"+button)): - f = open(GPIOPATH+"export", "w") - f.write(button) - f.close() - -# Make it an output pin -f = open(GPIOPATH+"gpio"+button+"/direction", "w") -f.write("in") -f.close() - -# Read every ms -fin = open(GPIOPATH+"gpio"+button+"/value", "r") -fout = open(GPIOPATH+"gpio"+LED+"/value", "w") - -while True: - fin.seek(0) - fout.seek(0) - fout.write(fin.read()) - time.sleep(ms/1000) diff --git a/books/beaglebone-cookbook/08realtime/code/pushLEDmmap.c b/books/beaglebone-cookbook/08realtime/code/pushLEDmmap.c deleted file mode 100644 index 35f826684c17650b3e7eddd66c404a9fad23ba70..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/pushLEDmmap.c +++ /dev/null @@ -1,68 +0,0 @@ -// From: http://stackoverflow.com/questions/13124271/driving-beaglebone-gpio -// -through-dev-mem -// user contributions licensed under cc by-sa 3.0 with attribution required -// http://creativecommons.org/licenses/by-sa/3.0/ -// http://blog.stackoverflow.com/2009/06/attribution-required/ -// Author: madscientist159 (http://stackoverflow.com/users/3000377/madscientist159) -// -// Read one gpio pin and write it out to another using mmap. -// Be sure to set -O3 when compiling. -#include <stdio.h> -#include <stdlib.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <signal.h> // Defines signal-handling functions (i.e. trap Ctrl-C) -#include "pushLEDmmap.h" - -// Global variables -int keepgoing = 1; // Set to 0 when Ctrl-c is pressed - -// Callback called when SIGINT is sent to the process (Ctrl-C) -void signal_handler(int sig) { - printf( "\nCtrl-C pressed, cleaning up and exiting...\n" ); - keepgoing = 0; -} - -int main(int argc, char *argv[]) { - volatile void *gpio_addr; - volatile unsigned int *gpio_datain; - volatile unsigned int *gpio_setdataout_addr; - volatile unsigned int *gpio_cleardataout_addr; - - // Set the signal callback for Ctrl-C - signal(SIGINT, signal_handler); - - int fd = open("/dev/mem", O_RDWR); - - printf("Mapping %X - %X (size: %X)\n", GPIO0_START_ADDR, GPIO0_END_ADDR, - GPIO0_SIZE); - - gpio_addr = mmap(0, GPIO0_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, - GPIO0_START_ADDR); - - gpio_datain = gpio_addr + GPIO_DATAIN; - gpio_setdataout_addr = gpio_addr + GPIO_SETDATAOUT; - gpio_cleardataout_addr = gpio_addr + GPIO_CLEARDATAOUT; - - if(gpio_addr == MAP_FAILED) { - printf("Unable to map GPIO\n"); - exit(1); - } - printf("GPIO mapped to %p\n", gpio_addr); - printf("GPIO SETDATAOUTADDR mapped to %p\n", gpio_setdataout_addr); - printf("GPIO CLEARDATAOUT mapped to %p\n", gpio_cleardataout_addr); - - printf("Start copying GPIO_07 to GPIO_31\n"); - while(keepgoing) { - if(*gpio_datain & GPIO_07) { - *gpio_setdataout_addr= GPIO_31; - } else { - *gpio_cleardataout_addr = GPIO_31; - } - //usleep(1); - } - - munmap((void *)gpio_addr, GPIO0_SIZE); - close(fd); - return 0; -} diff --git a/books/beaglebone-cookbook/08realtime/code/pushLEDmmap.h b/books/beaglebone-cookbook/08realtime/code/pushLEDmmap.h deleted file mode 100644 index a9b49331d9d9f31c7346d5842d0ba76f1620ef85..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/pushLEDmmap.h +++ /dev/null @@ -1,35 +0,0 @@ -// From: http://stackoverflow.com/questions/13124271/driving-beaglebone-gpio -// -through-dev-mem -// user contributions licensed under cc by-sa 3.0 with attribution required -// http://creativecommons.org/licenses/by-sa/3.0/ -// http://blog.stackoverflow.com/2009/06/attribution-required/ -// Author: madscientist159 (http://stackoverflow.com/users/3000377/madscientist159) - -#ifndef _BEAGLEBONE_GPIO_H_ -#define _BEAGLEBONE_GPIO_H_ - -#define GPIO0_START_ADDR 0x44e07000 -#define GPIO0_END_ADDR 0x44e08000 -#define GPIO0_SIZE (GPIO0_END_ADDR - GPIO0_START_ADDR) - -#define GPIO1_START_ADDR 0x4804C000 -#define GPIO1_END_ADDR 0x4804D000 -#define GPIO1_SIZE (GPIO1_END_ADDR - GPIO1_START_ADDR) - -#define GPIO2_START_ADDR 0x41A4C000 -#define GPIO2_END_ADDR 0x41A4D000 -#define GPIO2_SIZE (GPIO2_END_ADDR - GPIO2_START_ADDR) - -#define GPIO3_START_ADDR 0x41A4E000 -#define GPIO3_END_ADDR 0x41A4F000 -#define GPIO3_SIZE (GPIO3_END_ADDR - GPIO3_START_ADDR) - -#define GPIO_DATAIN 0x138 -#define GPIO_SETDATAOUT 0x194 -#define GPIO_CLEARDATAOUT 0x190 - -#define GPIO_03 (1<<3) -#define GPIO_07 (1<<7) -#define GPIO_31 (1<<31) -#define GPIO_60 (1<<28) -#endif \ No newline at end of file diff --git a/books/beaglebone-cookbook/08realtime/code/rt/cyclictest.png b/books/beaglebone-cookbook/08realtime/code/rt/cyclictest.png deleted file mode 100644 index 1e6780c155c297043268bda39a18e8acf77fbda2..0000000000000000000000000000000000000000 Binary files a/books/beaglebone-cookbook/08realtime/code/rt/cyclictest.png and /dev/null differ diff --git a/books/beaglebone-cookbook/08realtime/code/rt/hist.gen b/books/beaglebone-cookbook/08realtime/code/rt/hist.gen deleted file mode 100755 index e265fc7f745d22ba9fca9bd52bb2cb51f39890a4..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/rt/hist.gen +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# This code is from Julia Cartwright julia@kernel.org - -cyclictest -m -S -p 90 -h 400 -l "${1:-100000}" diff --git a/books/beaglebone-cookbook/08realtime/code/rt/hist.plt b/books/beaglebone-cookbook/08realtime/code/rt/hist.plt deleted file mode 100755 index 26d130b15bbc7dfe86373c71746b9897b1184884..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/rt/hist.plt +++ /dev/null @@ -1,17 +0,0 @@ -# This code is from Julia Cartwright julia@kernel.org - -set terminal png medium size 800,600 -# set terminal X11 persist -set output "cyclictest.png" -set datafile commentschars "#" - -set logscale y - -# trim some of the distortion from the bottom of the plot -set yrang [0.85:*] - -set xlabel "t (us)" -set ylabel "Count" - -plot "nort.hist" using 1:2 with histeps title "NON-RT", \ - "rt.hist" using 1:2 with histeps title "PREEMPT-RT" diff --git a/books/beaglebone-cookbook/08realtime/code/rt/install.sh b/books/beaglebone-cookbook/08realtime/code/rt/install.sh deleted file mode 100755 index 7240ba2cfee9747021e06709f9aa0d7c0d99e40b..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/rt/install.sh +++ /dev/null @@ -1,3 +0,0 @@ -sudo apt install rt-tests -# You can run gnuplot on the host -sudo apt install gnuplot diff --git a/books/beaglebone-cookbook/08realtime/code/rt/setup.sh b/books/beaglebone-cookbook/08realtime/code/rt/setup.sh deleted file mode 100755 index c8003f2c4c18382b561a69ab816ee05bb91e9561..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/08realtime/code/rt/setup.sh +++ /dev/null @@ -1,3 +0,0 @@ -# This may be needed to run rt -echo 950000 | sudo tee /sys/fs/cgroup/cpu/cpu.rt_runtime_us -echo 950000 | sudo tee /sys/fs/cgroup/cpu/user.slice/cpu.rt_runtime_us diff --git a/books/beaglebone-cookbook/08realtime/realtime.rst b/books/beaglebone-cookbook/08realtime/realtime.rst index 79fe98b2f429c5b7348da39314c505c5f04c4451..c306a7b460749635c4dee5f837afbbfe3491177f 100644 --- a/books/beaglebone-cookbook/08realtime/realtime.rst +++ b/books/beaglebone-cookbook/08realtime/realtime.rst @@ -62,19 +62,19 @@ pushbutton, and turns on the LED attached to *P9_12* when the button is pushed. .. _py_pushLED_code: -.. literalinclude:: code/pushLED.py +.. literalinclude:: ../code/08realtime/pushLED.py :caption: Monitoring a pushbutton (pushLED.py) :linenos: -:download:`pushLED.py <code/pushLED.py>` +:download:`pushLED.py <../code/08realtime/pushLED.py>` .. _realtime_pushLED_code: -.. literalinclude:: code/pushLED.js +.. literalinclude:: ../code/08realtime/pushLED.js :caption: Monitoring a pushbutton (pushLED.js) :linenos: -:download:`pushLED.js <code/pushLED.js>` +:download:`pushLED.js <../code/08realtime/pushLED.js>` Add the code to a file named ``pushLED.js`` and run it by using the following commands: @@ -112,11 +112,11 @@ Then add the code in :ref:`realtime_pushLED_c_code` to a file named ``pushLED.c` .. _realtime_pushLED_c_code: -.. literalinclude:: code/pushLED.c +.. literalinclude:: ../code/08realtime/pushLED.c :caption: Code for reading a switch and blinking an LED (pushLED.c) :linenos: -:download:`pushLED.c <code/pushLED.c>` +:download:`pushLED.c <../code/08realtime/pushLED.c>` Compile and run the code: @@ -280,22 +280,22 @@ Add the code in :ref:`realtime_pushLEDmmap_h` to a file named ``pushLEDmmap.h``. .. _realtime_pushLEDmmap_h: -.. literalinclude:: code/pushLEDmmap.h +.. literalinclude:: ../code/08realtime/pushLEDmmap.h :caption: Memory address definitions (pushLEDmmap.h) :linenos: -:download:`pushLEDmmap.h <code/pushLEDmmap.h>` +:download:`pushLEDmmap.h <../code/08realtime/pushLEDmmap.h>` Add the code in :ref:`realtime_pushLEDmmap_c` to a file named ``pushLEDmmap.c``. .. _realtime_pushLEDmmap_c: -.. literalinclude:: code/pushLEDmmap.c +.. literalinclude:: ../code/08realtime/pushLEDmmap.c :caption: Code for directly reading memory addresses (pushLEDmmap.c) :linenos: -:download:`pushLEDmmap.c <code/pushLEDmmap.c>` +:download:`pushLEDmmap.c <../code/08realtime/pushLEDmmap.c>` Now, compile and run the code: @@ -407,11 +407,11 @@ Here's how to run the scripts. .. _realtime_install_fig: -.. literalinclude:: code/rt/install.sh +.. literalinclude:: ../code/08realtime/rt/install.sh :caption: rt/install.sh :linenos: -:download:`rt/install.sh <code/rt/install.sh>` +:download:`rt/install.sh <../code/08realtime/rt/install.sh>` * Open up another window and start something that will create a load on the Bone, then run the following: @@ -425,11 +425,11 @@ The data is saved in *nort.hist*, which stands for no RT histogram. .. _realtime_hist_gen_fig: -.. literalinclude:: code/rt/hist.gen +.. literalinclude:: ../code/08realtime/rt/hist.gen :caption: hist.gen :linenos: -:download:`rt/hist.gen <code/rt/hist.gen>` +:download:`rt/hist.gen <../code/08realtime/rt/hist.gen>` .. note:: If you get an error: @@ -486,7 +486,7 @@ This will generate the file *cyclictest.png* which contains your plot. It shoul .. _realtime_cyclictest_fig: -.. figure:: code/rt/cyclictest.png +.. figure:: ../code/08realtime/rt/cyclictest.png :align: center :alt: Histogram of Non-RT and RT kernels running cyclictest diff --git a/books/beaglebone-cookbook/09capes/capes.rst b/books/beaglebone-cookbook/09capes/capes.rst index 0e38696e0c2efdd75ac20a7afbf84e98bdd9f2a2..eef75fffdddd722c9083b40eec6e150b8dc87864 100644 --- a/books/beaglebone-cookbook/09capes/capes.rst +++ b/books/beaglebone-cookbook/09capes/capes.rst @@ -125,7 +125,7 @@ The `manufacturer's website <http://bit.ly/1xd0r8p>`_ suggests enabling SPI0 by .. code-block:: shell-session bone$ export SLOTS=/sys/devices/bone_capemgr.*/slots - bone$ echo BB-SPIDEV0 > $SLOTS + bone$ echo BB-SPIDEV0 > $SLOTS Hmmm, something isn't working here. Here's how to see what happened: @@ -153,7 +153,7 @@ Hmmm, something isn't working here. Here's how to see what happened: .. annotations:: - <1> Shows there is a conflict for pin <code>P9_21</code>: it's already configured for pulse width modulation (PWM). + <1> Shows there is a conflict for pin `P9_21`: it's already configured for pulse width modulation (PWM). Here's how to see what's already configured: @@ -177,13 +177,13 @@ Here's how to see what's already configured: .. annotations:: - <1> You can see the eMMC, HDMI, and three PWMs are already using some of the pins. Slot 10 shows <code>P9_21</code> is in use by a PWM. + <1> You can see the eMMC, HDMI, and three PWMs are already using some of the pins. Slot 10 shows `P9_21` is in use by a PWM. You can unconfigure it by using the following commands: .. code-block:: bash - bone$ echo -10 > $SLOTS + bone$ echo -10 > $SLOTS bone$ cat $SLOTS 0: 54:PF--- 1: 55:PF--- @@ -206,7 +206,7 @@ Now, configure it for the MiniDisplay and run a test: .. code-block:: bash - bone$ echo BB-SPIDEV0 > $SLOTS + bone$ echo BB-SPIDEV0 > $SLOTS bone$ ./minidisplay-test @@ -527,51 +527,53 @@ Testing the quickBot motors interface (quickBot_motor_test.js) } } - function M1_set(speed) { <img src="callouts/8.png" alt="8"/> - speed = (speed > 1) ? 1 : speed; // <9> - speed = (speed < -1) ? -1 : speed; + function M1_set(speed) { // <8> + speed = (speed > 1) ? 1 : speed; // <9> + speed = (speed < -1) ? -1 : speed; b.digitalWrite(M1_FORWARD, b.LOW); b.digitalWrite(M1_BACKWARD, b.LOW); - if(speed > 0) { + if(speed > 0) { b.digitalWrite(M1_FORWARD, b.HIGH); - } else if(speed < 0) { + } else if(speed < 0) { b.digitalWrite(M1_BACKWARD, b.HIGH); } b.analogWrite(M1_SPEED, Math.abs(speed), freq); // <10> } function M2_set(speed) { - speed = (speed > 1) ? 1 : speed; - speed = (speed < -1) ? -1 : speed; + speed = (speed > 1) ? 1 : speed; + speed = (speed < -1) ? -1 : speed; b.digitalWrite(M2_FORWARD, b.LOW); b.digitalWrite(M2_BACKWARD, b.LOW); - if(speed > 0) { + if(speed > 0) { b.digitalWrite(M2_FORWARD, b.HIGH); - } else if(speed < 0) { + } else if(speed < 0) { b.digitalWrite(M2_BACKWARD, b.HIGH); } b.analogWrite(M2_SPEED, Math.abs(speed), freq); - <1> Define each pin as a variable. This makes it easy to change to another pin if you decide that is necessary. + .. annotations:: - <2> Make other simple parameters variables. Again, this makes it easy to update them. When creating this test, I found that the PWM frequency to drive the motors needed to be relatively low to get over the kickback shown in :ref:`quickBot_motor_kickback`. I also found that I needed to get up to about 70 percent duty cycle for my circuit to reliably start the motors turning. + <1> Define each pin as a variable. This makes it easy to change to another pin if you decide that is necessary. - <3> Use a simple variable such as `state` to keep track of the test phase. This is used in a `switch` statement to jump to the code to configure for that test phase and updated after configuring for the current phase in order to select the next phase. Note that the next phase isn’t entered until after a two-second delay, as specified in the call to `setTimeout()`. + <2> Make other simple parameters variables. Again, this makes it easy to update them. When creating this test, I found that the PWM frequency to drive the motors needed to be relatively low to get over the kickback shown in :ref:`quickBot_motor_kickback`. I also found that I needed to get up to about 70 percent duty cycle for my circuit to reliably start the motors turning. - <4> Perform the initial setup of all the pins. + <3> Use a simple variable such as `state` to keep track of the test phase. This is used in a `switch` statement to jump to the code to configure for that test phase and updated after configuring for the current phase in order to select the next phase. Note that the next phase isn't entered until after a two-second delay, as specified in the call to `setTimeout()`. - <5> The first time a PWM pin is used, it is configured with the update frequency. It is important to set this just once to the right frequency, because other PWM channels might use the same PWM controller, and attempts to reset the PWM frequency might fail. The <code>pinMode()</code> function doesn’t have an argument for providing the update frequency, so use the <code>analogWrite()</code> function, instead. You can review using the PWM in :ref:`motors_servo`. + <4> Perform the initial setup of all the pins. - <6> `updateMotors()` is the test function for the motors and is defined after all the setup and initialization code. The code calls this function every two seconds using the `setTimeout()` JavaScript function. The first call is used to prime the loop. + <5> The first time a PWM pin is used, it is configured with the update frequency. It is important to set this just once to the right frequency, because other PWM channels might use the same PWM controller, and attempts to reset the PWM frequency might fail. The `pinMode()` function doesn't have an argument for providing the update frequency, so use the `analogWrite()` function, instead. You can review using the PWM in :ref:`motors_servo`. - <7> The call to `console.log()` was initially here to observe the state transitions in the debug console, but it was replaced with the `updateLEDs()` call. Using the `USER` LEDs makes it possible to note the state transitions without having visibility of the debug console. `updateLEDs()` is defined later. + <6> `updateMotors()` is the test function for the motors and is defined after all the setup and initialization code. The code calls this function every two seconds using the `setTimeout()` JavaScript function. The first call is used to prime the loop. - <8> The `M1_set()` and `M2_set()` functions are defined near the bottom and do the work of configuring the motor drivers into a particular state. They take a single argument of `speed`, as defined between `-1` (maximum reverse), `0` (stop), and `1` (maximum forward). + <7> The call to `console.log()` was initially here to observe the state transitions in the debug console, but it was replaced with the `updateLEDs()` call. Using the `USER` LEDs makes it possible to note the state transitions without having visibility of the debug console. `updateLEDs()` is defined later. - <9> Perform simple bounds checking to ensure that speed values are between `-1` and `1`. + <8> The `M1_set()` and `M2_set()` functions are defined near the bottom and do the work of configuring the motor drivers into a particular state. They take a single argument of `speed`, as defined between `-1` (maximum reverse), `0` (stop), and `1` (maximum forward). - <10> The `analogWrite()` call uses the absolute value of `speed`, making any negative numbers a positive magnitude. + <9> Perform simple bounds checking to ensure that speed values are between `-1` and `1`. + + <10> The `analogWrite()` call uses the absolute value of `speed`, making any negative numbers a positive magnitude. .. _quickBot_motor_kickback: @@ -649,29 +651,31 @@ The `Fritzing custom PCB outline page <http://bit.ly/1xd1aGV>`_ describes how to board outline. Although it is possible to use a drawing tool like `Inkscape <https://inkscape.org/en/>`_, I chose to use `the SVG path command <http://bit.ly/1b2aZmn>`_ directly to create :ref:`capes_boardoutline_code`. -.. _capes_boardoutline_code: - -Outline SVG for BeagleBone cape (beaglebone_cape_boardoutline.svg) -=================================================================== - -.. <?xml version='1.0' encoding='UTF-8' standalone='no'?> -.. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" -.. width="306" height="193.5"><!--<a class="co" id="co_capes_bo_1_co" href="#callout_capes_bo_1_co"><img src="callouts/1.png" alt="1"/></a>--> -.. <g id="board"><!--<a class="co" id="co_capes_bo_2_co" href="#callout_capes_bo_2_co"><img src="callouts/2.png" alt="2"/></a>--> -.. <path fill="#338040" id="boardoutline" d="M 22.5,0 l 0,56 L 72,56 -.. q 5,0 5,5 l 0,53.5 q 0,5 -5,5 L 0,119.5 L 0,171 Q 0,193.5 22.5,193.5 -.. l 238.5,0 c 24.85281,0 45,-20.14719 45,-45 L 306,45 -.. C 306,20.14719 285.85281,0 261,0 z"/><!--<a class="co" id="co_capes_bo_3_co" href="#callout_capes_bo_3_co"><img src="callouts/3.png" alt="3"/></a>--> -.. </g> -.. </svg> - -.. ++++ -.. <dl class="calloutlist"> -.. <dt><a class="co" id="callout_capes_bo_1_co" href="#co_capes_bo_1_co"><img src="callouts/1.png" alt="1"/></a></dt><dd><p>This is a standard SVG header. The width and height are set based on the BeagleBone outline provided in the Adafruit library.</p></dd> -.. <dt><a class="co" id="callout_capes_bo_2_co" href="#co_capes_bo_2_co"><img src="callouts/2.png" alt="2"/></a></dt><dd><p>Fritzing requires the element to be within a layer called <code>board</code>.</p></dd> -.. <dt><a class="co" id="callout_capes_bo_3_co" href="#co_capes_bo_3_co"><img src="callouts/3.png" alt="3"/></a></dt><dd><p>Fritzing requires the color to be <code>#338040</code> and the layer to be called <code>boardoutline</code>. The units end up being 1/90 of an inch. That is, take the numbers in the SVG code and divide by 90 to get the numbers from the System Reference Manual.</p></dd> -.. </dl> -.. ++++ +.. callout:: + + .. code-block:: xml + :caption: Outline SVG for BeagleBone cape (beaglebone_cape_boardoutline.svg) + :name: capes_boardoutline_code + :linenos: + + <?xml version='1.0' encoding='UTF-8' standalone='no'?> + <svg xmlns="http://www.w3.org/2000/svg" version="1.1" + width="306" height="193.5"> <!-- <1> --> + <g id="board"> <!-- <2> --> + <path fill="#338040" id="boardoutline" d="M 22.5,0 l 0,56 L 72,56 + q 5,0 5,5 l 0,53.5 q 0,5 -5,5 L 0,119.5 L 0,171 Q 0,193.5 22.5,193.5 + l 238.5,0 c 24.85281,0 45,-20.14719 45,-45 L 306,45 + C 306,20.14719 285.85281,0 261,0 z"/> <!-- <3> --> + </g> + </svg> + + .. annotations:: + + <1> This is a standard SVG header. The width and height are set based on the BeagleBone outline provided in the Adafruit library. + + <2> Fritzing requires the element to be within a layer called `board` + + <3> Fritzing requires the color to be `#338040` and the layer to be called `boardoutline`. The units end up being 1/90 of an inch. That is, take the numbers in the SVG code and divide by 90 to get the numbers from the System Reference Manual. The measurements are taken from the :ref:`beagleboneblack-mechanical` section of the :ref:`BeagleBone Black System Reference Manual <beagleboneblack-home>`, as shown in :ref:`capes_dimensions_fig`. diff --git a/books/beaglebone-cookbook/09capes/code/quickBot_motor_test.js b/books/beaglebone-cookbook/09capes/code/quickBot_motor_test.js deleted file mode 100755 index ed6435b3c155b30d883a1a735e2387c2e60262c3..0000000000000000000000000000000000000000 --- a/books/beaglebone-cookbook/09capes/code/quickBot_motor_test.js +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env node -var b = require('bonescript'); -var M1_SPEED = 'P9_16'; // <1> -var M1_FORWARD = 'P8_15'; -var M1_BACKWARD = 'P8_13'; -var M2_SPEED = 'P9_14'; -var M2_FORWARD = 'P8_9'; -var M2_BACKWARD = 'P8_11'; -var freq = 50; // <2> -var fast = 0.95; -var slow = 0.7; -var state = 0; // <3> - -b.pinMode(M1_FORWARD, b.OUTPUT); // <4> -b.pinMode(M1_BACKWARD, b.OUTPUT); -b.pinMode(M2_FORWARD, b.OUTPUT); -b.pinMode(M2_BACKWARD, b.OUTPUT); -b.analogWrite(M1_SPEED, 0, freq); // <5> -b.analogWrite(M2_SPEED, 0, freq); - -updateMotors(); // <6> - -function updateMotors() { // <6> - //console.log("Setting state = " + state); // <7> - updateLEDs(state); // <7> - switch(state) { // <3> - case 0: - default: - M1_set(0); // <8> - M2_set(0); - state = 1; // <3> - break; - case 1: - M1_set(slow); - M2_set(slow); - state = 2; - break; - case 2: - M1_set(slow); - M2_set(-slow); - state = 3; - break; - case 3: - M1_set(-slow); - M2_set(slow); - state = 4; - break; - case 4: - M1_set(fast); - M2_set(fast); - state = 0; - break; - } - setTimeout(updateMotors, 2000); // <3> -} - -function updateLEDs(state) { // <7> - switch(state) { - case 0: - b.digitalWrite("USR0", b.LOW); - b.digitalWrite("USR1", b.LOW); - b.digitalWrite("USR2", b.LOW); - b.digitalWrite("USR3", b.LOW); - break; - case 1: - b.digitalWrite("USR0", b.HIGH); - b.digitalWrite("USR1", b.LOW); - b.digitalWrite("USR2", b.LOW); - b.digitalWrite("USR3", b.LOW); - break; - case 2: - b.digitalWrite("USR0", b.LOW); - b.digitalWrite("USR1", b.HIGH); - b.digitalWrite("USR2", b.LOW); - b.digitalWrite("USR3", b.LOW); - break; - case 3: - b.digitalWrite("USR0", b.LOW); - b.digitalWrite("USR1", b.LOW); - b.digitalWrite("USR2", b.HIGH); - b.digitalWrite("USR3", b.LOW); - break; - case 4: - b.digitalWrite("USR0", b.LOW); - b.digitalWrite("USR1", b.LOW); - b.digitalWrite("USR2", b.LOW); - b.digitalWrite("USR3", b.HIGH); - break; - } -} - -function M1_set(speed) { // <8> - speed = (speed > 1) ? 1 : speed; // <9> - speed = (speed < -1) ? -1 : speed; - b.digitalWrite(M1_FORWARD, b.LOW); - b.digitalWrite(M1_BACKWARD, b.LOW); - if(speed > 0) { - b.digitalWrite(M1_FORWARD, b.HIGH); - } else if(speed < 0) { - b.digitalWrite(M1_BACKWARD, b.HIGH); - } - b.analogWrite(M1_SPEED, Math.abs(speed), freq); // <10> -} - -function M2_set(speed) { - speed = (speed > 1) ? 1 : speed; - speed = (speed < -1) ? -1 : speed; - b.digitalWrite(M2_FORWARD, b.LOW); - b.digitalWrite(M2_BACKWARD, b.LOW); - if(speed > 0) { - b.digitalWrite(M2_FORWARD, b.HIGH); - } else if(speed < 0) { - b.digitalWrite(M2_BACKWARD, b.HIGH); - } - b.analogWrite(M2_SPEED, Math.abs(speed), freq); -} diff --git a/books/beaglebone-cookbook/code b/books/beaglebone-cookbook/code new file mode 160000 index 0000000000000000000000000000000000000000..269209bc64423a06e8caf11b91c7468805b287b2 --- /dev/null +++ b/books/beaglebone-cookbook/code @@ -0,0 +1 @@ +Subproject commit 269209bc64423a06e8caf11b91c7468805b287b2 diff --git a/books/index.rst b/books/index.rst index 4640aed024bb3d01e4e17a197c4c7c53acb6be1e..b31ab04b2ccc74efc620bff31a851c5bd88b0f6f 100644 --- a/books/index.rst +++ b/books/index.rst @@ -5,10 +5,10 @@ Books This is a collection of open-source books written to help Beagle developers. -`BeagleBone Cookbook <beaglebone-cookbook>`__ is a great introduction to programming +:ref:`BeagleBone Cookbook <beaglebone-cookbook>`__ is a great introduction to programming a BeagleBone using Linux from userspace, mostly using Python or JavaScript. -`PRU Cookbook <pru-cookbook>`__ provides numerous examples on using the incredible +:ref:`PRU Cookbook <pru-cookbook>`__ provides numerous examples on using the incredible ultra-low-latency microcontrollers inside the processors used on BeagleBone boards that are a big part of what has made BeagleBone such a popular platform. diff --git a/conf.py b/conf.py index 4b0342037fbeb8af77f4c646e425e4008d1bac26..431cc2611d207bb79a7e4e6a157a8b79ffb8cfd4 100644 --- a/conf.py +++ b/conf.py @@ -23,7 +23,10 @@ author = 'BeagleBoard.org Foundation' # -- General configuration --------------------------------------------------- +sys.path.append(os.path.abspath("./_ext")) + extensions = [ + "callouts", "sphinxcontrib.rsvgconverter", "sphinx_design" ] @@ -144,7 +147,6 @@ latex_elements = { "papersize": "a4paper", "maketitle": open(BBDOCS_BASE / "_static" / "latex" / "title.tex").read(), "preamble": open(BBDOCS_BASE / "_static" / "latex" / "preamble.tex").read(), - "fontpkg": r"\usepackage{charter}", "sphinxsetup": ",".join( ( "verbatimwithframe=false", @@ -156,6 +158,7 @@ latex_elements = { ) ), } +latex_engine = "xelatex" latex_logo = str(BBDOCS_BASE / "_static" / "images" / "logo-latex.pdf") latex_documents = [ ("index-tex", "beagleboard-docs.tex", "BeagleBoard Docs", author, "manual"), diff --git a/gitlab-build.sh b/gitlab-build.sh index ab7f7a3cf04c820d4c5f379a0346f181eab73939..2ae2851cdf76f13b8e4078fead609137efa5b533 100755 --- a/gitlab-build.sh +++ b/gitlab-build.sh @@ -37,13 +37,40 @@ sphinx-build -M latexpdf . public/$CI_COMMIT_BRANCH/ mv public/$CI_COMMIT_BRANCH/latex/beagleboard-docs.pdf public/$CI_COMMIT_BRANCH/ rm -rf public/$CI_COMMIT_BRANCH/latex -# elif [ "$CI_COMMIT_TAG" != "" ]; then - -# export GIT_BRANCH=$(git branch -a --contains tags/$CI_COMMIT_TAG | grep origin | sed 's/.*origin\///') -# sphinx-build -b html . public/$GIT_BRANCH/ -# sphinx-build -M latexpdf . public/$GIT_BRANCH/ -# mv public/$GIT_BRANCH/latex/beagleboard-docs.pdf public/$GIT_BRANCH/beagleboard-docs-$CI_COMMIT_TAG.pdf -# ln -s public/$GIT_BRANCH/latex/beagleboard-docs-$CI_COMMIT_TAG.pdf public/$GIT_BRANCH/beagleboard-docs.pdf -# rm -rf public/$GIT_BRANCH/latex +elif [ "$CI_COMMIT_TAG" != "" && "$CI_PROJECT_NAMESPACE" = "docs" ]; then + +# Find which branch has the tag commit +export GIT_BRANCH=$(git branch -a --contains tags/$CI_COMMIT_TAG | grep origin | sed 's/.*origin\///') +cat << EOF > PAGES +PAGES_URL = $CI_PAGES_URL +PAGES_SLUG = $GIT_BRANCH +GITLAB_USER = $CI_PROJECT_NAMESPACE +PROJECT_BRANCH = $GIT_BRANCH +GITLAB_HOST = $CI_SERVER_HOST +PROJECT_REPO = $CI_PROJECT_NAME +EOF +if [ "$GIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then +export GIT_BRANCH=latest +rm -rf public +cat <<HERE > public/index.html +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="refresh" content="0; url='latest/'" /> + </head> + <body> + <p>Please follow <a href="latest/">this link</a>.</p> + </body> +</html> +HERE +cp public/index.html /var/www/docs +fi +sphinx-build -b html . public/$GIT_BRANCH/ +sphinx-build -M latexpdf . public/$GIT_BRANCH/ +cp public/$GIT_BRANCH/latex/beagleboard-docs.pdf public/$GIT_BRANCH/beagleboard-docs-$CI_COMMIT_TAG.pdf +cp public/$GIT_BRANCH/latex/beagleboard-docs.pdf public/$GIT_BRANCH/beagleboard-docs.pdf +rm -rf public/$GIT_BRANCH/latex +sudo apk add rsync +rsync -a --delete public/$GIT_BRANCH/. /var/www/docs/$GIT_BRANCH fi diff --git a/index.rst b/index.rst index 8546bbb32e1b68b9e376d15c513d987668bca979..f70fe7e7b20ceaaf2014e5d711ba4998a898f6ba 100644 --- a/index.rst +++ b/index.rst @@ -8,6 +8,9 @@ BeagleBoard Documentation Welcome to the `BeagleBoard project documentation <https://git.beagleboard.org/docs/docs.beagleboard.io>`__. +Official documentation releases are provided at https://docs.beagle.cc (cached with local proxies) and +https://docs.beagleboard.org (non-cached, without proxies). + .. note:: The BeagleBoard.org Foundation is a US-based 501(c)3 non-profit organization providing open hardware computing solutions for a community of makers, educators and professionals that enable @@ -50,7 +53,23 @@ from source using appropriate design tools. :margin: 4 4 0 0 :gutter: 4 - .. grid-item-card:: + .. grid-item-card:: + :link: beagleboneblack-home + :link-type: ref + + **BeagleBone® AI-64** + ^^^ + + .. image:: boards/images/beaglebone-ai-64-400x.webp + :align: center + +++ + + A complete 64-bit AI and Machine Learning System with the convenience + and expandability of the BeagleBone® platform with the peripherals on + board to get started right away learning and building applications. + + + .. grid-item-card:: :link: beagleboneblack-home :link-type: ref diff --git a/intro/bone101/index.rst b/intro/bone101/index.rst index 05794524b03ddfd5bac1e2ab9bdcbb0b5ec5ff82..ee0950382a25bc7bb45f884a6b124c92499df24d 100644 --- a/intro/bone101/index.rst +++ b/intro/bone101/index.rst @@ -6,16 +6,13 @@ Bone101 .. note:: This page is under construction. Most of the information here is drastically out of date. -Most of the useful information has moved to :ref:`bone-cook-book-home` , but this can be -to be a place for nice introductory articles on using Bealges and Linux from a different -approach. +This is a collection of articles to aide in quickly understanding how to make use of BeagleBone boards +and other Beagles running Linux. Most of the useful information has moved to :ref:`bone-cook-book-home`, but some articles +are being built here from a different perspective. -Articles under construction: +Articles under construction or to be imported and updated: * :ref:`qwiic_stemma_grove_addons` - -Also, I don't want to completely lose the useful documentation we had at: - * https://beagleboard.github.io/bone101/Support/bone101/ .. toctree:: diff --git a/intro/bone101/qwiic-stemma-grove-addons.rst b/intro/bone101/qwiic-stemma-grove-addons.rst index ad11a0cde3b94869239020297a5a294db05c3632..ad24074babfadd390104c12528be57acc10b9c79 100644 --- a/intro/bone101/qwiic-stemma-grove-addons.rst +++ b/intro/bone101/qwiic-stemma-grove-addons.rst @@ -28,16 +28,18 @@ monitoring a digital light sensor. .. code-block:: bash - cd /sys/bus/i2c/devices/i2c-1 + cd /dev/bone/i2c/2 echo tsl2561 0x29 > new_device - watch -n0 cat "1-0029/iio:device0/in_illuminance0_input" + watch -n0 cat "2-0029/iio:device0/in_illuminance0_input" Once you issue this, your screen continuously refresh with luminance values from the add-on sensor. -In the above example, `/sys/bus/i2c/devices/i2c-1` comes from which I2C controller +In the above example, `/dev/bone/i2c/2` comes from which I2C controller we are using on the board and there are specific pins on the board where you can -access it. +access it. On BeagleBone boards, there is often a symbolic link to the controller +based upon the cape expansion header pins being used. See :ref:`bone-i2c` for the +cape expansion header pin assignments. `tsl2561` is the name of the driver we want to load and `0x29` is the address of the device on the I2C bus. If you want to know about I2C device addresses, the @@ -48,10 +50,10 @@ place to start. The `new_device` virtual file is documented in the On the last line, `watch <https://manpages.debian.org/bullseye/procps/watch.1.en.html>`__ is a program that will repeatedly run the command that follows. The `-n0` sets the refresh rate. The program `cat <https://manpages.debian.org/bullseye/coreutils/cat.1.en.html>`__ -will share the contents of the file `1-0029/iio\:device0/in_illuminance0_input`. +will share the contents of the file `2-0029/iio\:device0/in_illuminance0_input`. -`1-0029/iio:device0/in_illuminance0_input` is not a file on a disk, but output directly -from the driver. The 1 in `1-0029` represents the I2C controller index. The `0029` +`2-0029/iio:device0/in_illuminance0_input` is not a file on a disk, but output directly +from the driver. The leading 2 in `2-0029` represents the I2C controller index. The `0029` represents the device I2C address. Most small sensor and actuator drivers will show up as `Industrial I/O (IIO) devices <https://www.kernel.org/doc/html/v5.19/driver-api/iio/index.html>`__. New IIO devices get incrementing indexes. In this case, `iio:device0` is the first IIO device diff --git a/intro/contribution/git-usage.rst b/intro/contribution/git-usage.rst index 3eceec05b6c3fee42be4bcf67838ae3b49add449..cf6f936c6dbba95fa5e2a25a68ef1f1c5270a33e 100644 --- a/intro/contribution/git-usage.rst +++ b/intro/contribution/git-usage.rst @@ -468,7 +468,7 @@ typically do this using a new integration branch, then fetch it to your local machine to test everything, before merging it to your main branch. Committing changes to main branch ---------------- +--------------------------------- This section is intended for BeagleBoard developers, who are allowed to commit changes to the BeagleBoard main "official" branch. It describes the @@ -574,7 +574,7 @@ And push it to GitLab: git push --tags origin main Additional Resources ---------------- +-------------------- There are a lot of different nice guides to using Git on the web: diff --git a/intro/contribution/rst-cheat-sheet.rst b/intro/contribution/rst-cheat-sheet.rst index 3abc322223aa377d0112d191bab38e8bb031a4aa..db3626dac75aebc243d43e7f1353d7f388951037 100644 --- a/intro/contribution/rst-cheat-sheet.rst +++ b/intro/contribution/rst-cheat-sheet.rst @@ -29,14 +29,15 @@ more) the lenth of the heading text, for example: .. code-block:: ReStructuredText incorrect H1 - ##### # <1> + ##### <1> correct H1 - ############ # <2> + ############ <2> .. annotations:: - <1> length of heading sybol ``#`` is smaller than the content above. + <1> Length of heading sybol ``#`` is smaller than the content above. + <2> Shows the correct way of setting the document title (H1) with ``#``. - \ No newline at end of file + diff --git a/intro/support/index.rst b/intro/support/index.rst index 992650418c922e3951f072df7bd3f4a6d3af3bf9..b0d37435d9ca37ff17987be18720a5d4ebeda4f8 100644 --- a/intro/support/index.rst +++ b/intro/support/index.rst @@ -44,9 +44,9 @@ that provide the following: * What would you consider to be a success? .. important:: - Remember that community developers are volunteering their expertise. If you - want paid support, there are :ref:`consulting-resources` options for that. Respect - developers time and expertise and they might be happy to share with you. + Remember that community developers are volunteering their expertise. Respect + developers time and expertise and they might be happy to share with you. If you + want paid support, there are :ref:`consulting-resources` options for that. Diagnostic tools ================