Skip to content

tone: Work with 4.x, 5.0; AudioOut and PWMAudioOut #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 16, 2019

Conversation

jepler
Copy link
Contributor

@jepler jepler commented Sep 11, 2019

.. by creating new private functions for getting the right AudioOut and RawSample objects.

INCOMPATIBLE CHANGE: this removes support for CircuitPython versions before 3.x in tone()

Testing performed: On CPB, tone(board.SPEAKER, 440). On Metro M4 Express, `tone(board.A0, 440). Both tests were using CircuitPython 5.0.alpha versions.

Closes: #45

.. by creating new private functions for getting the right
AudioOut and RawSample objects.

INCOMPATIBLE CHANGE: this removes support for CircuitPython
versions before 3.x in tone()

Testing performed: On CPB, `tone(board.SPEAKER, 440)`.  On Metro
M4 Express, `tone(board.A0, 440).  Both tests were using
CircuitPython 5.0.alpha versions.

Closes: #45
@jepler jepler requested a review from kattni September 11, 2019 22:30
These functions are deliberately named with a leading underscore
to indicate that they are private functions to the simpleio module.
According to pylint, this import is not needed, as `sys` is never referenced
@kattni
Copy link
Contributor

kattni commented Sep 11, 2019

Tested on Circuit Playground Bluefruit with demo code from CircuitPython Essentials PWM guide page. Plays one tone, and then fails with pin in use, regardless of pin used. Tried with board.SPEAKER and board.A2 for use with piezo.

@jepler
Copy link
Contributor Author

jepler commented Sep 12, 2019

I expect to discover that the "pin in use" error is a problem in core, but I am still chasing it down, because I didn't make it happen without using simpleio yet. I did reproduce it with kattni's script and the code in this pull request, though:

import time
import board
import simpleio

while True:
    for f in (262, 294, 330, 349, 392, 440, 494, 523):
        # For the M0 boards:
        simpleio.tone(board.A2, f, 0.25)  # on for 1/4 second
        # For the M4 boards:
        # simpleio.tone(board.A1, f, 0.25)  # on for 1/4 second
        time.sleep(0.05)  # pause between notes
    time.sleep(0.5)

@jepler
Copy link
Contributor Author

jepler commented Sep 12, 2019

The problem that @kattni encountered is in core and has been filed as adafruit/circuitpython#2146 with proposed fix at adafruit/circuitpython#2147 -- but testing of this issue on CPB or other nRF boards will depend on using firmware with that fixed.

Copy link
Member

@ladyada ladyada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please verify it on a CPX with 4.x as well as 5.x :)

@kattni
Copy link
Contributor

kattni commented Sep 12, 2019

Verified that change works on CPX with 4.x and 5.x.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. Ideally we'd limit use of try/except for this.

 * where possible, check with sys.implementation.version, instead of try/except
 * reduce overall number of try/except clauses
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better! Thank you!

@tannewt tannewt merged commit e4ef881 into adafruit:master Sep 16, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 17, 2019
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x to 1.10.3 from 1.10.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#9 from hartzell/patch-2

Updating https://github.com/adafruit/Adafruit_CircuitPython_BME280 to 2.3.2 from 2.3.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_BME280#27 from ncguk/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground to 2.1.4 from 2.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_CircuitPlayground#69 from caternuson/iss68

Updating https://github.com/adafruit/Adafruit_CircuitPython_DS18X20 to 1.2.0 from 1.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_DS18X20#12 from LBertrandDC/asynchronous-functions

Updating https://github.com/adafruit/Adafruit_CircuitPython_DS2413 to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DS2413#9 from dherrada/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_GPS to 3.4.0 from 3.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#34 from dherrada/master
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#31 from dherrada/master
  > Merge branch 'master' into master

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTU21D to 0.9.0 from 0.8.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTU21D#5 from dherrada/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 3.4.0 from 3.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#27 from tannewt/remove_debug
  > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#25 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP3xxx to 1.1.0 from 1.0.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP3xxx#14 from brentru/update-examples

Updating https://github.com/adafruit/Adafruit_CircuitPython_MPR121 to 2.0.4 from 2.0.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_MPR121#20 from ntoll/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MPRLS to 1.1.0 from 1.0.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_MPRLS#6 from romanakozak/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MSA301 to 1.1.0 from 1.0.0:
  > added tap detection. Couldn't make latching work

Updating https://github.com/adafruit/Adafruit_CircuitPython_Nunchuk to 0.1.1 from 0.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Nunchuk#5 from ntoll/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCT2075 to 1.0.1 from 1.0.0:
  > fixed typos for (yet to be used) fault queue length

Updating https://github.com/adafruit/Adafruit_CircuitPython_SHT31D to 2.1.0 from 2.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_SHT31D#11 from WoefulDerelict/periodic_data_acquisition
  > Merge pull request adafruit/Adafruit_CircuitPython_SHT31D#10 from WoefulDerelict/temperature_docstring_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1306 to 2.6.4 from 2.6.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_SSD1306#29 from adafruit/tannewt-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Thermal_Printer to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Thermal_Printer#10 from caternuson/README_update

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC59711 to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLC59711#6 from demophoon/add-blinka-to-requirements-txt

Updating https://github.com/adafruit/Adafruit_CircuitPython_AVRprog to 1.2.0 from 1.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_AVRprog#10 from aaronaverill/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_FancyLED to 1.3.1 from 1.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_FancyLED#8 from schlafa/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 0.9.2 from 0.9.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#21 from fionawhim/rle-bmp
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#19 from cogliano/patch-2
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#18 from cogliano/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#17 from deshipu/master
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#15 from tannewt/fix_one_bit

Updating https://github.com/adafruit/Adafruit_CircuitPython_miniesptool to 0.1.5 from 0.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_miniesptool#11 from dherrada/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MotorKit to 1.3.1 from 1.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MotorKit#20 from adario7/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#11 from jerryneedell/jerryn_bytes

Updating https://github.com/adafruit/Adafruit_CircuitPython_RTTTL to 2.3.0 from 2.2.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_RTTTL#14 from hexthat/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_SimpleIO to 2.0.0 from 1.2.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_SimpleIO#46 from jepler/issue45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update simpleio.tone() to work with nRF52840
4 participants