diff --git a/books/beaglebone-cookbook/01basics/basics.rst b/books/beaglebone-cookbook/01basics/basics.rst index 4d66e20948fb1a0d7a05206c50034b53c98cedcc..f96f0876f209c605136ae3d93dbac24f893a346a 100644 --- a/books/beaglebone-cookbook/01basics/basics.rst +++ b/books/beaglebone-cookbook/01basics/basics.rst @@ -69,7 +69,13 @@ The Bone acting like a USB drive and the files you see are located on the Bone. .. _basics_open_vsc: Browse to http://192.168.7.2:3000 from your -host computer (:ref:`basics_05gettingStarted_fig`). +host computer (:ref:`basics_05gettingStarted_fig`). If the page is not found, run the following: + +.. code-block:: + + bone$ sudo systemctl start bb-code-server.service + +Wait a minute and try the URL again. .. _basics_05gettingStarted_fig: @@ -119,16 +125,16 @@ Solution update version This book uses `Debian <https://www.debian.org>`_, the Linux distribution that currently ships on the Bone. -However this book is based on a newer version (BeagleBoard.org Debian Bullseye IoT Image 2022-07-01) +However this book is based on a newer version (BeagleBoard.org Debian Bullseye IoT Image 2023-06-03) than what is shipping at the time of this writing. You can see which version your Bone is running by following the instructions in :ref:`basics_out_of_the_box` to log into the Bone. Then run: .. code-block:: bash - bone$ cat /ID.txt - BeagleBoard.org Debian Bullseye IoT Image 2022-07-01 + bone$ cat /etc/dogtag + BeagleBoard.org Debian Bullseye IoT Image 2023-06-03 -I'm running the 2022-07-01 version. +I'm running the 2023-06-03 version. Running the Python and JavaScript Examples =========================================== @@ -136,7 +142,7 @@ Running the Python and JavaScript Examples Problem -------- -You'd like to learn Python and JavaScript interact with the Bone to +You'd like to learn Python or JavaScript interact with the Bone to perform physical computing tasks without first learning Linux. Solution @@ -145,7 +151,7 @@ Solution Plug your board into the USB of your host computer and browse to http://192.168.7.2:3000 using Google Chrome or Firefox (as shown in :ref:`basics_out_of_the_box`). In the left -column, click on *EXAMPLES*, then *BeagleBone* and then *Black*. +column, click on *examples*, then *BeagleBone* and then *Black*. Several sample scripts will appear. Go and explore them. .. tip:: @@ -209,7 +215,7 @@ negative rail and 3.3 V (*P9_3*) is wired to the positive rail. Breadboard wired to BeagleBone Black ------------------------------------- -.. figure::figures/template_bb.png +.. figure:: figures/template_bb.png :align: center :alt: Breadboard @@ -234,7 +240,7 @@ Plug your Bone into a host computer via the USB cable. Open a browser browse to http://192.168.7.2:3000 on your host. You will see something like :ref:`basics_05gettingStarted_fig`. -Click the *EXAMPLES* folder on the left and then click *BeagleBoard* and then *Black*, +Click the *examples* folder on the left and then click *BeagleBoard* and then *Black*, finally double-click ``seqLEDs.py``. You can now edit the file. .. note:: @@ -281,7 +287,7 @@ Change to the directory that contains your file, make it executable, and then ru .. code-block:: bash bone$ cd ~/examples/BeagleBone/Black/ - bone$ <strong>./seqLEDs.py + bone$ ./seqLEDs.py The *cd* is the change directory command. After you *cd*, @@ -304,6 +310,9 @@ Solution On your host computer, open a browser and go to https://forum.beagleboard.org/tag/latest-images This shows you a list of dates of the most recent Debian images (:ref:`basics_deb1`). +.. todo + Update for 2023-06-03 + .. _basics_deb1: .. figure:: figures/deb1.png @@ -331,7 +340,6 @@ with *am335x-debian-11.3-iot-* is used for the non-AI boards. The one beginning with *am57xx-debian-* is for programming the Beagle AI's. .. note:: - The onboard flash is often called the *eMMC* memory. We just call it *onboard flash*, but you'll often see *eMMC* appearing in filenames of images used to update the onboard flash. diff --git a/books/beaglebone-cookbook/02sensors/figures/vsc-bash-tab.png b/books/beaglebone-cookbook/02sensors/figures/vsc-bash-tab.png index 2f53f6da4c5769fb40bc4b76211f282fdcd024c6..a9325308ef98123e9b7fe0ef47c0c23d12b66043 100644 Binary files a/books/beaglebone-cookbook/02sensors/figures/vsc-bash-tab.png and b/books/beaglebone-cookbook/02sensors/figures/vsc-bash-tab.png differ diff --git a/books/beaglebone-cookbook/02sensors/sensors.rst b/books/beaglebone-cookbook/02sensors/sensors.rst index cc7a020e673e43c0f8eb1c43af9637255c7922a6..28d0d7524e1b81a3a24406d3df2da269604564d6 100644 --- a/books/beaglebone-cookbook/02sensors/sensors.rst +++ b/books/beaglebone-cookbook/02sensors/sensors.rst @@ -3,6 +3,10 @@ Sensors ######## +.. |kohm| replace:: kΩ +.. |ohm| replace:: Ω +.. |deg| replace:: ° + In this chapter, you will learn how to sense the physical world with BeagleBone Black. Various types of electronic sensors, such as cameras and microphones, can be connected to the Bone using one or more interfaces provided by the standard USB 2.0 host port, @@ -11,7 +15,7 @@ as shown in :ref:`sensors_host_port`. .. note:: All the examples in the book assume you have cloned the Cookbook - repository on www.github.com. Go here :ref:`basics_repo` for instructions. + repository on git.beagleboard.org. Go here :ref:`basics_repo` for instructions. .. _sensors_host_port: @@ -113,7 +117,7 @@ By default, it takes you to your home directory. Notice that the prompt has chan .. note:: All the examples in the book assume you have cloned the - Cookbook repository on www.github.com. Go here + Cookbook repository on git.beagleboard.org. Go here :ref:`basics_repo` for instructions. - Double-click the *pushbutton.py* file to open it. @@ -122,7 +126,7 @@ By default, it takes you to your home directory. Notice that the prompt has chan .. code-block:: - root@beaglebone:~/boneSensors# ./pushbutton.js + debian@beaglebone:beaglebone-cookbook/code/02sensors$ ./pushbutton.py data= 0 data= 0 data= 1 @@ -150,7 +154,7 @@ To make this recipe, you will need: * Breadboard and jumper wires. * Pushbutton switch. -* Magnetic reed switch. +* Magnetic reed switch. (optional) You can wire up either a pushbutton, a magnetic reed switch, or both on the Bone, as shown in :ref:`js_pushbutton_fig`. @@ -163,31 +167,36 @@ or both on the Bone, as shown in :ref:`js_pushbutton_fig`. Diagram for wiring a pushbutton and magnetic reed switch input -The code in :ref:`js_pushbutton_code` +The code in :ref:`py_pushbutton_code` reads GPIO port *P9_42*, which is attached to the pushbutton. -.. _py_pushbutton_code: +.. tabs:: + .. group-tab:: Python -.. literalinclude:: ../code/02sensors/pushbutton.py - :caption: Monitoring a pushbutton (pushbutton.py) - :linenos: + .. _py_pushbutton_code: + + .. literalinclude:: ../code/02sensors/pushbutton.py + :caption: Monitoring a pushbutton (pushbutton.py) + :linenos: -:download:`pushbutton.py <../code/02sensors/pushbutton.py>` + :download:`pushbutton.py <../code/02sensors/pushbutton.py>` -.. _js_pushbutton_code: + .. group-tab:: c -.. literalinclude:: ../code/02sensors/pushbutton.js - :caption: Monitoring a pushbutton (pushbutton.js) - :linenos: + .. _c_pushbutton_code: + + .. literalinclude:: ../code/02sensors/pushbutton.c + :caption: Monitoring a pushbutton (pushbutton.c) + :linenos: -:download:`pushbutton.js <../code/02sensors/pushbutton.js>` + :download:`pushbutton.c <../code/02sensors/pushbutton.c>` -Put this code in a file called *pushbutton.js* following the steps in :ref:`sensors_getting_started`. +Put this code in a file called *pushbutton.py* following the steps in :ref:`sensors_getting_started`. In the VSC *bash* tab, run it by using the following commands: .. code-block:: bash - bone$ ./pushbutton.js + bone$ ./pushbutton.py data = 0 data = 0 data = 1 @@ -198,6 +207,18 @@ The command runs it. Try pushing the button. The code reads the pin and prints i You will have to press ^C (Ctrl-C) to stop the code. +If you want to run the C version do: + +.. code-block:: bash + + bone$ gcc -o pushbutton pushbutton.c -lgpiod + bone$ ./pushbutton + data = 0 + data = 0 + data = 1 + data = 1 + ^C + If you want to use the magnetic reed switch wired as shown in :ref:`js_pushbutton_fig`, change *P9_42* to *P9_26* which is gpio *14*. @@ -272,9 +293,10 @@ To make this recipe, you will need: - Breadboard and jumper wires. - 10k trimpot or - Flex resistor (optional) -- 22k resistor +- 22 |kohm| resistor A variable resistor with three terminals +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :ref:`sensors_analogIn_fig` shows a simple variable resistor (trimpot) wired to the Bone. One end terminal is wired to the ADC 1.8 V power supply on pin *P9_32*, @@ -287,26 +309,32 @@ is wired to one of the seven analog-in ports (*P9_36*). :align: center :alt: Analog - Wiring a 10k variable resistor (trimpot) to an ADC port + Wiring a 10 |kohm| variable resistor (trimpot) to an ADC port -:ref:`sensors_analogIn_code` shows the BoneScript code used to read the variable resistor. -Add the code to a file called _analogIn.js_ and run it; then change the resistor and run it again. The voltage read will change. +:ref:`py_analogIn_code` shows the code used to read the variable resistor. +Add the code to a file called *analogIn.py* and run it; then change the resistor and run it again. The voltage read will change. -.. _py_analogIn_code: +.. tabs:: -.. literalinclude:: ../code/02sensors/analogIn.py - :caption: Reading an analog voltage (analogIn.py) - :linenos: + .. group-tab:: Python -:download:`analogIn.py <../code/02sensors/analogIn.py>` + .. _py_analogIn_code: -.. _sensors_analogIn_code: + .. literalinclude:: ../code/02sensors/analogIn.py + :caption: Reading an analog voltage (analogIn.py) + :linenos: -.. literalinclude:: ../code/02sensors/analogIn.js - :caption: Reading an analog voltage (analogIn.js) - :linenos: + :download:`analogIn.py <../code/02sensors/analogIn.py>` + + .. group-tab:: JavaScript + + .. _sensors_analogIn_code: -:download:`analogIn.js <../code/02sensors/analogIn.js>` + .. literalinclude:: ../code/02sensors/analogIn.js + :caption: Reading an analog voltage (analogIn.js) + :linenos: + + :download:`analogIn.js <../code/02sensors/analogIn.js>` .. note:: @@ -314,11 +342,12 @@ Add the code to a file called _analogIn.js_ and run it; then change the resistor outputs a value between 0 and 4096. A variable resistor with two terminals +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some resistive sensors have only two terminals, such as the flex sensor in :ref:`sensors_flexResistor_fig` The resistance between its two terminals changes when it is flexed. In this case, we need to add a fixed resistor in series with the flex sensor. :ref:`sensors_flexResistor_fig` -shows how to wire in a 22k resistor to give a voltage to measure +shows how to wire in a 22 |kohm| resistor to give a voltage to measure across the flex sensor. .. _sensors_flexResistor_fig: @@ -338,7 +367,7 @@ Reading a Distance Sensor (Analog or Variable Voltage Sensor) Problem -------- -You want to measure distance with a `LV-MaxSonar-EZ1 Sonar Range Finder <http://bit.ly/1Mt5Elr>`_, +You want to measure distance with a `LV-MaxSonar-EZ1 Sonar Range Finder <https://www.sparkfun.com/products/11309>`_, which outputs a voltage in proportion to the distance. Solution @@ -365,25 +394,30 @@ as shown in :ref:`sensors_ultrasonic_fig`. The device outputs ~6.4 mV/in when po Wiring the LV-MaxSonar-EZ1 Sonar Range Finder to the *P9_33* analog-in port -:ref:`sensors_ultrasonicRange_code` +:ref:`py_ultrasonicRange_code` shows the code that reads the sensor at a fixed interval. -.. _py_ultrasonicRange_code: +.. tabs:: -.. literalinclude:: ../code/02sensors/ultrasonicRange.py - :caption: Reading an analog voltage (ultrasonicRange.py) - :linenos: + .. group-tab:: Python -:download:`ultrasonicRange.py <../code/02sensors/ultrasonicRange.py>` + .. _py_ultrasonicRange_code: -.. _sensors_ultrasonicRange_code: + .. literalinclude:: ../code/02sensors/ultrasonicRange.py + :caption: Reading an analog voltage (ultrasonicRange.py) + :linenos: + :download:`ultrasonicRange.py <../code/02sensors/ultrasonicRange.py>` -.. literalinclude:: ../code/02sensors/ultrasonicRange.js - :caption: Reading an analog voltage (ultrasonicRange.js) - :linenos: + .. group-tab:: JavaScript -:download:`ultrasonicRange.js <../code/02sensors/ultrasonicRange.js>` + .. _sensors_ultrasonicRange_code: + + .. literalinclude:: ../code/02sensors/ultrasonicRange.js + :caption: Reading an analog voltage (ultrasonicRange.js) + :linenos: + + :download:`ultrasonicRange.js <../code/02sensors/ultrasonicRange.js>` .. _sensors_hc-sr04: @@ -413,7 +447,7 @@ pulse width on the *Echo* output. The width of the pulse tells you the distance. To make this recipe, you will need: * Breadboard and jumper wires. -* 10 k and 20 k resistors +* 10 |kohm| and 20 |kohm| resistors * HC-SR04 Ultrsonic Range Sensor. Wire the sensor as shown in :ref:`sensors_hc-sr04_fig`. @@ -515,30 +549,36 @@ Then run the following commands: This will enable *eQEP2* on pins *P8_11* and *P8_12*. The *2* after the *qep* returned by *show-pins* shows it's *eQEP2*. -Finally, add the code in :ref:`digital_rotaryEncoder_js` -to a file named *rotaryEncoder.js* and run it. +Finally, add the code in :ref:`digital_rotaryEncoder_py` +to a file named *rotaryEncoder.py* and run it. -.. _digital_rotaryEncoder_py: +.. tabs:: -.. literalinclude:: ../code/02sensors/rotaryEncoder.py - :caption: Reading a rotary encoder (rotaryEncoder.py) - :linenos: + .. group-tab:: Python -:download:`rotaryEncoder.py <../code/02sensors/rotaryEncoder.py>` + .. _digital_rotaryEncoder_py: -.. _digital_rotaryEncoder_js: + .. literalinclude:: ../code/02sensors/rotaryEncoder.py + :caption: Reading a rotary encoder (rotaryEncoder.py) + :linenos: -.. literalinclude:: ../code/02sensors/rotaryEncoder.js - :caption: Reading a rotary encoder (rotaryEncoder.js) - :linenos: + :download:`rotaryEncoder.py <../code/02sensors/rotaryEncoder.py>` + + .. group-tab:: JavaScript + + .. _digital_rotaryEncoder_js: + + .. literalinclude:: ../code/02sensors/rotaryEncoder.js + :caption: Reading a rotary encoder (rotaryEncoder.js) + :linenos: -:download:`rotaryEncoder.js <../code/02sensors/rotaryEncoder.js>` + :download:`rotaryEncoder.js <../code/02sensors/rotaryEncoder.js>` Try rotating the encoder clockwise and counter-clockwise. You'll see an output like this: -.. code-block::bash - +.. code-block:: bash + data = 32 data = 40 data = 44 @@ -551,7 +591,6 @@ You'll see an output like this: data = 999972 ^C - The values you get for *data* will depend on which way you are turning the device and how quickly. You will need to press ^C (Ctrl-C) to end. @@ -618,11 +657,11 @@ If you don't need the NMEA formatting, you can skip the *npm* part and remove th .. note:: If you get an error like this - TypeError: Cannot call method 'readline' of undefined + *TypeError: Cannot call method 'readline' of undefined* -add this line to the end of file ``/usr/local/lib/node_modules/bonescript/serial.js``: + add this line to the end of file ``/usr/local/lib/node_modules/bonescript/serial.js``: -*exports.serialParsers = m.module.parsers;* + *exports.serialParsers = m.module.parsers;* .. _cape-headers-serial_fig: @@ -653,7 +692,7 @@ sensor that uses a standard |I2C|-based serial protocol. To make this recipe, you will need: * Breadboard and jumper wires. -* Two 4.7 k resistors. +* Two 4.7 |kohm| resistors. * TMP101 temperature sensor. Wire the TMP101, as shown in :ref:`sensors_i2cTemp_fig`. @@ -679,15 +718,18 @@ shows that you have wired your device to |I2C| bus *2*. Table of |I2C| outputs -Once the |I2C| device is wired up, you can use a couple handy |I2C| +Once the |I2C| device is wired up, you can use a couple handy |I2C| tools to test the device. Because these are Linux command-line tools, you have to use *2* as the bus number. *i2cdetect*, shown in :ref:`js_i2cTools`, shows which |I2C| devices are on the bus. The *-r* flag indicates which bus to use. -Our TMP101 is appearing at address *0x498*. You can use the *i2cget* command to read +Our TMP101 is appearing at address *0x49*. You can use the *i2cget* command to read the value. It returns the temperature in hexadecimal and degrees C. In this example, 0x18 = 24{deg}C, which is 75.2{deg}F. (Hmmm, the office is a bit warm today.) Try warming up the TMP101 with your finger and running *i2cget* again. +.. todo + fix deg + .. _js_i2cTools: |I2C| tools @@ -739,7 +781,7 @@ Assuming the TMP101 is on bus 2 (the last digit is the bus number) 0 -rw-rw-r-- 1 root gpio 4096 Dec 31 1999 uevent -Assuming the TMP101 is at address 0x48: +Assuming the TMP101 is at address 0x49 .. code-block:: bash @@ -760,18 +802,16 @@ Yes, it's there, now see what happened. .. code-block:: bash bone$ ls - 2-0049 delete_device device i2c-dev name - new_device of_node power subsystem uevent + 2-0049 delete_device device i2c-dev name new_device of_node power subsystem uevent Notice a new directory has appeared. It's for i2c bus 2, address 0x49. Look into it. .. code-block:: bash - bone$ cd 2-0048/hwmon/hwmon0 + bone$ cd 2-0049/hwmon/hwmon0 bone$ ls -F - device@ name power/ subsystem@ temp1_input temp1_max - temp1_max_hyst uevent update_interval + device@ name power/ subsystem@ temp1_input temp1_max temp1_max_hyst uevent update_interval bone$ cat temp1_input 24250 @@ -782,7 +822,7 @@ You can try the Linux Kernel Driver Database, https://cateee.net/lkddb/ to see them. Once the driver is in place, you can read it via code. -:ref:`py_i2cTemp_code` shows how to read the TMP101 from BoneScript. +:ref:`py_i2cTemp_code` shows how to read the TMP101. .. _py_i2cTemp_code: @@ -834,6 +874,7 @@ using the kernel driver. First you need to install the i2c module. :download:`i2ctmp101.py <../code/02sensors/i2ctmp101.py>` This gets only 8 bits for the temperature. See the TMP101 datasheet +(https://www.ti.com/product/TMP101) for details on how to get up to 12 bits. Reading Temperature via a Dallas 1-Wire Device @@ -862,7 +903,7 @@ You can wire it to any GPIO port. To make this recipe, you will need: * Breadboard and jumper wires. -* 4.7 k resistor +* 4.7 |kohm| resistor * DS18B20 1-wire temperature sensor. Wire up as shown in :ref:`sensors_1-wire_fig`. @@ -875,7 +916,9 @@ Wire up as shown in :ref:`sensors_1-wire_fig`. Wiring a Dallas 1-Wire temperature sensor -.. note:: +.. hide + The bit.ly doesn't work. + .. note:: This solution, written by Elias Bakken (@AgentBrum), originally appeared on`Hipstercircuits <http://bit.ly/1FaRbbK>`_. @@ -908,7 +951,7 @@ Now run the following command to discover the serial number on your device: I have two devices wired in parallel on the same P9_12 input. This shows the serial numbers for all the devices. -Finally, add the code in :ref:`sensors_onewire__code` in to a +Finally, add the code in :ref:`py_onewire__code` in to a file named *w1.py*, edit the path assigned to *w1* so that the path points to your device, and then run it. diff --git a/books/beaglebone-cookbook/03displays/displays.rst b/books/beaglebone-cookbook/03displays/displays.rst index b6d254b836adf69ca0a871a61d4584160bfde6bd..612d6d59c781ff26e6ec98d0f7778927f67ec90f 100644 --- a/books/beaglebone-cookbook/03displays/displays.rst +++ b/books/beaglebone-cookbook/03displays/displays.rst @@ -1,8 +1,12 @@ .. _beaglebone-cookbook-displays: -Displays and Other Outputs -########################### - +Displays and Other Outputs +########################### + +.. |I2C| replace:: I\ :sup:`2`\ C +.. |kohm| replace:: kΩ +.. |ohm| replace:: Ω + In this chapter, you will learn how to control physical hardware via BeagleBone Black's general-purpose input/output (GPIO) pins. The Bone has 65 GPIO pins that are brought out on two 46-pin headers, called @@ -10,7 +14,7 @@ BeagleBone Black's general-purpose input/output (GPIO) pins. The Bone has .. note:: All the examples in the book assume you have cloned the Cookbook - repository on www.github.com. Go here :ref:`basics_repo` for instructions. + repository on git.beagleboard.org. Go here :ref:`basics_repo` for instructions. .. _js_P8P9_fig: @@ -51,7 +55,7 @@ through *USR3*, but we'll refer to them as the *USER* LEDs. The four *USER* LEDs -Place the code shown in :ref:`js_internLED_code` in a file called ``internLED.js``. +Place the code shown in :ref:`py_internLED_code` in a file called ``internLED.py``. You can do this using VSC to edit files (as shown in :ref:`basics_vsc`) or with a more traditional editor (as shown in :ref:`tips_editing_files`). @@ -63,21 +67,20 @@ a more traditional editor (as shown in :ref:`tips_editing_files`). :download:`internLED.py <../code/03displays/internLED.py>` -.. _js_internLED_code: +.. _c_internLED_code: -.. literalinclude:: ../code/03displays/internLED.js - :caption: Using an internal LED (internLED.js) +.. literalinclude:: ../code/03displays/internLED.c + :caption: Using an internal LED (internLED.c) :linenos: -:download:`internLED.js <../code/03displays/internLED.js>` +:download:`internLED.c <../code/03displays/internLED.c>` In the *bash* command window, enter the following commands: .. code-block:: bash bone$ cd ~/beaglebone-cookbook-code/03displays - bone$ ./internLED.js - + bone$ ./internLED.py The *USER0* LED should now be flashing. @@ -98,14 +101,14 @@ Connect an LED to one of the GPIO pins using a series resistor to limit the current. To make this recipe, you will need: * Breadboard and jumper wires. -* 220R to 470R resistor. +* 220 |ohm| to 470 |ohm| resistor. * LED .. WARNING:: The value of the current limiting resistor depends on the LED you are using. The Bone can drive only 4 to 6 mA, so you might need a larger resistor to keep - from pulling too much current. A 330R or 470R resistor might be better. + from pulling too much current. A 330 |ohm| or 470 |ohm| resistor might be better. :ref:`displays_externLED_fig` shows how you can wire the LED to pin 14 of the *P9* header (*P9_14*). Every circuit in this book (:ref:`basics_wire_breadboard`) @@ -123,6 +126,9 @@ the LED. The _short_ lead always goes to ground. After you've wired it, start VSC (see :ref:`basics_vsc`) and find the code shown in :ref:`py_externLED_code`. +Notice that it looks very similar to the *internLED* code, in fact it only +differs in the line number (18 instead of 21). The built-in LEDs use the same +GPIO interface as the GPIO pins. .. _py_externLED_code: @@ -132,13 +138,13 @@ and find the code shown in :ref:`py_externLED_code`. :download:`externLED.py <../code/03displays/externLED.py>` -.. _js_externLED_code: +.. _c_externLED_code: -.. literalinclude:: ../code/03displays/externLED.js - :caption: Code for using an external LED (externLED.js) +.. literalinclude:: ../code/03displays/externLED.c + :caption: Code for using an external LED (externLED.c) :linenos: -:download:`externLED.js <../code/03displays/externLED.js>` +:download:`externLED.c <../code/03displays/externLED.c>` Save your file and run the code as before (:ref:`displays_onboardLED`). @@ -237,7 +243,7 @@ The pwm's are accessed through */dev/bone/pwm* bone$ ls 0 1 2 -Here we see six pwmchips that can be used, each has two channels. Explore one. +Here we see three pwmchips that can be used, each has two channels. Explore one. .. code-block:: bash @@ -248,8 +254,9 @@ Here we see six pwmchips that can be used, each has two channels. Explore one. bone$ ls capture duty_cycle enable period polarity power uevent - Here is where you can set the period and duty_cycle (in ns) and enable the pwm. - Attach in LED to P9_14 and if you set the period long enough you can see the LED flash. + +Here is where you can set the period and duty_cycle (in ns) and enable the pwm. +Attach in LED to P9_14 and if you set the period long enough you can see the LED flash. .. code-block:: bash @@ -300,7 +307,7 @@ This solution uses an `Adafruit Bicolor 8x8 LED Square Pixel Matrix w/|I2C| Back To make this recipe, you will need: * Breadboard and jumper wires -* Two 4.7 R resistors. +* Two 4.7 |kohm| resistors. * |I2C| LED matrix The LED matrix is a 5 V device, but you can drive it from 3.3 V. Wire, as shown in :ref:`displays_i2cMatrix_fig`. @@ -315,8 +322,6 @@ The LED matrix is a 5 V device, but you can drive it from 3.3 V. Wire, as shown :ref:`sensors_i2c_temp` shows how to use *i2cdetect* to discover the address of an |I2C| device. -.. |I2C| replace:: I\ :sup:`2`\ C - Run the *i2cdetect -y -r 2* command to discover the address of the display on |I2C| bus 2, as shown in :ref:`displays_i2cdetect`. .. _displays_i2cdetect: @@ -338,7 +343,7 @@ Using |I2C| command-line tools to discover the address of the display 70: 70 -- -- -- -- -- -- -- Here, you can see a device at *0x49* and *0x70*. I know I have a temperature -sensor at *0x49*, so the LED matrix must be at *0.70*. +sensor at *0x49*, so the LED matrix must be at *0x70*. Find the code in :ref:`displays_matrix_i2c` and run it by using the following command: @@ -352,22 +357,25 @@ Find the code in :ref:`displays_matrix_i2c` and run it by using the following co LED matrix display (matrixLEDi2c.py) ===================================== -.. code-block:: C +.. literalinclude:: ../code/03displays/matrixLEDi2c.py + :caption: LED matrix display (matrixLEDi2c.py) + :linenos: - include::../code/03displays/matrixLEDi2c.py +:download:`matrixLEDi2c.py <../code/03displays/matrixLEDi2c.py>` + .. annotations:: -1. This line states which bus to use. The last digit gives the BoneScript bus number. + <1> This line states which bus to use. The last digit gives the |I2C| bus number. -2. This specifies the address of the LED matrix, *0x70* in our case. + <2> This specifies the address of the LED matrix, *0x70* in our case. -3. This indicates which LEDs to turn on. The first byte is for the first column of ``green`` LEDs. In this case, all are turned off. The next byte is for the first column of ``red`` LEDs. The hex *0x3c* number is *0b00111100* in binary. This means the first two red LEDs are off, the next four are on, and the last two are off. The next byte (*0x00*) says the second column of *green* LEDs are all off, the fourth byte (*0x42* = *0b01000010*) says just two *red* LEDs are on, and so on. Declarations define four different patterns to display on the LED matrix, the last being all turned off. + <3> This indicates which LEDs to turn on. The first byte is for the first column of ``green`` LEDs. In this case, all are turned off. The next byte is for the first column of ``red`` LEDs. The hex *0x3c* number is *0b00111100* in binary. This means the first two red LEDs are off, the next four are on, and the last two are off. The next byte (*0x00*) says the second column of *green* LEDs are all off, the fourth byte (*0x42* = *0b01000010*) says just two *red* LEDs are on, and so on. Declarations define four different patterns to display on the LED matrix, the last being all turned off. -4. Send three commands to the matrix to get it ready to display. + <4> Send three commands to the matrix to get it ready to display. -5. Now, we are ready to display the various patterns. After each pattern is displayed, we sleep a certain amount of time so that the pattern can be seen. + <5> Now, we are ready to display the various patterns. After each pattern is displayed, we sleep a certain amount of time so that the pattern can be seen. -6. Finally, send commands to the LED matrix to set the brightness. This makes the display fade out and back in again. + <6> Finally, send commands to the LED matrix to set the brightness. This makes the display fade out and back in again. .. _displays_drive5V: diff --git a/books/beaglebone-cookbook/04motors/motors.rst b/books/beaglebone-cookbook/04motors/motors.rst index a159a8db3024e4195e52d0369c646539b67a4f9d..9bfc351f2ca3d45309246f199a22fd9fc45d3a96 100644 --- a/books/beaglebone-cookbook/04motors/motors.rst +++ b/books/beaglebone-cookbook/04motors/motors.rst @@ -7,6 +7,11 @@ Motors .. |ohm| replace:: Ω +.. |deg| replace:: ° + +.. todo + Figure out degrees + 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? @@ -14,11 +19,10 @@ The type of motor you use depends on the type of motion you want: - R/C or hobby servo motor Can be quickly positioned at various absolute angles, but some don't spin. In fact, many can turn only about 180{deg}. - - - Stepper motor - Spins and can also rotate in precise relative angles, such as turning 45{deg}. Stepper motors come in two types: ``bipolar`` (which has four wires) and ``unipolar`` (which has five or six wires). - - DC motor - Spins either clockwise or counter-clockwise and can have the greatest speed of the three. But a DC motor can't easily be made to turn to a given angle. +- Stepper motor + Spins and can also rotate in precise relative angles, such as turning 45°. Stepper motors come in two types: ``bipolar`` (which has four wires) and ``unipolar`` (which has five or six wires). +- DC motor + Spins either clockwise or counter-clockwise and can have the greatest speed of the three. But a DC motor can't easily be made to turn to a given angle. When you know which type of motor to use, interfacing is easy. This chapter shows how to interface with each of these motors. @@ -34,7 +38,7 @@ When you know which type of motor to use, interfacing is easy. This chapter show .. note:: All the examples in the book assume you have cloned the Cookbook repository on - www.github.com. Go here :ref:`basics_repo` for instructions. + git.beagleboard.org. Go here :ref:`basics_repo` for instructions. .. _motors_servo: @@ -83,9 +87,9 @@ in :ref:`py_servoMotor_code`. You need to configure the pin for PWM. .. code-block:: bash - bone$ <strong>cd ~/beaglebone-cookbook-code/04motors</strong> - bone$ <strong>config-pin P9_16 pwm</strong> - bone$ <strong>./servoMotor.py</strong> + bone$ cd ~/beaglebone-cookbook-code/04motors + bone$ config-pin P9_16 pwm + bone$ ./servoMotor.py .. _py_servoMotor_code: @@ -123,10 +127,10 @@ Combine the code from :ref:`digital_rotaryEncoder_js` and :ref:`motors_servo`. .. code-block:: bash - bone$ <strong>config-pin P9_16 pwm</strong> - bone$ <strong>config-pin P8_11 eqep</strong> - bone$ <strong>config-pin P8_12 eqep</strong> - bone$ <strong>./servoEncoder.py</strong> + bone$ config-pin P9_16 pwm + bone$ config-pin P8_11 eqep + bone$ config-pin P8_12 eqep + bone$ ./servoEncoder.py .. _py_servoEncoder_code: @@ -154,7 +158,7 @@ but it won't. Most motors require more current than the GPIO ports on the Bone Our solution is to use a transistor to control the current to the bone. Here we configure the encoder to returns value between 0 and 180 inclusive. This value is then -mapped to a value between *min* (0.6 ma) and *max* (2.5 ms). This number is converted from +mapped to a value between *min* (0.6 ms) and *max* (2.5 ms). This number is converted from milliseconds and nanoseconds (time 1000000) and sent to the servo motor via the pwm. @@ -319,11 +323,12 @@ Wire, as shown in :ref:`motors_unipolar_fig`. The IC in :ref:`motors_unipolar_fig` is illustrated upside down from the way it is usually displayed. -That is, the notch for pin 1 is on the bottom. This made drawing the diagram much cleaner. + That is, the notch for pin 1 is on the bottom. This made drawing the diagram much cleaner. -Also, notice the ``banded`` wire running the *P9_7* (5 V) to the UL2003A. -The stepper motor I'm using runs better at 5 V, so I'm using the Bone's 5 V power supply. -The signal coming from the GPIO pins is 3.3 V, but the U2003A will step them up to 5 V to drive the motor. + Also, notice the ``banded`` wire running the *P9_7* (5 V) to the UL2003A. + The stepper motor I'm using runs better at 5 V, so I'm using the Bone's 5 V power supply. + The signal coming from the GPIO pins is 3.3 V, but the U2003A will step them up to 5 V to drive + the motor. .. _motors_unipolar_fig: @@ -357,7 +362,4 @@ so :ref:`motors_unistepperMotor_code` shows only the lines that you need to chan The code in this example makes the following changes: * The *states* are different. Here, we have two pins high at a time. -* The time between steps (*ms*) is shorter, and the number of steps per - -direction (*max*) is bigger. The unipolar stepper I'm using has many -more steps per rotation, so I need more steps to make it go around. +* The time between steps (*ms*) is shorter, and the number of steps per direction (*max*) is bigger. The unipolar stepper I'm using has many more steps per rotation, so I need more steps to make it go around. diff --git a/books/beaglebone-cookbook/05tips/figures/latest-images.png b/books/beaglebone-cookbook/05tips/figures/latest-images.png index 360c36a3277d4fe01a1c25accb648a1847f0510d..256efd34c051fd66ff49a8abc72d2c9760f21556 100644 Binary files a/books/beaglebone-cookbook/05tips/figures/latest-images.png and b/books/beaglebone-cookbook/05tips/figures/latest-images.png differ diff --git a/books/beaglebone-cookbook/05tips/tips.rst b/books/beaglebone-cookbook/05tips/tips.rst index 9a272ddbd1a089cc8166766c8d5e967bae6a0483..612ea8bdbc6c5897682410b5282665f54568cde7 100644 --- a/books/beaglebone-cookbook/05tips/tips.rst +++ b/books/beaglebone-cookbook/05tips/tips.rst @@ -26,7 +26,8 @@ You want to use BeagleBone Black as a desktop computer with keyboard, mouse, and Solution --------- -The Bone comes with USB and a microHDMI output. All you need to do is connect your keyboard, mouse, and HDMI display to it. +The Bone comes with USB and a microHDMI output. All you need to do is connect your keyboard, mouse, +and HDMI display to it. To make this recipe, you will need: @@ -57,7 +58,8 @@ The adapter looks something like :ref:`tips_HDMI_adaptor_fig`. Female HDMI-to-male microHDMI adapter -Plug the small end into the microHDMI input on the Bone and plug your HDMI cable into the other end of the +Plug the small end into the microHDMI input on the Bone and plug your HDMI cable +into the other end of the adapter and your monitor. If nothing displays on your Bone, reboot. If nothing appears after the reboot, edit the ``/boot/uEnv.txt`` file. Search for the line containing @@ -72,18 +74,22 @@ If nothing appears after the reboot, edit the ``/boot/uEnv.txt`` file. Search fo Then reboot. -.. PRODUCTION: in the following tip, we're trying to display the hash symbol (#), all by itself, in constant width. Using *#* produces an empty space in the build, and I don't know how to escape special characters within what should be literal strings. +.. PRODUCTION: in the following tip, we're trying to display the hash symbol (#), +.. all by itself, in constant width. Using *#* produces an empty space in the build, +.. and I don't know how to escape special characters within what should be literal strings. -.. Adding to my confusion, the # signs are dropped in the first paragraph of the tip, but not in the second, which is formatted in the same exact way. +.. Adding to my confusion, the # signs are dropped in the first paragraph of the tip, +.. but not in the second, which is formatted in the same exact way. -.. Also, using ## in the code italicizes the second # and everything after it in the line, which should not happen. +.. Also, using ## in the code italicizes the second # and everything after it in the line, +.. which should not happen. The ``/boot/uEnv.txt`` file contains a number of configuration commands that are executed at boot time. The *#* character is used to add comments; that is, everything to the right of a +# is ignored by the Bone and is assumed to be for humans to read. In the previous example, *###Disable auto loading* is a comment that informs us the next line(s) are for disabling things. Two *disable_uboot_overlay* -commands follow. Both should be commented-out and won't be executed by the Bon +commands follow. Both should be commented-out and won't be executed by the Bone. Why not just remove the line? Later, you might decide you need more general-purpose input/output (GPIO) pins and don't need the HDMI display. If so, just remove the *#* from the ``disable_uboot_overlay_video=1`` @@ -121,7 +127,7 @@ Solution -------- For projects that require a host computer, we assume that you are running -`Linux Ubuntu 20.04 LTS <http://bit.ly/1wXOwkw>`_. You can be running either a native installation, +`Linux Ubuntu 22.04 LTS <http://bit.ly/1wXOwkw>`_. You can be running either a native installation, through `Windows Subsystem for Linux <https://docs.microsoft.com/en-us/windows/wsl/>`_, via a virtual machine such as `VirtualBox <https://www.virtualbox.org/>`_, or in the cloud (`Microsoft Azure <https://portal.azure.com/>`_ or `Amazon Elastic Compute Cloud <http://aws.amazon.com/ec2/>`_, EC2, for example). @@ -136,7 +142,8 @@ Getting to the Command Shell via SSH Problem -------- -You want to connect to the command shell of a remote Bone from your host pass:[<span class="keep-together">computer</span>]. +You want to connect to the command shell of a remote Bone from your host +computer. Solution --------- @@ -149,14 +156,29 @@ connect by using the following command to log in as user *debian*, (note the *$* .. code-block:: bash host$ ssh debian@192.168.7.2 - Warning: Permanently added 'bone,192.168.7.2' (ECDSA) to the list of known hosts. - Last login: Mon Dec 22 07:53:06 2014 from yoder-linux.local + Warning: Permanently added '192.168.7.2' (ED25519) to the list of known hosts. + Debian GNU/Linux 11 + + BeagleBoard.org Debian Bullseye IoT Image 2023-06-03 + Support: https://bbb.io/debian + default username:password is [debian:temppwd] + + + The programs included with the Debian GNU/Linux system are free software; + the exact distribution terms for each program are described in the + individual files in /usr/share/doc/*/copyright. + + Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent + permitted by applicable law. + Last login: Thu Jun 8 14:02:40 2023 from 192.168.7.1 bone$ .. _tips_passwords: -*debian* has the default password *tempped* It's best to change the password: -============================================================================== +Default password +---------------- + +*debian* has the default password *temppwd*. It's best to change the password: .. code-block:: bash @@ -167,6 +189,27 @@ connect by using the following command to log in as user *debian*, (note the *$* Retype new UNIX password: password: password updated successfully +Removing the *Message of the Day* +================================= + +Problem +------- + +Every time you login a long message is displayed that you don't need to see. + +Solution +-------- + +The contents of the files `/etc/motd`, `/etc/issue` and `/etc/issue.net` are displayed +everytime you long it. You can prevent them from being displayed by moving them elsewhere. + +.. code-block:: bash + + bone$ sudo mv /etc/motd /etc/motd.orig + bone$ sudo mv /etc/issue /etc/issue.orig + bone$ sudo mv /etc/issue.net /etc/issue.net.orig + +Now, the next time you `ssh` in they won't be displayed. .. _tips_serial: @@ -185,6 +228,10 @@ Sometimes, you can't connect to the Bone via SSH, but you have a network working There is a way to access the command line to fix things without requiring extra hardware. (:ref:`tips_FTDI` shows a way that works even if you don't have a network working over USB, but it requires a special serial-to-USB cable.) +.. note:: + This method doesn't work with WSL. + + First, check to ensure that the serial port is there. On the host computer, run the following command: .. code-block:: bash @@ -193,8 +240,8 @@ First, check to ensure that the serial port is there. On the host computer, run 0 crw-rw---- 1 root dialout 166, 0 Jun 19 11:47 /dev/ttyACM0 -``/dev/ttyACM0`` is a serial port on your host computer that the Bone creates when it boots up. -The letters *crw-rw----* show that you can't access it as a normal user. However, you ``can`` +*/dev/ttyACM0* is a serial port on your host computer that the Bone creates when it boots up. +The letters *crw-rw----* show that you can't access it as a normal user. However, you can access it if you are part of *dialout* group. See if you are in the *dialout* group: .. code-block:: bash @@ -330,12 +377,11 @@ Log in to your Bone and enter the following command: .. code-block:: bash bone$ cat /etc/dogtag - BeagleBoard.org Debian Bullseye IoT Image 2022-07-01 + BeagleBoard.org Debian Bullseye IoT Image 2023-06-03 -:ref:`basics_latest_os` shows how to open the ``ID.txt`` file to see the OS version. -The ``/etc/dogtag`` file has the same contents and is easier to find if you already -have a command prompt. See :ref:`basics_install_os` if you need to update your OS. +:ref:`basics_latest_os` shows how to open the ``/etc/dogtag`` file to see the OS version. +See :ref:`basics_install_os` if you need to update your OS. Controlling the Bone Remotely with a VNC ========================================= @@ -348,10 +394,24 @@ You want to access the BeagleBone's graphical desktop from your host computer. Solution --------- -Run the installed Virtual Network Computing (VNC) server: +Install and run a Virtual Network Computing (VNC) server: + +.. todo + Check this with desktop installed .. code-block:: bash + bone$ sudo apt update + bone$ sudo apt install tightvncserver + Reading package lists... Done + Building dependency tree... Done + Reading state information... Done + The following additional packages will be installed: + ... + update-alternatives: using /usr/bin/Xtightvnc to provide /usr/bin/Xvnc (Xvnc) in auto mode + update-alternatives: using /usr/bin/tightvncpasswd to provide /usr/bin/vncpasswd (vncpasswd) in auto mode + Processing triggers for libc-bin (2.31-13+deb11u6) ... + bone$ tightvncserver You will require a password to access your desktops. @@ -410,10 +470,13 @@ Click Connect to start graphical access to your Bone, as shown in :ref:`tips_vnc You need to have X Windows installed and running for the VNC to work. Here's how to install it. This needs some 250M of disk space and 19 minutes to install. +.. todo + This isn't working as of 8-June-2023 + .. code-block:: bash bone$ bone$ sudo apt install bbb.io-xfce4-desktop - bone$ cp /etc/bbb.io/templates/fbdev.xorg.conf /etc/X11/xorg.conf + bone$ sdo cp /etc/bbb.io/templates/fbdev.xorg.conf /etc/X11/xorg.conf bone$ startxfce4 /usr/bin/startxfce4: Starting X server /usr/bin/startxfce4: 122: exec: xinit: not found @@ -645,7 +708,7 @@ Solution For the correct instructions for the image you are using, go to `latest-images <http://forum.beagleboard.org/tag/latest-images>`_ and click on the image you are using. -I'm running Debian 11.x (Bullseye), the middle one. +I'm running Debian 11.x (Bullseye), the top one, on the BeagleBone Black. .. _tips_latest-images_fig: @@ -655,7 +718,8 @@ I'm running Debian 11.x (Bullseye), the middle one. Latest Beagle Images -Scroll to the top of the page and you'll see instructions on setting up Wifi. The instructions here are based on using +networkctl+ +Scroll to the top of the page and you'll see instructions on setting up Wifi. +The instructions here are based on using **networkctl**. .. _tips_networkfig: @@ -807,6 +871,7 @@ reach the Internet in general, nor can the Internet reach it. On one hand, this no good can't access your Bone. On the other hand, your Bone can't reach the rest of the world. Letting your bone see the world: setting up IP masquerading +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You need to set up IP masquerading on your host and configure your Bone to use it. Here is a solution that works with a host computer running Linux. Add the code in :ref:`tips_ipmasq_code` to a @@ -874,21 +939,21 @@ Web servers typically listen to port *80*. First, look up the IP address of your .. code-block:: bash - host$ ifconfig - eth0 Link encap:Ethernet HWaddr 00:e0:4e:00:22:51 - inet addr:137.112.41.35 Bcast:137.112.41.255 Mask:255.255.255.0 - inet6 addr: fe80::2e0:4eff:fe00:2251/64 Scope:Link - UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 - RX packets:5371019 errors:0 dropped:0 overruns:0 frame:0 - TX packets:4720856 errors:0 dropped:0 overruns:0 carrier:0 - collisions:0 txqueuelen:1000 - RX bytes:1667916614 (1.6 GB) TX bytes:597909671 (597.9 MB) - - eth1 Link encap:Ethernet HWaddr 00:1d:60:40:58:e6 - ... - - -It's the number following *inet addr:*, which in my case is *137.112.41.35*. + host$ ip a + 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 + inet 127.0.0.1/8 scope host lo + valid_lft forever preferred_lft forever + inet6 ::1/128 scope host + valid_lft forever preferred_lft forever + 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1280 qdisc mq state UP group default qlen 1000 + link/ether 00:15:5d:7c:e8:dc brd ff:ff:ff:ff:ff:ff + inet 172.31.43.210/20 brd 172.31.47.255 scope global eth0 + valid_lft forever preferred_lft forever + inet6 fe80::215:5dff:fe7c:e8dc/64 scope link + valid_lft forever preferred_lft forever + +It's the number following *inet*, which in my case is *172.31.43.210*. .. tip:: @@ -902,7 +967,7 @@ Then run the following, using your host's IP address: .. code-block:: bash host$ sudo iptables -t nat -A PREROUTING -p tcp -s 0/0 \ - -d 137.112.41.35 --dport 1080 -j DNAT --to 192.168.7.2:80 + -d 172.31.43.210 --dport 1080 -j DNAT --to 192.168.7.2:80 Now browse to your host computer at port *1080*. That is, if your host's IP address @@ -931,11 +996,11 @@ First install and check the status: .. code-block:: bash + bone$ sudo apt update bone$ sudo apt install ufw bone$ sudo ufw status Status: inactive - Now turn off everything coming in and leave on all outgoing. Note, this won't take effect until *ufw* is enabled. @@ -968,9 +1033,10 @@ Just to be sure, you can install *nmap* on your host computer to see what ports 80/tcp open http 3000/tcp open ppp -Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds + Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds -Currently there are three ports visible: 22, 80 and 3000 (visual studio code) Now turn on the firewall and see what happens. +Currently there are three ports visible: 22, 80 and 3000 (visual studio code). +Now turn on the firewall and see what happens. .. code-block:: bash @@ -987,8 +1053,7 @@ Currently there are three ports visible: 22, 80 and 3000 (visual studio code) N PORT STATE SERVICE 22/tcp open ssh -Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds - + Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds Only port 22 (ssh) is accessible now. @@ -1000,7 +1065,7 @@ The firewall will remain on, even after a reboot. Disable it now if you don't wa Firewall stopped and disabled on system startup -See the How-To Geek article for more examples. +See the `How-To Geek article <https://www.howtogeek.com/devops/how-to-secure-your-linux-server-with-a-ufw-firewall/>`_ for more examples. .. _tips_apt: @@ -1019,7 +1084,7 @@ Solution Your Bone needs to be on the network for this to work. See :ref:`networking_wired`, :ref:`networking_wireless`, or :ref:`networking_usb`. -The easiest way to install more software is to use +apt+: +The easiest way to install more software is to use **apt**: .. code-block:: bash @@ -1038,7 +1103,7 @@ How do you find out what software you can install? Try running this: bone$ apt-cache pkgnames | sort > /tmp/list bone$ wc /tmp/list - 67303 67303 1348342 /tmp/list + 67974 67974 1369852 /tmp/list bone$ less /tmp/list @@ -1046,7 +1111,7 @@ The first command lists all the packages that *apt* knows about and sorts them a them in ``/tmp/list``. The second command shows why you want to put the list in a file. The *wc* command counts the number of lines, words, and characters in a file. In our case, there are over 67,000 packages from which we can choose! The *less* command displays the sorted -list, one page at a time. Press the space bar to go to the next page. Press Q to quit. +list, one page at a time. Press the space bar to go to the next page. Press **q** to quit. Suppose that you would like to install an online dictionary (*dict*). Just run the following command: @@ -1119,7 +1184,7 @@ If you booted from the microSD card, run the following command: The *df* command shows what partitions are already mounted. -The line */dev/mmcblk0p2 7.2G 2.0G 4.9G 29% /* shows that *mmcblk0* partition *p2* +The line ``/dev/mmcblk0p2 7.2G 2.0G 4.9G 29% /`` shows that *mmcblk0* partition *p2* is mounted as */*, the root file system. The general rule is that the media you're booted from (either the onboard flash or the microSD card) will appear as *mmcblk0*. The second partition (*p2*) is the root of the file system. @@ -1172,7 +1237,7 @@ Solution To free up space, you can remove preinstalled packages or discover big files to remove. Removing preinstalled packages - +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You might not need a few things that come preinstalled in the Debian image, including such things as OpenCV, the Chromium web browser, and some documentation. @@ -1194,7 +1259,7 @@ Here's how you can remove these: Discovering big files - +^^^^^^^^^^^^^^^^^^^^^ The *du* (disk usage) command offers a quick way to discover big files: @@ -1243,7 +1308,7 @@ following command to see what's taking up the space in ``/var``: .. code-block:: bash - bone$ sudo du -sh /usr/* + bone$ sudo du -sh /var/* 4.0K /var/backups 76M /var/cache 93M /var/lib @@ -1300,7 +1365,7 @@ After a moment, you'll see the following: keys to navigate the file structure to discover where the big unused files are. Press ? for help. .. warning:: - Be careful not to press the D key, because it's used to delete a file or directory. + Be careful not to press the **d** key, because it's used to delete a file or directory. .. _misc_libsoc: diff --git a/books/beaglebone-cookbook/06iot/iot.rst b/books/beaglebone-cookbook/06iot/iot.rst index 343e8b85210ee0c30e59698c21cfb2b8cb4a81e6..12118def4f8215070948c70272951b827abb8b17 100644 --- a/books/beaglebone-cookbook/06iot/iot.rst +++ b/books/beaglebone-cookbook/06iot/iot.rst @@ -91,7 +91,7 @@ BeagleBone Black already has the *nginx* web server running. When you point your browser to *192.168.7.2*, you are using the *nginx* web server. The web pages are served from */var/www/html/*. Add the HTML in :ref:`networking_index_html` -to a file called */var/www/html/test.html*, and then point your browser to *192.168.7.2://test.html*. +to a file called */var/www/html/test.html*, and then point your browser to *192.168.7.2:/test.html*. .. _networking_index_html: @@ -128,7 +128,7 @@ Solution with a small core and easy-to-extend philosophy. :ref:`networking_builtin_server` shows how to use nginx, the web server that's already running. This recipe shows how easy it is to build your own server. This is an adaptation of -`Python WebServer With Flask and Raspberry Pi <https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5>`_. +`Python WebServer With Flask and Raspberry Pi <https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d>`_. First, install flask: @@ -209,9 +209,14 @@ function. Now, let’s create a new Python script. We will name it 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. +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. -Next important thing on the above code, is that we created a dictionary of variables (a set of keys, such as the title that is associated with values, such as HELLO!) to pass into the template. On “returnâ€, we will return the index.html template to the web browser using the variables in the templateData dictionary. +Next important thing on the above code, is that we created a dictionary of variables +(a set of keys, such as the title that is associated with values, such as HELLO!) +to pass into the template. +On “returnâ€, we will return the *index1.html* template to the web browser using +the variables in the *templateData* dictionary. Execute the Python script: @@ -232,7 +237,7 @@ Open any web browser and browse to 192.168.7.2:8080. You should see: Note that the page’s content changes dynamically any time that you refresh it with the actual variable data passed by Python script. In our case, -“title†is a fixed value, but “time†change it every second. +“title†is a fixed value, but “time†changes every minute. Displaying GPIO Status in a Web Browser - reading a button =========================================================== @@ -253,7 +258,6 @@ To make this recipe, you will need: * Pushbutton switch. Wire your pushbutton as shown in :ref:`js_pushbutton_fig`. - Wire a button to *P9_11* and have the web page display the value of the button. Let’s use a new Python script named *app2.py*. @@ -266,7 +270,7 @@ Let’s use a new Python script named *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 +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 page through “button†that is part of our variable dictionary: *templateData*. @@ -286,7 +290,6 @@ Now, run the following command: bone$ ./app2.py - Point your browser to `http://192.168.7.2:8080`, and the page will look like :ref:`flask_app2_fig`. @@ -318,17 +321,15 @@ Now that we know how to “read†GPIO Status, let’s change them. What we wil the web page. We have an LED connected to *P9_14*. Controlling remotely we will change its status from LOW to HIGH and vice-versa. -The python script Let’s create a new Python script and named it *app3.py*. +Create a new Python script and name it *app3.py*. .. _flask_app3: -A simple Flask-based web server to read a GPIO (app3.py) - -.. code-block:: python - - include::../code/06iot/flask/app3.py - +.. literalinclude:: ../code/06iot/flask/app3.py + :caption: A simple Flask-based web server to read a GPIO (app3.py) + :linenos: +:download:`app3.py <../code/06iot/flask/app3.py>` What we have new on above code is the new “routeâ€: @@ -336,26 +337,24 @@ What we have new on above code is the new “routeâ€: From the webpage, calls will be generated with the format: - http://192.168.7.2:8081/ledRed/on or http://192.168.7.2:8081/ledRed/off - For the above example, *ledRed* is the “deviceName†and *on* or *off* are examples of possible “actionâ€. Those routes will be identified and properly “workedâ€. The main steps are: * Convert the string “ledREDâ€, for example, on its equivalent GPIO pin. The integer variable ledRed is equivalent to P9_14. We store this value on variable “actuator†-* For each actuator, we will analyze the “actionâ€, or “command†and act properly. If “action = on†for example, we must use the command: GPIO.output(actuator, GPIO.HIGH) +* For each actuator, we will analyze the “actionâ€, or “command†and act properly. + If “action = on†for example, we must use the command: ``f.write("1")`` * Update the status of each actuator -* Update the variable library * Return the data to index.html -Let’s now create an index.html to show the GPIO status of each -actuator and more important, create “buttons†to send the commands: +Let’s now create an *index.html* to show the GPIO status of each +actuator and more importantly, create “buttons†to send the commands: .. _flask_index3: @@ -369,7 +368,6 @@ actuator and more important, create “buttons†to send the commands: bone$ ./app3.py - Point your browser as before and you will see: .. _flask_app3_fig: @@ -395,6 +393,9 @@ You have live, continuous, data coming into your Bone via one of the Analog Ins Solution --------- +.. todo + Check this + Analog in - Continuous (This is based on information at: http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components/Kernel/Kernel_Drivers/ADC.html#Continuous%20Mode) Reading a continuous analog signal requires some set up. First go to the iio devices directory. @@ -406,8 +407,8 @@ Reading a continuous analog signal requires some set up. First go to the iio dev buffer/ in_voltage0_raw in_voltage2_raw in_voltage4_raw in_voltage6_raw name power/ subsystem@ dev in_voltage1_raw in_voltage3_raw in_voltage5_raw in_voltage7_raw of_node@ scan_elements/ uevent - -Here you see the files used to read the one shot values. Look in *scan_elements* to see how to enable continuous input. +Here you see the files used to read the one shot values. +Look in *scan_elements* to see how to enable continuous input. .. code-block:: bash @@ -417,7 +418,10 @@ Here you see the files used to read the one shot values. Look in *scan_elements* in_voltage0_type in_voltage2_en in_voltage3_index in_voltage4_type in_voltage6_en in_voltage7_index in_voltage1_en in_voltage2_index in_voltage3_type in_voltage5_en in_voltage6_index in_voltage7_type -Here you see three values for each analog input, _en (enable), _index (index of this channel in the buffer’s chunks) and _type (How the ADC stores its data). (See the link above for details.) Let's use the input at *P9.40* which is *AIN1*. To enable this input: +Here you see three values for each analog input, _en (enable), + _index (index of this channel in the buffer’s chunks) and + _type (How the ADC stores its data). (See the link above for details.) + Let's use the input at *P9.40* which is *AIN1*. To enable this input: .. code-block:: bash @@ -452,8 +456,8 @@ Let's use a 512 sample buffer. You might need to experiment with this. 1KHz sine wave sampled at 8KHz -An example Python program that does the above and the reads and -plot the buffer is here: analogInContinuous.py +An example Python program that does the above and reads and +plots the buffer is **analogInContinuous.py**. .. _analog_code: @@ -566,10 +570,10 @@ A number of files get installed, including the ADC file. Now try rerunning. bone$ ./analogInContinuous.py Hit ^C to stop -Here's the output of a 10KHz sine wave. +Here's the output of a 10KHz triangle wave. .. TODO - Is this trun: (The plot is wrong, but eLinux won't let me fix it.) + Is this true: (The plot is wrong, but eLinux won't let me fix it.) .. _analog_tri_fig: @@ -603,7 +607,7 @@ First, you need to `set up a Gmail account <https://mail.google.com>`_, if you d Then add the code in :ref:`networking_nodemailer_code` to a file named ``emailTest.py``. Substitute your own Gmail username. For the password: * Go to: https://myaccount.google.com/security -* Select App password. +* Go to *2-Step Verification* and at the bottom, select App password. * Generate your own 16 char password and copy it into ``emailTest.py``. * Be sure to delete password when done https://myaccount.google.com/apppasswords . @@ -639,7 +643,7 @@ Sending an SMS Message ======================= .. TODO - My twilio account is suspended. + My twilio account is suspended, using yoder@rose-hulman.edu. Problem -------- @@ -654,23 +658,37 @@ but you will need to `verify the number <http://bit.ly/1MrHBBF>`_ to which you a to `Twilio's home page <https://www.twilio.com/>`_ and set up an account. Note your account SID and authorization token. If you are using the free version, be sure to `verify your numbers <http://bit.ly/19c7GZ7>`_. -Next, install Trilio by using the following command: +Next, install Trilio by using the following command for python: + +.. todo + Need to show setup.sh file too. Test everything. .. code-block:: bash - bone$ npm install -g twilio + bone$ sudo apt install python-pip + bone$ sudo pip install twilio +or for Javascript: -Finally, add the code in :ref:`networking_twilio_code` to a file named ``twilio-test.js`` and run it. Your text will be sent. +.. code-block:: bash + + bone$ npm install -g twilio + +Finally, add the code in :ref:`networking_twilio_code` to a file named ``twilioTest.py`` and run it. Your text will be sent. .. _networking_twilio_code: +.. literalinclude:: ../code/06iot/twilioTest.py + :caption: Sending SMS messages using Twilio (``twilioTest.py``) + :linenos: + +:download:`twilioTest.py <../code/06iot/twilioTest.py>` + .. literalinclude:: ../code/06iot/twilio-test.js :caption: Sending SMS messages using Twilio (``twilio-test.js``) :linenos: :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. @@ -695,7 +713,7 @@ Because your Bone is on the network, it's not hard to access the current weather bash$ export APPID="Your key" -* Then add the code in :ref:`networking_weather_code` to a file named ``weather.js``. +* Then add the code in :ref:`networking_weather_code` to a file named ``weather.py``. * Run the python script. @@ -711,18 +729,19 @@ Because your Bone is on the network, it's not hard to access the current weather 2. Prints the forecast for the next day. 3. Prints everything returned by the weather site. +Uncomment what you want to be displayed. + Run this by using the following commands: .. code-block:: bash - bone$ chmod *x weather.py bone$ ./weather.js Getting weather - Temp: 85.1 - Humid: 50 - Low: 62.02 - High: 85.1 - sunrise: 2022-07-14 14:32:46 + Temp: 73.72 + Humid: 31 + Low: 54.21 + High: 75.47 + sunrise: 2023-06-09 14:21:07 The weather API returns lots of information. Use Python to extract the information you want. @@ -757,7 +776,7 @@ Creating a Project and App export API_KEY='XXX' export API_SECRET_KEY='XXX' export BEARER_TOKEN='XXX' - export TOKEN='4XXX' + export TOKEN='XXXX' export TOKEN_SECRET='XXX' * Next, source the file so the values will appear in your bash session. @@ -816,9 +835,9 @@ Around line 15 is the *id* number. Paste in the value returned above. :download:`twitter_delete_tweet.py <../code/06iot/twitter_delete_tweet.py>` .. TODO - Start Here + Start Here. Update for python. -The code in :ref:`networking_pushbutton_code` snds a tweet whenever a button is pushed. +The code in :ref:`networking_pushbutton_code` sends a tweet whenever a button is pushed. .. _networking_pushbutton_code: @@ -848,47 +867,29 @@ but you want to program it graphically. Solution --------- +.. todo + Need to figure out how to add the twitter node and the gpio node. + `Node-RED <http://nodered.org/>`_ is a visual tool for wiring the IoT. It makes it easy to turn on a light when a certain hashtag is tweeted, or spin a motor if the forecast is for hot weather. -Installing Node-RED +Starting Node-RED ==================== -To install Node-RED, run the following commands: +Node-RED is already installed, to run Node-RED, use the following command to start. .. code-block:: bash - bone$ cd # Change to home directory - bone$ git clone https://github.com/node-red/node-red.git - bone$ cd node-red/ - bone$ npm install --production # almost 6 minutes - bone$ cd nodes - bone$ git clone https://github.com/node-red/node-red-nodes.git # 2 seconds - bone$ cd ~/node-red - + bone$ sudo systemctl start nodered -To run Node-RED, use the following commands: +Or run the following to have Node-RED start everytime you reboot. .. code-block:: bash - bone$ cd ~/node-red - bone$ node red.js - Welcome to Node-RED - - -- 18 Aug 16:31:43 - [red] Version: 0.8.1.git -- 18 Aug 16:31:43 - [red] Loading palette nodes -- 18 Aug 16:31:49 - [26-rawserial.js] Info : only really needed for Windows boxes without serialport npm module installed. -- 18 Aug 16:31:56 - ------------------------------------------ -- 18 Aug 16:31:56 - [red] Failed to register 44 node types -- 18 Aug 16:31:56 - [red] Run with -v for details -- 18 Aug 16:31:56 - ------------------------------------------ -- 18 Aug 16:31:56 - [red] Server now running at http://127.0.0.1:1880/ -- 18 Aug 16:31:56 - [red] Loading flows : flows_yoder-debian-bone.json - + bone$ sudo systemctl enable --now nodered -The second-to-last line informs you that Node-RED is listening on part *1880*. Point your browser to +Node-RED is listening on part *1880*. Point your browser to http://192.168.7.2:1880, and you will see the screen shown in :ref:`networking_node_red_fig`. .. _networking_node_red_fig: @@ -1048,17 +1049,19 @@ to a file called ``launchPad.ino`` and run it on your LaunchPad. :download:`launchPad.ino <../code/06iot/launchPad/launchPad.ino>` -1. Set the mode for the built-in red and green LEDs. +.. annotations:: -2. Start the serial port at 9600 baud. + <1> Set the mode for the built-in red and green LEDs. -3. Prompt the user, which in this case is the Bone. + <2> Start the serial port at 9600 baud. -4. Set the LEDs to the current values of the *red* and *green* variables. + <3> Prompt the user, which in this case is the Bone. -5. Wait for characters to arrive on the serial port. + <4> Set the LEDs to the current values of the *red* and *green* variables. -6. After the characters are received, read it and respond to it. + <5> Wait for characters to arrive on the serial port. + + <6> After the characters are received, read it and respond to it. On the Bone, add the script in :ref:`js_launchPadBeagle_code` to a file called `launchPad.js` and run it. diff --git a/books/beaglebone-cookbook/07kernel/figures/KernelConfig3.16.png b/books/beaglebone-cookbook/07kernel/figures/KernelConfig3.16.png deleted file mode 100644 index 37a1e00aa73f141ed75ff464ae125eb8f3b2fc53..0000000000000000000000000000000000000000 Binary files a/books/beaglebone-cookbook/07kernel/figures/KernelConfig3.16.png and /dev/null differ diff --git a/books/beaglebone-cookbook/07kernel/figures/KernelConfig5.10.png b/books/beaglebone-cookbook/07kernel/figures/KernelConfig5.10.png new file mode 100644 index 0000000000000000000000000000000000000000..f0308fc85a89362ae23519d70c0ee2344b2390b4 Binary files /dev/null and b/books/beaglebone-cookbook/07kernel/figures/KernelConfig5.10.png differ diff --git a/books/beaglebone-cookbook/07kernel/kernel.rst b/books/beaglebone-cookbook/07kernel/kernel.rst index 2e3d18ed6896fdde2bc9fe811f0939aeb7cd5a55..a58663c82050d4976d7d845a477e05b0d8a30206 100644 --- a/books/beaglebone-cookbook/07kernel/kernel.rst +++ b/books/beaglebone-cookbook/07kernel/kernel.rst @@ -12,14 +12,6 @@ You usually won't need to mess with the kernel, but sometimes you might want to that requires a different kernel. This chapter shows how to switch kernels. The nice thing is you can have multiple kernels on your system at the same time and select from among them which to boot up. -.. TODO - is this still true? - -.. note:: - We assume here that you are logged on to your Bone as *root* and superuser privileges. - You also need to be logged in to your Linux host computer as a nonsuperuser. - - Updating the Kernel ==================== @@ -36,11 +28,11 @@ Use the following command to determine which kernel you are running: .. code-block:: bash bone$ uname -a - Linux beaglebone 3.8.13-bone67 #1 SMP Wed Sep 24 21:30:03 UTC 2014 armv7l + Linux beaglebone 5.10.168-ti-r62 #1bullseye SMP PREEMPT Tue May 23 20:15:00 UTC 2023 armv7l GNU/Linux GNU/Linux -The *3.8.13-bone67* string is the kernel version. +The *5.10.168-ti-r62* string is the kernel version. To update to the current kernel, ensure that your Bone is on the Internet (:ref:`networking_usb` or :ref:`networking_wired`) and then run the following commands: @@ -49,19 +41,29 @@ To update to the current kernel, ensure that your Bone is on the Internet bone$ apt-cache pkgnames | grep linux-image | sort | less ... - linux-image-3.15.8-armv7-x5 - linux-image-3.15.8-bone5 - linux-image-3.15.8-bone6 - ... - linux-image-3.16.0-rc7-bone1 + linux-image-5.10.162-ti-r59 + linux-image-5.10.162-ti-rt-r56 + linux-image-5.10.162-ti-rt-r57 + linux-image-5.10.162-ti-rt-r58 + linux-image-5.10.162-ti-rt-r59 + linux-image-5.10.168-armv7-lpae-x71 + linux-image-5.10.168-armv7-rt-x71 + linux-image-5.10.168-armv7-x71 + linux-image-5.10.168-bone71 + linux-image-5.10.168-bone-rt-r71 + linux-image-5.10.168-ti-r60 + linux-image-5.10.168-ti-r61 + linux-image-5.10.168-ti-r62 + linux-image-5.10.168-ti-rt-r60 + linux-image-5.10.168-ti-rt-r61 + linux-image-5.10.168-ti-rt-r62 ... - linux-image-3.8.13-bone60 - linux-image-3.8.13-bone61 - linux-image-3.8.13-bone62 - bone$ sudo apt install linux-image-3.14.23-ti-r35 + + bone$ sudo apt install linux-image-5.10.162-ti-rt-r59 bone$ sudo reboot + bone$ uname -a - Linux beaglebone 3.14.23-ti-r35 #1 SMP PREEMPT Wed Nov 19 21:11:08 UTC 2014 armv7l + Linux beaglebone 5.10.162-ti-rt-r59 #1 SMP PREEMPT Wed Nov 19 21:11:08 UTC 2014 armv7l GNU/Linux @@ -86,7 +88,7 @@ Solution --------- The solution is to run in kernel space by building a kernel module. There are entire -`books on writing Linux Device Drivers <http://bit.ly/1Fb0usf>`_. This recipe assumes that +`books on writing Linux Device Drivers <https://bootlin.com/doc/books/ldd3.pdf>`_. This recipe assumes that the driver has already been written and shows how to compile and install it. After you've followed the steps for this simple module, you will be able to apply them to any other module. @@ -105,7 +107,7 @@ Headers for the version of the kernel you're running: .. code-block:: bash - bone$ sudo apt install linux-headers-``uname -r`` + bone$ sudo apt install linux-headers-`uname -r` .. note:: @@ -136,37 +138,38 @@ Now, compile the kernel module by using the *make* command: .. code-block:: bash bone$ make - make -C /lib/modules/3.8.13-bone67/build \ - SUBDIRS=/home/debian/beaglebone-cookbook-code/07kernel/hello modules - make[1]: Entering directory `/usr/src/linux-headers-3.8.13-bone67' - CC [M] /home/debian/beaglebone-cookbook-code/07kernel/hello/hello.o - Building modules, stage 2. - MODPOST 1 modules - 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' + make -C /lib/modules/5.10.168-ti-r62/build M=$PWD + make[1]: Entering directory '/usr/src/linux-headers-5.10.168-ti-r62' + CC [M] /home/debian/docs.beagleboard.io/books/beaglebone-cookbook/code/07kernel/hello.o + MODPOST /home/debian/docs.beagleboard.io/books/beaglebone-cookbook/code/07kernel/Module.symvers + CC [M] /home/debian/docs.beagleboard.io/books/beaglebone-cookbook/code/07kernel/hello.mod.o + LD [M] /home/debian/host/BeagleBoard/docs.beagleboard.io/books/beaglebone-cookbook/code/07kernel/hello.ko + make[1]: Leaving directory '/usr/src/linux-headers-5.10.168-ti-r62' + bone$ ls Makefile hello.c hello.mod.c hello.o Module.symvers hello.ko hello.mod.o modules.order - Notice that several files have been created. ``hello.ko`` is the one you want. Try a couple of commands with it: .. code-block:: bash bone$ modinfo hello.ko - filename: /home/debian/beaglebone-cookbook-code/07kernel/hello/hello.ko - srcversion: 87C6AEED7791B4B90C3B50C + filename: /home/debian/host/BeagleBoard/docs.beagleboard.io/books/beaglebone-cookbook/code/07kernel/hello.ko + license: GPL + description: Hello World Example + author: Boris Houndleroy depends: - vermagic: 3.8.13-bone67 SMP mod_unload modversions ARMv7 thumb2 p2v8 + name: hello + vermagic: 5.10.168-ti-r62 SMP preempt mod_unload modversions ARMv7 p2v8 + bone$ sudo insmod hello.ko bone$ dmesg | tail -4 - [419313.320052] bone-iio-helper helper.15: ready - [419313.322776] bone-capemgr bone_capemgr.9: slot #8: Applied #1 overlays. - [491540.999431] Loading hello module... - [491540.999476] Hello world - + [ 377.944777] lm75 1-004a: hwmon1: sensor 'tmp101' + [ 377.944976] i2c i2c-1: new_device: Instantiated device tmp101 at 0x4a + [85819.772666] Loading hello module... + [85819.772687] Hello, World! The first command displays information about the module. The *insmod* command inserts the module into the running kernel. If all goes well, nothing is displayed, but the module does print something in the kernel log. The *dmesg* command displays @@ -373,22 +376,32 @@ To download and compile the kernel, follow these steps: .. code-block:: bash - host$ git clone https://github.com/RobertCNelson/bb-kernel.git # <1> - host$ cd bb-kernel - host$ git tag # <2> - host$ git checkout 3.8.13-bone60 -b v3.8.13-bone60 # <3> - host$ ./build_kernel.sh # <4> + host$ git clone https://git.beagleboard.org/RobertCNelson/ti-linux-kernel-dev # <1> + host$ cd ti-linux-kernel-dev + host$ git checkout ti-linux-5.10.y # <2> + host$ ./build_deb.sh # <3> + +.. note:: + If you are using a 64 bit Bone, **git checkout ti-linux-arm64-5.10.y** 1. The first command clones a repository with the tools to build the kernel for the Bone. -2. This command lists all the different versions of the kernel that you can build. You'll need to pick one of these. How do you know which one to pick? A good first step is to choose the one you are currently running. *uname -a* will reveal which one that is. When you are able to reproduce the current kernel, go to `Linux Kernel Newbies <http://kernelnewbies.org/>`_ to see what features are available in other kernels. `LinuxChanges <http://bit.ly/1AjiL00>`_ shows the features in the newest kernel and `LinuxVersions <http://bit.ly/1MrIHx3>`_ links to features of previous kernels. -3. When you know which kernel to try, use *git checkout* to check it out. This command checks out at tag *3.8.13-bone60* and creates a new branch, *v3.8.13-bone60*. -4. *build_kernel* is the master builder. If needed, it will download the cross compilers needed to compile the kernel (`linaro <http://www.linaro.org/>`_ is the current cross compiler). If there is a kernel at ``~/linux-dev``, it will use it; otherwise, it will download a copy to ``bb-kernel/ignore/linux-src``. It will then patch the kernel so that it will run on the Bone. +2. When you know which kernel to try, use *git checkout* to check it out. + This command checks out branch *ti-linux-5.10.y*. +3. *build_deb.sh* is the master builder. If needed, it will download the cross compilers + needed to compile the kernel (`gcc <https://gcc.gnu.org/>`_ is the current cross compiler). + If there is a kernel at ``~/linux-dev``, it will use it; otherwise, + it will download a copy to ``ti-linux-kernel-dev/ignore/linux-src``. + It will then patch the kernel so that it will run on the Bone. + +.. note:: + *build_deb.sh* may ask you to install additional files. Just run **sudo apt install *files*** to + install them. After the kernel is patched, you'll see a screen similar to :ref:`kernel_config_fig`, on which you can configure the kernel. .. _kernel_config_fig: -.. figure:: figures/KernelConfig3.16.png +.. figure:: figures/KernelConfig5.10.png :align: center :alt: Kernel configuration menu @@ -397,7 +410,7 @@ After the kernel is patched, you'll see a screen similar to :ref:`kernel_config_ You can use the arrow keys to navigate. No changes need to be made, so you can just press the right arrow and Enter to start the kernel compiling. The entire process took about 25 minutes on my 8-core host. -The ``bb-kernel/KERNEL`` directory contains the source code for the kernel. The ``bb-kernel/deploy`` +The ``ti-linux-kernel-dev/KERNEL`` directory contains the source code for the kernel. The ``ti-linux-kernel-dev/deploy`` directory contains the compiled kernel and the files needed to run it. .. _kernel_install: @@ -405,61 +418,105 @@ directory contains the compiled kernel and the files needed to run it. Installing the Kernel on the Bone =================================== -To copy the new kernel and all its files to the microSD card, you need to halt the Bone, -and then pull the microSD card out and put it in an microSD card reader on your host computer. -Run *Disk* (see :ref:`basics_latest_os`) to learn where the microSD card appears on your host -(mine appears in ``/dev/sdb``). Then open the ``bb-kernel/system.sh`` file and find this line near the end: - -.. code-block:: bash - - MMC=/dev/sde - - -Change that line to look like this (where */dev/sdb* is the path to your device): - -.. code-block:: bash - - MMC=/dev/sdb - - -Now, while in the ``bb-kernel`` directory, run the following command: - -.. code-block:: bash - - host$ tools/install_kernel.sh - [sudo] password for yoder: - - I see... - fdisk -l: - Disk /dev/sda: 160.0 GB, 160041885696 bytes - Disk /dev/sdb: 3951 MB, 3951034368 bytes - Disk /dev/sdc: 100 MB, 100663296 bytes - - lsblk: - NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT - sda 8:0 0 149.1G 0 disk - ├─sda1 8:1 0 141.1G 0 part / - ├─sda2 8:2 0 1K 0 part - └─sda5 8:5 0 8G 0 part [SWAP] - sdb 8:16 1 3.7G 0 disk - ├─sdb1 8:17 1 16M 0 part - └─sdb2 8:18 1 3.7G 0 part - sdc 8:32 1 96M 0 disk - ----------------------------- - Are you 100% sure, on selecting [/dev/sdb] (y/n)? y - - -The script lists the partitions it sees and asks if you have the correct one. -If you are sure, press Y, and the script will uncompress and copy the files to -the correct locations on your card. When this is finished, eject your card, plug -it into the Bone, and boot it up. Run *uname -a*, and you -will see that you are running your compiled kernel. +The **./build_deb.sh** script creates a single .deb file that contains all the files needed for the new kernel. +You find it here: + +.. code-block:: bash + + host$ cd ti-linux-kernel-dev/deploy + host$ ls -sh + total 40M + 7.7M linux-headers-5.10.168-ti-r62_1xross_armhf.deb 8.0K linux-upstream_1xross_armhf.buildinfo + 33M linux-image-5.10.168-ti-r62_1xross_armhf.deb 4.0K linux-upstream_1xross_armhf.changes + 1.1M linux-libc-dev_1xross_armhf.deb + +The **linux-image-** file is the one we want. It contains over 3000 files. + +.. code-block:: bash + + host$ dpkg -c linux-image-5.10.168-ti-r62_1xross_armhf.deb | wc + 3251 19506 379250 + +The **dpkg** command lists all the files in the .deb file and the wc counts all the lines in the output. +You can see those files with: + +.. code-block:: bash + + host$ dpkg -c linux-image-5.10.168-ti-r62_1xross_armhf.deb | less + drwxr-xr-x root/root 0 2023-06-12 12:57 ./ + drwxr-xr-x root/root 0 2023-06-12 12:57 ./boot/ + -rw-r--r-- root/root 4763113 2023-06-12 12:57 ./boot/System.map-5.10.168-ti-r62 + -rw-r--r-- root/root 191331 2023-06-12 12:57 ./boot/config-5.10.168-ti-r62 + drwxr-xr-x root/root 0 2023-06-12 12:57 ./boot/dtbs/ + drwxr-xr-x root/root 0 2023-06-12 12:57 ./boot/dtbs/5.10.168-ti-r62/ + -rwxr-xr-x root/root 90644 2023-06-12 12:57 ./boot/dtbs/5.10.168-ti-r62/am335x-baltos-ir2110.dtb + -rwxr-xr-x root/root 91362 2023-06-12 12:57 ./boot/dtbs/5.10.168-ti-r62/am335x-baltos-ir3220.dtb + -rwxr-xr-x root/root 91633 2023-06-12 12:57 ./boot/dtbs/5.10.168-ti-r62/am335x-baltos-ir5221.dtb + -rwxr-xr-x root/root 88684 2023-06-12 12:57 ./boot/dtbs/5.10.168-ti-r62/am335x-base0033.dtb + +You can see it's putting things in the **/boot** directory. + +Note: You can also look into the other two .deb files and see what they install. + +Move the **linux-image-** file to your Bone. + +.. code-block:: bash + + host$ scp linux-image-5.10.168-ti-r62_1xross_armhf.deb bone:. + +You might have to use debian@192.168.7.2 for bone if you haven't set everything up. + +Now ssh to the bone. + +.. code-block:: bash + + host$ ssh bone + bone$ ls -sh + bin exercises linux-image-5.10.168-ti-r62_1xross_armhf.deb + +Now install it. + +.. code-block:: bash + + bone$ sudo dpkg --install linux-image-5.10.168-ti-r62_1xross_armhf.deb + +Wait a while. (Mine took almore 2 minutes.) Once done check /boot. + +.. code-block:: bash + + bone$ ls -sh /boot + total 40M + 160K config-4.19.94-ti-r50 4.0K SOC.sh 4.0K uEnv.txt.orig + 180K config-5.10.168-ti-r62 3.5M System.map-4.19.94-ti-r50 9.7M vmlinuz-4.19.94-ti-r50 + 4.0K dtbs 4.1M System.map-5.10.168-ti-r62 8.6M vmlinuz-5.10.168-ti-r62 + 6.4M initrd.img-4.19.94-ti-r50 4.0K uboot + 6.8M initrd.img-5.10.168-ti-r62 4.0K uEnv.txt + +You see the new kernel files along with the old files. Check uEnv.txt. + +.. code-block:: bash + + bone$ head /boot/uEnv.txt + #Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0 + # uname_r=4.19.94-ti-r50 + uname_r=5.10.168-ti-r62 + +I added the commented out uname_r line to make it easy to switch between versions of the kernel. + +Reboot and test out the new kernel. + +.. code-block:: bash + + bone$ sudo reboot .. _kernel_using_cross_compiler: Using the Installed Cross Compiler =================================== +.. todo + This should be removed + Problem -------- @@ -483,12 +540,12 @@ Solution :ref:`kernel_compiling` installs a cross compiler, but you need to set up a couple of things so that it can be found. :ref:`kernel_compiling` installed the -kernel and other tools in a directory called ``bb-kernel``. Run the +kernel and other tools in a directory called ``ti-linux-kernel-dev``. Run the following commands to find the path to the cross compiler: .. code-block:: bash - host$ cd bb-kernel/dl + host$ cd ti-linux-kernel-dev/dl host$ ls gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux.tar.xz @@ -535,7 +592,7 @@ to the *$PATH* the shell uses to find the commands it runs: .. code-block:: bash host$ pwd - /home/yoder/BeagleBoard/bb-kernel/dl/\ + /home/yoder/BeagleBoard/ti-linux-kernel-dev/dl/\ gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin host$ echo $PATH @@ -551,7 +608,7 @@ to be run. Currently, the cross-development tools are not in the *$PATH*. Let's host$ export PATH=`pwd`:$PATH host$ echo $PATH - /home/yoder/BeagleBoard/bb-kernel/dl/\ + /home/yoder/BeagleBoard/ti-linux-kernel-dev/dl/\ gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin:\ /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\ /usr/games:/usr/local/games @@ -605,6 +662,9 @@ The *file* command shows that *a.out* was compiled for an ARM processor. Applying Patches ================= +.. todo + Remove patches? + Problem -------- @@ -626,13 +686,13 @@ Solution Here's how to use it: - Install the kernel sources (:ref:`kernel_compiling`). -- Change to the kernel directory (+cd bb-kernel/KERNEL+). -- Add :ref:`kernel_hello_patch` to a file named ``hello.patch`` in the ``bb-kernel/KERNEL`` directory. +- Change to the kernel directory (+cd ti-linux-kernel-dev/KERNEL+). +- Add :ref:`kernel_hello_patch` to a file named ``hello.patch`` in the ``ti-linux-kernel-dev/KERNEL`` directory. - Run the following commands: .. code-block:: bash - host$ cd bb-kernel/KERNEL + host$ cd ti-linux-kernel-dev/KERNEL host$ patch -p1 < hello.patch patching file hello/Makefile patching file hello/hello.c @@ -668,7 +728,7 @@ Before making your changes, check out a new branch: .. code-block:: bash - host$ cd bb-kernel/KERNEL + host$ cd ti-linux-kernel-dev/KERNEL host$ git status # On branch master nothing to commit (working directory clean) @@ -689,7 +749,7 @@ to the kernel you want. I did some work with a simple character driver that we c .. code-block:: bash - host$ cd bb-kernel/KERNEL/drivers/char/ + host$ cd ti-linux-kernel-dev/KERNEL/drivers/char/ host$ git status # On branch hello1 # Changes not staged for commit: diff --git a/books/beaglebone-cookbook/08realtime/realtime.rst b/books/beaglebone-cookbook/08realtime/realtime.rst index cba4820d7c752f563b1f1ece414893b4a124e8bf..238fe70e1f716afb712f57b1224ff79d85cd500d 100644 --- a/books/beaglebone-cookbook/08realtime/realtime.rst +++ b/books/beaglebone-cookbook/08realtime/realtime.rst @@ -28,8 +28,8 @@ JavaScript and moving up with increasing speed (and effort) to using the PRUs. .. _realtime_JavaScript: -I/O with JavaScript -==================== +I/O with Python and JavaScript +============================== Problem -------- @@ -77,12 +77,12 @@ pushbutton, and turns on the LED attached to *P9_12* when the button is pushed. :download:`pushLED.js <../code/08realtime/pushLED.js>` -Add the code to a file named ``pushLED.js`` and run it by using the following commands: +Add the code to a file named ``pushLED.py`` and run it by using the following commands: .. code-block:: bash - bone$ chmod *x pushLED.js - bone$ ./pushLED.js + bone$ chmod *x pushLED.py + bone$ ./pushLED.py data = 0 data = 0 data = 1 @@ -104,8 +104,9 @@ You want to use the C language to process inputs in real time, or Python/JavaScr Solution --------- -:ref:`realtime_JavaScript` shows how to control an LED with a pushbutton using JavaScript. This recipe accomplishes -the same thing using C. It does it in the same way, opening the correct /sys/class/gpio files and reading an writing them. +:ref:`realtime_JavaScript` shows how to control an LED with a pushbutton using Python and JavaScript. +This recipe accomplishes the same thing using C. +It does it in the same way, opening the correct /sys/class/gpio files and reading an writing them. Wire up the pushbutton and LED as shown in :ref:`realtime_pushLED_fig`. Then add the code in :ref:`realtime_pushLED_c_code` to a file named ``pushLED.c``. @@ -162,7 +163,7 @@ First, download and install *devmem2*: .. code-block:: bash - bone$ wget http://free-electrons.com/pub/mirror/devmem2.c + bone$ wget http://bootlin.com/pub/mirror/devmem2.c bone$ gcc -o devmem2 devmem2.c bone$ sudo mv devmem2 /usr/bin @@ -199,7 +200,7 @@ Memory Map chapter (sensors). Table 2-2 indicates that *GPIO0* starts at address go to Section 25.4.1, "GPIO Registers." This shows that *GPIO_DATAIN* has an offset of *0x138*, *GPIO_CLEARDATAOUT* has an offset of *0x190*, and *GPIO_SETDATAOUT* has an offset of *0x194*. -This means you read from address *0x44E0_7000* * *0x138* = *0x44E0_7138* to see the status of the LED: +This means you read from address *0x44E0_7000* + *0x138* = *0x44E0_7138* to see the status of the LED: .. code-block:: bash @@ -211,7 +212,7 @@ This means you read from address *0x44E0_7000* * *0x138* = *0x44E0_7138* to see The returned value *0xC000C404* (*1100 0000 0000 0000 1100 0100 0000 0100* in binary) has bit 31 set to *1*, which means the LED is on. Turn the LED off by writing *0x80000000* (*1000 0000 0000 0000 0000 0000 0000 0000* binary) -to the *GPIO_CLEARDATA* register at *0x44E0_7000* * *0x190* = *0x44E0_7190*: +to the *GPIO_CLEARDATA* register at *0x44E0_7000* + *0x190* = *0x44E0_7190*: .. code-block:: bash @@ -495,13 +496,16 @@ This will generate the file *cyclictest.png* which contains your plot. It shoul Notice the NON-RT data have much longer latenices. They may not happen often (fewer than 10 times in each bin), but they are occurring and may be enough to miss a real-time deadline. -The PREEMPT-RT times are all under a 150s. +The PREEMPT-RT times are all under a 150 us. .. _realtime_simpPRU: I/O with simpPRU ================= +.. todo + This should be checked. + Problem -------- diff --git a/books/beaglebone-cookbook/09capes/capes.rst b/books/beaglebone-cookbook/09capes/capes.rst index 3e4d590b010cbf5518780cc27b0e9fe68946df0f..adee4818fccad2c0debe9090f98d568d81158a64 100644 --- a/books/beaglebone-cookbook/09capes/capes.rst +++ b/books/beaglebone-cookbook/09capes/capes.rst @@ -11,8 +11,8 @@ because you need to move the Bone and you don't want wires coming loose, or beca you want to share your hardware with the masses. You can easily expand the functionality of the Bone by adding a `cape <http://bit.ly/1wucweC>`_. -A cape is simply a board--often a printed circuit board (PCB) that connects to the +P8+ -and +P9+ headers and follows a few standard pin usages. You can stack up to four capes onto the +A cape is simply a board--often a printed circuit board (PCB) that connects to the **P8** +and **P9** headers and follows a few standard pin usages. You can stack up to four capes onto the Bone. Capes can range in size covering a few pins to much larger than the Bone. .. todo:: Add cape examples of various sizes @@ -274,7 +274,8 @@ LCD Backside :align: center :alt: -Next, take a note of each pin utilized by each cape. The `BeagleBone Capes catalog <http://beaglebonecapes.com>`_ +Next, take a note of each pin utilized by each cape. +The `BeagleBone Capes catalog <https://beagleboard.org/capes>`_ provides a graphical representation for the pin usage of most capes, as shown in :ref:`Audio_cape_pins_fig` for the Circuitco Audio Cape. .. note:: #TODO# Bela would make a better example for an audio cape. The CircuitCo cape is no longer available. @@ -299,9 +300,15 @@ In most cases, the same pin should never be used on two different capes, though - VDD_3V3 - The 3.3 V power supply (*VDD_3V3*) pins can be shared by all capes to supply power, but the total combined consumption of all the capes should be less than 500 mA (250 mA per *VDD_3V3* pin). - VDD_5V - - The 5.0 V power supply (*VDD_5V*) pins can be shared by all capes to supply power, but the total combined consumption of all the capes should be less than 2 A (1 A per +VD*_5V+ p*n). It is possible for one, and only one, of the capes to _provide_ power to this pin rather than consume it, and it should provide at least 3 A to ensure proper system function. Note that when no voltage is applied to the DC connector, nor from a cape, these pins will not be powered, even if power is provided via USB. + The 5.0 V power supply (*VDD_5V*) pins can be shared by all capes to supply power, + but the total combined consumption of all the capes should be less than 2 A (1 A per +VDD_5V+ pin). + It is possible for one, and only one, of the capes to *provide* power to this pin rather than consume it, + and it should provide at least 3 A to ensure proper system function. + Note that when no voltage is applied to the DC connector, nor from a cape, + these pins will not be powered, even if power is provided via USB. - SYS_5V - - The regulated 5.0 V power supply (*SYS_5V*) pins can be shared by all capes to supply power, but the total combined consumption of all the capes should be less than 500 mA (250 mA per *SYS_5V* pin). + The regulated 5.0 V power supply (*SYS_5V*) pins can be shared by all capes to supply power, + but the total combined consumption of all the capes should be less than 500 mA (250 mA per *SYS_5V* pin). - VADC and AGND - The ADC reference voltage pins can be shared by all capes. - I2C2_SCL and I2C2_SDA @@ -639,7 +646,7 @@ of all your traces and cleaning up any questionable routing created by the autor The PCB in :ref:`capes_quickRobo_pcb` is a two-sided board. One color (or shade of gray in the printed book) represents traces on one side of the board, and the other color (or shade of gray) is the other side. Sometimes, you'll see a trace come to a small circle and then change colors. This is where it is switching sides of the board -through what's called a _via_. One of the goals of PCB design is to minimize the number of vias. +through what's called a *via*. One of the goals of PCB design is to minimize the number of vias. :ref:`capes_quickRobo_pcb` wasn't my first try or my last. My approach was to see what was needed to hook where and move the components around to make it easier for the autorouter to carry out its job. @@ -772,11 +779,8 @@ PCB Design Alternatives There are other free PCB design programs. Here are a few. -TO PROD: The headings I've marked as bold lines really should be subheadings of "PCB Design Alternatives," -but AsciiDoc won't let me go that deep (to the level). Is what I've done the best solution, -or is there a way to create another heading level? - -*EAGLE* +EAGLE +----- `Eagle PCB <https://en.wikipedia.org/wiki/EAGLE_(program)>`_ and `DesignSpark PCB <https://en.wikipedia.org/wiki/DesignSpark_PCB>`_ are two popular design programs. Many capes (and other PCBs) are designed with Eagle PCB, and the files are available. @@ -803,7 +807,7 @@ and PCB shown in :ref:`capes_miniDisplay_pcb`. #TODO#: The MiniDisplay cape is not currently available, so this example should be updated. A good starting point is to take the PCB layout for the MiniDisplay and edit it for your project. -The connectors for +P8+ and +P9+ are already in place and ready to go. +The connectors for **P8** and **P9** are already in place and ready to go. Eagle PCB is a powerful system with many good tutorials online. The free version runs on Windows, Mac, and Linux, but it has three `limitations <https://en.wikipedia.org/wiki/EAGLE_(program)#License_model>`_: @@ -883,14 +887,16 @@ Ensure that the correct version number appears. If you are moving a design from Fritzing to Eagle, see :ref:`capes_schematic_migration` for tips on converting from one to the other. -*DesignSpark PCB* +DesignSpark PCB +--------------- The free `DesignSpark <http://bit.ly/19cbwS0>`_ doesn't have the same limitations as Eagle PCB, but it runs only on Windows. Also, it doesn't seem to have the following of Eagle at this time. .. _capes_upverter: -*Upverter* +Upverter +-------- In addition to free solutions you run on your desktop, you can also work with a browser-based tool called `Upverter <https://upverter.com/>`_. With Upverter, you can collaborate easily, editing @@ -903,9 +909,9 @@ your designs from anywhere on the Internet. It also provides many conversion opt .. _capes_kicad: Kicad -======= +----- -Unlike the previously mentioned free (no-cost) solutions, `Kicad <http://bit.ly/1b2bnBg>`_ +Unlike the previously mentioned free (no-cost) solutions, `Kicad <https://www.kicad.org/>`_ is open source and provides some features beyond those of Fritzing. Notably, `CircuitHub site <http://circuithub.com/>`_ (discussed in :ref:`capes_production`) provides support for uploading Kicad designs. @@ -920,11 +926,16 @@ Problem You created your schematic in Fritzing, but it doesn't integrate with everything you need. How can you move the schematic to another tool? +.. todo + Is this up to date? + Solution --------- -Use the `Upverter schematic-file-converter <https://github.com/ljmljz/schematic-file-converter>`_ Python script. For example, suppose that you want -to convert the Fritzing file for the diagram shown in :ref:`capes_quickRobo_fig`. First, install Upverter. +Use the `Upverter schematic-file-converter <https://github.com/ljmljz/schematic-file-converter>`_ Python script. +For example, suppose that you want +to convert the Fritzing file for the diagram shown in :ref:`capes_quickRobo_fig`. +First, install Upverter. I found it necessary to install +libfreetype6+ and +freetype-py+ onto my system, but you might not need this first step: @@ -948,7 +959,7 @@ I found it necessary to install +libfreetype6+ and +freetype-py+ onto my system, .. note:: - All these commands are being run on the Linux-based host computer, as shown by the +host$+ prompt. + All these commands are being run on the Linux-based host computer, as shown by the **host$** prompt. Log in as a normal user, not +root+. Now, install the ``schematic-file-converter`` tool: @@ -1057,7 +1068,7 @@ After Upverter is installed, run the file (``quickBot.fzz``) that generated :ref No one said it would be pretty! -I found that Eagle was more generous at reading in the +eaglexml+ format than the +eagle+ format. +I found that Eagle was more generous at reading in the **eaglexml** format than the **eagle** format. This also made it easier to hand-edit any translation issues. .. _capes_prototype: @@ -1081,7 +1092,7 @@ To make this recipe, you will need: * Multimeter * Your other components -Upload your design to `OSH Park <http://oshpark.com>` and order a few boards. :ref:`capes_oshpark_share` shows a resulting +Upload your design to `OSH Park <http://oshpark.com>`_ and order a few boards. :ref:`capes_oshpark_share` shows a resulting `shared project page for the quickBot cape <http://bit.ly/1MtlzAp>`_ created in :ref:`capes_layout`. We'll proceed to break down how this design was uploaded and shared to enable ordering fabricated PCBs. @@ -1108,7 +1119,7 @@ The `WikiHow article on creating Zip files <http://bit.ly/1B4GqRU>`_ might be he Things on the `OSH Park website <http://oshpark.com>`_ are reasonably self-explanatory. You'll need to create an account and upload the Zip file containing the `Gerber files <https://en.wikipedia.org/wiki/Gerber_format>`_ you created. If you are a cautious person, you might choose to examine the Gerber files with a Gerber file viewer first. The `Fritzing fabrication FAQ <https://aisler.net/partners/fritzing>`_ -offers several suggestions, including `gerbv <http://gerbv.sourceforge.net/>`_ for Windows and Linux users. +offers several suggestions, including `gerbv <http://gerbv.geda-project.org/>`_ for Windows and Linux users. When your upload is complete, you'll be given a quote, shown images for review, and presented with options for accepting and ordering. After you have accepted the design, your `list of accepted designs <https://oshpark.com/project_history>`_ @@ -1126,7 +1137,10 @@ looking to make some money on your design, you'll want to go another route, like Now is a good time to ensure that you have all of your components and a soldering station set up as in :ref:`capes_soldering`, as well as an oscilloscope, as used in :ref:`capes_verify`. -When you get your board, it is often informative to "buzz out" a few connections by using a multimeter. If you've never used a multimeter before, the `SparkFun <http://bit.ly/18bUgeA>`_ or `Adafruit <http://bit.ly/1Br5Xtv>`_ tutorials might be helpful. Set your meter to continuity testing mode and probe between points where the headers are and where they should be connecting to your components. This would be more difficult and less accurate after you solder down your components, so it is a good idea to keep a bare board around just for this purpose. +When you get your board, it is often informative to "buzz out" a few connections by using a multimeter. +If you've never used a multimeter before, the `SparkFun <https://learn.sparkfun.com/tutorials/how-to-use-a-multimeter/all>`_ +or `Adafruit <http://bit.ly/1Br5Xtv>`_ tutorials might be helpful. +Set your meter to continuity testing mode and probe between points where the headers are and where they should be connecting to your components. This would be more difficult and less accurate after you solder down your components, so it is a good idea to keep a bare board around just for this purpose. You'll also want to examine your board mechanically before soldering parts down. You don't want to waste components on a PCB that might need to be altered or replaced. @@ -1165,6 +1179,9 @@ series on creating a cape, including how to wire and program the EEPROM. The current effort to document how to enable software for a cape is ongoing at https://docs.beagleboard.org/latest/boards/capes. +.. todo + This needs updating. + .. _capes_production: Putting Your Cape Design into Production diff --git a/books/beaglebone-cookbook/10parts/parts.rst b/books/beaglebone-cookbook/10parts/parts.rst index bc445be20b011546114eb32770b04867759b77fe..07e6911f276673ba6aedee2d95edc24fa65bbba4 100644 --- a/books/beaglebone-cookbook/10parts/parts.rst +++ b/books/beaglebone-cookbook/10parts/parts.rst @@ -1,5 +1,9 @@ .. _beaglebone-cookbook-parts: +.. |I2C| replace:: I\ :sup:`2`\ C +.. |kohm| replace:: kΩ +.. |ohm| replace:: Ω + Parts and Suppliers #################### @@ -8,23 +12,21 @@ We have listed only one or two sources here, but you can often find a given part .. table:: United States suppliers - +-------------+------------------------------------+------------------------------------+ - | Supplier | Website | Notes | - +=============+====================================+====================================+ - | Adafruit | http://www.adafruit.com | Good for modules and parts | - +-------------+------------------------------------+------------------------------------+ - | Amazon | http://www.amazon.com/ | Carries everything | - +-------------+------------------------------------+------------------------------------+ - | Digikey | http://www.digikey.com/ | Wide range of components | - +-------------+------------------------------------+------------------------------------+ - | MakerShed | http://www.makershed.com/ | Good for modules, kits, and tools | - +-------------+------------------------------------+------------------------------------+ - | RadioShack | http://www.radioshack.com/ | Walk-in stores | - +-------------+------------------------------------+------------------------------------+ - | SeeedStudio | http://www.seeedstudio.com/depot/ | Low-cost modules | - +-------------+------------------------------------+------------------------------------+ - | SparkFun | http://www.sparkfun.com | Good for modules and parts | - +-------------+------------------------------------+------------------------------------+ + +-------------+------------------------------------------------------------------+------------------------------------+ + | Supplier | Website | Notes | + +=============+==================================================================+====================================+ + | Adafruit | http://www.adafruit.com | Good for modules and parts | + +-------------+------------------------------------------------------------------+------------------------------------+ + | Amazon | http://www.amazon.com/ | Carries everything | + +-------------+------------------------------------------------------------------+------------------------------------+ + | Digikey | http://www.digikey.com/ | Wide range of components | + +-------------+------------------------------------------------------------------+------------------------------------+ + | MakerShed | http://www.makershed.com/ | Good for modules, kits, and tools | + +-------------+------------------------------------------------------------------+------------------------------------+ + | SeeedStudio | https://www.seeedstudio.com/SBC-Beaglebone-Original-c-2031.html? | Low-cost modules | + +-------------+------------------------------------------------------------------+------------------------------------+ + | SparkFun | http://www.sparkfun.com | Good for modules and parts | + +-------------+------------------------------------------------------------------+------------------------------------+ .. table:: Other suppliers @@ -38,8 +40,8 @@ Prototyping Equipment ====================== Many of the hardware projects in this book use jumper wires and a breadboard. -We prefer the preformed wires that lie flat on the board. <<parts_jumper>> lists places -with jumper wires, and <<parts_breadboard>> shows where you can get breadboards. +We prefer the preformed wires that lie flat on the board. :ref:`parts_jumper` lists places +with jumper wires, and :ref:`parts_breadboard` shows where you can get breadboards. .. _parts_jumper: @@ -65,34 +67,32 @@ with jumper wires, and <<parts_breadboard>> shows where you can get breadboards. +=============+=============================================================================================================================================+ | Amazon | http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dtoys-and-games&field-keywords=breadboards&sprefix=breadboards%2Ctoys-and-games | +-------------+---------------------------------------------------------------------------------------------------------------------------------------------+ - | Digikey | http://www.digikey.com/product-search/en/prototyping-products/solderless-breadboards/2359510?k=breadboard | - +-------------+---------------------------------------------------------------------------------------------------------------------------------------------+ - | RadioShack | http://www.radioshack.com/search?q=breadboard | + | Digikey | https://www.digikey.com/en/products/filter/solderless-breadboards/638 | +-------------+---------------------------------------------------------------------------------------------------------------------------------------------+ | SparkFun | https://www.sparkfun.com/search/results?term=breadboard | +-------------+---------------------------------------------------------------------------------------------------------------------------------------------+ | CircuitCo | https://elinux.org/BeagleBoneBreadboard (no longer manufactured, but design available) | +-------------+---------------------------------------------------------------------------------------------------------------------------------------------+ -If you want something more permanent, try `Adafruit's Perma-Proto Breadboard <https://www.adafruit.com/product/1609>`_, laid out like a breadboard. +If you want something more permanent, try `Adafruit's Perma-Proto Breadboard <https://www.adafruit.com/product/1609>`_, +laid out like a breadboard. .. _app_resistor: Resistors ========== -We use 220 , 1k, 4.7k, 10k, 20k, and 22k resistors in this book. -All are 0.25 W. The easiest way to get all these, and many more, is to order `SparkFun's Resistor Kit <http://bit.ly/1EXREh8>`_. +We use 220 , 1k, 4.7k, 10k, 20k, and 22 |kohm| resistors in this book. +All are 0.25 W. The easiest way to get all these, and many more, is to order +`SparkFun's Resistor Kit <http://bit.ly/1EXREh8>`_. It's a great way to be ready for future projects, because it has 500 resistors. -`RadioShack's 500-piece Resistor Assortment <http://shack.net/1B4Io4V>`_ is a bit more -expensive, but it has a wider variety of resistors. If you don't need an entire kit of resistors, you can order a la carte from a number of places. -`RadioShack has 5-packs <http://shack.net/1E5NoIC>`_, and DigiKey has more than a quarter million +DigiKey has more than a quarter million `through-hole resistors <http://bit.ly/1C6WQjZ>`_ at good prices, but make sure you are ordering the right one. -You can find the 10 k trimpot (or variable resistor) at `SparkFun 10k POT <http://bit.ly/18ACvpm>`_, -`Adafruit 10k POT <http://bit.ly/1NKg1Tv>`_, or `RadioShack 10k POT <http://shack.net/1Ag286e>`_. +You can find the 10 |kohm| trimpot (or variable resistor) at `SparkFun 10k POT <http://bit.ly/18ACvpm>`_ or +`Adafruit 10k POT <http://bit.ly/1NKg1Tv>`_. Flex resistors (sometimes called *flex sensors* or *bend sensors*) are available at `SparkFun flex resistors <http://bit.ly/1Br7HD2>`_ and `Adafruit flex resistors <http://bit.ly/1HCGoql>`_. @@ -106,8 +106,8 @@ Even `Amazon NPN transitor <http://amzn.to/1AjvcsD>`_ has it. `Adafruit NPN tran will gladly sell you 100,000. The `1N4001 <http://bit.ly/1EbRzF6>`_ is a popular 1A diode. Buy one at `SparkFun diode <http://bit.ly/1Ajw54G>`_, -10 at `Adafruit diode <http://bit.ly/1Gs05zP>`_, 25 at `RadioShack diode <http://shack.net/1E5OTXi>`_, -or 40,000 at `DigiKey diode <http://bit.ly/18ADlT2>`_. +10 at `Adafruit diode <http://bit.ly/1Gs05zP>`_, +or 10,000 at `DigiKey diode <https://www.digikey.com/en/products/detail/mdd/1N4001/15517721>`_. Integrated Circuits ===================== @@ -117,15 +117,18 @@ cheaply in large quantities from `DigiKey PCA9306 <http://bit.ly/1Fb8REd>`_, but package. Instead, you can get it from `SparkFun PCA9306 on a Breakout board <http://bit.ly/19ceTsd>`_, which plugs into a breadboard. The L293D is an `H-bridge IC <http://bit.ly/1wujQqk>`_ with which you can control large loads (such as motors) in -both directions. `SparkFun L393D <http://bit.ly/18bXChR>`_, `Adafruit L393D <http://bit.ly/1xd43Yh>`_, and -`DigiKey L393D <http://bit.ly/18bXKOk>`_ all have it in a DIP package that easily plugs into a breadboard. +both directions. `SparkFun L293D <http://bit.ly/18bXChR>`_, `Adafruit L293D <http://bit.ly/1xd43Yh>`_, and +`DigiKey L293D <https://www.digikey.com/en/products/detail/stmicroelectronics/L293D/634700>`_ +all have it in a DIP package that easily plugs into a breadboard. The ULN2003 is a 7 darlington NPN transistor IC array used to drive motors one way. You can get it from -`DigiKey ULN2003 <http://bit.ly/1D5UQIB>`_. A possible substitution is ULN2803 available from +`DigiKey ULN2003 <https://www.digikey.com/en/products/detail/texas-instruments/ULN2003AN/277624>`_. +A possible substitution is ULN2803 available from `SparkFun ULN2003 <http://bit.ly/1xd4oKy>`_ and `Adafruit ULN2003 <http://bit.ly/1EXWhaU>`_. -The TMP102 is an I^2^C-based digital temperature sensor. You can buy them in bulk from -`DigiKey TMP102 <http://bit.ly/1EA02Vx>`_, but it's too small for a breadboard. `SparkFun TMP102 <http://bit.ly/1GFafAE>`_ +The TMP102 is an |I2C|-based digital temperature sensor. You can buy them in bulk from +`DigiKey TMP102 <https://www.digikey.com/en/products/filter/temperature-sensors/analog-and-digital-output/518?s=N4IgTCBcDaIC4FsAOBGADBAugXyA>`_, +but it's too small for a breadboard. `SparkFun TMP102 <http://bit.ly/1GFafAE>`_ sells it on a breakout board that works well with a breadboard. The DS18B20 is a one-wire digital temperature sensor that looks like a three-terminal transistor. @@ -137,16 +140,16 @@ Opto-Electronics `LEDs <http://bit.ly/1BwZvQj>`_ are *light-emitting diodes*. LEDs come in a wide range of colors, brightnesses, and styles. You can get a basic red LED at `SparkFun red LED <http://bit.ly/1GFaHPi>`_, -`Adafuit red LED <http://bit.ly/1GFaH1M>`_, `RadioShack red LED <http://shack.net/1KWVVGE>`_, and `DigiKey red LED <http://bit.ly/1b2f2PD>`_. +`Adafuit red LED <http://bit.ly/1GFaH1M>`_, and `DigiKey red LED <http://bit.ly/1b2f2PD>`_. -Many places carry bicolor LED matrices, but be sure to get one with an I^2^C interface. +Many places carry bicolor LED matrices, but be sure to get one with an |I2C| interface. `Adafruit LED matrix <http://bit.ly/18AENVn>`_ is where I got mine. Capes ====== There are a number of sources for capes for BeagleBone Black. -`eLinux.org BeagleBoard.org capes page <http://bit.ly/1AjlXJ9>`_ keeps a current list. +`BeagleBoard.org capes page <http://docs.beagleboard.org/>`_ keeps a current list. Miscellaneous ============== @@ -161,8 +164,6 @@ Here are some things that don't fit in the other categories. +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | USB WiFi adapter | `Adafruit WiFi adapter <http://www.adafruit.com/products/814>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ - | Female HDMI to male microHDMI adapter | `Amazon HDMI to microHDMI adapter <http://amzn.to/1C5BcLp>`_ | - +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | HDMI cable | `SparkFun HDMI cable <https://www.sparkfun.com/products/11572>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | Micro HDMI to HDMI cable | `Adafruit HDMI to microHDMI cable <http://www.adafruit.com/products/1322>`_ | @@ -174,8 +175,6 @@ Here are some things that don't fit in the other categories. | Powered USB hub | `Amazon power USB hub <http://amzn.to/1NKm2zB>`_, | | | `Adafruit power USB hub <http://www.adafruit.com/products/961>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ - | Keyboard with USB hub | `Amazon keyboard with USB hub <http://amzn.to/1FbblSX>`_ | - +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | Soldering iron | `SparkFun soldering iron <http://bit.ly/1FMfUkP>`_, | | | `Adafruit soldering iron <http://bit.ly/1EXZ6J1>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ @@ -219,16 +218,9 @@ Here are some things that don't fit in the other categories. +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | BLE USB dongle | `Adafruit BLE USB dongle <http://www.adafruit.com/products/1327>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ - | SensorTag | `DigiKey SensorTag <http://bit.ly/18AGPVt>`_, | - | | `Amazon SensorTag <http://amzn.to/1EA2B9U>`_, | - | | `TI SensorTag <https://store.ti.com/CC2541-SensorTag-Development-Kit-P3192.aspx>`_ | - +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | Syba SD-CM-UAUD USB Stereo Audio Adapter | `Amazon USB audio adapter <http://amzn.to/1EA2GdI>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | Sabrent External Sound Box USB-SBCV | `Amazon USB audio adapter (alt) <http://amzn.to/1C74kTU>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ | Vantec USB External 7.1 Channel Audio Adapter | `Amazon USB audio adapter (alt2) <http://amzn.to/19cinev>`_ | +-----------------------------------------------------+---------------------------------------------------------------------------------------+ - | Nokia 5110 LCD | `Adafruit 5110 LCD <http://bit.ly/1Ag6LgG>`_, | - | | `SparkFun 5110 LCD <http://bit.ly/19cizdu>`_ | - +-----------------------------------------------------+---------------------------------------------------------------------------------------+ diff --git a/books/beaglebone-cookbook/11misc/figures/Makefile b/books/beaglebone-cookbook/11misc/figures/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..bf01a3248aef0988a85054a044f650cd3fa1e386 --- /dev/null +++ b/books/beaglebone-cookbook/11misc/figures/Makefile @@ -0,0 +1,19 @@ +obj-m += tmp114.o + +KDIR ?= /lib/modules/$(shell uname -r)/build +PWD := $(CURDIR) + +all: + make -C $(KDIR) M=$(PWD) modules + +clean: + make -C $(KDIR) M=$(PWD) cleanobj-m += tmp114.o + +KDIR ?= /lib/modules/$(shell uname -r)/build +PWD := $(CURDIR) + +all: + make -C $(KDIR) M=$(PWD) modules + +clean: + make -C $(KDIR) M=$(PWD) clean diff --git a/books/beaglebone-cookbook/11misc/misc.rst b/books/beaglebone-cookbook/11misc/misc.rst new file mode 100644 index 0000000000000000000000000000000000000000..2bb7775bcc06ff885004a472c2f64e2683a73753 --- /dev/null +++ b/books/beaglebone-cookbook/11misc/misc.rst @@ -0,0 +1,450 @@ +.. _beaglebone-cookbook-misc: + +.. |I2C| replace:: I\ :sup:`2`\ C + +Misc +#### + +Here are bits and pieces of ideas that are being developed. + +Converting a tmp117 to a tmp114 +================================ + +Problem +------- + +You have a tmp114 temperature sensor and you need a driver for it. + +Solution +-------- + +Find a similar driver and convert it to the tmp114. + +Let's first see if there is a driver for it already. Run the following on the bone using the tab key in place +of <tab>. + +.. code-block:: bash + + bone$ modinfo tmp<tab><tab> + tmp006 tmp007 tmp102 tmp103 tmp108 tmp401 tmp421 tmp513 + bone$ modinfo tmp + +Here you see a list of modules that match *tmp*, unfortunately *tmp114* is not there. +Let's see if there are any matches in */lib/modules*. + +.. code-block:: bash + + bone$ find /lib/modules/ -iname "*tmp*" + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/iio/temperature/tmp006.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/iio/temperature/tmp007.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/hwmon/tmp103.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/hwmon/tmp421.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/hwmon/tmp108.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/hwmon/tmp513.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/hwmon/tmp401.ko.xz + /lib/modules/5.10.168-ti-arm64-r104/kernel/drivers/hwmon/tmp102.ko.xz + +Looks like the same list, but here we can see what type of driver it is, either *hwmon* or *iio*. +hwmon is an older `harware monitor <https://docs.kernel.org/hwmon/hwmon-kernel-api.html>`_. +iio is the newer, and prefered, `Industrial IO driver +<https://www.kernel.org/doc/html/v4.12/driver-api/iio/index.html>`_. +Googling tmp006 and tmp007 shows that they are Infrared Thermopile Sensors, not the same at the *tmp114*. +(Google it). Let's keep looking for a more compatible device. + +Browse over to http://kernel.org to see if there are tmp114 drivers in the newer versions of the kernel. +The first line in the table is **mainline**. Click on the **browse** link on the right. +Here you will see the top level of the Linux sourse tree for the *mainline* version of the kernel. +Click on **drivers** and then **iio**. Finally, since tmp114 is a temperture sensor, click on **temperature**. +Here you see all the source code for the iio temperature drivers for the mainline version of the kernel. +We've seen tmp006 and tmp007 as before, tmp117 is new. Maybe it will work. Click on **tmp117.c** to see the code. +Looks like it also works for the tmp116 too. Let's try convering it to work with the tmp114. + +A quick way to copy the code to the bone is to right-click on the **plain** link and select *Copy link address*. +Then, on the bone enter **wget** and paste the link. Mine looks like the following, yours will be similar. + +.. code-block:: bash + + bone$ wget https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/drivers/iio/temperature/tmp117.c?h=v6.4-rc7 + bone$ mv 'tmp117.c?h=v6.4-rc7' tmp117.c + bone$ cp tmp117.c tmp114.c + +The **mv** command moves the downloaded file to a usable name and the **cp** copies to a new file with the new name. + +Compiling the module +^^^^^^^^^^^^^^^^^^^^ + +Next we need to compile the driver. To do this we need to load the corresponding header files for the +version of the kernel that's beening run. + +.. code-block:: bash + + bone$ uname -r + 5.10.168-ti-arm64-r105 + +Here you see which version I'm running, yours will be similar. Now load the headers. + +.. code-block:: bash + + bone$ sudo apt install linux-headers-`uname -r` + +Next create a *Makefile*. Put the following in a file called *Makefile*. + +.. _misc_makefile: + +.. literalinclude:: figures/Makefile + :caption: Makefile for compiling module (Makefile) + :linenos: + +:download:`Makefile <figures/Makefile>` + +Now you are ready to compile: + +.. code-block:: bash + + bone$ make + make -C /lib/modules/5.10.168-ti-arm64-r105/build M=/home/debian/play modules + make[1]: Entering directory '/usr/src/linux-headers-5.10.168-ti-arm64-r105' + CC [M] /home/debian/play/tmp114.o + /home/debian/play/tmp114.c: In function ‘tmp117_identify’: + /home/debian/play/tmp114.c:150:7: error: implicit declaration of function ‘i2c_client_get_device_id’; did you mean ‘i2c_get_device_id’? [-Werror=implicit-function-declaration] + 150 | id = i2c_client_get_device_id(client); + | ^~~~~~~~~~~~~~~~~~~~~~~~ + | i2c_get_device_id + /home/debian/play/tmp114.c:150:5: warning: assignment to ‘const struct i2c_device_id *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] + 150 | id = i2c_client_get_device_id(client); + | ^ + cc1: some warnings being treated as errors + make[2]: *** [scripts/Makefile.build:286: /home/debian/play/tmp114.o] Error 1 + make[1]: *** [Makefile:1822: /home/debian/play] Error 2 + make[1]: Leaving directory '/usr/src/linux-headers-5.10.168-ti-arm64-r105' + make: *** [Makefile:7: all] Error 2 + +Well, the good news is, it is compiling, that means it found the correct headers. +But now the work begins converting to the tmp114. + +Converting to the tmp114 +^^^^^^^^^^^^^^^^^^^^^^^^ + +You are mostly on your own for this part, but here are some suggestions: + +- First get it to compile without errors. In this case, the function at line 150 isn't defined. + Try commenting it out and recompiling. +- Once it's compiling without errors, try running it. First open another window and login to beagle. + Then run: + + .. code-block:: bash + + bone$ dmesg -Hw + +This will display the kernel messages. The **-H** put them in *human* readable form, and the **-w** waits for +more messages. + +- Next, "insert" it in the running kernel: + +.. code-block:: bash + + bone$ sudo insmod tmp114.ko + +If all worked you shouldn't see any messages, either after the command or in the dmesg window. +If you want to insert the module again, you will have to remove it first. +Remove with: + +.. code-block:: bash + + bone$ sudo rmmod tmp114 + +Now we need to tell the kernel we have an |I2C| device and which bus and which address. + +Finding your |I2C| device +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Each |I2C| device appears at a certain address on a given bus. My device is on bus 3, +so I run: + +.. code-block:: bash + + bone$ i2cdetect -y -r 3 + 0 1 2 3 4 5 6 7 8 9 a b c d e f + 00: -- -- -- -- -- -- -- -- + 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 40: -- -- -- -- -- -- -- -- -- -- -- -- -- 4d -- -- + 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 70: -- -- -- -- -- -- -- -- + +This shows there is a device at address **0x4d**. If you don't know your bus number, +just try a few until you find it. + +The temperature is in register 0 for my device and it's 16 bits (one word), +it is read with: + +.. code-block:: bash + + bone$ i2cget -y 3 0x4d 0 w + 0xb510 + +The tmp114 swaps the two bytes, so the real temperature is **0x10b5**, or so. +You need to look up the datawsheet to learn how to comvert it. + +Registers and IDs +^^^^^^^^^^^^^^^^^ + +Each |I2C| device has a number of internal registers that interact with the device. +The tmp114 uses different register numbers than the tmp117, so you need to change these values. +To do this, Google for the data sheets for each and look them up. +I found them at: https://www.ti.com/lit/gpn/tmp114 and https://www.ti.com/lit/gpn/tmp117. + +Creating a new device +^^^^^^^^^^^^^^^^^^^^^ + +Once you've converted the module for the tmp114 and inserted it, you can now create a new device. + +.. code-block:: bash + + bone$ cd /sys/class/i2c-adapter/i2c-3 + bone$ sudo chgrp gpio * + bone$ sudo chmod g+w * + bone$ ls -ls + total 0 + 0 --w--w---- 1 root gpio 4096 Jun 22 18:24 delete_device + 0 lrwxrwxrwx 1 root root 0 Jan 1 1970 device -> ../../20030000.i2c + 0 drwxrwxr-x 3 root gpio 0 Jun 22 18:20 i2c-dev + 0 -r--rw-r-- 1 root gpio 4096 Jun 22 18:20 name + 0 --w--w---- 1 root gpio 4096 Jun 22 18:20 new_device + 0 lrwxrwxrwx 1 root root 0 Jan 1 1970 of_node -> ../../../../../firmware/devicetree/base/bus@f0000/i2c@20030000 + 0 drwxrwxr-x 2 root gpio 0 Jun 22 18:20 power + 0 lrwxrwxrwx 1 root root 0 Jan 1 1970 subsystem -> ../../../../../bus/i2c + 0 -rw-rw-r-- 1 root gpio 4096 Jun 22 18:20 uevent + +The first line changes to the directory to where we can create the new device. +The final **3** in the path is for bus **3**, your milage may vary. +We then change the group to **gpio** and give it write permission. +You only need to do this once. + +Now make a new device. + +.. code-block:: bash + + bone$ echo tmp114 0x4d > new_device + +Look in the demsg window and you should see: + +.. code-block:: bash + + [Jun22 19:24] tmp114 3-004d: tmp114_identify id (0x1114) + [ +0.000027] tmp114 3-004d: tmp114_probe id (0x1114) + [ +0.000502] i2c i2c-3: new_device: Instantiated device tmp114 at 0x4d + +It's been found! Let's see what it knows about it. + +.. code-block:: bash + + bone$ iio_info + Library version: 0.24 (git tag: v0.24) + ... + iio:device1: tmp114 + 1 channels found: + temp: (input) + 2 channel-specific attributes found: + attr 0: raw value: 4257 + attr 1: scale value: 7.812500 + No trigger on this device + +I've left out some of the lines, at the bottom you see the tmp114, and +two values (**raw** and **scale**) that were read from it. Let's read them ourselves. +Do an *ls* and you'll see a new directory, **3-004d**. This is address 0x4d on bus 3, +just what we wanted. + +.. code-block:: bash + + bone$ cd 3-004d/iio:device1 + bone$ ls + dev in_temp_raw in_temp_scale name power subsystem uevent + bone$ cat in_temp_raw + 4275 + +You'll have to look in the datasheet to learn how to convert the temperature. + +If you try to run i2cget again, you'll get an error: + +.. code-block:: bash + + bone$ i2cget -y 3 0x4d 0 w + Error: Could not set address to 0x4d: Device or resource busy + +This is because the module is using it. Delete the device and you'll have access again. + +.. code-block:: bash + + bone$ echo 0x4d > /sys/class/i2c-adapter/i2c-3/delete_device + bone$ i2cget -y 3 0x4d 0 w + 0x8e10 + +You should also see a message in dmesg. + + +Documenting with Sphinx +======================== + +Problem +------- + +You want to add or update the Beagle documentation. + +Solution +-------- + +BeagleBoard.org uses the `Sphinx Python Documentation Generator +<https://www.sphinx-doc.org/en/master/index.html>`_ and the +`rst <https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html>`_ markup language. + +Here's what you need to do to fork the repository and render a local copy of +the documentation. Browse to https://docs.beagleboard.org/latest/ and click on +the **Edit on GitLab** button on the upper-right of the page. Clone the repository. + +.. code-block:: bash + + bash$ git clone git@git.beagleboard.org:docs/docs.beagleboard.io.git + bash$ cd docs.beagleboard.io + +Then run the following to load the **code** submodule + +.. code-block:: bash + + bash$ git submodule update --init + +Now, sync changes with upstream: + +.. code-block:: bash + + bone$ git remote add upstream https://git.beagleboard.org/docs/docs.beagleboard.io.git + bone$ git fetch upstream + bone$ git pull upstream main + +Downloading Sphinx +^^^^^^^^^^^^^^^^^^ +Run the following to download Sphinx. Note: This will take a while, it loads +some 6G bytes. + +.. code-block:: bash + + bone$ sudo apt update + bone$ sudo apt upgrade + bone$ sudo apt install -y \ + make git wget \ + doxygen graphviz librsvg2-bin\ + texlive-latex-base texlive-latex-extra latexmk texlive-fonts-recommended \ + python3 python3-pip \ + python3-sphinx python3-sphinx-rtd-theme python3-sphinxcontrib.svg2pdfconverter \ + python3-pil \ + imagemagick-6.q16 librsvg2-bin webp \ + texlive-full texlive-latex-extra texlive-fonts-extra \ + fonts-freefont-otf fonts-dejavu fonts-dejavu-extra fonts-freefont-ttf + bone$ python3 -m pip install --upgrade pip + bone$ pip install -U sphinx_design + bone$ pip install -U sphinxcontrib-images + bone$ pip install -U sphinx-serve + +These instructions came from `lorforlinux +<https://beagleboard.slack.com/archives/C8S7EKZC2/p1684940872699269>`_ +on the Beagleboard Slack channel. + +Now go to the cloned *docs.beagleboard.io* repository folder and do the following. +To clean build directory: + +.. code-block:: bash + + bone$ cd docs.beagleboard.io + bone$ make clean + +To generate HTML output of docs: + +.. code-block:: bash + + bone$ make html + +To generate PDF output of docs: + +.. code-block:: bash + + bone$ make latexpdf + +To preview docs on your local machine: + +.. code-block:: bash + + bone$ sphinx-serve + +Then point your browser to localhost:8081. + +.. tip:: + You can keep the sphinx-serve running until you clean the build directory + using make clean. + Warnings will be hidden after first run of make html or make latexpdf, + to see all the warnings again just run make clean before building HTML or PDF + + +Creating A New Book +^^^^^^^^^^^^^^^^^^^^ +- Create a new book folder here: + https://git.beagleboard.org/docs/docs.beagleboard.io/-/tree/main/books +- Create rst files for all the chapters in there respective folders so + that you can easily manage media for that chapter as shown here: + https://git.beagleboard.org/docs/docs.beagleboard.io/-/tree/main/books/pru-cookbook +- Create an index.rst file in the book folder and add a table of content (toc) + for all the chapters. For example see this file: + https://git.beagleboard.org/docs/docs.beagleboard.io/-/raw/main/books/pru-cookbook/index.rst +- Add the bookname/index.rst reference in the main index file as well: + https://git.beagleboard.org/docs/docs.beagleboard.io/-/raw/main/books/index.rst +- At last you have to update the two files below to render the book in HTML and + PDF version of the docs respectively: + https://git.beagleboard.org/docs/docs.beagleboard.io/-/raw/main/index.rst + https://git.beagleboard.org/docs/docs.beagleboard.io/-/raw/main/index-tex.rst + + + +Running Sparkfun's qwiic Python Examples +======================================== + +Many of the Sparkfun qwiic devices have Python examples showing +how to use them. Unfortunately the examples assume |I2C| bus +1 is used, but the qwiic bus on the Play is bus 5. +Here is a quick hack to get the Sparkfun Python examples to use +bus 5. I'll show it for the Joystick, but it should work for the +others as well. + +First, browse to Sparkfun's qwiic Joystick page, +https://www.sparkfun.com/products/15168 and click on the +**DOCUMENTS** tab and then on **Python Package**. Follow the pip +instillation instructions (sudo pip install sparkfun-qwiic-joystick) + +Next, uninstall the current qwiic |I2C| package. + +.. code-block:: shell-session + + bone$ sudo pip uninstall sparkfun-qwiic-i2c + +Then clone the Qwiic |I2C| repo: + +.. code-block:: shell-session + + bone$ git clone git@github.com:sparkfun/Qwiic_I2C_Py.git + bone$ cd Qwiic_I2C_Py/qwiic_i2c + +Edit **linux_i2c.py** and go to around line 62 and change it to: + +.. code-block:: shell-session + + iBus = 5 + +Next, cd up a level to the Qwiic_I2C_Py directory and reinstall + +.. code-block:: bash + + bone$ cd .. + bone$ sudo python setup.py install + +Finally, run one of the Joystick examples. If it isn't using +bus 5, try reinstalling setup.py again. diff --git a/books/beaglebone-cookbook/11misc/tabs b/books/beaglebone-cookbook/11misc/tabs new file mode 100644 index 0000000000000000000000000000000000000000..7df12743533fbfb058f711d4146fca9bbab51e08 --- /dev/null +++ b/books/beaglebone-cookbook/11misc/tabs @@ -0,0 +1,31 @@ +.. tabs:: + + .. group-tab:: Commands + + .. code-block:: shell-session + + bone$ sudo apt update + bone$ sudo apt upgrade + bone$ sudo apt install -y \ + make git wget \ + doxygen graphviz librsvg2-bin\ + texlive-latex-base texlive-latex-extra latexmk texlive-fonts-recommended \ + python3 python3-pip \ + python3-sphinx python3-sphinx-rtd-theme python3-sphinxcontrib.svg2pdfconverter \ + python3-pil \ + imagemagick-6.q16 librsvg2-bin webp \ + texlive-full texlive-latex-extra texlive-fonts-extra \ + fonts-freefont-otf fonts-dejavu fonts-dejavu-extra fonts-freefont-ttf + bone$ python3 -m pip install --upgrade pip + bone$ pip install -U sphinx_design + bone$ pip install -U sphinxcontrib-images + bone$ pip install -U sphinx-serve + + .. group-tab:: Shell Output + + .. code-block:: shell-session + + bone$ git remote add upstream https://git.beagleboard.org/docs/docs.beagleboard.io.git + bone$ git fetch upstream + bone$ git pull upstream main + \ No newline at end of file diff --git a/books/beaglebone-cookbook/code b/books/beaglebone-cookbook/code index e103135d4cd1387e0bfa37b468e3137b9a34e60f..ba615b3a1e8de7f99345817225c491e05151d454 160000 --- a/books/beaglebone-cookbook/code +++ b/books/beaglebone-cookbook/code @@ -1 +1 @@ -Subproject commit e103135d4cd1387e0bfa37b468e3137b9a34e60f +Subproject commit ba615b3a1e8de7f99345817225c491e05151d454 diff --git a/books/beaglebone-cookbook/index.rst b/books/beaglebone-cookbook/index.rst index ebc0977f2a91739024d2bba730277380c1359c32..096a3ed1ee6fbca0bd68ed64e27ee19239336b0e 100644 --- a/books/beaglebone-cookbook/index.rst +++ b/books/beaglebone-cookbook/index.rst @@ -6,7 +6,7 @@ BeagleBone Cookbook .. admonition:: Contributors - Author: `Mark A. Yoder <Mark.A.Yoder@Rose-Hulman.edu>`_ - - Book revision: v2.0 beta + - Book revision: v2.1 beta A cookbook for programming Beagles @@ -23,3 +23,4 @@ A cookbook for programming Beagles 08realtime/realtime.rst 09capes/capes.rst 10parts/parts.rst + 11misc/misc.rst diff --git a/conf.py b/conf.py index baec57caf5ef4233c173805a8f5ace1b0869b93f..7e86c2c9c7a4e9e5c577d26e34985e3198462d28 100644 --- a/conf.py +++ b/conf.py @@ -31,7 +31,8 @@ extensions = [ "sphinx_design", "sphinxcontrib.images", "sphinx.ext.imgconverter", - "sphinx.ext.todo" + "sphinx.ext.todo", + "sphinx_tabs.tabs" ] todo_include_todos = True diff --git a/notes.md b/notes.md new file mode 100644 index 0000000000000000000000000000000000000000..c3f6694840f66e907e458617d28312bd699381f1 --- /dev/null +++ b/notes.md @@ -0,0 +1,7 @@ +# update Submodules: + +``` +git submodule update --remote --merge +``` + +