edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
ShinjiQune
Published © GPL3+

Off-grid Waterproof Protection for Field Prototype Tests

Off-grid Waterproof Protection for Field Prototype Tests using a Solar Panel, Mobile Battery and a Ethernet Cable

IntermediateProtip24 hours74
Off-grid Waterproof Protection for Field Prototype Tests

Things used in this project

Hardware components

Plastic Enclosure, Precision Miniature Case
Plastic Enclosure, Precision Miniature Case
×1
desiccant (Diatomaceous earth reccomended)
×1
Mobile Battery (commercially available in Japan)
A battery with overcharge and over-discharge protection and a capacity of around 3000mAh is sufficient. PSE certification is generally all that's needed.
×1
LED string illumination
Used for the pass-through test. The link is Japanese one but anything that can be powered via a USB Type-A plug will be available.
×1
Empty wine bottle
We'll make a makeshift pass-through test lamp by packing it with LED strings. Make sure to use an empty wine bottle. I used a small bottle of red wine that I bought at a hotel during my first business trip to Germany. After the test, you can continue to use it as a bedside lamp.
×1
Solar Panel, 3.5W, micro USB
×1
Ethernet Cable, 1 m
Ethernet Cable, 1 m
×1
RJ45 breakout board
Used to sensor or LED devices
×1
RJ45 breakout board for bread board
Used in main plastic enclosure
×1
Supercapacitor, 0.22 F
Supercapacitor, 0.22 F
I bought a supercapacitor 5.5V - 0.22F from uxcell Japan.
×1

Software apps and online services

VS Code
Microsoft VS Code

Hand tools and fabrication machines

Cut-resistant gloves
This is needed absolutely to save your fingers to be lost.
Hot glue gun (generic)
Hot glue gun (generic)
Drill / Driver, Cordless
Drill / Driver, Cordless
Multitester
This is used to test the continuity of each core wire in an Ethernet cable. Any device capable of measuring resistance can be used.

Story

Read more

Schematics

The schematic

The schematic diagram of the immortal field prototype.

Code

Introducing the Watchdog Timer

C/C++
Code Snippet for introducing the watchdog timer in the pico-sdk
#include "hardware/watchdog.h"
// In a loop
  // Long processing time of up to 5 seconds
  int state = cyw43_arch_wifi_connect_timeout_ms(
              WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 5000
  );
  // Always feed your guard dog after a long period of work.
  watchdog_update();
  // If you absolutely need them to sleep for more than 8 seconds,
  // you can use a for loop.
  for (int i = 0; i < 10; i++) {
    sleep_ms(1000);
    watchdog_update(); // Do not forget feeding
  }

High Side Switching

C/C++
The high side switching for defeating the ghost of LEDs
// Define pin numbers depending on your microcontroller board
const uint LED_SOURCE  = 17;
const uint LED_RED     = 13;
const uint LED_GREEN   = 14;
const uint LED_BLUE    = 15;

// Make a function to turn off all LEDs
void turn_off_all_leds(void) {
    gpio_put(LED_SOURCE, 0);
    gpio_put(LED_RED, 1);
    gpio_put(LED_GREEN, 1);
    gpio_put(LED_BLUE, 1);
}

// Make a function to ready all LEDs
void ready_all_leds(void) {
    gpio_put(LED_SOURCE, 1);
    sleep_ms(20);
}

// Use above functions in controlling LEDs
void haniwa_led_blink_red(int seconds) {
    // Call "ready" at first
    ready_all_leds();
    for (int i = 0; i < seconds; i++) {
        gpio_put(LED_RED, 0);
        sleep_ms(500);
        gpio_put(LED_RED, 1);
        sleep_ms(500);
        watchdog_update();
    }
    // Call "turn-off" immediately after use to save energy
    turn_off_all_leds();
}

Non-Blocking LED-Blinking

C/C++
Blinking LEDs with no blocking loop which use for example "sleep_ms(500)".
// Start blinking LEDs with the specified colors, interval, and count
void start_led_blink(bool r, bool g, bool b, uint32_t interval_ms, int count) {
    turn_off_all_leds();

    p_target_r = r;
    p_target_g = g;
    p_target_b = b;
    p_interval_ms = interval_ms;
    p_remaining_counts = count * 2; // Each cycle has an ON and OFF state

    p_last_toggle_time = to_ms_since_boot(get_absolute_time());    
    p_led_is_on = false; // Start with LEDs off
    p_is_running = true;

    // Start with the first toggle immediately to turn on the LEDs
    ready_all_leds();
    if (p_target_r) gpio_put(LED_RED, 0);
    if (p_target_g) gpio_put(LED_GREEN, 0);
    if (p_target_b) gpio_put(LED_BLUE, 0);
    p_led_is_on = true;
    p_remaining_counts--;
}

// Monitor time called from the main loop to handle LED blinking
void poll_led_blink(void) {
    if (!p_is_running) return;

    uint32_t now = to_ms_since_boot(get_absolute_time());

    if (now - p_last_toggle_time >= p_interval_ms) {
        p_last_toggle_time = now;

        if (p_remaining_counts <= 0) {
            turn_off_all_leds();
            p_is_running = false;
            return;
        }

        if (p_led_is_on) {
            // Turn off LEDs
            if (p_target_r) gpio_put(LED_RED, 1);
            if (p_target_g) gpio_put(LED_GREEN, 1);
            if (p_target_b) gpio_put(LED_BLUE, 1);
            p_led_is_on = false;
        } else {
            // Turn on LEDs
            ready_all_leds();
            if (p_target_r) gpio_put(LED_RED, 0);
            if (p_target_g) gpio_put(LED_GREEN, 0);
            if (p_target_b) gpio_put(LED_BLUE, 0);
            p_led_is_on = true;
        }

        p_remaining_counts--;
    }
}


///// in haniwa_main.cpp
void update_led_status(LEDStatus status) {
    // Turn off all LEDs before updating the status
    turn_off_all_leds();

    switch(status) {
        case STATUS_GO:
            start_led_blink(true, false, false, 500, 10); // Blink Red for GO watering
            printf("Haniwa: Red Alert! GO Watering!\n");
            break;
            
        case STATUS_TOO_MUCH:
            start_led_blink(false, false, true, 500, 10); // Blink Blue for TOO_MUCH water
            printf("Haniwa: Blue Alert! TOO_MUCH water.\n");
            break;

        case STATUS_ERROR:
            start_led_blink(false, false, true, 100, 50); // Fast Blink Blue for ERROR
            printf("Haniwa: Blue Alert!! ERROR occurred.\n");
            break;

        case STATUS_SKIP:
        default:
            start_led_blink(false, true, false, 500, 10); // Blink Green for SKIP water
            printf("Haniwa: All Green. SKIP Watering.\n");
            break;
    }
}

// in the main loop
while (true) {
  poll_led_blink();

  if (haniwa_recv_result(&current_status)) {
    update_led_status(current_status); 
    printf("Haniwa: Updated LED status based on the decision.\n");
  }
  
  // Take a short interval to keep the TCP connection
  sleep_ms(10);
  
}

HANIWA-Guardian

Source codes for haniwa guardian

Credits

ShinjiQune
7 projects • 1 follower
Ph. D. in Engineering, Optics, 3D Holograms. Designer for High Power Laser Manufacturing Systems. Project Leader regarding Metal AM Monitor.

Comments