├── .gitignore ├── Arduino ├── LED_RGBW │ └── LED_RGBW.ino └── README.md ├── README.md └── idf └── RGB_LED_Control ├── CMakeLists.txt ├── Makefile ├── README.md └── main ├── CMakeLists.txt ├── component.mk └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .vscode/ 3 | sdkconfig 4 | sdkconfig.old -------------------------------------------------------------------------------- /Arduino/LED_RGBW/LED_RGBW.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This example works on STAMP-C3 and STAMP-C3U. 3 | It is copied from the "Freenove_WS2812_Lib_for_ESP32" library example. 4 | Install "Freenove_WS2812_Lib_for_ESP32" library First. 5 | Depends: 6 | - [Freenove_WS2812_Lib_for_ESP32]https://github.com/Freenove/Freenove_WS2812_Lib_for_ESP32 7 | */ 8 | 9 | #include "Freenove_WS2812_Lib_for_ESP32.h" 10 | 11 | #define LEDS_COUNT 1 12 | #define LEDS_PIN 2 13 | #define CHANNEL 0 14 | 15 | Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL, TYPE_GRB); 16 | 17 | u8 m_color[5][3] = { 18 | {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 255}, {0, 0, 0} 19 | }; 20 | 21 | int delayval = 100; 22 | 23 | void setup() { 24 | strip.begin(); 25 | strip.setBrightness(10); 26 | } 27 | void loop() { 28 | for (int j = 0; j < 5; j++) { 29 | for (int i = 0; i < LEDS_COUNT; i++) { 30 | strip.setLedColorData(i, m_color[j][0], m_color[j][1], m_color[j][2]); 31 | strip.show(); 32 | delay(delayval); 33 | } 34 | delay(500); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Arduino/README.md: -------------------------------------------------------------------------------- 1 | # STAMP-C3/C3U Arduino Example 2 | 3 | 1. Use Arduino to open the projects. 4 | 2. Install ESP32 in Board Manager and all dependency libraries. 5 | 3. Select board type to "ESP32C3 Dev Module". 6 | 4. Enter download boot mode by holding STAMP-C3/C3U's center button and then connect it to the computer. 7 | 5. You can see serial port now, select the right serial port. 8 | 6. Compile, upload and run the example. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STAMP-C3 IDF Example 2 | 3 | 1. Use IDF to open the RGB_LED_CONTROL folder [RGB_LED_CONTROL](/idf/RGB_LED_CONTROL). 4 | 2. Connect the STAMP C3 to the computer and select the corresponding serial port. 5 | 3. Select ESP32C3 chip. 6 | 4. Compile and burn and open the serial port. 7 | 8 | The test environment is ESP-IDF v4.4.1-472-gc9140caf8c -------------------------------------------------------------------------------- /idf/RGB_LED_Control/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/led_strip) 6 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 7 | project(RGB_LED_Control) 8 | -------------------------------------------------------------------------------- /idf/RGB_LED_Control/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := led_strip 7 | 8 | EXTRA_COMPONENT_DIRS = ./common_components/led_strip 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | -------------------------------------------------------------------------------- /idf/RGB_LED_Control/README.md: -------------------------------------------------------------------------------- 1 | # STAMP-C3 IDF Example 2 | 3 | 1. Use IDF to open the RGB_LED_CONTROL folder [RGB_LED_CONTROL](/idf/RGB_LED_CONTROL). 4 | 2. Connect the STAMP C3 to the computer and select the corresponding serial port. 5 | 3. Select ESP32C3 chip. 6 | 4. Compile and burn and open the serial port. 7 | 8 | The test environment is ESP-IDF v4.4.1-472-gc9140caf8c -------------------------------------------------------------------------------- /idf/RGB_LED_Control/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "main.c" 2 | INCLUDE_DIRS ".") 3 | -------------------------------------------------------------------------------- /idf/RGB_LED_Control/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /idf/RGB_LED_Control/main/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sdkconfig.h" 3 | #include "freertos/FreeRTOS.h" 4 | #include "freertos/task.h" 5 | #include "freertos/event_groups.h" 6 | #include "esp_wifi.h" 7 | #include "esp_log.h" 8 | #include "driver/rmt.h" 9 | #include "led_strip.h" 10 | #include "esp_event.h" 11 | #include "nvs_flash.h" 12 | 13 | #include "esp_system.h" 14 | #include "lwip/err.h" 15 | #include "lwip/sys.h" 16 | #include "soc/rtc_cntl_reg.h" 17 | 18 | #include "driver/gpio.h" 19 | #include "driver/adc.h" 20 | #include 21 | #include "esp_system.h" 22 | 23 | #define STAMP_C3 24 | // #define STAMP_C3U 25 | 26 | #define RMT_TX_CHANNEL RMT_CHANNEL_0 27 | led_strip_t *strip; 28 | 29 | #ifdef STAMP_C3 30 | uint8_t PINS[] = {4, 5, 6, 7, 8, 10, 1, 0, 20, 9, 18, 19}; 31 | #define BTN_PIN 3 32 | #endif 33 | 34 | #ifdef STAMP_C3U 35 | uint8_t PINS[] = {4, 5, 6, 7, 8, 10, 1, 0, 21, 20, 3, 18, 19}; 36 | #define BTN_PIN 9 37 | #endif 38 | 39 | #define RMT_TX_GPIO 2 40 | 41 | uint8_t brill_red = 0; // Initial brilliance 42 | uint8_t brill_green = 25; // idem 43 | uint8_t brill_blue = 25; // idem 44 | #define brill 20 // inside main loop: max value for brilliance 45 | 46 | void update_led(uint8_t r, uint8_t g, uint8_t b) { 47 | ESP_ERROR_CHECK(strip->set_pixel(strip, 0, r, g, b)); 48 | ESP_ERROR_CHECK(strip->refresh(strip, 0)); 49 | } 50 | 51 | uint8_t state = 1; 52 | 53 | void io_reverse() { 54 | state = !state; 55 | ESP_LOGI("IO REVERSE", "IO STATE: %d", state); 56 | for (uint8_t index = 0; index < sizeof(PINS); index++) { 57 | gpio_set_level(PINS[index], state); 58 | } 59 | } 60 | 61 | uint8_t base_mac_addr[6] = {0}; 62 | 63 | void app_main(void) { 64 | // Init RMT 65 | rmt_config_t config = RMT_DEFAULT_CONFIG_TX(RMT_TX_GPIO, RMT_TX_CHANNEL); 66 | // set counter clock to 40MHz 67 | config.clk_div = 2; 68 | 69 | ESP_ERROR_CHECK(rmt_config(&config)); 70 | ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); 71 | 72 | // install ws2812 driver 73 | led_strip_config_t strip_config = 74 | LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t)config.channel); 75 | strip = led_strip_new_rmt_ws2812(&strip_config); 76 | if (!strip) { 77 | ESP_LOGE("Main", "Install WS2812 driver failed"); 78 | } 79 | 80 | // Get base MAC address from EFUSE BLK0(default option) 81 | esp_efuse_mac_get_default(base_mac_addr); 82 | 83 | ESP_LOGI("Main", "MAC: %X%X%X%X%X%X", base_mac_addr[0], base_mac_addr[1], 84 | base_mac_addr[2], base_mac_addr[3], base_mac_addr[4], 85 | base_mac_addr[5]); 86 | 87 | // INIT IO MODE 88 | for (uint8_t index = 0; index < sizeof(PINS); index++) { 89 | gpio_reset_pin(PINS[index]); 90 | gpio_set_direction(PINS[index], GPIO_MODE_OUTPUT); 91 | gpio_set_pull_mode(PINS[index], GPIO_PULLUP_ONLY); 92 | } 93 | 94 | gpio_set_direction(BTN_PIN, GPIO_MODE_INPUT); 95 | gpio_set_pull_mode(BTN_PIN, GPIO_PULLUP_ONLY); 96 | 97 | // update_led(0, 255, 200); 98 | ESP_LOGI("Main", "Initial LED brilliance set to: r(%d), g(%d) and b(%d)", 99 | brill_red, brill_green, brill_blue); 100 | update_led(brill_red, brill_green, brill_blue); 101 | 102 | while (true) { 103 | if (gpio_get_level(BTN_PIN) == 0) { 104 | vTaskDelay(5 / portTICK_RATE_MS); 105 | if (gpio_get_level(BTN_PIN) == 0) { 106 | int r = rand() % brill; // was "% 256" 107 | int g = rand() % brill; 108 | int b = rand() % brill; 109 | update_led(r, g, b); 110 | io_reverse(); 111 | while (gpio_get_level(BTN_PIN) == 0) { 112 | srand((unsigned)b); 113 | } 114 | ESP_LOGI("Main", "MAC: %X%X%X%X%X%X", base_mac_addr[0], 115 | base_mac_addr[1], base_mac_addr[2], base_mac_addr[3], 116 | base_mac_addr[4], base_mac_addr[5]); 117 | ESP_LOGI( 118 | "Main", 119 | "LED brilliance for r(%d), g(%d) and b(%d). Maximum: %d", r, 120 | g, b, brill); 121 | } 122 | } 123 | vTaskDelay(10 / portTICK_RATE_MS); 124 | } 125 | } 126 | --------------------------------------------------------------------------------