This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1015-Q1: ADS1015 - linux/libiio issue while creating buffer

Part Number: ADS1015-Q1
Other Parts Discussed in Thread: ADS1015

Hi,

I am having issues using libiio to read from ADS1015.

I can get access to the context and the device. I can even enable the desired channels but when I run the function to create the buffer  iio_device_create_buffer I'm always getting a null.

It is displaying errno 22  : Invalid argument

I use this function (iio_channel_is_scan_element) to make sure that the channels are buffer capable.

iio_info output : 

iio:device2: ads1015
9 channels found:
voltage0-voltage1: (input, index: 0, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: scale value: 3.000000000
attr 1: raw value: 0
attr 2: sampling_frequency value: 128
voltage0-voltage3: (input, index: 1, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: raw value: 0
attr 1: scale value: 3.000000000
attr 2: sampling_frequency value: 128
voltage1-voltage3: (input, index: 2, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: raw value: 0
attr 1: scale value: 3.000000000
attr 2: sampling_frequency value: 128
voltage2-voltage3: (input, index: 3, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: scale value: 3.000000000
attr 1: raw value: 0
attr 2: sampling_frequency value: 128
voltage0: (input, index: 4, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: scale value: 2.000000000
attr 1: raw value: 0
attr 2: sampling_frequency value: 3300
voltage1: (input, index: 5, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: sampling_frequency value: 3300
attr 1: scale value: 2.000000000
attr 2: raw value: 0
voltage2: (input, index: 6, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: scale value: 2.000000000
attr 1: sampling_frequency value: 3300
attr 2: raw value: 0
voltage3: (input, index: 7, format: le:s-12/16->>4)
3 channel-specific attributes found:
attr 0: scale value: 2.000000000
attr 1: raw value: 0
attr 2: sampling_frequency value: 3300
timestamp: (input, index: 8, format: le:s-64/64->>0)

code: 

nt main () {

struct iio_context* ctx = iio_create_local_context();
if (!ctx) {
  LOG(ERROR) << "No context found";
  return;
}

struct iio_device *dev = iio_context_find_device(ctx, deviceName.c_str());
if (!dev) {
  LOG(ERROR) << "ADS1015 not found";
  return;
}

struct iio_channel** voltage = new iio_channel*[4];

for (int i = 0; i < 4; i++) {
  voltage[i] = iio_device_get_channel(dev, i+4);
  LOG(INFO) << "Channel found: " << iio_channel_get_id(voltage[i]);
}

if (!voltage[0] || !voltage[1] || !voltage[2] || !voltage[3]) {
  LOG(ERROR) << "Channels not found";
  delete[] voltage;
  return;
}

LOG(INFO) << "Sample size " << iio_device_get_sample_size(dev);

for (int i = 0; i < 4; i++) {
  if (iio_channel_is_scan_element(voltage[i])) {
   iio_channel_enable(voltage[i]);
   if (iio_channel_is_enabled(voltage[i])) LOG(INFO) << "Channel enable: " << iio_channel_get_id(voltage[i]);
  }
}

LOG(INFO) << "Sample size " << iio_device_get_sample_size(dev) << " bytes";

size_t buffer_length = SAMPLE_CNT;
dev = iio_context_find_device(ctx, deviceName.c_str());
if (dev) buffer = iio_device_create_buffer(dev, buffer_length, false);

if (!buffer) {
  LOG(ERROR) << "Error creating buffer " << errno;
  delete[] voltage;
  return;
}

}

  • Jorge,


    I'm sorry, but we don't have the expertise to support your question.

    While we may put up a link to a linux driver on the website, we did not create the driver itself. Please check with the linux community to see if they can help with this invalid argument error.


    Joseph Wu