Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit 720282df authored by Deepak Khatri's avatar Deepak Khatri :dog:
Browse files

Merge branch 'main' of git.beagleboard.org:lorforlinux/docs.beagleboard.io

parents 5ac1ff63 bc42720b
Branches
Tags
1 merge request!151Docs updates, version banner, and todo lists
Showing
with 627 additions and 29 deletions
...@@ -41,10 +41,23 @@ Demos & tutorials ...@@ -41,10 +41,23 @@ Demos & tutorials
beginner beginner
.. card::
:link: beagleconnect-freedom-using-arduino-zephyr-template
:link-type: ref
**Using Arduino Zephyr Template**
^^^
Getting started with arduino Zephyr template on your BeagleConnect Freedom board.
+++
.. admonition:: Complexity level
beginner
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
:hidden: :hidden:
demos-and-tutorials/using-micropython demos-and-tutorials/using-micropython
demos-and-tutorials/using-zephyr demos-and-tutorials/using-zephyr
demos-and-tutorials/using-greybus demos-and-tutorials/using-greybus
\ No newline at end of file demos-and-tutorials/using-arduino-zephyr-template
\ No newline at end of file
.. _beagleconnect-freedom-using-arduino-zephyr-template:
Using Arduino Zephyr Template
##############################
The `Arduino Core API module for zephyr <https://github.com/zephyrproject-rtos/gsoc-2022-arduino-core>`_ leverages the power of Zephyr under an
Arduino-C++ style abtraction layer thus helping zephyr new-comers to start using
it without worrying about learning new APIs and libraries.
Using this template you can run arduino code on your BeagleConnect Freedom.
.. todo::
Add pin diagram for BeagleConnect Freedom that can be used in the template.
Setup Arduino workspace
***********************
If this is your first time using zephyr, `Install Zephyr SDK <https://docs.zephyrproject.org/latest/develop/getting_started/index.html#install-the-zephyr-sdk>`_ and install ``cc1352-flasher``
using command ``pip install cc1352-flasher`` before following the steps below.
1. Create a workspace folder:
.. code:: shell-session
mkdir arduino-workspace
cd arduino-workspace
2. Setup virtual environment
.. code:: shell-session
python -m venv .venv
source .venv/bin/activate
pip install west
3. Setup Zephyr app:
.. code:: shell-session
west init -m https://openbeagle.org/beagleconnect/arduino-zephyr-template .
west update
4. Setup Arduino module
.. code:: shell-session
ln -srf modules/lib/ArduinoCore-API/api modules/lib/Arduino-Zephyr-API/cores/arduino/.
5. Install python deps
.. code:: shell-session
pip install -r zephyr/scripts/requirements-base.txt
Arduino Code
============
You can find ``main.cpp`` file in the directory ``arduino-workspace/arduino-zephyr-template/src/``
which contains your arduino code. The default code prints ``Hello World`` on the serial monitor.
.. code:: shell-session
nano arduino-workspace/arduino-zephyr-template/src/main.cpp
.. code-block:: shell-session
:caption: main.cpp
#include <Arduino.h>
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("Hello World");
delay(5000);
}
Press ``CTRL+O`` and ``ENTER`` to save, ``CTRL+X`` to exit.
.. important::
You must start your ``main.cpp`` code with ``#include <Arduino.h>``.
Build the Arduino directory
===========================
Before flashing, run the command below to build the ``arduino-zephyr-template`` for the board
``beagleconnect_freedom``.
.. code:: shell-session
west build -b beagleconnect_freedom arduino-zephyr-template -p
.. note::
Only if you are following the steps from the beginning then the above command will work.
Otherwise, make sure that you are in the ``arduino-workspace`` directory and setup
virtual environment using command ``source .venv/bin/activate``.
Flash BeagleConnect Freedom
============================
Make sure that your BeagleConnect Freedom is connected with your linux system
via USB.
.. code:: shell-session
west flash
Serial Output
=============
Considering your BeagleConnect Freedom is connected to ``/dev/ttyACM0`` you can see the serial output coming from your BeagleConnect Freedom.
.. code:: shell-session
tio /dev/ttyACM0
Arduino blink code running on BeagleConnect Freedom
***************************************************
For BeagleConnect Freedom LNK LED will work as ``LED_BUILTIN`` in Arduino code.
First you have to modify ``main.cpp`` located in the directory ``arduino-workspace/arduino-zephyr-template/src/``
created at the time of setup.
.. code-block:: shell-session
:caption: main.cpp
#include <Arduino.h>
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Before doing ``Build`` and ``Flash``, you must activate the virtual environment in the ``arduino-workspace`` directory which has been created earlier.
.. code:: shell-session
source .venv/bin/activate
Now, execute the build command.
.. code:: shell-session
west build -b beagleconnect_freedom arduino-zephyr-template -p
Make sure your BeagleConnect Freedom is connected to your linux system via USB.
Finally, flash using the command below. The ``LNK`` LED of BeagleConnect will start blinking after flashing
is complete.
.. code:: shell-session
west flash
.. tip::
You can try more `Arduino examples <https://docs.arduino.cc/built-in-examples/>`_ on BeagleConnect Freedom.
\ No newline at end of file
...@@ -54,9 +54,27 @@ For tethering to your PC you'll need a USB-C data cable. ...@@ -54,9 +54,27 @@ For tethering to your PC you'll need a USB-C data cable.
Access VSCode Access VSCode
**************** ****************
You can acces VSCode in two ways:
1. :ref:`beagleplay-usb-vscode`
2. :ref:`beagleplay-access-point-vscode`
.. _beagleplay-usb-vscode:
USB
====
Once connected, you can browse to `192.168.7.2:3000 <http://192.168.7.2:3000>`_ to access the VSCode IDE Once connected, you can browse to `192.168.7.2:3000 <http://192.168.7.2:3000>`_ to access the VSCode IDE
to browse documents and start programming your BeaglePlay! to browse documents and start programming your BeaglePlay!
.. _beagleplay-access-point-vscode:
Access Point
============
By default BeaglePlay Access Point is enabled, You can connect to ``BeaglePlay-XXXX`` Access Point with the password ``BeaglePlay`` and then
browse to `192.168.7.2:3000 <http://192.168.7.2:3000>`_ to access the VSCode IDE.
.. note:: .. note::
You may get a warning about an invalid or self-signed certificate. This is a limitation of You may get a warning about an invalid or self-signed certificate. This is a limitation of
...@@ -70,6 +88,9 @@ to browse documents and start programming your BeaglePlay! ...@@ -70,6 +88,9 @@ to browse documents and start programming your BeaglePlay!
BeaglePlay VSCode IDE (192.168.7.2:3000) BeaglePlay VSCode IDE (192.168.7.2:3000)
.. tip::
For more Wifi and Access Point related info go to :ref:`beagleplay-connect-wifi`
.. _beagleplay-demos-and-tutorials: .. _beagleplay-demos-and-tutorials:
Demos and Tutorials Demos and Tutorials
......
...@@ -209,7 +209,7 @@ wpa_cli (XFCE) ...@@ -209,7 +209,7 @@ wpa_cli (XFCE)
Another way of connecting to a WiFi access point is to edit the ``wpa_supplicant`` configuration file. Another way of connecting to a WiFi access point is to edit the ``wpa_supplicant`` configuration file.
Step 1: Open up termina Step 1: Open up terminal
======================== ========================
Open up a terminal window either from ``Applications > Terminal Emulator`` Or from Task Manager. Open up a terminal window either from ``Applications > Terminal Emulator`` Or from Task Manager.
......
boards/beagleplay/demos-and-tutorials/images/qwiic/beagleplay-qwiic-oled-connection.webp

