BBC-Microbit PIR sensor #bluetoothmesh #ble #gpio #sensor #zephyrbluetoothmesh


DFox1
 

Hi All,
Im currently working on my 3rd year engineering project and I need some help/guidance as I'm a complete beginner. My project is a home monitoring system and my plan is to use PIR motion sensors inside the house, using Bluetooth mesh.

I have a few BBC Microbits and I have managed to implement the Mesh demo example from zephyr v1.14.
My plan is to try and replace the switch functions (button_pressed .. etc) to allow the motion sensor connected to GPIO PIN 0 on the BBC micro bit board. So when motion is detected it would act like how the button press function works on the boards.

My issue is I'm not sure how to program this and read the GPIO 0 pin, I want something like if motion sensor = 1 send messaged to light LED to other BBC micro bits. If motion sensor=0 do nothing.

From the microbit.c file:
#define BUZZER_PIN     EXT_P0_GPIO_PIN  // replace buzzer_pin with motion sensor ???

static void button_pressed(struct device *dev, struct gpio_callback *cb,
   u32_t pins)
{
struct mb_display *disp = mb_display_get();
 
if (pins & BIT(SW0_GPIO_PIN)) {
k_work_submit(&button_work);
} else {
u16_t target = board_set_target();
 
if (target > 0x0009) {
mb_display_print(disp, MB_DISPLAY_MODE_SINGLE,
 K_SECONDS(2), "A");
} else {
mb_display_print(disp, MB_DISPLAY_MODE_SINGLE,
 K_SECONDS(2), "%X", (target & 0xf));
}
}
}
 
... 

void board_play_tune(const char *str)
{
while (*str) {
u32_t period, duration = 0U;
 
while (*str && !isdigit((unsigned char)*str)) {
str++;
}
 
while (isdigit((unsigned char)*str)) {
duration *= 10U;
duration += *str - '0';
str++;
}
 
if (!*str) {
break;
}
 
if (str[1] == '#') {
period = get_period(*str, true);
str += 2;
} else {
period = get_period(*str, false);
str++;
}
 
if (period) {
pwm_pin_set_usec(pwm, BUZZER_PIN, period, period / 2U); 
}
 
k_sleep(duration);
 
/* Disable the PWM */
pwm_pin_set_usec(pwm, BUZZER_PIN, 0, 0);
}
}
.....

static void configure_button(void)
{
static struct gpio_callback button_cb;
 
k_work_init(&button_work, button_send_pressed);
 
gpio = device_get_binding(SW0_GPIO_CONTROLLER);

gpio_pin_configure(gpio, SW0_GPIO_PIN,
   (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
    GPIO_INT_ACTIVE_LOW));
gpio_pin_configure(gpio, SW1_GPIO_PIN,
   (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
    GPIO_INT_ACTIVE_LOW));
 
gpio_init_callback(&button_cb, button_pressed,
   BIT(SW0_GPIO_PIN) | BIT(SW1_GPIO_PIN));
gpio_add_callback(gpio, &button_cb);
 
gpio_pin_enable_callback(gpio, SW0_GPIO_PIN);
gpio_pin_enable_callback(gpio, SW1_GPIO_PIN);
}
 
I appreciate any help that you could give me. Thanks!

Join users@lists.zephyrproject.org to automatically receive all group messages.