From 512e041717dd312ebe187c0c5a8308c9cfa5dea5 Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Sun, 6 Apr 2025 12:55:40 +0200 Subject: [PATCH] init converting project from micro python to c --- .gitignore | 4 +- CIRCUITPY/.vscode/settings.json | 15 -- CmakeLists.txt | 30 +++ README.md | 20 +- node1.c | 240 ++++++++++++++++++ .../CIRCUITPY}/boot_out.txt | 0 .../CIRCUITPY}/code.py | 0 .../lib/adafruit_bme280/__init__.py | 0 .../CIRCUITPY}/lib/adafruit_bme280/basic.mpy | Bin .../lib/adafruit_bme280/protocol.mpy | Bin .../lib/adafruit_bus_device/__init__.py | 0 .../lib/adafruit_bus_device/i2c_device.mpy | Bin .../lib/adafruit_bus_device/spi_device.mpy | Bin .../lib/adafruit_esp32spi/PWMOut.mpy | Bin .../lib/adafruit_esp32spi/__init__.py | 0 .../adafruit_esp32spi/adafruit_esp32spi.mpy | Bin .../adafruit_esp32spi_socket.mpy | Bin .../adafruit_esp32spi_wifimanager.mpy | Bin .../adafruit_esp32spi_wsgiserver.py | 0 .../lib/adafruit_esp32spi/digitalio.mpy | Bin .../lib/adafruit_minimqtt/__init__.py | 0 .../adafruit_minimqtt/adafruit_minimqtt.mpy | Bin .../lib/adafruit_minimqtt/matcher.mpy | Bin .../CIRCUITPY}/weather_station/__init__.py | 0 .../CIRCUITPY}/weather_station/airlift.py | 0 .../CIRCUITPY}/weather_station/bme280.py | 0 .../CIRCUITPY}/weather_station/pubsub.py | 0 .../CIRCUITPY}/weather_station/timer.py | 0 .../rsync-exclude.txt | 0 .../settings.sample.toml | 0 sync.sh => old_micro_python_code/sync.sh | 0 pico_sdk_import.cmake | 84 ++++++ 32 files changed, 372 insertions(+), 21 deletions(-) delete mode 100755 CIRCUITPY/.vscode/settings.json create mode 100644 CmakeLists.txt create mode 100644 node1.c rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/boot_out.txt (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/code.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_bme280/__init__.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_bme280/basic.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_bme280/protocol.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_bus_device/__init__.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_bus_device/i2c_device.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_bus_device/spi_device.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/PWMOut.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/__init__.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/adafruit_esp32spi.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/adafruit_esp32spi_wifimanager.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_esp32spi/digitalio.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_minimqtt/__init__.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_minimqtt/adafruit_minimqtt.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/lib/adafruit_minimqtt/matcher.mpy (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/weather_station/__init__.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/weather_station/airlift.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/weather_station/bme280.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/weather_station/pubsub.py (100%) rename {CIRCUITPY => old_micro_python_code/CIRCUITPY}/weather_station/timer.py (100%) rename rsync-exclude.txt => old_micro_python_code/rsync-exclude.txt (100%) rename settings.sample.toml => old_micro_python_code/settings.sample.toml (100%) rename sync.sh => old_micro_python_code/sync.sh (100%) create mode 100644 pico_sdk_import.cmake diff --git a/.gitignore b/.gitignore index 2e60230..5e384b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ -CIRCUITPY/settings.toml +settings.toml .DS_Store .vscode/ +build/ +.cache/ diff --git a/CIRCUITPY/.vscode/settings.json b/CIRCUITPY/.vscode/settings.json deleted file mode 100755 index 641b76d..0000000 --- a/CIRCUITPY/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "python.languageServer": "None", - "python.linting.pylintEnabled": false, - "python.analysis.diagnosticSeverityOverrides": { - "reportMissingModuleSource": "none" - }, - "python.analysis.extraPaths": [ - "/Users/travis.shears/.vscode/extensions/joedevivo.vscode-circuitpython-0.1.20-darwin-arm64/boards/0x239A/0x80F4", - "/Users/travis.shears/.vscode/extensions/joedevivo.vscode-circuitpython-0.1.20-darwin-arm64/stubs", - "/Users/travis.shears/Library/Application Support/Code/User/globalStorage/joedevivo.vscode-circuitpython/bundle/20230815/adafruit-circuitpython-bundle-py-20230815/lib" - ], - "circuitpython.board.version": "8.2.0", - "circuitpython.board.vid": "0x239A", - "circuitpython.board.pid": "0x80F4" -} \ No newline at end of file diff --git a/CmakeLists.txt b/CmakeLists.txt new file mode 100644 index 0000000..d2c83be --- /dev/null +++ b/CmakeLists.txt @@ -0,0 +1,30 @@ +# What CMake to start at +cmake_minimum_required( VERSION 3.31 ) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +#set(PICO_BOARD pico CACHE STRING "Board type") + +# Pull in SDK (must be before project) +include( pico_sdk_import.cmake ) + +# Set the name and version of the project + +project(test C CXX ASM) +# project(test VERSION 1.0.0 ) + +# Initialize the SDK +pico_sdk_init() + + +# the executable +add_executable( node1 node1.c ) +pico_set_program_version(node1 "0.1") +pico_set_program_name(node1 "node_one") + +# pull in common dependencies +target_link_libraries( node1 pico_stdlib ) + +# create map/bin/hex file etc. +pico_add_extra_outputs( node1 ) diff --git a/README.md b/README.md index 589dab7..8ebb50b 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,23 @@ A DIY weather station on my balcony that is hooked up to [Home Assistant](https://www.home-assistant.io/). -The code is [CircuitPython](https://circuitpython.org/). It follows many of the patterns I learned in creating an [aquarium controller](https://git.sr.ht/~travisshears/sewa-reef-controller). +The source code started as [CircuitPython](https://circuitpython.org/) following +many of the patterns I learned in creating an [aquarium controller](https://git.sr.ht/~travisshears/sewa-reef-controller). +I have since switch to using C. -## Capabilities +## Capabilities Right now the station is fairly limited measuring only temperature, humidity, -and atmospheric pressure. I have plans to expand the project to also measure -noise levels, and wind. +and atmospheric pressure. I have plans to expand the project to in the end measure: + +- tempature +- humidity +- atmospheric pressure +- noise levels +- wind speed +- wind direction +- rain fall +- light ## Hardware @@ -17,12 +27,12 @@ Sensors: MCs: - [Raspberry Pi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/) -- [Adafruit Airlift](https://www.adafruit.com/product/4201) Other: - [Weatherproof Enclosure](https://shop.pimoroni.com/products/weatherproof-cover-for-outdoor-sensors?variant=40047884468307) _Note: I would not recommend buying from pimoroni from EU as shipping tax is huge!_ + ## Images Circuit board: diff --git a/node1.c b/node1.c new file mode 100644 index 0000000..4d58302 --- /dev/null +++ b/node1.c @@ -0,0 +1,240 @@ +#include +#include "pico/stdlib.h" +#include "hardware/pio.h" +#include "hardware/clocks.h" +#include "blink_led.pio.h" + +// == TM1637Display == +// #define TM1637_CMD_DATA_AUTO 0x40 +#define TM1637_DELAY_US 20 // Delay time in microseconds +#define TM1637_CMD_DATA_FIXED 0x44 +#define TM1637_CMD_ADDR_START 0xC0 +#define TM1637_CMD_DISPLAY 0x88 +#define TM1637_BRIGHTNESS 5 // min 0 max 7 + +typedef struct { + uint clock_pin; + uint data_pin; +} TM1637Display; + +TM1637Display tm1637_init(uint clock_pin, uint data_pin); +void tm1637_write_command(const TM1637Display *d, uint8_t command); +void tm1637_display_number(const TM1637Display *d, uint num); +void tm1637_start(const TM1637Display *display); +void tm1637_stop(const TM1637Display *display); +void tm1637_write_bit(const TM1637Display *display, bool bit); +bool tm1637_write_byte(const TM1637Display *display, uint8_t byte); +void tm1637_write_command(const TM1637Display *display, uint8_t command); + + +const uint8_t tm1637_num_patterns[10] = { + 0x3F, // 0 + 0x06, // 1 + 0x5B, // 2 + 0x4F, // 3 + 0x66, // 4 + 0x6D, // 5 + 0x7D, // 6 + 0x07, // 7 + 0x7F, // 8 + 0x6F // 9 +}; + +TM1637Display tm1637_init(uint clock_pin, uint data_pin) { + TM1637Display display; + display.clock_pin = clock_pin; + display.data_pin = data_pin; + + + gpio_init(display.clock_pin); + gpio_init(display.data_pin); + + gpio_set_dir(display.clock_pin, GPIO_OUT); + gpio_set_dir(display.data_pin, GPIO_OUT); + tm1637_write_command(&display, TM1637_CMD_DISPLAY | TM1637_BRIGHTNESS); + return display; +} + +void tm1637_start(const TM1637Display *display) { + gpio_set_dir(display->data_pin, GPIO_OUT); + gpio_put(display->data_pin, 1); + gpio_put(display->clock_pin, 1); + sleep_us(TM1637_DELAY_US); + gpio_put(display->data_pin, 0); + sleep_us(TM1637_DELAY_US); + gpio_put(display->clock_pin, 0); +} + +void tm1637_stop(const TM1637Display *display) { + gpio_set_dir(display->data_pin, GPIO_OUT); + gpio_put(display->clock_pin, 0); + gpio_put(display->data_pin, 0); + sleep_us(TM1637_DELAY_US); + gpio_put(display->clock_pin, 1); + sleep_us(TM1637_DELAY_US); + gpio_put(display->data_pin, 1); + sleep_us(TM1637_DELAY_US); +} + +void tm1637_write_bit(const TM1637Display *display, bool bit) { + gpio_put(display->clock_pin, 0); + if (bit) + { + gpio_set_dir(display->data_pin, GPIO_IN); + } + else + { + gpio_set_dir(display->data_pin, GPIO_OUT); + gpio_put(display->data_pin, 0); + } + sleep_us(TM1637_DELAY_US); + gpio_put(display->clock_pin, 1); + sleep_us(TM1637_DELAY_US); + gpio_put(display->clock_pin, 0); + gpio_set_dir(display->data_pin, GPIO_OUT); +} + +bool tm1637_write_byte(const TM1637Display *display, uint8_t byte) { + for (int i = 0; i < 8; i++) + { + tm1637_write_bit(display, byte & 0x01); + byte >>= 1; + } + // Wait for ACK + gpio_set_dir(display->data_pin, GPIO_IN); + sleep_us(TM1637_DELAY_US); + gpio_put(display->clock_pin, 0); + sleep_us(TM1637_DELAY_US); + gpio_put(display->clock_pin, 1); + sleep_us(TM1637_DELAY_US); + bool ack = !gpio_get(display->data_pin); + gpio_put(display->clock_pin, 0); + gpio_set_dir(display->data_pin, GPIO_OUT); + return ack; +} + +void tm1637_write_command(const TM1637Display *display, uint8_t command) { + tm1637_start(display); + tm1637_write_byte(display, command); + tm1637_stop(display); +} + +void tm1637_display_number(const TM1637Display *display, uint num) { + if (num > 9999) return; + + uint8_t digits[4] = {0}; + + // Extract digits and store them in the array from most significant digit to least significant digit + for (int i = 0; i < 4; i++) + { + digits[3 - i] = num % 10; + num /= 10; + } + + tm1637_start(display); + bool ack = tm1637_write_byte(display, TM1637_CMD_DATA_FIXED); + tm1637_stop(display); + if(!ack) return tm1637_display_number(display, num); + + for (int i = 0; i < 4; i++) + { + tm1637_start(display); + bool ack1 = tm1637_write_byte(display, TM1637_CMD_ADDR_START + i); + bool ack2 = tm1637_write_byte(display, tm1637_num_patterns[digits[i]]); + tm1637_stop(display); + if(!ack1 || !ack2) return tm1637_display_number(display, num); + } +} + +// == LEDS == +void init_leds() { + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); +} +void set_led(bool state) { + gpio_put(PICO_DEFAULT_LED_PIN, state); +} +// == RGB_LED == + +// #define RGB_LED_PIN PICO_DEFAULT_LED_PIN +#define RGB_PIO_FREQ 2000 +// PIO blink example: https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-cc-part-3-how-to-use-pio/123ff7700bc547c79a504858c1bd8110 +// static const uint led_pin = 25; +// static const float pio_freq = 2000; +void init_rgb_leds() { + //Choose PIO instance (0 or 1) + PIO pio = pio0; + // Get first free state machine in PIO 0 + uint sm = pio_claim_unused_sm(pio, true); + + // Add PIO program to PIO instruction memory. SDK will find location and + // return with the memory offset of the program. + uint offset = pio_add_program(pio, &blink_program); + + // Calculate the PIO clock divider + float div = (float)clock_get_hz(clk_sys) / RGB_PIO_FREQ; + + // Initialize the program using the helper function in our .pio file + blink_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN, div); + + // Start running our PIO program in the state machine + pio_sm_set_enabled(pio, sm, true); + +} + +// == Buttons == +#define ARM_BTN_GPIO 15 +void init_btn(uint pin) { + gpio_init(pin); + gpio_set_dir(pin, GPIO_IN); + gpio_pull_up(pin); +} + +alarm_id_t armed_timer_id; +int64_t armed_cb() { + printf("ROCKET ARMED\n"); + return 0; +} + +bool arm_btn_pressed = false; +void check_btns() { + if(!gpio_get(ARM_BTN_GPIO) && !arm_btn_pressed) { + printf("BTN PRESSED\n"); + armed_timer_id = add_alarm_in_ms(5000, armed_cb, NULL, false); + arm_btn_pressed = true; + set_led(true); + } + + if(gpio_get(ARM_BTN_GPIO) && arm_btn_pressed) { + printf("BTN LET GO\n"); + cancel_alarm(armed_timer_id); + arm_btn_pressed = false; + set_led(false); + } +} + +int main() { + stdio_init_all(); + // const TM1637Display digit_display_001 = tm1637_init(12, 13); + // const TM1637Display digit_display_002 = tm1637_init(14, 15); + + // init_btn(ARM_BTN_GPIO); + // init_leds(); + init_rgb_leds(); + + // static absolute_time_t delayed_by_ms (const absolute_time_t t, uint32_t ms) + + // volatile bool timer_fired = false; + + while (true) { + check_btns(); + sleep_us(50); + + // for (int i = 0; i <= 9999; i ++) { + // printf("Display: %d \n", i); + // // tm1637_display_number(&digit_display_001, i); + // tm1637_display_number(&digit_display_002, i); + // sleep_ms(100); + // } + } +} diff --git a/CIRCUITPY/boot_out.txt b/old_micro_python_code/CIRCUITPY/boot_out.txt similarity index 100% rename from CIRCUITPY/boot_out.txt rename to old_micro_python_code/CIRCUITPY/boot_out.txt diff --git a/CIRCUITPY/code.py b/old_micro_python_code/CIRCUITPY/code.py similarity index 100% rename from CIRCUITPY/code.py rename to old_micro_python_code/CIRCUITPY/code.py diff --git a/CIRCUITPY/lib/adafruit_bme280/__init__.py b/old_micro_python_code/CIRCUITPY/lib/adafruit_bme280/__init__.py similarity index 100% rename from CIRCUITPY/lib/adafruit_bme280/__init__.py rename to old_micro_python_code/CIRCUITPY/lib/adafruit_bme280/__init__.py diff --git a/CIRCUITPY/lib/adafruit_bme280/basic.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_bme280/basic.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_bme280/basic.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_bme280/basic.mpy diff --git a/CIRCUITPY/lib/adafruit_bme280/protocol.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_bme280/protocol.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_bme280/protocol.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_bme280/protocol.mpy diff --git a/CIRCUITPY/lib/adafruit_bus_device/__init__.py b/old_micro_python_code/CIRCUITPY/lib/adafruit_bus_device/__init__.py similarity index 100% rename from CIRCUITPY/lib/adafruit_bus_device/__init__.py rename to old_micro_python_code/CIRCUITPY/lib/adafruit_bus_device/__init__.py diff --git a/CIRCUITPY/lib/adafruit_bus_device/i2c_device.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_bus_device/i2c_device.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_bus_device/i2c_device.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_bus_device/i2c_device.mpy diff --git a/CIRCUITPY/lib/adafruit_bus_device/spi_device.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_bus_device/spi_device.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_bus_device/spi_device.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_bus_device/spi_device.mpy diff --git a/CIRCUITPY/lib/adafruit_esp32spi/PWMOut.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/PWMOut.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/PWMOut.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/PWMOut.mpy diff --git a/CIRCUITPY/lib/adafruit_esp32spi/__init__.py b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/__init__.py similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/__init__.py rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/__init__.py diff --git a/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi.mpy diff --git a/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy diff --git a/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wifimanager.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wifimanager.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wifimanager.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wifimanager.mpy diff --git a/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/adafruit_esp32spi_wsgiserver.py diff --git a/CIRCUITPY/lib/adafruit_esp32spi/digitalio.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/digitalio.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_esp32spi/digitalio.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_esp32spi/digitalio.mpy diff --git a/CIRCUITPY/lib/adafruit_minimqtt/__init__.py b/old_micro_python_code/CIRCUITPY/lib/adafruit_minimqtt/__init__.py similarity index 100% rename from CIRCUITPY/lib/adafruit_minimqtt/__init__.py rename to old_micro_python_code/CIRCUITPY/lib/adafruit_minimqtt/__init__.py diff --git a/CIRCUITPY/lib/adafruit_minimqtt/adafruit_minimqtt.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_minimqtt/adafruit_minimqtt.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_minimqtt/adafruit_minimqtt.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_minimqtt/adafruit_minimqtt.mpy diff --git a/CIRCUITPY/lib/adafruit_minimqtt/matcher.mpy b/old_micro_python_code/CIRCUITPY/lib/adafruit_minimqtt/matcher.mpy similarity index 100% rename from CIRCUITPY/lib/adafruit_minimqtt/matcher.mpy rename to old_micro_python_code/CIRCUITPY/lib/adafruit_minimqtt/matcher.mpy diff --git a/CIRCUITPY/weather_station/__init__.py b/old_micro_python_code/CIRCUITPY/weather_station/__init__.py similarity index 100% rename from CIRCUITPY/weather_station/__init__.py rename to old_micro_python_code/CIRCUITPY/weather_station/__init__.py diff --git a/CIRCUITPY/weather_station/airlift.py b/old_micro_python_code/CIRCUITPY/weather_station/airlift.py similarity index 100% rename from CIRCUITPY/weather_station/airlift.py rename to old_micro_python_code/CIRCUITPY/weather_station/airlift.py diff --git a/CIRCUITPY/weather_station/bme280.py b/old_micro_python_code/CIRCUITPY/weather_station/bme280.py similarity index 100% rename from CIRCUITPY/weather_station/bme280.py rename to old_micro_python_code/CIRCUITPY/weather_station/bme280.py diff --git a/CIRCUITPY/weather_station/pubsub.py b/old_micro_python_code/CIRCUITPY/weather_station/pubsub.py similarity index 100% rename from CIRCUITPY/weather_station/pubsub.py rename to old_micro_python_code/CIRCUITPY/weather_station/pubsub.py diff --git a/CIRCUITPY/weather_station/timer.py b/old_micro_python_code/CIRCUITPY/weather_station/timer.py similarity index 100% rename from CIRCUITPY/weather_station/timer.py rename to old_micro_python_code/CIRCUITPY/weather_station/timer.py diff --git a/rsync-exclude.txt b/old_micro_python_code/rsync-exclude.txt similarity index 100% rename from rsync-exclude.txt rename to old_micro_python_code/rsync-exclude.txt diff --git a/settings.sample.toml b/old_micro_python_code/settings.sample.toml similarity index 100% rename from settings.sample.toml rename to old_micro_python_code/settings.sample.toml diff --git a/sync.sh b/old_micro_python_code/sync.sh similarity index 100% rename from sync.sh rename to old_micro_python_code/sync.sh diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake new file mode 100644 index 0000000..a0721d0 --- /dev/null +++ b/pico_sdk_import.cmake @@ -0,0 +1,84 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG)) + set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG}) + message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')") +endif () + +if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG) + set(PICO_SDK_FETCH_FROM_GIT_TAG "master") + message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG") +endif() + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") +set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + ) + endif () + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE})