Software

Coming soon.

There are already some basic examples in my Github repository.

Getting started

Compared to the Picoclick-C3T the C3 is optimized to be used with the Arduino framework which is probably great for most users. Of course the ESP-IDF can still be used for the C3, but the flashing configurations don't have to be changed like for the C3T.

I'm always using Visual Studio Code with the PlatformIO plugin to flash my microcontrollers. If you haven't worked with it yet I can recommend going through the quick start guide by Rui Santos (RandomNerdTutorials).

If you have set it up correctly you can simply start by adding a project folder to your workspace. In doing so you have to right click somewhere in the workspace and select "Add Folder to Workspace...". A great way to start is by choosing one of the Picoclick-C3 projects from my Github repository. Once added, the project structure should look like the structure shown in the right image. The two most important files are the main.cpp which is the file where all the project code goes in and the platform.ini which is the configuration file of the project. Latter defines what processor you are using, which COM-port the Picoclick is connected to and other build settings.

platform.ini

The project configuration file of your Picoclick project can look like this, where a ; defines a comment. If the upload_port and monitor_port are commented out, PlatformIO will assign these ports automatically. If only one device is connected to your computer this will work fine.

[env:arduino-esp32c3]
platform = https://github.com/Jason2866/platform-espressif32.git
board = esp32-c3-devkitm-1
board_build.flash_mode = qio
build_flags = 
	-DCORE_DEBUG_LEVEL=0
framework = arduino
upload_speed = 460800
;upload_port = /dev/cu.usbmodem11101
monitor_speed = 115200
;monitor_port = /dev/cu.usbmodem11101
platform_packages = 
	framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32#master
lib_deps = 
	fastled/FastLED@^3.5.0

The lip_deps defines which libraries and which versions are used. The FastLED library is used to control the APA102 LEDs and thus should be present in every project. If using other libraries these should be added to this list.

config.h

The config.h file is not neccessary but will clean up your main project file a bit. It defines the hardware definitions of the Picoclick and thus are always the same. Furthermore it contains some useful FastLED things and the function for reading the battery voltage. This file can be included by adding the line #include "config.h" in your main project and it should look like this:

// Picoclick C3 hardware definitions
#define ADC_ENABLE_PIN  3
#define APA102_SDI_PIN  7
#define APA102_CLK_PIN  6
#define ADC_PIN         4
#define BUTTON_PIN      5

#define FPC_IO_1        2
#define FPC_IO_2        8
#define FPC_IO_BTN      BUTTON_PIN

#define SDA_PIN         FPC_IO_1
#define SCL_PIN         FPC_IO_2

#define NUM_LEDS        2
CRGB leds[NUM_LEDS];

#define BAT_VOLT_MULTIPLIER   1.43
#define BAT_VOLT_OFFSET       0

void set_fastled(CRGB c0, CRGB c1){
    leds[0] = c0;
    leds[1] = c1;
    FastLED.show();
}

void set_fastled(CRGB c0){
    leds[0] = c0;
    leds[1] = c0;
    FastLED.show();
}

void switch_colors_fastled(){
    CRGB c_tmp = leds[1];
    leds[1] = leds[0];
    leds[0] = c_tmp;
    FastLED.show();
}

float get_battery_voltage(){
  digitalWrite(ADC_ENABLE_PIN, LOW);
  delayMicroseconds(10);
  int sum = 0;
  for(int i=0; i<100; i++){
    sum = sum + analogRead(ADC_PIN);
  }
  float result = sum/100.0;
  digitalWrite(ADC_ENABLE_PIN, HIGH);
  return float(result) * BAT_VOLT_MULTIPLIER + BAT_VOLT_OFFSET;
}

If the config.h file isn't used you have to add all these pin definitions in the top of your main.cpp file.

main.cpp

The main project file includes the code for your board and is similar to the .ino file for the Arduino IDE.

Following code is a basic example which will change the color of both LEDs if the button is pressed. If the button is press & hold for one second or the button isn't pressed for 10 seconds the Picoclick will turn off by entering the deep sleep mode with esp_deep_sleep_start(). Again, this won't enter the deep sleep of the ESP32 because the Picoclick will loose power beforehand due to the latching circuit.

#include <Arduino.h>
#include <WiFi.h>
#include <FastLED.h>
#include "config.h"

int color = 0;

void setup(){
  pinMode(BUTTON_PIN, INPUT);
  pinMode(ADC_ENABLE_PIN, OUTPUT);
  pinMode(ADC_PIN, INPUT);
  analogReadResolution(12);
  digitalWrite(ADC_ENABLE_PIN, HIGH);

  btStop();
  WiFi.mode(WIFI_OFF);

  FastLED.addLeds<APA102, APA102_SDI_PIN, APA102_CLK_PIN, BGR>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(180);
  delay(50);

  set_fastled(CRGB::Blue);
  delay(500);
}

unsigned long t_last_press = 0;

void loop() {
  // Change color if the button is pressed. After the eight click, generate random color. Press & hold for 1 second to turn off the device.
  // Device will turn off after 10 seconds not pressing the button.
  if(digitalRead(BUTTON_PIN) == 1){
    color++;
    CRGB tmp_color = CRGB::Black;

    if(color == 1) tmp_color = CRGB::Green;
    else if(color == 2) tmp_color = CRGB::Red;
    else if(color == 3) tmp_color = CRGB::Yellow;
    else if(color == 4) tmp_color = CRGB::White;
    else if(color == 5) tmp_color = CRGB::Orange;
    else if(color == 6) tmp_color = CRGB::Aqua;
    else if(color == 7) tmp_color = CRGB::HotPink;
    else if(color == 8) tmp_color = CRGB::LimeGreen;
    else{
      int r = random(255), g = random(255), b = random(255);
      tmp_color = CRGB(r, g, b);
    }

    set_fastled(tmp_color);

    unsigned long t_pressed = millis();
    while(digitalRead(BUTTON_PIN) == 1){
      delay(10);
      if(millis() > t_pressed + 1000){
        set_fastled(CRGB::Red);
        delay(1000);
        esp_deep_sleep_start();
      }
    }
    t_last_press = millis();
  }

  if(millis() - t_last_press > 10000){
    set_fastled(CRGB::Red);
    delay(1000);
    esp_deep_sleep_start();
  }
}

Last updated