From 14314f54c0a8ef73c75315541e4bd9e4bb59c9be Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Sat, 28 Feb 2026 20:47:02 +1100 Subject: [PATCH] build is set up --- README.md | 15 ++++- relay/.gitignore | 1 + relay/CMakeLists.txt | 19 ++++++ relay/main.c | 15 +++++ relay/pico_sdk_import.cmake | 121 ++++++++++++++++++++++++++++++++++++ 5 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 relay/.gitignore create mode 100644 relay/CMakeLists.txt create mode 100644 relay/main.c create mode 100644 relay/pico_sdk_import.cmake diff --git a/README.md b/README.md index a2e10f3..08afc77 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,17 @@ A connector lets you use the mesh network over bluetooth, they would be somewher - TP4056 Charger ($2.11) | [Buy](https://www.amazon.com/18650-Board-TP4056-Module-Protect/dp/B09SWBM31Z?crid=C8N1XC4HLDXF&dib=eyJ2IjoiMSJ9.Ucrx7MAXbCG7TEifdeu7RmSnK3LGRgsxnNN2Vvbzxt8PDRbYg_8aqnR4aTsyQpZx2CcgioGKLXpBZ_tNYS2AlUP4XybzGQ0zI2LGu4bn-GBb5kZTp3F0gEpDL1jiQkanKi1jxQv5jR0kTFtn432DA38uKen0RL37BQjW0P4jxGOHfKF6IPB4myUbQ9VcP0-BnH9qRUvGoJzAtzP71FoQOVjD0ZweFCZ9zLc7fCa7iXw.C08ESSiAZHdEtUpxkY-RoC8xiG_Di4Q_aIVbzopsJXM&dib_tag=se&keywords=TP4056&qid=1772238259&sprefix=%2Caps%2C263&sr=8-1) # Setting up your device -idk yet haven't coded it lmao :sob: \ No newline at end of file +There are provided `.uf2` files in the Releases tab which you can easily flash to your Pico depending on which node you're building. + +# Setting up your device (building from source) +Depending on whether you're building a relay, you will need to cd into a different directory, but the command is the same. You will need the Raspberry Pi Pico SDK to build, [this video](https://www.youtube.com/watch?v=JhajoAyP8e4) is a good place to get that installed. + +For relays for example: +1. `cd relay` +2. `mkdir build` +3. `cd build` +4. `cmake -DPICO_SDK_PATH=$PICO_SDK_PATH ..` + +For connectors it's the same but the folder should be "connector" instead of "relay". + +This will put a `.uf2` file in the current directory, you can now boot your board in the BOOTSEL mode by holding the white button when plugging in the board, and then dragging the `.uf2` file into the drive that appears in your file explorer. \ No newline at end of file diff --git a/relay/.gitignore b/relay/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/relay/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/relay/CMakeLists.txt b/relay/CMakeLists.txt new file mode 100644 index 0000000..478c96e --- /dev/null +++ b/relay/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 4.2) + +include(pico_sdk_import.cmake) + +project(relay C CXX ASM) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +set(PICO_EXAMPLES_PATH $(PROJECT_SOURCE_DIR)) + +pico_sdk_init() + +add_executable(relay + main.c + ) + +target_link_libraries(relay pico_stdlib) + +pico_add_extra_outputs(relay) \ No newline at end of file diff --git a/relay/main.c b/relay/main.c new file mode 100644 index 0000000..1aed12a --- /dev/null +++ b/relay/main.c @@ -0,0 +1,15 @@ +#include "pico/stdlib.h" + +#define LED_PIN 25 + +int main() { + gpio_init(LED_PIN); + gpio_set_dir(LED_PIN, GPIO_OUT); + + while (true) { + gpio_put(LED_PIN, 1); + sleep_ms(2000); + gpio_put(LED_PIN, 0); + sleep_ms(2000); + } +} \ No newline at end of file diff --git a/relay/pico_sdk_import.cmake b/relay/pico_sdk_import.cmake new file mode 100644 index 0000000..d493cc2 --- /dev/null +++ b/relay/pico_sdk_import.cmake @@ -0,0 +1,121 @@ +# 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() + +# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +# following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following +# disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +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 () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + ) + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Populate( + pico_sdk + QUIET + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + GIT_SUBMODULES_RECURSE FALSE + + SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src + BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build + SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild + ) + else () + FetchContent_Populate( + pico_sdk + QUIET + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG} + + SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src + BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build + SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild + ) + endif () + + 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})