Topics

BBC-Microbit GPIO Mesh demo #nrf51822 #ble #sensor #zephyrbluetoothmesh #bluetooth


DFox1
 

Hi im a beginner trying to work with the bbc microbits for my engineering project, my task involves using mesh networking on the bbc microbits to send a message to the user's computer stating motion is detected by a PIR motion sensor.
Im currently building off the demo as all I need is to change the button press to read the GPIO pin which the motion sensor will be hooked up to on the board. Then as the motion is detected it will act as if the button has been pressed like in the mesh demo and send a message to the other devices on the network.
My current problem is that the program only reads the connection pin and switches to a 1 instead of 0, it doesn't react to motion from the sensor.It is switching between 0 and 1 while the cable is connected to the GPIO pin.
Can someone please help I cannot get this to work , I have also tried the button examples and the GPIO examples on zephyr.

snippets of code taken from mesh_demo
#define PIR EXT_P0_GPIO_PIN
 
static struct device *gpio;
static struct device *nvm;
static struct device *pwm;
 
static struct k_work button_work;
static void button_send_pressed(struct k_work *work)
{
printk("button_send_pressed()\n");
board_button_1_pressed();
}
 
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));
}
}
}
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, PIR ,
   (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
    GPIO_INT_ACTIVE_HIGH|
  GPIO_INT_DEBOUNCE | GPIO_PUD_PULL_UP));
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(PIR ) | BIT(SW1_GPIO_PIN));
gpio_add_callback(gpio, &button_cb);
 
gpio_pin_enable_callback(gpio, PIR );
gpio_pin_enable_callback(gpio, SW1_GPIO_PIN);
while (1) {
u32_t val=1;
int ret;
printk("toggling pin %d\n", PIR );
ret = gpio_pin_read(gpio, PIR , &val);
if (ret) {
printk("error %d\n",PIR );
}
if (val){
val=0;
}else {
val=1;
 
}
printk("VALUE pin %d\n", val);
k_sleep(100);
}
 
Any help would be great, my main issue is the fact I can't get the microbit board to react to the motion sensor when motion is detected.