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 
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