Example: biology

CircuitPython Essentials - Adafruit Industries

CircuitPython EssentialsCreated by Kattni Rembor updated on 2022-02-14 12:29:38 PM EST Adafruit IndustriesPage 1 of 1155566791010111111111212121212141717181 8181919232424242525292931333839394141414 248 Table of ContentsCircuitPython EssentialsCircuitPython Pins and Modules CircuitPython Pins import board I2C, SPI, and UART What Are All the Available Names? Microcontroller Pin Names CircuitPython Built-In ModulesCircuitPython Built-Ins Thing That Are Built In and Work Flow Control Math Tuples, Lists, Arrays, and Dictionaries Classes, Objects and Functions Lambdas Random NumbersCircuitPython Digital In & Out Find the pins!

Dec 12, 2021 · However, CircuitPython makes this simpler by including the I2C singleton in the boa rd module. Instead of the two lines of code above, you simply provide the singleton as the I2C object. So if you were using the TSL2591 and its CircuitPython library, the two above lines of code would be replaced with: tsl2591 = adafruit_tsl2591.TSL2591(board.I2C())

Tags:

  Make, Circuitpython, Circuitpython makes

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of CircuitPython Essentials - Adafruit Industries

1 CircuitPython EssentialsCreated by Kattni Rembor updated on 2022-02-14 12:29:38 PM EST Adafruit IndustriesPage 1 of 1155566791010111111111212121212141717181 8181919232424242525292931333839394141414 248 Table of ContentsCircuitPython EssentialsCircuitPython Pins and Modules CircuitPython Pins import board I2C, SPI, and UART What Are All the Available Names? Microcontroller Pin Names CircuitPython Built-In ModulesCircuitPython Built-Ins Thing That Are Built In and Work Flow Control Math Tuples, Lists, Arrays, and Dictionaries Classes, Objects and Functions Lambdas Random NumbersCircuitPython Digital In & Out Find the pins!

2 Read the DocsCircuitPython Analog In Creating the analog input get_voltage Helper Main Loop Changing It Up Wire it up Reading Analog Pin ValuesCircuitPython Analog Out Creating an analog output Setting the analog output Main Loop Find the pinCircuitPython Audio Out Play a Tone Play a Wave File Wire It UpCircuitPython MP3 AudioCircuitPython PWM PWM with Fixed Frequency Create a PWM Output Main Loop PWM Output with Variable Frequency Wire it up Where's My PWM? Adafruit IndustriesPage 2 of 1154949515253535455585959606162636364656 6666768686970727373747475767780818282858 6888989919192929494 CircuitPython Servo Servo Wiring Standard Servo Code Continuous Servo CodeCircuitPython Cap Touch Create the Touch Input Main Loop Find the Pin(s) CircuitPython Internal RGB LED Create the LED Brightness Main Loop Making Rainbows (Because Who Doesn't Love 'Em!)

3 Circuit Playground Express RainbowCircuitPython NeoPixel Wiring It Up The Code Create the LED NeoPixel Helpers Main Loop NeoPixel RGBW Read the DocsCircuitPython DotStar Wire It Up The Code Create the LED DotStar Helpers Main Loop Is it SPI? Read the DocsCircuitPython UART Serial The Code Wire It Up Where's my UART? Trinket M0: Create UART before I2 CCircuitPython I2C Wire It Up Find Your Sensor I2C Sensor Data Where's my I2C? CircuitPython HID Keyboard and Mouse CircuitPython Keyboard Emulator Create the Objects and Variables The Main Loop Non-US Keyboard Layouts CircuitPython Mouse Emulator Create the Objects and Variables CircuitPython HID Mouse Helpers Adafruit IndustriesPage 3 of 1159595981001011011021021031031041041051 05106106107107107 Main LoopCircuitPython Storage Logging the TemperatureCircuitPython CPU TempCircuitPython Expectations Always Run the Latest Version of CircuitPython and Libraries I have to continue using CircuitPython or , where can I find compatible libraries?

