---
title: "MedicBox for WizFi360-EVB-Pico"
url: "https://maker.wiznet.io/jeenowden/contest/medicbox-for-wizfi360-evb-pico/"
markdown_url: "https://maker.wiznet.io/jeenowden/contest/medicbox-for-wizfi360-evb-pico/md"
type: "Contests"
author: "jeenowden"
author_url: "https://maker.wiznet.io/jeenowden/"
original_author: "jees kim"
license: "MIT license (MIT)"
published: "2022-10-28"
language: "en"
tags: ["Health & Medical Devices", "Cloud"]
hardware: ["WIZnet WizFi360-EVB-Pico", "SparkFun Pushbutton switch 12mm"]
likes: 10
views: 3118
comments: 7
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# MedicBox for WizFi360-EVB-Pico

> Smart Medication Management System with Alarm Reminder.

Original author: jees kim

## Components

- **WIZnet WizFi360-EVB-Pico** x 1
- **SparkFun Pushbutton switch 12mm** x 3 ([docs](https://www.sparkfun.com/products/9190))
- Software: **Microsoft Azure IoT Hub** ([docs](https://learn.microsoft.com/en-gb/azure/iot-hub/))
- Software: **WIZnet WizFi360-EVB-Pico-AZURE-C** ([docs](https://github.com/Wiznet/WizFi360-EVB-Pico-AZURE-C))

## Documents and links

- [WizFi360-Pico SourceCode](https://github.com/jeesang7/WizFi360-EVB-Pico-C/tree/contest) (code): github
- [LED & Push Switch for Pico](https://maker.wiznet.io/_lib/download.asp?path=project/7907&downfile=694844443%5F1666565789%2Epng) (schematics)

## Article

## Purpose

Sometimes, I can't remember if I took the medicine, or I forget to take it at the desired time.

Vitamins and blood pressure pills, have to take every day, but sometimes you forget and don't take them.

Based on C language, It is a system that allows you to set the desired time and check whether you are taking the medicine.

## Design

I was thinking about how to manage my morning, lunch, and dinner medications.

We needed at least three containers, and we needed a way for each container to be identified by an alarm or indicator light.

![](https://maker.wiznet.io/upload/ckeditor5/1015660776%5F1666745175%2Ejpg)

Especially, I planned to implement the function by controlling GPIO using wizfi360-pico.

## LED & Push Button

By using the LED and button, you can store various medications and check whether they are taken or not.

It is a simple operation process:

If the LED is on, take your medicine.
When you have taken your medicine, press the button to turn off the LED.

For people who take various medications, 3 pairs of LEDs and buttons are configured as a controller.

![](https://maker.wiznet.io/upload/ckeditor5/267221056%5F1666440867%2Epng)

First, configure a pair of LEDs and Buttons.

![](https://maker.wiznet.io/upload/ckeditor5/694844443%5F1666565789%2Epng)

![](https://maker.wiznet.io/upload/ckeditor5/694844443%5F1666565539%2Ejpg)

## Azure IoT Hub

Using Azure IoT Hub, LED status can be checked remotely.

Using Azure IoT Hub service, I connected my flask-based personal server. You can check the status of the WizFi360-Pico device anytime, anywhere by connecting to a smartphone through this server.

![](https://maker.wiznet.io/upload/ckeditor5/267221056%5F1666441381%2Epng)

Guides and References for connecting to Azure IoT Hub can be found in the repository below:

<https://github.com/Wiznet/WizFi360-EVB-Pico-AZURE-C>

## Debugging using picoprobe

Debugging is possible using [picoprobe](https://github.com/raspberrypi/picoprobe) in Wizfi360-pico !

Also, I was able to debug using picoprobe in vscode, which I personally use.

![](https://maker.wiznet.io/upload/ckeditor5/1015660776%5F1666745758%2Ejpg)

![](https://maker.wiznet.io/upload/ckeditor5/369532972%5F1666939590%2EPNG)

## Without Azure

I used another option for the Azure credit issue, refer to the link below:

<https://github.com/Wiznet/WizFi360-EVB-Pico-C>

![](https://maker.wiznet.io/upload/ckeditor5/694844443%5F1666560892%2Epng)

This option can connect the server using TCP Socket communication without Azure.

In macOS or Linux, you could check the sending/receiving of messages on the server simply by using [netcat(nc)](https://nc110.sourceforge.io/).

![](https://maker.wiznet.io/upload/ckeditor5/694844443%5F1666561458%2Epng)

## WizFi360-EVB-Pico-C

You can refer to the following commit link for code changes:

<https://github.com/jeesang7/WizFi360-EVB-Pico-C/commit/411d89ad0e4ea9b86c05b7a5bd133dbe203c9221>

#### examples/TCP_Client_Demo/app_main.c

```c
extern int32_t gpio_handler (void);
...

static void app_medicbox (void *argument) {
  int32_t status;

  printf("GPIO control for MedicBox\r\n");
  gpio_handler();
}
...

void app_initialize (void) {
  ...
  osThreadNew(app_medicbox, NULL, &app_main_attr);
}
```

I've added one more FreeRTOS task, that task allows you to control LEDs and buttons.

#### examples/TCP_Client_Demo/iot_demo.c

```c
...
#include "pico/stdlib.h"
...

const uint BTN_PIN_1 = 13;
const uint LED_PIN_1 = 14;
const uint BTN_PIN_2 = 12;
const uint LED_PIN_2 = 15;
const uint BTN_PIN_3 = 9;
const uint LED_PIN_3 = 10;
...

int demo( void )
{
    ...
    while(1)
    {   
        ...
        if(retval > 0){
            ...

            if (strncmp(g_tcp_recv_buf, "ledon1", 6) == 0) {
                printf("receive ledon1 then gpio led1 on!\n");
                gpio_put(LED_PIN_1, 1);
            }

            if (strncmp(g_tcp_recv_buf, "ledon2", 6) == 0) {
                printf("receive ledon2 then gpio led2 on!\n");
                gpio_put(LED_PIN_2, 1);
            }

            if (strncmp(g_tcp_recv_buf, "ledon3", 6) == 0) {
                printf("receive ledon3 then gpio led3 on!\n");
                gpio_put(LED_PIN_3, 1);
            }
        }
    }
}

int gpio_handler(void)
{
    // #1
    gpio_init(BTN_PIN_1);
    gpio_set_dir(BTN_PIN_1, GPIO_IN);
    // We are using the button to pull down to 0v when pressed, so ensure that when
    // unpressed, it uses internal pull ups. Otherwise when unpressed, the input will
    // be floating.
    gpio_pull_up(BTN_PIN_1);

    gpio_init(LED_PIN_1);
    gpio_set_dir(LED_PIN_1, GPIO_OUT);
    gpio_put(LED_PIN_1, 0);
    sleep_ms(1000);
    gpio_put(LED_PIN_1, 1);

    // #2
    gpio_init(BTN_PIN_2);
    gpio_set_dir(BTN_PIN_2, GPIO_IN);
    gpio_pull_up(BTN_PIN_2);

    gpio_init(LED_PIN_2);
    gpio_set_dir(LED_PIN_2, GPIO_OUT);
    gpio_put(LED_PIN_2, 0);
    sleep_ms(1000);
    gpio_put(LED_PIN_2, 1);

    // #3
    gpio_init(BTN_PIN_3);
    gpio_set_dir(BTN_PIN_3, GPIO_IN);
    gpio_pull_up(BTN_PIN_3);

    gpio_init(LED_PIN_3);
    gpio_set_dir(LED_PIN_3, GPIO_OUT);
    gpio_put(LED_PIN_3, 0);
    sleep_ms(1000);
    gpio_put(LED_PIN_3, 1);


    while (1)
    {
        if (gpio_get(BTN_PIN_1)) {
            printf("button1 pushed\n");
            gpio_put(LED_PIN_1, 0);
        }

        if (gpio_get(BTN_PIN_2)) {
            printf("button2 pushed\n");
            gpio_put(LED_PIN_2, 0);
        }

        if (gpio_get(BTN_PIN_3)) {
            printf("button3 pushed\n");
            gpio_put(LED_PIN_3, 0);
        }

        sleep_ms(250);
    }
}
```

When the 'ledon1' string is input in the *demo* function, the first led is turned on. The other two LEDs were processed in the same way.

*gpio_handler* function initializes and sets gpio, I put it in a while loop to handle the button.

If you have any questions about the above code, please leave your inquiry in the comments.

## Upcycling

Medicbox is made using product packaging or plastic.

It's not very beautiful to look at, but it's meaningful to be able to make new products using discarded things.

![](https://maker.wiznet.io/upload/ckeditor5/1015660776%5F1666743345%2Ejpg)

![](https://maker.wiznet.io/upload/ckeditor5/1015660776%5F1666743373%2Ejpg)

And, because I made a product that is unique in the world, it is precious to me.

## Application

In the app, you can simply check whether you are taking your medicine and set a reminder.

![](https://maker.wiznet.io/upload/ckeditor5/369532972%5F1666940099%2Ejpeg)

## Links

[Embedded media](https://www.youtube.com/embed/WGAY_tN9-3o)

- [hackster.io](https://www.hackster.io/jeesang-kim/medicbox-for-wizfi360-evb-pico-819608)

- [Facebook](https://m.facebook.com/story.php?story_fbid=pfbid02N9FRNgr9sUurT32BijqGcEu2gwdQtfNwvogq3BA4L2kJCoGVD9fwZ8pqiyB1ozfWl&id=100029311451088)

- [Instagram](https://www.instagram.com/p/CiprQg_vMxV/?igshid=YmMyMTA2M2Y=)

---

Source: https://maker.wiznet.io/jeenowden/contest/medicbox-for-wizfi360-evb-pico/
