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 TinyPICO from the ESP32 board selection list and off you go. 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 & EXAMPLE CODE

DOTSTAR LIBRARY

YOUTUBE SUBSCRIBER LIBRARY

NEO7SEGMENT LIBRARY

TMP1075 TEMPERATURE SENSOR


RE-INSTALLING or updating MicroPython

 

Even though your TinyPICO ships with MicroPython installed, you can just connect it to the Arduino IDE and flash it with C++ code. If you do that, MicroPython will be erased from your board in the process of flashing it, so what if you want to get MicroPython back on there?

There are 2 ways to get MicroPython onto your TinyPICO (or any other ESP32 development board):

Install the latest pre-built firmware

You can download and the latest firmware builds for your TinyPICO directly from the Micropython website and then deploy it to your TinyPICO by following the instructions.

Compile MicroPython from source

If you are adventurous, you can download the Espressif IDF and MicroPython source and compile it yourself.

HELPER LIBRARY

MicroPython

We’ve created a MicroPython helper library that makes accessing some of the features of the TinyPICO easy!

NOTE: This helper library is now included inside the official MicroPython TinyPICO firmware on the MicroPython downloads page, so there is no need to add this, or the Dotstar libraries.

Also, all TinyPICO’s shipped from indie or the TinyPICO shop include the helper library in the firmware provided. If you got your board from another source, then it’s likely to have an older MicroPython firmware on it that has the helper and Dotstar loaded into the file system instead..

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()

# 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 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()

# 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)


HELPER LIBRARY

ARDUINO

We’ve also created a TinyPICO Arduino helper library that makes accessing some of the features of the TinyPICO easy, including directly controlling the on-board Dotstar RGB LED without needing any other LED libraries!

The TinyPICO Arduino helper library is available from the library manager inside the Arduino IDE.

TinyPICO-Helper-Arduino-Library-Manager.png

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();

// 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> // Initialise the TinyPICO library TinyPICO tp = TinyPICO(); void setup() { // Used for debug output only Serial.begin(115200); } void loop() { // Cycle the DotStar LED colour every 25 milliseconds tp.DotStar_CycleColor(25); // You can set the DotStar LED colour directly using r,g,b values // tp.DotStar_SetPixelColor( 255, 128, 0 ); // You can set the DotStar LED colour directly using a uint32_t value // tp.DotStar_SetPixelColor( 0xFFC900 ); // You can clear the DotStar LED too // tp.DotStar_Clear(); // To power down the DotStar LED for deep sleep you call this // tp.DotStar_SetPower( false ); }