No sound from buzzer on custom board with nrf9160

Hi All,

I am unsuccessfully trying to make the buzzer (KLJ-5020) of my custom board with an nrf9160 beep. I have setup the different dts and config files of my custom board by following this tutorial.

I tried different samples including blinky_pwm and this tutorial. The buzzer is connected to the GPIO5 pin, I use VS code and SDK 2.4.1. I use a 3.7V 1000mah battery.

I only have a multimeter for checking the hardware although I am not sure what to check on the buzzer pins, I am a complete beginner in electronic and did not design the board myself.

On the software side I use pwm on GPIO5 to drive the buzzer with a 1000Hz signal (I just want a simple beep). I saw here that GPIO5 on the nrf9160 is a MISO pin, could that be the issue?

I can't tell what is wrong. Any help would be greatly appreciated.

Best wishes  

Schematic:

nrf9160vs_nrf9160.overlay

/*
 * Copyright (c) 2019, Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/dt-bindings/led/led.h>

#include "nrf52-bindings.h"

&arduino_spi { /* MOSI on D11 / P0.23 */
	compatible = "nordic,nrf-spim";
	led_strip: ws2812@0 {
		compatible = "worldsemi,ws2812-spi";

		/* SPI */
		reg = <0>; /* ignored, but necessary for SPI bindings */
		spi-max-frequency = <SPI_FREQ>;

		/* WS2812 */
		chain-length = <1>; /* arbitrary; change at will */
		color-mapping = <LED_COLOR_ID_GREEN
				 LED_COLOR_ID_RED
				 LED_COLOR_ID_BLUE>;
		spi-one-frame = <ONE_FRAME>;
		spi-zero-frame = <ZERO_FRAME>;
	};
};

/ {
	aliases {
		led-strip = &led_strip;
		buzzer-pwm = &buzzer;
	};

	pmwbuzzer {
		compatible = "pwm-leds";
		status = "okay";

		buzzer: buzzer_pwm{
			pwms = < &pwm1 0 PWM_HZ(880) PWM_POLARITY_NORMAL>;
			label = "PMW_1";
		};
	};
};

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

&pinctrl {
	pwm1_default: pwm1_default {
		group1 {
			psels = <NRF_PSEL(PWM_OUT0, 0, 5)>;
		};
	};

	pwm1_sleep: pwm1_sleep {
		group1 {
			psels = <NRF_PSEL(PWM_OUT0, 0, 5)>;
			low-power-enable;
		};
	};
};

main.c

/*
 * Copyright (c) 2017 Linaro Limited
 * Copyright (c) 2018 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <errno.h>
#include <string.h>

#define LOG_LEVEL 4
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);

#include <zephyr/kernel.h>
#include <zephyr/drivers/led_strip.h>
#include <zephyr/drivers/pwm.h>

#define STRIP_NODE		DT_ALIAS(led_strip)
#define STRIP_NUM_PIXELS	DT_PROP(DT_ALIAS(led_strip), chain_length)

#define DELAY_TIME K_MSEC(10000)

#define RGB(_r, _g, _b) { .r = (_r), .g = (_g), .b = (_b) }

static const struct led_rgb colors[] = {
	RGB(0x0f, 0x00, 0x00), /* red */
	RGB(0x00, 0x0f, 0x00), /* green */
	RGB(0x00, 0x00, 0x0f), /* blue */
	RGB(0x0f, 0x0f, 0x0f), /* white */
};


struct led_rgb pixels[STRIP_NUM_PIXELS];

static const struct device *const strip = DEVICE_DT_GET(STRIP_NODE);
const struct pwm_dt_spec buzzer = PWM_DT_SPEC_GET(DT_ALIAS(buzzer_pwm));


int main(void)
{
	LOG_INF("Starting test...");

	if (!device_is_ready(buzzer.dev))
	{
		LOG_ERR("Buzeer not ready");
	}

	LOG_DBG("beep");
	pwm_set_dt(&buzzer, PWM_HZ(1000), PWM_HZ(1000) / 2);
	k_msleep(10000);
	


	size_t cursor = 0, color = 0;
	int rc;

	if (device_is_ready(strip)) {
		LOG_INF("Found LED strip device %s", strip->name);
	} else {
		LOG_ERR("LED strip device %s is not ready", strip->name);
		return 0;
	}

	LOG_INF("Displaying pattern on strip");
	while (1) {
		memset(&pixels, 0x00, sizeof(pixels));
		memcpy(&pixels[cursor], &colors[color], sizeof(struct led_rgb));
		rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);

		if (rc) {
			LOG_ERR("couldn't update strip: %d", rc);
		}

		cursor++;
		if (cursor >= STRIP_NUM_PIXELS) {
			cursor = 0;
			color++;
			if (color == ARRAY_SIZE(colors)) {
				color = 0;
			}
		}

		k_sleep(DELAY_TIME);
		//play_beep_once();
	}
	return 0;
}

prj.conf

# Stacks and heaps
CONFIG_MAIN_STACK_SIZE=3072
CONFIG_HEAP_MEM_POOL_SIZE=16384

CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_PWM=y
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_PWM_LOG_LEVEL_DBG=y

CONFIG_LED_STRIP=y
CONFIG_LED_STRIP_LOG_LEVEL_DBG=y
CONFIG_WS2812_STRIP=y
CONFIG_WS2812_STRIP_SPI=y


CONFIG_NEWLIB_LIBC=y
CONFIG_DK_LIBRARY=y
CONFIG_PWM_NRFX=y

sources:

3683.hello_world.zip

logs:

Parents Reply Children
Related