4 Switching Between CircuitPython and Arduino The Difference Between Express And Non-Express Boards Non-Express Boards: Gemma, Trinket, and QT Py Differences Between CircuitPython and MicroPython Differences Between CircuitPython and PythonCircuitPython Resetting Soft Reset Hard Reset Reset Into Specific Mode More InfoCircuitPython Libraries and DriversCircuitPython Libraries Adafruit IndustriesPage 4 of 115 CircuitPython Essentials You've gone through the Welcome to CircuitPython guide ( ). You've already gotten everything setup, and you've gotten CircuitPythonrunning. Great! Now what? CircuitPython Essentials !There are a number of core modules built into CircuitPython and commonly usedlibraries available.

5 This guide will introduce you to these and show you an example ofhow to use each section will present you with a piece of code designed to work with differentboards, and explain how to use the code with each board. These examples work withany board designed for CircuitPython , including Circuit Playground Express, TrinketM0, Gemma M0, QT Py, ItsyBitsy M0 Express, ItsyBitsy M4 Express, Feather M0 Express, Feather M4 Express, Metro M4 Express, Metro M0 Express, Trellis M4 Express, and Grand Central M4 examples require external components, such as switches or sensors. You'll findwiring diagrams where applicable to show you how to wire up the necessarycomponents to work with each 's get started learning the CircuitPython Essentials !

6 CircuitPython Pins and Modules CircuitPython is designed to run on microcontrollers and allows you to interface withall kinds of sensors, inputs and other hardware peripherals. There are tons of guidesshowing how to wire up a circuit, and use CircuitPython to, for example, read datafrom a sensor, or detect a button press. Most CircuitPython code includes hardwaresetup which requires various modules, such as board or digitalio. You importthese modules and then use them in your code. How does CircuitPython know to look Adafruit IndustriesPage 5 of 115for hardware in the specific place you connected it, and where do these modulescome from?

7 This page explains both. You'll learn how CircuitPython finds the pins on yourmicrocontroller board, including how to find the available pins for your board andwhat each pin is named. You'll also learn about the modules built into CircuitPython ,including how to find all the modules available for your PinsWhen using hardware peripherals with a CircuitPython compatible microcontroller,you'll almost certainly be utilising pins. This section will cover how to access yourboard's pins using CircuitPython , how to discover what pins and board-specificobjects are available in CircuitPython for your board, how to use the board-specificobjects, and how to determine all available pin names for a given pin on your board When you're using any kind of hardware peripherals wired up to your microcontrollerboard, the import list in your code will include import board.

8 The board module isbuilt into CircuitPython , and is used to provide access to a series of board-specificobjects, including pins. Take a look at your microcontroller board. You'll notice thatnext to the pins are pin labels. You can always access a pin by its pin label. However,there are almost always multiple names for a given see all the available board-specific objects and pins for your board, enter the REPL(>>>) and run the following commands:import boarddir(board)Here is the output for the QT Py. You may have a different board, and this list will vary,based on the board. Adafruit IndustriesPage 6 of 115 The following pins have labels on the physical QT Py board: A0, A1, A2, A3, SDA, SCL,TX, RX, SCK, MISO, and MOSI.

9 You see that there are many more entries available in board than the labels on the QT can use the pin names on the physical board, regardless of whether they seem tobe specific to a certain example, you do not have to use the SDA pin for I2C - you can use it for a buttonor the flip side, there may be multiple names for one pin. For example, on the QT Py,pin A0 is labeled on the physical board silkscreen, but it is available in CircuitPythonas both A0 and D0. For more information on finding all the names for a given pin,see the What Are All the Available Pin Names? ( ) section results of dir(board) for CircuitPython compatible boards will look similar tothe results for the QT Py in terms of the pin names, A0, D0, etc.

10 However, someboards, for example, the Metro ESP32-S2, have different styled pin names. Here is theoutput for the Metro that most of the pins are named in an IO# style, such as IO1 and IO2. Those pinson the physical board are labeled only with a number, so an easy way to know how toaccess them in CircuitPython , is to run those commands in the REPL and find the pinnaming , SPI, and UARTYou'll also see there are often (but not always!) three special board-specific objectsincluded: I2C, SPI, and UART - each one is for the default pin-set used for each ofthe three common protocol busses they are named for. These are called singletons.


Related search queries