CircuitPython Built-Ins

CircuitPython comes 'with the kitchen sink' - a lot of the things you know and love about classic Python 3 (sometimes called CPython) already work. There are a few things that don't but we'll try to keep this list updated as we add more capabilities!

This is not an exhaustive list! It's just some of the many featuers you can use

Things that are Built In and Work

flow control

All the usual if, elif, else, for, while... work just as expected

math

import math will give you a range of handy mathematical functions

>>> dir(math)
['__name__', 'e', 'pi', 'sqrt', 'pow', 'exp', 'log', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'copysign', 'fabs', 'floor', 'fmod', 'frexp', 'ldexp', 'modf', 'isfinite', 'isinf', 'isnan', 'trunc', 'radians', 'degrees']

CircuitPython supports 30-bit wide floating point values so you can use int's and float's whenever you expect

tuples, lists, arrays, and dictionaries

You can organize data in ()',  []'s , and {}'s including strings, objects, floats, etc

classes/objects and functions

We use objects and functions extensively in our libraries so check out one of our many examples like this MCP9808 library for class examples

lambdas

Yep! You can create function-functions with lambda just the way you like em:

>>> g = lambda x: x**2
>>> g(8)
64

 

Things to watch out for!

  • The wide body of python libraries have not been ported over, so while we wish you could import numpy, numpy isn't available. So you may have to port some code over yourself!
  • For the ATSAMD21 based boards (Feather M0, Metro M0, Trinket M0, Gemma M0, Circuit PlayGround Express) there's a limited amount of RAM, we've found you can have about 250-ish lines of python (that's with various libraries) before you hit MemoryErrors. The upcoming SAMD51 chipset will help with that a ton but its not yet available)
  • Non-Express boards like Trinket M0 and Gemma M0 and non-Express Feathers do not include all of the hardware support. For example, audioio and bitbangio are not included.
  • Integers can only be up to 31 bits. Integers of unlimited size are not supported.
  • We keep up with MicroPython stable releases, so check out the core 'differences' they document here.
Last updated on 2017-12-01 at 04.59.09 PM Published on 2017-10-12 at 10.43.39 PM