libpruio (BB D/A - I/O fast and easy)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
mcorrea
Posts: 1
Joined: Feb 06, 2017 11:33

Re: libpruio (BB D/A - I/O fast and easy)

Postby mcorrea » Feb 16, 2017 14:29

Mr TJF, thanks for the explanation and for the libary. It is super functional to serius projects. You can see below my code that reads two ADC channels and after the reading it prints the values.

I'd like to efetuate some electrical measurements with the values. To do that, I'd like to write all the algorithms using Pyton or C in the Cloud9. I have to access the variable v1[] and v2[] in the code bellow which uses the libpruio and runs at the PRU.

How could I do this? I mean, how could I acces these values and use then in aprogram witten in C/C++ or Pyton in the Cloud9?


Code: Select all

#include "../c_wrapper/pruio.h" // include header   // Include libaries
#include "time.h"   
   
int main(int argc, char **argv)   
{   
 float n[256];   //Declaration of variables
float v1[128];   
float v2[128];   
 int i = 0;   
   
  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 0);   //Create a new driver structure
  pruio_adc_setStep(io, 9, 1, 0, 0, 0);    //Step 9, AIN-0
  pruio_adc_setStep(io, 10, 2, 0, 0, 0);   //Step 10, AIN-1
   
  if (pruio_config(io, 128, 3<<9 , 156250, 4)){    // upload settings: 128 samples, 6250 Hz, 16 bits
                              printf("config failed (%s)\n", io->Errr);}   
  else {   
   
  if (pruio_rb_start(io)) printf("rb_start failed (%s)\n", io->Errr); // start measurement   //Starts the rb_mode
   
  else{   
        sleep(1);   //One second breathing
        do{   
                if(io->DRam[0] == (i)){   //Logic to fill the buffer: If Dram[0] changes, store the Adc value read.
                        n[i] = io->Adc->Value[i];   
                        i=i+1;   
                }   
        }while(i < 256);   //256 times, because the ring buffer has 128 x 2 positions
   
        for(i = 0; i<=127; i++ ){   //Logic to divide values of each ADC in two differents vectors.
         v1[i] = n[2*i];   
         v2[i] = n[2*i +1];   
        }   
   
        printf("adc1*************\n");   //Print the value of the AIN0
        for(i=0; i<=127; i++){   
         printf("%f \n", v1[i]*1.8/65536);   
         }   
   
        printf("\n adc2*************\n");   //Print the value of the AIN1
        for(i=0; i<=127; i++){   
         printf("%f \n ", v2[i]*1.8/65536);   
        }   
   
}   
   
}   
  pruio_destroy(io);        /* destroy driver structure */   
        return 0;   
}   
TJF
Posts: 3340
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: libpruio (BB D/A - I/O fast and easy)

Postby TJF » Feb 16, 2017 20:32

Hi mcorrea, sorry i don't understand your question.

mcorrea wrote:... To do that, I'd like to write all the algorithms using Pyton or C in the Cloud9. I have to access the variable v1[] and v2[] in the code bellow which uses the libpruio and runs at the PRU.

This code does not run at the PRU. It runs at the ARM CPU.

mcorrea wrote:How could I do this? I mean, how could I acces these values and use then in aprogram witten in C/C++ or Pyton in the Cloud9?

You're already running C code. If you want to use Python instead, you can either create a Python binding by transforming the C header with SWIG. Or check out the CType based Python bindings, which you can find here.

Regards
TJF
Posts: 3340
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: libpruio (BB D/A - I/O fast and easy)

Postby TJF » Feb 17, 2017 7:03

@mcorrea

One more hint: I wonder why you use RB mode. RB mode is designed for use cases with continuous measurements, when the amount of data is bigger than the ERam size (which is 256k by default). Another use case is when evaluation of the data must happen during the measurement.

In your case you sample 256 values (= 512 bytes) and then quit the program. When you use MM mode instead, the code gets much easier (untested):

Code: Select all

#include "../c_wrapper/pruio.h" // include header   // Include libaries
#include "time.h"

int main(int argc, char **argv)
{
  int i = 0;

  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 0);   //Create a new driver structure
  pruio_adc_setStep(io, 9, 1, 0, 0, 0);    //Step 9, AIN-0
  pruio_adc_setStep(io, 10, 2, 0, 0, 0);   //Step 10, AIN-1

  if (pruio_config(io, 128, 3<<9 , 156250, 4)){    // upload settings: 128 samples, 6400 Hz, 16 bits
                              printf("config failed (%s)\n", io->Errr);}
  else {
    if (pruio_mm_start(io, 0, 0, 0, 0)) printf("mm_start failed (%s)\n", io->Errr); // start measurement   //Starts in mm_mode

    else{
      printf("adc1*************\n");   //Print the value of the AIN0
      for(i = 0; i < io->Adc->Samples; i += io->Adc->ChAz)
        printf("%f \n", (io->Adc->Value[i] * 1.8 / 65520));

      printf("\n adc2*************\n");   //Print the value of the AIN1
      for(i = 1; i < io->Adc->Samples; i += io->Adc->ChAz)
        printf("%f \n", (io->Adc->Value[i] * 1.8 / 65520));
    }
  }
  pruio_destroy(io);        /* destroy driver structure */
  return 0;
}


Regards
chenhx
Posts: 1
Joined: Mar 19, 2018 16:57

Re: libpruio (BB D/A - I/O fast and easy)

Postby chenhx » Mar 19, 2018 17:05

Hi,

I meet an error in building cmakefbc.

---------
Make Error at doxy/CMakeLists.txt:6 (INCLUDE):
include could not find load file:

UseFb-Doc


