Skip to content

Commit

Permalink
boards: bbc_microbit_v2: Add buzzer
Browse files Browse the repository at this point in the history
Tie pwm1 to buzzer pin and adjust sample.

Signed-off-by: Lars Knudsen <[email protected]>
  • Loading branch information
larsgk authored and henrikbrixandersen committed Jan 30, 2024
1 parent 515ef17 commit a3c4d22
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
13 changes: 13 additions & 0 deletions boards/arm/bbc_microbit_v2/bbc_microbit_v2-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@
};
};

pwm1_default: pwm1_default {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 0)>;
nordic,invert;
};
};

pwm1_sleep: pwm1_sleep {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 0)>;
low-power-enable;
};
};
};
8 changes: 8 additions & 0 deletions boards/arm/bbc_microbit_v2/bbc_microbit_v2.dts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@
status = "okay";
};

&pwm1 {
/* buzzer */
status = "okay";
pinctrl-0 = <&pwm1_default>;
pinctrl-1 = <&pwm1_sleep>;
pinctrl-names = "default", "sleep";
};

&uart0 {
compatible = "nordic,nrf-uart";
status = "okay";
Expand Down
27 changes: 22 additions & 5 deletions samples/boards/bbc_microbit/sound/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,46 @@ Overview
********

This sample demonstrates how to use a piezo buzzer connected
to port P0 on the edge connector of the BBC micro:bit board.
to port P0 on the edge connector of the **BBC micro:bit v1** or
using the on-board buzzer on the **BBC micro:bit v2**.

Requirements
************

A separate piezo buzzer connected to the board. One example is the MI:Power
board that has a piezo buzzer in addition to a coin-cell battery. Resellers of
this board can be fairly easily found using online search.
Using **BBC micro:bit v1**, a separate piezo buzzer must be connected to the board.
One example is the MI:Power board that has a piezo buzzer in addition to a
coin-cell battery. Resellers of this board can be fairly easily found using online search.

The upgraded **BBC micro:bit v2** board does not need a separate buzzer as it has one
built-in on the backside of the board (marked as 'speaker').


Building and running
********************

The sample can be built as follows:

Building for a BBC micro:bit v1
-------------------------------

.. zephyr-app-commands::
:zephyr-app: samples/boards/bbc_microbit/sound
:board: bbc_microbit
:goals: build flash
:compact:

Building for a BBC micro:bit v2
-------------------------------

.. zephyr-app-commands::
:zephyr-app: samples/boards/bbc_microbit/sound
:board: bbc_microbit_v2
:goals: build flash
:compact:

Sample Output
=============

This sample outputs sounds through a connected piezo buzzer based on
This sample outputs sounds through a piezo buzzer based on
button presses of the two main buttons. For each press the current
output frequency will be printed on the 5x5 LED display.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/ {
zephyr,user {
/* period cell corresponds to initial period */
pwms = <&pwm1 0 PWM_USEC(1500) PWM_POLARITY_NORMAL>;
};
};
1 change: 0 additions & 1 deletion samples/boards/bbc_microbit/sound/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ CONFIG_GPIO=y
CONFIG_DISPLAY=y
CONFIG_MICROBIT_DISPLAY=y
CONFIG_PWM=y
CONFIG_PWM_NRF_SW=y
4 changes: 3 additions & 1 deletion samples/boards/bbc_microbit/sound/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ sample:
name: BBC micro:bit Sound
tests:
sample.board.bbc_microbit.sound:
platform_allow: bbc_microbit
platform_allow:
- bbc_microbit
- bbc_microbit_v2
tags: sound

0 comments on commit a3c4d22

Please sign in to comment.