Connecting to BeagleBone Black Hardware

You can use MATLAB® to connect to and interact with BeagleBone Black hardware. For example, you can:

  • Control onboard LEDs.

  • Read and write values to GPIO pins.

  • Read voltage values from analog input (ADC) pins.

  • Write values to PWM pins.

  • Connect to devices that are connected to:

    • Serial port

    • I2C interface

    • SPI interface

  • Take still images using the web camera.

  • Use the Linux® command shell.

When you create a connection to the BeagleBone Black hardware, you assign that connection to a object whose name you specify. For example:

bbb = beaglebone

Use the object to control the BeagleBone Black hardware. For example, you can use the object to illuminate an LED or read the logical state of a GPIO pin:

writeLED(bbb,'usr0',1)
readDigitalPin(bbb,'P9_12')

You can also use the object to create a connection to serial, I2C, and SPI devices attached to the BeagleBone Black hardware. For example, you can create a connection to a serial device and assign that connection to a object:

serial = beaglebone.serialdev(bbb,'/dev/ttyO1',9600)

A connection remains active until you clear all of the objects that use the connection. You cannot create a new connection to a board while the previous connection to the same board is active. In the preceding examples, the bbb and serial objects use the same connection. Even if you clear bbb, the connection remains active while serial exists. Trying to create a new connection produces an error.

clear bbb
bbb2 = beaglebone
Error using beaglebone (line 146)
An active connection to beaglebone-computername already exists. 
You cannot create another connection.
Clearing serial closes the connection. You can then create a new connection to the BeagleBone Black hardware without producing an error.
clear serial
bbb2 = beaglebone

Related Topics