ADC testing / SD data logging / unit testing / Documentation

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
kumt
Posts: 4
Joined: Tue Oct 10, 2017 7:04 pm

ADC testing / SD data logging / unit testing / Documentation

Post by kumt » Wed Oct 23, 2019 9:36 pm

Hello All,
As I started to build my application, some questions, as stated below, crossed my mind. Any help/suggestions are welcome.
  1. Is it possible to route DAC values to ADC internally for the sole purpose of testing ADC functionality?
  2. How to avoid loss of data transfer from ADC to SD card during a power cycle? For example: If I am continuously logging data into a file on the SD card for 30 minutes and the power turned off say after 15 min of data logging. What is the best way to save 15 minutes of data safely?
  3. Is it possible to implement unit testing in pyboard?
  4. What is the best way to document the code?
Thank you all for the help
kumt

User avatar
jimmo
Posts: 1847
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ADC testing / SD data logging / unit testing / Documentation

Post by jimmo » Thu Oct 24, 2019 11:24 am

kumt wrote:
Wed Oct 23, 2019 9:36 pm
Is it possible to route DAC values to ADC internally for the sole purpose of testing ADC functionality?
I don't think so... (or at least I'm not aware of a way to do this, but haven't looked in detail). It would probably be simpler to either wire it up externally, or bypass it at the software level.
kumt wrote:
Wed Oct 23, 2019 9:36 pm
How to avoid loss of data transfer from ADC to SD card during a power cycle? For example: If I am continuously logging data into a file on the SD card for 30 minutes and the power turned off say after 15 min of data logging. What is the best way to save 15 minutes of data safely?
What's the actual problem you're seeing? Do the writes go missing? Or are you seeing filesystem corruption?

One thing is to ensure is that you flush the file after each write.
kumt wrote:
Wed Oct 23, 2019 9:36 pm
Is it possible to implement unit testing in pyboard?
For your actual Python code... I'd unit test it in regular Python on your PC, using all the regular Python unit testing and mocking libraries.

Or use the Unix (or Windows) "port" of MicroPython, which should be almost identical to running it on the pyboard (but without the hardware access, which you could provide stubs for).

If you want to test it on real hardware, one thing you could look at is the MicroPython test suite, which has a way to run on hardware (see tests/run-tests, and in particular look at the test cases in tests/pyb).
kumt wrote:
Wed Oct 23, 2019 9:36 pm
What is the best way to document the code?
Comments is the obvious answer, but of course this means that your code will end up being larger, which may cause it to no longer fit on the board. The solution to this is to use the cross compiler (mpy-cross) to covert it to a .mpy file before copying to the board.

kumt
Posts: 4
Joined: Tue Oct 10, 2017 7:04 pm

Re: ADC testing / SD data logging / unit testing / Documentation

Post by kumt » Thu Oct 24, 2019 2:38 pm

jimmo wrote:
Thu Oct 24, 2019 11:24 am
kumt wrote:
Wed Oct 23, 2019 9:36 pm
Is it possible to route DAC values to ADC internally for the sole purpose of testing ADC functionality?
I don't think so... (or at least I'm not aware of a way to do this, but haven't looked in detail). It would probably be simpler to either wire it up externally, or bypass it at the software level.
How would you bypass the values at the software level for testing ADC read?
jimmo wrote:
Thu Oct 24, 2019 11:24 am
kumt wrote:
Wed Oct 23, 2019 9:36 pm
How to avoid loss of data transfer from ADC to SD card during a power cycle? For example: If I am continuously logging data into a file on the SD card for 30 minutes and the power turned off say after 15 min of data logging. What is the best way to save 15 minutes of data safely?
What's the actual problem you're seeing? Do the writes go missing? Or are you seeing filesystem corruption?

One thing is to ensure is that you flush the file after each write.
I will check the results and will let you know what is happening.
jimmo wrote:
Thu Oct 24, 2019 11:24 am
kumt wrote:
Wed Oct 23, 2019 9:36 pm
Is it possible to implement unit testing in pyboard?
For your actual Python code... I'd unit test it in regular Python on your PC, using all the regular Python unit testing and mocking libraries.

Or use the Unix (or Windows) "port" of MicroPython, which should be almost identical to running it on the pyboard (but without the hardware access, which you could provide stubs for).

If you want to test it on real hardware, one thing you could look at is the MicroPython test suite, which has a way to run on hardware (see tests/run-tests, and in particular look at the test cases in tests/pyb).
Thank you for the suggestion.
jimmo wrote:
Thu Oct 24, 2019 11:24 am
kumt wrote:
Wed Oct 23, 2019 9:36 pm
What is the best way to document the code?
Comments is the obvious answer, but of course this means that your code will end up being larger, which may cause it to no longer fit on the board. The solution to this is to use the cross compiler (mpy-cross) to covert it to a .mpy file before copying to the board.
Thank you for the suggestion.

User avatar
jimmo
Posts: 1847
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ADC testing / SD data logging / unit testing / Documentation

Post by jimmo » Sat Oct 26, 2019 10:06 am

kumt wrote:
Thu Oct 24, 2019 2:38 pm
How would you bypass the values at the software level for testing ADC read?
I meant that where ever your code writes to the DAC, to instead "inject" the value into whatever process is reading from the ADC. Sorry that wasn't clear.

Something like set a flag, and when the flag is set, writes to the DAC set a global variable, and reads from the ADC read that global variable (accounting for whatever scale factors and bit widths).

Post Reply