- Marián Hubinský
- Technologies
- 3903 views
Pascal wrapper of the usbDrDaqApi.h for Free pascal, Lazarus and maybe Delphi.
What do you need to start using the DrDAQ with Pascal?
- Windows
- Install Freepascal or Lazarus
- Install Picoscope / Picolog program or PicoSDK from: www.picotech.com/downloads
- download usbDrDaqApi.pas and PicoStatus.pas and include them in your sorce code
- Linux / Raspbian
- Install Picoscope program or Linux Drivers from: www.picotech.com/downloads/linux
- follow instructions on page above for setting permissions
- download usbDrDaqApi.pas and PicoStatus.pas and include them in your source code
- good place for reading is also usbdrdaqCon.c from Pico SDK
For testing the driver installation and DrDAQ connection, you may use my program DrDAQ_cnt below.
Programming manual Pico-DrDAQ-pmen.pdf and a piece of working brain.
Example source code with comments:
program example_drdaq;
uses sysutils, usbDrDaqApi, PicoStatus;
var
DrDAQhandle : int16;
ivalue : int16;
overflow : word;
InfoStr : array[0..63] of char;
Status : PICO_STATUS;
fValue : single;
begin
Status := UsbDrDaqOpenUnit(DrDAQhandle); //try to open DrDAQ
if Status = 0 then //opened succesfully
begin
UsbDrDaqEnableRGBLED(DrDAQhandle,1); //enable RGB LED
UsbDrDaqSetRGBLED(DrDAQhandle, 0, 40, 0); //set little bit of GREEN
UsbDrDaqSetSigGenBuiltIn(DrDAQhandle, 0, 1000000, 56, USB_DRDAQ_SINE); //set signal generator to 1 Vpp, 56 Hz, Sine
UsbDrDaqGetSingle(DrDAQhandle, USB_DRDAQ_CHANNEL_LIGHT, ivalue, overflow); //read raw value from light sensor
Writeln('Light sensor raw output: ', ivalue);
UsbDrDaqSetScalings(DrDAQhandle, USB_DRDAQ_CHANNEL_TEMP, 0); //set Degree Celsius scale
UsbDrDaqGetSingleF(DrDAQhandle, USB_DRDAQ_CHANNEL_TEMP, fvalue, overflow); //read single floating value
Writeln('Temperature sensor output: ', format('%4f '#$00b0'C',[fvalue*0.1]));
Status := UsbDrDaqGetUnitInfo(DrDAQhandle, InfoStr, 64, ivalue, PICO_BATCH_AND_SERIAL); //read info string
Writeln('DrDAQ batch and serial: ',InfoStr);
UsbDrDaqCloseUnit(DrDAQhandle);
end
else Writeln('Error during open: ',Status);
end.
Possible issues:
- Windows
- check correct DLL architecture 32/64 bit
- Linux
- If you get issues with library 'libusbdrdaq.so.2' under linux try one of the following options:
- in Lazarus project options: Compiler Options -> Paths -> Libraries add
/opt/picoscope/lib/libusbdrdaq.so.2.0.0
- Create symlink in folder where is your program compiled, pointing to
/opt/picoscope/lib/libusbdrdaq.so.2.0.0
with this command while you are in your binary output folder:ln -s /opt/picoscope/lib/libusbdrdaq.so.2.0.0 libusbdrdaq.so.2
and from Lazarus project options: Compiler Options -> Compilation and Linking:
Enable setting: "Pass options to linker with "-k", delimiter is space" and add:-R ./
- try to run as root
Pascal version of usbDrDaqApi.h file usbDrDaqApi.pas and PicoStatus.h as well PicoStatus.pas.
Example project for Lazarus: picoDrDaq-Lazarus.zip.
Program for testing Driver installation and USB connection, source code DrDAQ_cnt.lpr (download and compile by command fpc DrDAQ_cnt.lpr). Complete project in single archive: DrDAQ_cnt.zip. Tested under Linux x64, Raspbian on Raspi 3B+, Win32 and Win64.
Compiled binaries
- Raspbian: DrDAQ_cnt-arm
- Linux x64 DrDAQ_cnt-x86_64
- Win32 DrDAQ_cnt-i386.exe
- Win64 DrDAQ_cnt-x86_64.exe
Some useful files are also in https://www.elso.sk/download/pico/
Raspbian - driver quick installation
type following commands into terminal window:
- download driver from Picotech website:
wget https://labs.picotech.com/debian/pool/main/libu/libusbdrdaq/libusbdrdaq_2.0.40-1r2131_armhf.deb
- install downloaded file:
sudo dpkg -i libusbdrdaq_2.0.40-1r2131_armhf.deb
- download compiled test program:
wget https://www.elso.sk/drdaq/DrDAQ_cnt-arm
- set execute bit:
chmod -x DrDAQ_cnt-arm
- run it:
./DrDAQ_cnt-arm