20.9 KiB

boards/beagleplay/demos-and-tutorials/images/qwiic/beagleplay-qwiic-oled-ipaddress.webp

196 KiB

...@@ -39,7 +39,7 @@ BeaglePlay's Linux kernel is patched with a mikrobus driver that automatically r ...@@ -39,7 +39,7 @@ BeaglePlay's Linux kernel is patched with a mikrobus driver that automatically r
Does my add-on have ClickID? Does my add-on have ClickID?
============================ ============================
Look for the "ID" logo on the board. It's near PWM pin on upper right hand side in the illustration shown below. Look for the board's ``'D`` (ID) logo. It's near the PWM pin on the upper right-hand side in the illustration below.
.. figure:: images/mikrobus-linux-board-illustration.png .. figure:: images/mikrobus-linux-board-illustration.png
:width: 940 :width: 940
...@@ -54,34 +54,40 @@ Example of examining boot log to see a ClickID was detected. ...@@ -54,34 +54,40 @@ Example of examining boot log to see a ClickID was detected.
.. code:: shell-session .. code:: shell-session
debian@BeaglePlay:~$ dmesg | grep mikrobus debian@BeaglePlay:~$ dmesg | grep mikrobus
[ 2.096254] mikrobus:mikrobus_port_register: registering port mikrobus-0 [ 2.096254] mikrobus:mikrobus_port_register: registering port mikrobus-0
[ 2.096325] mikrobus mikrobus-0: mikrobus port 0 eeprom empty probing default eeprom [ 2.096325] mikrobus mikrobus-0: mikrobus port 0 eeprom empty probing default eeprom
[ 2.663698] mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 1, driver=opt3001, protocol=3, reg=44 [ 2.663698] mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 1, driver=opt3001, protocol=3, reg=44
[ 2.663711] mikrobus_manifest:mikrobus_manifest_parse: Ambient 2 Click manifest parsed with 1 devices [ 2.663711] mikrobus_manifest:mikrobus_manifest_parse: Ambient 2 Click manifest parsed with 1 devices
[ 2.663783] mikrobus mikrobus-0: registering device : opt3001 [ 2.663783] mikrobus mikrobus-0: registering device : opt3001
To use the add-on, see :ref:`beagleplay-mikrobus-using`.
.. note:: .. note::
Not all Click boards with ClickID have valid ``manifest`` entries.
Then you can follow :ref:`beagleplay-mikrobus-clickid-inavalid-manifests` to make your
add-on detected.
Not all Click boards with ClickID have valid ``manifest`` entries. To use the add-on, see :ref:`beagleplay-mikrobus-using`.
.. _beagleplay-mikrobus-without-clickid: .. _beagleplay-mikrobus-without-clickid:
What if my add-on doesn't have ClickID? What if my add-on doesn't have ClickID?
*************************************** ***************************************
If add-on doesn't have clickID then it can not be detected directly.
.. code:: shell-session
It is still possible a ``manifest`` has been created for your add-on as we have created over 100 of them. debian@BeaglePlay:~$ dmesg | grep mikrobus
[ 2.123994] mikrobus:mikrobus_port_register: registering port mikrobus-0
[ 2.124059] mikrobus mikrobus-0: mikrobus port 0 eeprom empty probing default eeprom
Available ``manifest`` can be installed that has been created for your add-on as we have created over 100 of them.
You can install the existing manifest files onto your BeaglePlay. First, make sure you have the You can install the existing manifest files onto your BeaglePlay. First, make sure you have the
latest manifests installed in your system. latest manifests installed in your system.
.. code:: console .. code:: console
sudo apt update sudo apt update
.. code:: console
sudo apt install bbb.io-clickid-manifests sudo apt install bbb.io-clickid-manifests
...@@ -123,6 +129,13 @@ Take a look at the list of ``manifest`` files to see if the Click or other mikro ...@@ -123,6 +129,13 @@ Take a look at the list of ``manifest`` files to see if the Click or other mikro
COLOR-2-CLICK.mnfb HEART-RATE-7-CLICK.mnfb PROXIMITY-9-CLICK.mnfb WAVEFORM-CLICK.mnfb COLOR-2-CLICK.mnfb HEART-RATE-7-CLICK.mnfb PROXIMITY-9-CLICK.mnfb WAVEFORM-CLICK.mnfb
COLOR-7-CLICK.mnfb HEART-RATE-CLICK.mnfb PROXIMITY-CLICK.mnfb WEATHER-CLICK.mnfb COLOR-7-CLICK.mnfb HEART-RATE-CLICK.mnfb PROXIMITY-CLICK.mnfb WEATHER-CLICK.mnfb
Below command to grant root privileges of the intended user and then enter passsword.
This will take you to the different shell.
.. code:: bash
sudo su
Then, load the appropriate ``manifest`` using the ``mikrobus`` bus driver. For example, with the Ambient 2 Click, Then, load the appropriate ``manifest`` using the ``mikrobus`` bus driver. For example, with the Ambient 2 Click,
you can write that ``manifest`` to the ``mikrobus-0`` ``new_device`` entry. you can write that ``manifest`` to the ``mikrobus-0`` ``new_device`` entry.
...@@ -130,16 +143,23 @@ you can write that ``manifest`` to the ``mikrobus-0`` ``new_device`` entry. ...@@ -130,16 +143,23 @@ you can write that ``manifest`` to the ``mikrobus-0`` ``new_device`` entry.
cat /lib/firmware/mikrobus/AMBIENT-2-CLICK.mnfb > /sys/bus/mikrobus/devices/mikrobus-0/new_device cat /lib/firmware/mikrobus/AMBIENT-2-CLICK.mnfb > /sys/bus/mikrobus/devices/mikrobus-0/new_device
.. note:: You can now exit this shell.
We will be adding a link to the ``mikrobus-0`` device at ``/dev/play/mikrobus`` in the near .. code:: shell
future, but you can find it for now at ``/sys/bus/mikrobus/devices/mikrobus-0``. If you
need to supply an ID (manifest), this is the directory where you will do it.
Manifesto: https://git.beagleboard.org/beagleconnect/manifesto exit
Patched Linux with out-of-tree Mikrobus driver: https://git.beagleboard.org/beagleboard/linux Once done, you can check it using command ``dmesg | grep mikrobus`` which shows that
add-on is now detected.
.. code:: shell-session
debian@BeaglePlay:~$ dmesg | grep mikrobus
[ 2.096254] mikrobus:mikrobus_port_register: registering port mikrobus-0
[ 2.096325] mikrobus mikrobus-0: mikrobus port 0 eeprom empty probing default eeprom
[ 2.663698] mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 1, driver=opt3001, protocol=3, reg=44
[ 2.663711] mikrobus_manifest:mikrobus_manifest_parse: Ambient 2 Click manifest parsed with 1 devices
[ 2.663783] mikrobus mikrobus-0: registering device : opt3001
.. note:: .. note::
...@@ -150,8 +170,75 @@ you can write that ``manifest`` to the ``mikrobus-0`` ``new_device`` entry. ...@@ -150,8 +170,75 @@ you can write that ``manifest`` to the ``mikrobus-0`` ``new_device`` entry.
To make it stick, ... To make it stick, ...
To use the add-on, see :ref:`beagleplay-mikrobus-using`. .. _beagleplay-mikrobus-clickid-inavalid-manifests:
What if my add-on has invalid manifest entries?
************************************************
Not all Click boards with ClickID have valid manifest entries.
If your add-on has clickID but shows the command output like below.
.. code:: shell-session
debian@BeaglePlay:~$ dmesg | grep mikrobus
[ 2.119771] mikrobus:mikrobus_port_register: registering port mikrobus-0
[ 2.119842] mikrobus mikrobus-0: mikrobus port 0 eeprom empty probing default eeprom
[ 2.261113] mikrobus_manifest:mikrobus_manifest_header_validate: manifest version too new (150.189 > 0.3)
[ 2.261130] mikrobus mikrobus-0: invalid manifest size -22
There are some available manifest that can be used to write in the eeprom of clickID board.
Once you ``sudo apt update`` and ``sudo apt install bbb.io-clickid-manifests`` then you
can see the list of manifests using command ``ls /lib/firmware/mikrobus/``. Let's take
the ``Accel Click - ClickID`` Board with invalid manifest entries, To get the valid manifest
we need to write ``ACCEL-CLICK.mnfb`` to eeprom of ClickID board using the following commands.
First check the file name for the add-on device. It can be in the form of ``w1_bus_master1-xx-xxxxxxx``.
.. code:: shell-session
debian@BeaglePlay:~$ ls /sys/bus/w1/devices/
w1_bus_master1 w1_bus_master1-xx-xxxxxxx
Then in the following command, ``/lib/firmware/mikrobus/ACCEL-CLICK.mnfb`` is the path of manifest file and
``/sys/bus/w1/devices/w1_bus_master1-xx-xxxxxxx/mikrobus_manifest`` is path for one wire eeprom clickID board.
You must replace the the file name ``w1_bus_master1-xx-xxxxxxx`` with your clickID board file in the
below command.
.. code:: shell-session
debian@BeaglePlay:~$ sudo dd if=/lib/firmware/mikrobus/ACCEL-CLICK.mnfb of=/sys/bus/w1/devices/w1_bus_master1-xx-xxxxxxx/mikrobus_manifest
0+1 records in
0+1 records out
132 bytes copied, 0.0144496 s, 9.1 kB/s
Now, Reboot your BeaglePlay. After rebooting, the add-on has been detected with valid manifest entries.
.. code:: shell-session
debian@BeaglePlay:~$ dmesg | grep mikrobus
[ 2.126654] mikrobus:mikrobus_port_register: registering port mikrobus-0
[ 2.126727] mikrobus mikrobus-0: mikrobus port 0 eeprom empty probing default eeprom
[ 2.797179] mikrobus_manifest:mikrobus_manifest_attach_device: parsed device 1, driver=adxl345, protocol=3, reg=1d
[ 2.797191] mikrobus_manifest:mikrobus_manifest_parse: Accel Click manifest parsed with 1 devices
[ 2.797267] mikrobus mikrobus-0: registering device : adxl345
.. note::
The updation has done in the eeprom of clickID board. It will not
forget after reboot.
.. note::
We will be adding a link to the ``mikrobus-0`` device at ``/dev/play/mikrobus`` in the near
future, but you can find it for now at ``/sys/bus/mikrobus/devices/mikrobus-0``. If you
need to supply an ID (manifest), this is the directory where you will do it.
Manifesto: https://git.beagleboard.org/beagleconnect/manifesto
Patched Linux with out-of-tree Mikrobus driver: https://git.beagleboard.org/beagleboard/linux
To use the add-on, see :ref:`beagleplay-mikrobus-using`.
.. _beagleplay-mikrobus-using: .. _beagleplay-mikrobus-using:
......
...@@ -6,3 +6,264 @@ Using QWIIC ...@@ -6,3 +6,264 @@ Using QWIIC
See :ref:`qwiic_stemma_grove_addons`. See :ref:`qwiic_stemma_grove_addons`.
A link to the appropriate I2C controller can be found at ``/dev/play/qwiic/i2c``. A link to the appropriate I2C controller can be found at ``/dev/play/qwiic/i2c``.
.. todo::
The above link may changed or outdated!!
OLED Display using QWIIC
=========================
Let's see a simple way to use an I2C QWIIC OLED from Sparkfun with only minor
modifications to the source code. (They will probably have this working by default in the future)
The Sparkfun Qwiic OLED Display Library Comes in 3 Parts:
- QWIIC_I2C_Py - We will need to modify this
- QWIIC-OLED-Base
- QWIIC-OLED-Display
The reason we need to modify Qwiic_I2C_Py is that by default, the library expects only one
I2C Bus to be present for something like a Raspberry Pi, but our Beagle has many!
Specifically, we want to use I2C-5 which is the bus connected to the QWIIC header.
Wiring/Connection
===================
Make the connection as shown below.
.. figure:: images/qwiic/beagleplay-qwiic-oled-connection.*
:width: 600
:align: center
:alt: BeaglePlay QWIIC OLED Connection
BeaglePlay QWIIC OLED Connection
You can check what bus a device is connected to by scanning it.
First lets see what buses are available.
.. code:: shell-session
debian@BeaglePlay:~$ ls /dev/ | grep "i2c"
i2c-0
i2c-1
i2c-2
i2c-3
i2c-5
You can now scan each bus as follows:
.. code:: shell-session
i2cdetect -y -r 0
The ``0`` corresponds to ``i2c-0``. we can then replace ``0`` with each bus untill we find the oled,
in this case, we know we are looking for a device at address ``0x3C``.
.. code:: shell-session
debian@BeaglePlay:~$ i2cdetect -y -r 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Note that when we see a ``UU``, this indicates that there is a device which is
currently being used by another linux process.This is most likely another I2C device that
the Beagle uses, such as the EEPROM. You can safely ignore this, but it's helpful to know
what you're looking at.
Moving on, let's see Bus 5 (Hint, I2C-5 is the QWIIC connector):
.. code:: shell-session
debian@BeaglePlay:~$ i2cdetect -y -r 5
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Using Python libraries to display on OLED.
===========================================
let's install sparkfun Qwiic_I2C_Py Library.
.. code:: shell-session
git clone https://github.com/virtualRadish/Qwiic_I2C_Py_LC
Change directory to ``Qwiic_I2C_Py_LC``.
.. code:: shell-session
cd Qwiic_I2C_Py_LC/
Install ``setup.py``.
.. code:: shell-session
sudo python setup.py install
Install python libraries for OLED Displays.
.. code:: shell-session
sudo pip install sparkfun-qwiic-oled-base
sudo pip install sparkfun-qwiic-oled-display
Let's create a file ``HelloWorld.py`` to display some text on display.
.. code:: shell-session
nano HelloWorld.py
Now copy paste the text below, then press CTRL+O and ENTER to save, CTRL+X to exit.
.. code:: shell-session
from __future__ import print_function
import qwiic_oled_display
import sys
import time
def runExample():
# These three lines of code are all you need to initialize the
# OLED and print the splash screen.
# Before you can start using the OLED, call begin() to init
# all of the pins and configure the OLED.
print("\nSparkFun OLED Display - Hello World Example\n")
# Create instance with parameters for Qwiic OLED Display
myOLED = qwiic_oled_display.QwiicOledDisplay(0x3C)
if not myOLED.connected:
print("The Qwiic OLED Display isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
myOLED.begin()
# clear(ALL) will clear out the OLED's graphic memory.
myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
# To actually draw anything on the display, you must call the display() function.
myOLED.display() # Display buffer contents
time.sleep(1)
# clear(PAGE) will clear the SBC display buffer.
myOLED.clear(myOLED.PAGE) # Clear the display's buffer
# Display buffer contents
myOLED.display()
time.sleep(1)
# Print "Hello World"
# ---------------------------------------------------------------------------
# Add text
myOLED.print("Hello World!")
myOLED.set_cursor(0, 10) # Set cursor to top-left
myOLED.print("I'm BeaglePlay!")
# Display buffer contents
myOLED.display()
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit) as exErr:
print("\nEnding OLED Hello Example")
sys.exit(0)
Now run it. After executing following command, "Hello World!" in first line and "I'm BeaglePlay!"
in second line will be printed on OLED display.
.. code:: shell-session
python HelloWorld.py
.. figure:: images/qwiic/beagleplay-qwiic-oled-helloworld.*
:width: 600
:align: center
:alt: BeaglePlay QWIIC OLED HelloWorld.py Output
BeaglePlay QWIIC OLED HelloWorld.py Output
Now, lets display our current IP Address.
Shout out out to `this <https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib>`_ StackOverflow one-liner which gets our IP Address cleanly so we can
display it as a string:
.. code:: shell-session
ipAddr = ((([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0]
[1]]) + ["no IP found"])[0])
Additionaly in above text we can display our current IP Address using below script.
You can create a new file then copy paste it and run.
.. code:: shell-session
from __future__ import print_function
import qwiic_oled_display
import sys
import time
import socket
def runExample():
IPAddr=(([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) + ["no IP found"])[0]
# These three lines of code are all you need to initialize the
# OLED and print the splash screen.
# Before you can start using the OLED, call begin() to init
# all of the pins and configure the OLED.
print("\nSparkFun OLED Display - Hello World Example\n")
# Create instance with parameters for Qwiic OLED Display
myOLED = qwiic_oled_display.QwiicOledDisplay(0x3C)
if not myOLED.connected:
print("The Qwiic OLED Display isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
myOLED.begin()
# clear(ALL) will clear out the OLED's graphic memory.
myOLED.clear(myOLED.ALL) # Clear the display's memory (gets rid of artifacts)
# To actually draw anything on the display, you must call the display() function.
myOLED.display() # Display buffer contents
time.sleep(1)
# clear(PAGE) will clear the SBC display buffer.
myOLED.clear(myOLED.PAGE) # Clear the display's buffer
# Display buffer contents
myOLED.display()
time.sleep(1)
# Print "Hello World"
# ---------------------------------------------------------------------------
# Add text
myOLED.print("Hello World!")
myOLED.set_cursor(0, 10) # Set cursor to top-left
myOLED.print("I'm BeaglePlay!")
myOLED.set_cursor(0, 25) # Set cursor to top-left
myOLED.print("My IP Is:")
myOLED.print(IPAddr)
# Display buffer contents
myOLED.display()
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit) as exErr:
print("\nEnding OLED Hello Example")
sys.exit(0)
You will now see current IP Address as well on OLED display.
.. figure:: images/qwiic/beagleplay-qwiic-oled-ipaddress.*
:width: 600
:align: center
:alt: IP Address on QWIIC OLED Display
Credits: `Andrei Aldea, Nishka Rao, Brian Berner <https://www.hackster.io/506688/beagleplay-qwiic-oled-hello-world-ee7270>`_
\ No newline at end of file
...@@ -161,6 +161,51 @@ Understanding the code ...@@ -161,6 +161,51 @@ Understanding the code
<4> Wait 1 Second <4> Wait 1 Second
Blink an LED using Python
*************************
Using python you can write a script to blink an LED.
First you need to install ``python3-libgpiod`` using the command below,
.. code:: console
sudo apt-get install python3-libgpiod
Now, create a python file ``blinky.py`` and open it using ``nano`` editor using the command below,
.. code:: console
nano blinky.py
Copy the script below and paste it to the ``blinky.py`` file.
.. code-block:: console
:caption: blinky.py
import gpiod
import time
chip=gpiod.Chip('gpiochip2')
lines = chip.get_line(14)
lines.request(consumer='beagle', type=gpiod.LINE_REQ_DIR_OUT, default_val=0)
while True:
lines.set_value(1)
time.sleep(1)
lines.set_value(0)
time.sleep(1)
Press ``CTRL+O`` & ``ENTER`` to save the ``blinky.py`` script and then ``CTRL+X`` to exit.
To run the ``blinky.py`` script execute the command below,
.. code:: console
python blinky.py
After running the code you can see the LED connected to ``GPIO14`` or ``HAT Pin 08`` blinking.
Read a Button Read a Button
************** **************
......
...@@ -80,8 +80,9 @@ If using an original BeagleBone or PocketBeagle, you are done. ...@@ -80,8 +80,9 @@ If using an original BeagleBone or PocketBeagle, you are done.
If using BeagleBone Black, BeagleBone Blue, BeagleBone AI, BeagleBone AI-64, BeaglePlay or other board with on-board eMMC If using BeagleBone Black, BeagleBone Blue, BeagleBone AI, BeagleBone AI-64, BeaglePlay or other board with on-board eMMC
flash and you desire to write the image to your on-board eMMC, you'll need to follow the flash and you desire to write the image to your on-board eMMC, you'll need to follow the
instructions at http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Flashing_eMMC. instructions at http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Flashing_eMMC.
When the flashing is complete, all 4 USRx LEDs will be steady off and possibly During flash all 4 USRx LEDs will show sequential chaser pattern. When the flashing is complete, all 4 USRx LEDs will be
power down the board upon completion. This can take up to 45 minutes. Power-down your board, remove the SD card and apply power again to finish. steady off and possibly power down the board upon completion. This can take up to 45 minutes. Power-down your board,
remove the SD card and apply power again to finish.
Start your Beagle Start your Beagle
***************** *****************
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment