Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW BCM2835 Library for Raspberry Pi

Overview

The LabVIEW BCM2835 library expands the GPIO interface with the Raspberry Pi (RPi) 2/3 over and above what is available with the MakerHub LINX package. The original C library was created by Mike McCauley (and others) and can be found at this link. This library has been converted to a Linux shared object which is compatible with LabVIEW-LINX. The LabVIEW library is built using this shared object as a base, and it consists of a range of functions which interface with the shared object using Call Library Function Nodes.

 

Main Pinout.png

The figure above illustrates the GPIO and alternative modes that are available with the library; this is header J8 on the RPi 3. The functionality offered by the LabVIEW library is as follows:

  • All 26 GPIO pins are available as input/outputs, with the exception that GPIO2 and 3 (pins 3 and 5) cannot be configured as inputs with internal pull-down resistors because of the onboard I2C pull-up resistors.
  • When configured as inputs, the GPIOs can be configured with internal pull-up or internal pull-down resistors.
  • A 'Set-Clear Multi' VI is available to simultaneously set or clear a range of  GPIOs.
  • A 'Write Multi' VI is available to simultaneously write 0 or 1 to a range of GPIOs.
  • Event detection is available on GPIOs configured as inputs, with options of high/low level detection, synchronous rising/falling edge detection, and asynchronous rising/falling edge detection.
  • The two PWM channels, 0 and 1, can be enabled, with two output pins available for both channels. PWM0 appears on pins 12 and 32; PWM1 appears on pins 33 and 35.
  • The SPI chip select signals SPI_CE0_N and SPI_CE1_N are available for use. (These are not useable on LINX)
  • I2C functionality is available, with similar functionality to LINX I2C.

 

 

Palette Details

When the library is installed it can be found in the Addons menu on the block diagram:

 

Main.png

Three main VIs are found in this first palette:

  • Initialize: Opens the BCM2835 library. Must be called before accessing any other function in the library. It will return an error if the library cannot be opened.
  • Init + Version: Identical  to 'Initialize', except that it also returns the library version embedded in the C-code("10050", which is version 1.5). Note that this version number has nothing to do with the LabVIEW VIPM version number. This VI can be used instead of 'Initialize'.
  • Close: Must be used when the program ends to release the library and any resources.

 

GPIO Palette

GPIO.png

 

The standard GPIO VIs are:

  • GPIO Function: Used to set a GPIO to input, output, or one of its ALT modes.
  • GPIO Pullup: Sets the internal pull-up resistor for a GPIO to pull-up, pull-down, or off.
  • Set-Clear GPIO: Sets (logic 1) or clears (logic 0) a single GPIO.
  • Write GPIO: Similar to Set-Clear GPIO, writes a '0' or '1' to a single GPIO.
  • GPIO Level: Reads back the level of a GPIO. Works whether the GPIO is an input or output.

 

 

GPIO Multi

  • Set-Clear Multi: Simultaneously sets or clears a range of selected GPIOs.
  • Write Multi: Simultaneously writes to a range of selected GPIOs. More flexible than 'Set-Clear Multi', as some GPIOs can be set high and others set low.
  • Write Mask: Similar to 'Write Multi', as it simultaneously writes to a range of selected GPIOs. It is however more complicated than 'Write Multi' though, as 'Set-Clear GPIO' or 'Set-Clear Multi' must be used to clear GPIOs. The 'Write Multi' VI is recommended over 'Write Mask'.

 

 

Event Detect

  • Set Event Detect: Sets the event detection mode on an input, with options of high/low level detection, synchronous rising/falling edge detection, and asynchronous rising/falling edge detection.
  • Check Event Status: Check whether the set event has been detected on a GPIO.
  • Clear Event Status: Clears the GPIO event in the event status register.
  • Clear Event Detect: Clears the event detection mode on the GPIO. Use when ending the program to reset the pin back to normal.
  • Multi Check Event Status: Checks for detected events on a range of GPIOs.
  • Multi Clear Event Status: Clears the detected events for a range of GPIOs.

 

 

PWM Palette

PWM.png

The PWM VIs are:

  • PWM Clock: Sets the PWM clock divider, which effectively sets the highest PWM frequency available and the resolution of the PWM signal.
  • Set PWM Pin: Sets the PWM channel/pin to use. Options are PWM0 on pins 12 and 32, and/or PWM1 on pins 33 and 35.
  • PWM Mode: Sets the PWM mode to 'Mark-space' or 'Balanced', and also includes a control to turn the PWM signal on or off. Note that only 'Mark-space' mode has been tested. Users are free to experiment with 'Balanced' mode.
  • PWM Set Timing Parameters: Sets the timing of the PWM signal in terms of frequency and duty-cycle, or period and duty-cycle.

 

 

SPI Palette

SPI.png

 

The SPI VIs are:

  • SPI Open: Must be used before other SPI VIs to enable SPI functionality.
  • SPI Configure: Configures SPI settings such as chip select, data mode, etc. Note that in terms of bit order, only 'MSB First' is supported in the library.
  • SPI Data Transfer: Used to transfer data between the RPi (SPI master) and a SPI slave device.
  • SPI Close: Use when the program is ending to release SPI resources.

 

 

I2C Palette

I2C.png

The I2C VIs are:

  • I2C Open: Must be used before other I2C VIs to enable SPI functionality.
  • I2C Configure: Sets the slave device address and the I2C clock speed. The clock speeds available are 100kHz, 400kHz, 1MHz, 1.666MHz, and 1.689MHz. If only one slave device is used in the system, then this function only needs to be used once, at the start of the program. If more than one I2C slave devices are used, then this function needs to be used every time a different device is accessed. See the example "" for more details.
  • I2C Write: Writes a number of bytes to the I2C slave.
  • I2C Read: Reads a number of bytes from the I2C slave.
  • I2C Write-Read (Repeated Start): Implements I2C repeated start functionality. Current untested.
  • I2C Read (Repeated Start): Implements I2C read repeated start functionality. Current untested.
  • I2C Close: Use when the program is ending to release I2C resources.

 

 

Timing Palette

Timing.png

Two timing VI's are also included, although the accuracy is unverified, particularly for the microseconds function. Users are free to experiment with these timing functions. For example, the 'Delay msec' function may be used in place of the LabVIEW 'Wait ms' function,

  • Delay ms: Delays for the specified number of milliseconds.
  • Delay us: Delays for the specified number of microseconds.

 

 

Prerequisite Software

The user must have the following software/packages already on the PC before installing the BCM2835 Library and examples (refer to this document):

  • LabVIEW 2014 SP1 32-bit (Home Bundle used in this document).
  • JKI VIPM (Version 2016.0.0 build 1986 used in this document)
  • Digilent MakerHub LINX (VIPM version 3.0.1.192)

 

Supported SW and OS

  • Only LabVIEW 2014 32-bit is supported (as this is the only version supported by MakerHub LINX).
  • Only Windows OS's are supported (again, this is because MakerHub LINX is not supported on Mac/Linux).

 

Supported Hardware

  • Raspberry Pi 3 Model B
  • Raspberry Pi 2 Model B - expected to work, but untested by the author.

 

 

Installation Details

Comprehensive installation details are included in the PDF document below. Note that there are two packages:

  1. LabVIEW BCM2835 Library (lib_dm_bcm2835-0.3.6.21.vip)
  2. Examples package (dmlabview_rpi_lib_dmlv_rpi-1.2.1.12.vip)

 

It is important to install the BCM2835 library first, then the examples package.

 

The Linux shared object that the library uses must also be copied to the Raspberry Pi. Full details are given in the PDF document.

 

 

 

Comments
Member mcusir
Member

I have downloaded the relevant documents, thank you for your dedication!

Member DMurrayIRL
Member

Hi all, has anyone who downloaded the library been able to use it with an RPi 2? I want to check if it's definitely compatible with that RPi version, but don't have one to hand. Thanks...

Member 014702580369
Member

Error on my computer, help me, Thanks !asfasf.PNG

Member DMurrayIRL
Member

 

Have you installed LINX and everything else required? Look here. Also check out the LINX forums here and here.

 

 

Member 014702580369
Member

I followed the instructions but still error, help me. Thanks DMurrayIRL !aaaaaaaa.PNGeroo.PNG

Member DMurrayIRL
Member

What you have is a problem with installing LINX (and not the BCM2835 library), which I'm not involved with and so have no idea how to help you here. Your best option is to post the issue on the LINX support forums so that the developers can help you. Also, search through other posts in that forum as I think other people will have had similar issues to you. Sorry I can't be of more help, but I just don't understand enough about the LINX installation process.

 

Edit to add: Here's some posts which may help:

https://www.labviewmakerhub.com/forums/viewtopic.php?f=12&t=1429&hilit=installation#p7244

https://www.labviewmakerhub.com/forums/viewtopic.php?f=12&t=1370

Member 014702580369
Member

I'm still wrong, help me , implore DMurrayIRL Smiley Sad(nam.PNG

Member Seperthar
Member

Hi, I am having trouble with the PWM output using the PWM 1Channel example you provided. When using default settings there was no signal (see oscilloscope image with straight line and vi screenshot with clock divider 8). After playing with the settings I was able to get a readout that showed a wave with the correct frequency but an incorrect duty cycle. Upon trying to change the duty cycle during run time nothing happened (see other two images). Using the Blink example through the same port worked just fine. Any ideas on what could be causing this issue?

Working 16 clock divisionOscilloscope not workingworking.pngnot working.png

Member DougHarper
Member

Hello Derek:

 

I'd like to follow up on the question posted above by Seperthar (a student working with me at Western Kentucky University).  We have been unable to get the BCM2835 library to generate a PWM signal.  Other examples in the library such as Blink and Write Multi etc. work fine.  When we run the PWM 1 Channel example the application runs fine and doesn't generate any run time error.  However, we do not see a PWM type signal on the expected channel.  We have tested the output both with an oscilloscope and using an LED.  We tried multiple combinations of the settings including using different pins, periods, duty cycles, etc.  The only thing that seemed to change the output was that depending on the value of the Clock Divider input sometimes the output was always high, sometimes always low, and we found one combination that gave a PWM looking signal that had the correct period but the duty cycle was incorrect and we couldn't change it to other values.  

 

I notice that the documentation says ...

 

 

"The PWM functionality on the RPi 3 (and probably RPi 2 as well) drives the audio jack J7. If you have any audio SW and/or drivers driving J7, then it is unlikely that you will be able to use the PWM functionality for other purposes."

 

Is there a chance that this could be our issue?  I do not think that we have any drivers using the audio jack, but I am not sure how to tell for sure.  Or do you have any other troubleshooting recommendations that we could follow?

 

We are attempting to use the Pi to control a motor and we need a PWM signal to set the motor speed.

 

By the way, the documentation that you have provided for this project is superb.  Installation of the library was easy when following the detailed instructions with screenshots that you provided.  Thanks for the contribution to the community !!

 

Regards,

 

Doug Harper

WKU Professor of Physics, CLA

 

 

Member DMurrayIRL
Member

Hi Doug,

 

Apologies for the delay in replying to the original post. I'm very rusty on the RPi and this library as I haven't done any RPi work of late, but my first thoughts are that your circuit should be working if the other projects are working. First of all, are any errors being flagged in the VI? They should cause the program to stop, and might give a clue. If there aren't any errors then there is something going on at a more fundamental RPi level which I will struggle to help with. A possible audio conflict may indeed be the problem, but I'm not sure how to rule that out. Regarding other debug options, I was first going to suggest that you try the other PWM pins but I see you've already done that. Other questions/things to try:

 

  • Are you on RPi 3 or 2? The circuit isn't tested on RPi 2, although still I expect it to work.
  • The RPi OS may be an issue. I always used default Debian (NOOBS) builds and had no issue, but I can't guarantee that the library will be fine on other RPi OS's. Also, even with Debian, something else installed on it may be causing conflicts with PWM pins. I'm not sure how to check that. It may be worth starting with a fresh Debian NOOBS install on a different card to see if the issue is solved.
  • Also, try a different RPi (2 or 3) board if you have one available. If one works and another doesn't, swap the cards to narrow down the problem i.e. this might reveal a faulty board.
  • Rather than using LabVIEW and this library, try to get the PWM pins working using other coding methods. (Again, I haven't used RPi in a while so I'm hazy on "other methods", but a quick internet search should reveal all.) For example, if the original BCM2835 code as written by Mike McCauley doesn't work, then there is a more fundamental issue occurring (which I believe to be the case).  

I don't really have anything else to add, but let me know how you get on with any of the above.

 

Derek.

Member AWK073
Member

Running 2 examples together in one VI 

for example write mask and MCP3008 SPI example

I want to make a VI that reads 8 Channel of MCP 3008 with ''Single Ended'' setting plus in that VI I want to control other GPIO pins. for exp: To switch a PIN Low to High for switching ON/OFF a LED.

I have made this program 8 channels data is showing on labview and GPIO pin connected with LED is also Switching ON/OFF with a button.

Problem is that when I stop the program RPI3 get disconnected without giving any errors.

Can some one look at my VI to solve the problem.

I think problem is when I am using 2 ''BCM 2835 library'' close and ''LINX close''. 

https://drive.google.com/file/d/1NOlbygyEZrRoAiLxI3BmljiTd7D2hO7k/view?usp=sharing

 

 

Member dmoradi
Member

 Hi,

I am having problem using the SPI with Chip Select 1. It works fine with CS0, but when i select the CS1 it doesnt modify the actual state of the pin.

any suggestion?

Thanks 

Davood

Member WrenchHand77
Member

If anybody else is having trouble with the PWM functionality, I can confirm that following the first two steps in this link explaining how to disable the default audio driver fixed the problem for me.  

 

Thanks for all your hard work on this Derek.  It saved my Sr. Design project from the jaws of disaster.  

 

Member Bstryk
Member

Disabling the audio driver FINALLY fixed my PWM issues.  Wish I would have seen this post weeks ago. 

Member JAGod
Member

Hello

I want to develop a raspberry based device that communicates with LabVIEW using your libraries.

So far, your libraries works great but I need to interact with GUI in the raspberry operative system (Raspbian PIXEL) designed on LabVIEW but I´m not able to do that.

My question is: how can I deploy an application (LabVIEW + BCM2835) on a raspberry and interact with it Raspbian SO trough ??.