Qwiic receive buffer not flushing w/ qwiic_i2c library

I have m Tsunami sound board connected to the Qwiic connector. I am programming in Python using the qwiic_i2c python library. I can read/write to the board, but its seems that the receive buffer is not clearing after I read the data. There is no flush() method in the library, so how do I clear out the data?

TIA

If there isn’t a in-built function to use, the next step might be to try and create one…I poked around 3 AI models to see if they had any code suggestions, and all basically suggested the same workaround: implement a ‘read until empty’ function, here’s a scaffold:

If no flush command exists, one workaround is to read all available bytes until none are left. Here’s an example pattern in Python:

```
import qwiic_i2c

i2c = qwiic_i2c.getI2CConnection()
address = 0x10 # Example Tsunami I2C address

def read_all():
** data = **
** while True:**
** try:**
** # Read one byte at a time**
** byte = i2c.read_byte(address)**
** data.append(byte)**
** except Exception:**
** # Likely an empty buffer or NACK**
** break**
** return data**

cleared_data = read_all()
print(“Cleared buffer:”, cleared_data)
```

This isn’t elegant, but it works if the Tsunami doesn’t provide a “clear buffer” command.

Perpplexity also had an interesting suggestion of using a dummy read to clear it;

2. Dummy Read

Perform a “dummy read” to force the buffer to clear, even if the data isn’t used:

** **with qwiic_i2c.getI2CDriver() as i2c:** ** _ = i2c.readBlock(device_address, register, buffer_size) # Discard the result** **

Those might be decent starting points :smiley:

Sadly, this flush code did not work.mAt this point, i have tried the i2c libraries from Sparkfun, Adafruit and smbus. None are without issues. At this point I’m going with works, and stick to the serial interface.

1 Like

Sometimes the old way is still the way! Sorry the others didn’t work out