Skip to content

Does readBytes() have delay? #1712

Answered by pschatzmann
hexer97149 asked this question in Q&A
Discussion options

You must be logged in to vote

Why so complicated ? your code is quite difficult to understand: If I get your logic right, you just want to write out binary data delimited with a line feed.

I suggest to do something like this instead:

loop() {
    int16_t sample;
    size_t bytes_read = i2sStream.readBytes((uint8_t*) &sample, sizeof(int16_t));
    assert(bytes_read==sizeof(int16_t)); // i2s uses blocking read, so this should always be treu
    Serial.write((uint8_t*)&sample, sizeof(int16_t));
    Serial.print('\n'); // for cr or Serial.println() for cr lf
}

There is still one issue however: you generate 2 * 3 (=2 bytes + delimiter) * 16000 * 8 bits per second = 768000 but your Serial transmission rate is much lower. Th…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pschatzmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants