I'm trying to detect air bubbles in water pipes and want to use an FDC2114 Capacitive Sensor. For my project I need to get at least 6000 SPS out of the FDC. I tried to use an Arduino Mini Pro 3,3V as well as an Raspberry Pi B+, but I never get close to this point, even if the theoretical maximum of the chip is 13,3kSPS.

I use 4,7kOhm Pullups and clock frequency is set to 400kHz.

On the Raspberry, I measured the time which passed while filling an list of 10.000 Samples: 8361704µs/10.000Samples --> 836µs/Sample --> 1196 SPS

Measuring the time with time.time() results in the given 8361704µs, while time.clock() results in 1379672µs, which means that the CPU is waiting for apprx. 7 seconds. htop is also showing process status D.

strace writes ioctl(3, _IOC(0, 0x07, 0x20, 0x00), 0xbeacaa8c) = 0, which seems to be the key why the communication is that slow, but I don't have a clue how to interpret these lines. Why is the Communication that slow, espeacially on the Raspberry which should have enough power to receive this amount of data?

#! /usr/bin/env python3
import smbus
import time

#I2C-Adress and Register of FDC2114
address = 0x2a
DATA3 = 0x06

#Open I2C-Bus
FDC = smbus.SMBus(1)

end_time1 = time.time()
start_time1 = time.time()

#Configuration of FDC2114
FDC.write_i2c_block_data(address, 0x0B, [0x00, 0x64]) #RCOUNT_CH3, See Table 20 (Data sheet)
FDC.write_i2c_block_data(address, 0x13, [0x00, 0x32]) #SETTLECOUNT_CH3, See Table 28 (Data sheet)
FDC.write_i2c_block_data(address, 0x17, [0x10, 0x01]) #CLOCK_DIVIDERS_CH3, See Table 32 (Data sheet)
FDC.write_i2c_block_data(address, 0x19, [0x38, 0x00]) #ERROR_CONFIG, See Table 37 (Data sheet)
FDC.write_i2c_block_data(address, 0x1B, [0x02, 0x0D]) #MUX_CONFIG, See Table 39 (Data sheet)
FDC.write_i2c_block_data(address, 0x21, [0x60, 0x00]) #DRIVE_CURRENT_CH3, See Table 41 (Data sheet) 
FDC.write_i2c_block_data(address, 0x1A, [0xD6, 0x81]) #CONFIG, See Table 38 (Data sheet), MUST be written LAST

#Function for reading Register
def readData(reg):
    data = []
    for i in range(10000):
        read = FDC.read_i2c_block_data(address, reg, 2)
        data.append(read[0] & 15)
        data[i] = data[i] << 8
        data[i] += read[1]
    return data[50]

#Read and print Register, Time Measurement  
while True:
    timedelta1 = end_time1 - start_time1
    start_time1 = time.time()
    start_time = time.time()
    end_time = time.time()
    timedelta = end_time - start_time
    end_time1 = time.time()
  • "htop is also showing process status D" -> indicates it is stuck waiting on I/O with the hardware, i.e., it is not doing anything at that time. This implies it might be the sensor itself that is the bottleneck. Have you ever had it working at the speed you believe it should work? – goldilocks Oct 13 '17 at 20:30
  • You are right, the communication itself was the problem. I changed the i2C-Clock to 800kHz, which is double of the specification. Now it's way faster than before, so the bottleneck is the I2C Communication. I found out using an oscilloscope, that the duration of an HIGH and an LOW Signal is too long. I think the solution would be to use 400kHz and change the time of HIGH and LOW, that they are exactly in the specification of the chip. But I don't know, if I have any influence of the I2C Timing of the Raspberry?. – J. Mustard Oct 16 '17 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.