CMake Error: Could not find cmake module file: CMakeDetermineFbcCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_Fbc_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_Fbc_COMPILER
CMake Error: Could not find cmake module file: /home/debian/cmakefbc/CMakeFiles/3.5.2/CMakeFbcCompiler.cmake
CMake Error at cmakefbc_deps/CMakeLists.txt:4 (PROJECT):
No CMAKE_Fbc_COMPILER could be found.

Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_Fbc_COMPILER to the full path to the compiler, or to the compiler
name if it is in the PATH.


CMake Error: Could not find cmake module file: CMakeFbcInformation.cmake
CMake Error: CMAKE_Fbc_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/home/debian/cmakefbc/CMakeFiles/CMakeOutput.log".
--------

uname -a
Linux beaglebone 4.4.113-ti-r148 #1 SMP Wed Mar 7 19:19:19 UTC 2018 armv7l GNU/Linux

I don't know what is the problem. I tried both cmake 2.8.3 and cmake 3.5.2, but they don't work.....
TJF
Posts: 3340
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: libpruio (BB D/A - I/O fast and easy)

Postby TJF » Mar 28, 2018 8:13

Hi chenhx, welcome to the forum!

First, sorry for the late answer. I got the notification on your post just today.

You didn't mention it, but I guess you're using the libpruio-0.4 version from https://github.com/DTJF/libpruio.

chenhx wrote:Make Error at doxy/CMakeLists.txt:6 (INCLUDE):
include could not find load file:

UseFb-Doc

There's a problem in the cmakefbc installation on your system. CMake tries to load the script UseFb-Doc.cmake, but couldn't find it in the CMAKE_MODULE_PATH.

chenhx wrote:...
CMake Error: Could not find cmake module file: /home/debian/cmakefbc/CMakeFiles/3.5.2/CMakeFbcCompiler.cmake
CMake Error at cmakefbc_deps/CMakeLists.txt:4 (PROJECT):

Either install cmakefbc for the 3.5.2 version.

Or use the cmake files shipped with the libpruio package by executing the preparing command

Code: Select all

cmake . -DCMAKE_MODULE_PATH=./cmake/Modules


for in-source builds, or for out-of-source in a subfolder in the projects directory

Code: Select all

mkdir build
cd build
cmake .. -DCMAKE_MODULE_PATH=../cmake/Modules

Good luck!
TJF
Posts: 3340
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

libpruio version 0.6 is out now

Postby TJF » Sep 12, 2018 19:32

Image

Major highlights:

  • Debian packages, easy installation
  • Python bindings and examples available
  • Pinmuxing faster and unlimited
It's tested on kernel 3.8.13 and several 4.x versions (-bone and -ti).

1) Packages

Arend Lammertink created Debian packages and hosts them at his server. The following resources are available:

Code: Select all

   Size | Package                      | Description

1291932 | libpruio_0.6.0.tar.xz        | source code
  45686 | libpruio_0.6.0_armhf.deb     | shared lib binary and LKM
  80620 | libpruio-bin_0.6.0_armhf.deb | executable examples
  18552 | libpruio-dev_0.6.0_armhf.deb | examples/bindings C
  27626 | libpruio-bas_0.6.0_armhf.deb | examples/bindings FreeBASIC
  17902 | python-pruio_0.6.0_armhf.deb | examples/bindings Python
4083394 | libpruio-doc_0.6.0_all.deb   | documentation
(Size may vary, just a rough marker for the download volume.)

In order to download them from the PPA, add it to your sources list

Code: Select all

sudo echo "deb http://beagle.tuks.nl/debian jessie" > /etc/apt/sources.list.d/tuks.nl.list
sudo echo "deb-src http://beagle.tuks.nl/debian jessie" >> /etc/apt/sources.list.d/tuks.nl.list
(In case of 3.8 kernel replace 'jessie' by 'wheezy'.)

Then grep the security keyring by

Code: Select all

wget -qO - http://beagle.tuks.nl/debian/public.key | sudo apt-key add -

and install as usual

Code: Select all

sudo apt-get install libpruio-dev # development in C programming language
sudo apt-get install libpruio-bas # development in FreeBASIC
sudo apt-get install python-pruio # development in Python
sudo apt-get install libpruio-doc # common documentation
sudo apt-get install libpruio-bin # test pre-compiled examples (!read docs first!)

All these packages depend on the binary package 'libpruio'. The -lkm package installs a new system group on your box, named 'pruio'. Note: removing the package does not remove this group (a Debian policy). Find details in the online docs.

2) Python

Python bindings are now shipped in the 'python-pruio' package. It also contains example source code (the reduced C set).

Packing for several Python versions is a mess, and out of my league. My solution: the code installs to folder '/usr/share/doc/python-pruio/examples'. Copy that directory to your working directory, and there execute the source code with your prefered Python version.

It's my first Python experience, so please be patient and report in case of trouble.

3) Pinmuxing

This version has advanced pinmuxing capabilities. It doesn't need a punmux-helper device tree overlay any more. The remaining overlay action is enabling the PRUSS and loading the `uio_pruss` driver, ie by the following configuration in file '/boot/uEnx.txt':

Code: Select all

enable_uboot_overlays=1
uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo
#enable_uboot_cape_universal=1

Instead libpruio uses its own loadable kernel module. This fixes the kernel 4.x PWMSS bug and can set all modes for all header pins, which are not claimed by the kernel. You don't need cape_universal* overlays any more. This speeds up boot time and reduces kernel memory footprint. (The wheezy -lkm package is broken, you've to install from source - sorry.)

The package manager installs a new system user group named 'pruio' at your box. Make yourself a member of that group and you can do pinmuxing from user space (without administrator privileges). Therefor execute 'sudo adduser <YourUserID> pruio'

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest