PLATFORMS

TP_Platforms.jpg

TinyPICO ships with MicroPython v1.10 pre flashed and some code to flash random colours on the APA102, so you know it’s working when you first plug it in. You can find out more on the MicroPython ESP32 QuickRef

TinyPICO also works great in the Arduino IDE - Just select ESP32 Pico Kit from the board selection list and off you go. We are hoping to have TinyPICO included in the boards list at a future time. Find out more about installing the Arduino IDE

If you are a C gun and love working low level, you can also write firmware for the TinyPICO using Espressif’s IDF which is about direct as you can get :-)


MicroPython CODE ON GITHUB

There is lots of MicroPython code on the internet, and we have listed some useful ones here:

TinyPICO Helper Library

DOTSTAR LIBRARY

YOUTUBE SUBSCRIBER LIBRARY

NEO7SEGMENT LIBRARY

TMP1075 TEMPERATURE SENSOR


HELPER LIBRARY

MicroPython

We’ve created a small helper library for MicroPython when using TinyPICO to make life easier!

Useful Pin Assignments

# Battery
BAT_VOLTAGE = const(35)
BAT_CHARGE = const(34)

# APA102 Dotstar pins for production boards
DOTSTAR_CLK = const(12)
DOTSTAR_DATA = const(2)
DOTSTAR_PWR = const(13)

# SPI
SPI_MOSI = const(23)
SPI_CLK = const(18)
SPI_MISO = const(19)

#I2C
I2C_SDA = const(21)
I2C_SCL = const(22)

#DAC
DAC1 = const(25)
DAC2 = const(26)

Helper Functions

# Get a *rough* estimate of the current battery voltage
# If the battery is not present, the charge IC will still report it's trying to charge at X voltage
# so it will still show a voltage.
def get_battery_voltage()

# Return the current charge state of the battery - we need to read the value multiple times
# to eliminate false negatives due to the charge IC not knowing the difference between no battery
# and a full battery not charging - This is why the charge LED flashes
def get_battery_charging()

# Return the internal PICO-D4 temperature in Farenheit
def get_internal_temp_F()

# Return the internal PICO-D4 temperature in Celcius
def get_internal_temp_C()

# Power to the on-oard Dotstar is controlled by a PNP transistor, so low is ON and high is OFF
# We also need to set the Dotstar clock and data pins to be inputs to prevent power leakage when power is off
# This might be improved at a future date
# The reason we have power control for the Dotstar is that it has a quiescent current of around 1mA, so we
# need to be able to cut power to it to minimise power consumption during deep sleep or with general battery powered use
# to minimse un-needed battery drain
def set_dotstar_power( state )

# Dotstar rainbow colour wheel
def dotstar_color_wheel( wheel_pos )

# Go into deep sleep but shut down the APA first to save power
# Use this  if you want lowest deep  sleep current
def go_deepsleep( t )

Example Use

from machine import SPI, Pin
import tinypico as TinyPICO
from micropython_dotstar import DotStar
import time, random, micropython

# Configure SPI for controlling the DotStar
# Internally we are using software SPI for this as the pins being used are not hardware SPI pins
spi = SPI(sck=Pin( TinyPICO.DOTSTAR_CLK ), mosi=Pin( TinyPICO.DOTSTAR_DATA ), miso=Pin( TinyPICO.SPI_MISO) ) 
# Create a DotStar instance
dotstar = DotStar(spi, 1, brightness = 0.5 ) # Just one DotStar, half brightness
# Turn on the power to the DotStar
TinyPICO.set_dotstar_power( True )

# Say hello
print("\nHello from TinyPICO!")
print("--------------------\n")

# Show some info on boot 
print("Battery Voltage is {}V".format( TinyPICO.get_battery_voltage() ) )
print("Battery Charge State is {}\n".format( TinyPICO.get_battery_charging() ) )

# Show available memory
print("Memory Info - micropython.mem_info()")
print("------------------------------------")
micropython.mem_info()

# Read the data every 15 seconds
update_interval = 5
# Make sure it fires immediately by starting it in the past
update_temp_time = time.time() - 10

def print_temp():
    global update_interval
    global update_temp_time

    # We only run the contents of this function every 5 seconds
    if update_temp_time < time.time():
        update_temp_time = time.time() + update_interval

        # Grab the temperates and print them
        print("\nInternal PICO-D4 Temp: {}°F {:.2f}°C".format( TinyPICO.get_internal_temp_F(), TinyPICO.get_internal_temp_C() ) )


# Create a colour wheel index int
color_index = 0

# Rainbow colours on the Dotstar
while True:
    # Get the R,G,B values of the next colour
    r,g,b = TinyPICO.dotstar_color_wheel( color_index )
    # Set the colour on the dotstar
    dotstar[0] = ( r, g, b, 0.5)
    # Increase the wheel index
    color_index += 1
    # Sleep for 20ms so the colour cycle isn't too fast
    time.sleep_ms(20)

    # Print the internal PICO-D4 temperature in F and C
    print_temp()


HELPER LIBRARY

ARDUINO

We’ve created a small helper library for MicroPython when using TinyPICO to make life easier!

Useful Pin Assignments

 
// APA102 Dotstar
#define DOTSTAR_PWR 13
#define DOTSTAR_DATA 2
#define DOTSTAR_CLK 12

// Battery
#define BAT_CHARGE 34
#define BAT_VOLTAGE 35
 

Helper Functions

// Class constructor
TinyPICO(); 

// Get a *rough* estimate of the current battery voltage
// If the battery is not present, the charge IC will still report it's trying to charge at X voltage
// so it will still show a voltage.
float GetBatteryVoltage();

// Return the current charge state of the battery - we need to read the value multiple times
// to eliminate false negatives due to the charge IC not knowing the difference between no battery
// and a full battery not charging - This is why the charge LED flashes
bool IsChargingBattery();

// Return the internal PICO-D4 temperature in Farenheit
uint8_t Get_Internal_Temp_F();

// Return the internal PICO-D4 temperature in Celcius
float Get_Internal_Temp_C();

// Power to the on-oard Dotstar is controlled by a PNP transistor, so low is ON and high is OFF
// We also need to set the Dotstar clock and data pins to be inputs to prevent power leakage when power is off
// The reason we have power control for the Dotstar is that it has a quiescent current of around 1mA, so we
// need to be able to cut power to it to minimise power consumption during deep sleep or with general battery powered use
// to minimse un-needed battery drain
void DotStar_SetPower( bool state );

// On-board Dotstar control
void DotStar_Clear();
void DotStar_SetBrightness( uint8_t );
void DotStar_SetPixelColor( uint32_t c );
void DotStar_SetPixelColor( uint8_t r, uint8_t g, uint8_t b );
void DotStar_Show( void );
void DotStar_CycleColor();
void DotStar_CycleColor( unsigned long wait );      
void DotStar_CycleColor();
void DotStar_CycleColor( unsigned long wait );

// Convert R,G,B values to uint32_t
uint32_t Color( uint8_t r, uint8_t g, uint8_t b );

 

Example Use

#include <TinyPICO.h>

// Interval between internal temperature reads
unsigned long next_temp_read = 0;   // Next time step in milliseconds 
uint8_t temp_read_interval = 1000;  // This is in milliseconds

// Initialise the TinyPICO library
TinyPICO tp = TinyPICO();

void setup()
{
    // Used for debug output only
    Serial.begin(115200);
}

void loop()
{
    // Cycle the DotStar colour every 25 miliseconds
    tp.DotStar_CycleColor(25);

    // You can set the DotStar colour directly using r,g,b values
    // tp.DotStar_SetPixelColor( 255, 128, 0 );

    // You can set the DotStar colour directly using a uint32_t value
    // tp.DotStar_SetPixelColor( 0xFFC900 );

    // You can aclear the DotStar too
    // tp.DotStar_Clear();

    // To power down the DotStar for deep sleep you call this
    // tp.DotStar_SetPower( false );

    // Print the internal temperature of the PICO-D4
    print_temp();
}

void print_temp()
{
    // We only run the contents of this function every *temp_read_interval* step
    if ( millis() > next_temp_read + temp_read_interval )
    {
        next_temp_read = millis();

        // Grab the temperature in Farenheit
        uint8_t temp_farenheit = tp.Get_Internal_Temp_F();

        // Grab the temperature in Celcius
        float temp_celsius = tp.Get_Internal_Temp_C();

        // Print the temperatures to the output console
        Serial.print("Temp In PICO-D4 ");
        Serial.print(temp_farenheit);
        Serial.print("°F ");
        Serial.print(temp_celsius);
        Serial.println("°C");
    }
}