This page contains some example code. A very simple example is shown as source code here. The other examples are described in text form. Find the corresponding source code and pre-compiled binaries in the folder examples.
Feel free to send your testing code (max. 200 LOC) to the author for extending this section:
Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
The following examples are designed to run in text mode at the console.
This example operates the driver in IO mode. Default settings are used to read the analog input lines AIN 0 to 7 and output 13 lines of sampled data at the console. It's designed as a minimal example to show the basic code.
The output of the program looks like (FreeBASIC version)
First the source code of the FreeBASIC version (unfortunately with incorrect syntax highlighting - this Doxygen version cannot switch off the highlighting):
And here's a similar version in C syntax:
This example shows how to get information about the original devices configurations. It creates a new PruIo instance and analyses the original (initial) configuration of the devices GPIOs, Control Module and ADC. It's designed to run in console mode and stops after printing out a listing like
A similar version in C syntax is included named analyse.c.
This example shows how to get input from digital and analog devices. It creates a new PruIo instance and prints out the state of all the digital and analog lines. It's designed to run in console mode and creates continuous output like
The first line is a scale to support identifying the bit positions. The next four lines show the state of the GPIOs 0 to 3. The last line is the sampled ADC data form AIN 0 to 7 as hexadecimal values in 16 bit format.
You can watch the heartbeat (user LED 0) in the third line (GPIO-1, bit 21). The last analog value (AIN7) is the measured voltage on the board (it should be the half of 3.3 V: &hEE80 * 1.8 V / (4095 SHL 4) = 1.677 V).
To quit the program press any key.
A version in C syntax is included named io_inout.c. This version prints out all values in one line and uses octal numbers for the GPIO state, instead of binary numbers.
This example shows how to unlock and control an internal CPU ball. It creates a new PruIo instance and unlocks the User3 LED ball as output. Then it continuously blinks this LED in SOS code (short, short, short - long, long, long - short, short, short). The output looks like:
The blinking code may get disturbed by the system (kernel), which is also blinking the LED on mmc1 interrupts. Execute the mentioned command to get rid of this interferences. (Replace 'none' by 'mmc1' to restore the original configuration.)
To quit the program press any key.
A similar version in C syntax is included named sos.c.
This example shows how to use header pins as output. It creates a new PruIo instance and sets four header pins in output mode to control a stepper motor. Connect a common GRND and the inputs of the stepper driver board to pins H8_08, H8_10, H8_12 and H8_14. Ie. use a x113647 driver board and a 28BYJ-48 stepper motor. (Note: the header pin output is 3.3 V by a maximum current of 5 mA). This program is designed to run in console mode and prints out user information like
The user can control speed and direction of the motor by pressing the listed keys. Ie. press
and so on. Any other (not listed) keystroke quits the program.
A similar version in C syntax is included named stepper.c.
The following examples are designed to run in grafic mode. They open a grafic window. You need a display connected to the Beaglebone (ie. a HDMI monitor). Sorry, no C versions (due to long and complex code for grafics).
This example shows how to receive fast ADC input in IO mode. It opens a grafic window and creates a new PruIo instance for drawing continuously the sampled analog data from all channels (AIN0 to AIN7) as line grafic with colored lines. By default it creates a full screen window without a frame. You can customize the window by setting the size as command line option (ie like ./oszi 640x400
for width = 640 and hight = 400).
The grafic is scaled 0 V at the bottom and 1.8 V at the top. You can toggle the channels on or off by pressing keys 0 to 7 (0 = AIN0, ... 7 = AIN7), but you cannot de-activate the last channel (at least one channel stays active). Key '+' restores the default setting (all channels active). Any other key quits the program.
The less channels are activated, the faster the ADC device samples the data. Ie. check it by connecting a constant frequency sine wave (0 to maximal 1.8 V) to a channel and switch off the others one by one.
This example shows how to use triggers to start a measurement in MM mode and how to customize an ADC step (for the analog trigger 2). It opens a grafic window and creates a new PruIo instance for MM. By default it creates a full screen window without a frame. You can customize the window by setting the size as command line option (ie like ./triggers 640x400
for width = 640 and hight = 400).
The grafic is scaled 0 V at the bottom and 1.8 V at the top. The sampling rate is 1 kHz. You can start a measurement of two channels (AIN4 and AIN7) by a trigger. Choose one of the trigger types form the menu
Further keystrokes (other than 0 to 3) quit the program.
After choosing a trigger type (1 to 3), the program waits for the trigger event. So make sure to prepare a cable to connect header pins before testing.
Here's an instruction how you can test the program. First, execute the binary with a customized window size by
and you'll see the above mentioned menu in an empty grafic window. The next steps depend on the trigger to test:
0 = no trigger (start immediately)
1 = GPIO trigger (pin P8_07)
waiting for GPIO trigger (pin P8_07 low) ...
. Nothing else happens.2 = analog trigger (AIN4 > 0.9 V)
waiting for analog trigger (AIN4 > 0.9 V) ...
. Nothing else happens.3 = analog pre-trigger (any AIN < 0.9 V)
waiting for analog pre-trigger (any AIN < 0.9 V) ...
. Nothing else happens.