You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently analogbufio.BufferedIn blocks until the number of samples requested have been collected. I'm working on a non-blocking ring buffered version which will enable continuous data transfer. It could work like this:
>>>length=60>>>mybuffer=array.array("H", [0x0000] *length)
>>>rate=10>>># create a RingIn object and start reading the ADC into it via DMA>>>adcbuf=analogbufio.RingIn(board.GP26, sample_rate=rate, mybuffer)
>>>adcbuf.count25>>>adcbuf.count# this will keep going up and up at 10 Hz37>>>adcbuf.last# this is the last index of the buffer that was written to55>>>adcbuf.last# it will wrap around according to the length of the buffer10>>>mybuffer[adcbuf.last] # this will return the most recent ADC conversion (as of the time that adcbuf.last executes)124>>>delmybuffer# needs to tolerate this, so we make sure the RingIn still refers to the buffer object>>>adcbuf.ring[adcbuf.last] # maybe like this>>>127
Or the RingIn could allocate the array itself, e.g. adcbuf = analogbufio.RingIn(board.GP26, sample_rate=rate, length=length) Wondering what advice you could offer regarding creation and management of persistent objects like this?
The text was updated successfully, but these errors were encountered:
Generally I like the model of allocating the large chunk of memory outside of the object. That way you can reuse it in a different object if you really want to.
In the Python API, I would expose the indices though. Instead, make an iterator available to get the next value. Take a look at PulseIn for an example.
I'd also suggest adding this to a new module so we don't need to include it everywhere analogbufio is.
Currently
analogbufio.BufferedIn
blocks until the number of samples requested have been collected. I'm working on a non-blocking ring buffered version which will enable continuous data transfer. It could work like this:Or the RingIn could allocate the array itself, e.g.
adcbuf = analogbufio.RingIn(board.GP26, sample_rate=rate, length=length)
Wondering what advice you could offer regarding creation and management of persistent objects like this?The text was updated successfully, but these errors were encountered: