Editing Circuitpython
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 12: | Line 12: | ||
If you need more help, here is a [https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython more detailed description on the installation process at adafruit.com] | If you need more help, here is a [https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython more detailed description on the installation process at adafruit.com] | ||
− | |||
− | |||
= CircuitPy Drive = | = CircuitPy Drive = | ||
Line 76: | Line 74: | ||
print("On") | print("On") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Keyboard emulator == | == Keyboard emulator == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="python" line='line'> | <syntaxhighlight lang="python" line='line'> | ||
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries | # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries | ||
Line 158: | Line 114: | ||
keyboard_layout.write("Hi There") # ...Print the string | keyboard_layout.write("Hi There") # ...Print the string | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | = Using Libraries = | ||
+ | Here is an example of how to use libraries, in this case to read the accelerometer of the Arduino Nano Connect RP2024. | ||
+ | |||
+ | Download the library (in this case it is in the zip from Adafruit, see [https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect/accelerometer-gyroscope Download Project Bundle]). | ||
+ | |||
+ | Copy the library folders into the library folder on the USB drive (CIRCUITPY). | ||
+ | |||
+ | [[File:Cp08-lib.png|x250px]] | ||
+ | [[File:Cp09-lib02.png|x250px]] | ||
+ | |||
+ | Now you can use the libraries, e.g. for reading the accelerometer using the adafruit_lsm6ds library. | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
+ | # SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries | ||
+ | # | ||
+ | # SPDX-License-Identifier: MIT | ||
+ | import time | ||
+ | import board | ||
+ | from adafruit_lsm6ds.lsm6dsox import LSM6DSOX | ||
+ | |||
+ | i2c = board.I2C() # uses board.SCL and board.SDA | ||
+ | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller | ||
+ | sensor = LSM6DSOX(i2c) | ||
+ | |||
+ | while True: | ||
+ | print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration)) | ||
+ | print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro)) | ||
+ | print("") | ||
+ | time.sleep(0.5) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | for more details see: [https://learn.adafruit.com/circuitpython-on-the-arduino-nano-rp2040-connect/accelerometer-gyroscope on how to use the onboard IMU of the Arduino Nano RP2040 Connect (LSM6DSOXTR)] | ||
= Finding your PIN names - Pin mapping script = | = Finding your PIN names - Pin mapping script = | ||
Line 163: | Line 153: | ||
CircuitPython uses it own names which makes it easier to use the same code on different boards. But this requires you to first find out which PINs on your physical board map to the logical pins in the program code. | CircuitPython uses it own names which makes it easier to use the same code on different boards. But this requires you to first find out which PINs on your physical board map to the logical pins in the program code. | ||
− | There is a [https://learn.adafruit.com/circuitpython-essentials/circuitpython-pins-and-modules pin mapping scriptt avaiable for this at Adafruit]. You can download the [https://learn.adafruit.com/circuitpython-essentials/circuitpython-pins-and-modules project bundel there]. Here is the script, too | + | There is a [https://learn.adafruit.com/circuitpython-essentials/circuitpython-pins-and-modules pin mapping scriptt avaiable for this at Adafruit]. You can download the [https://learn.adafruit.com/circuitpython-essentials/circuitpython-pins-and-modules project bundel there]. Here is the script, too: |
<syntaxhighlight lang="python" line='line'> | <syntaxhighlight lang="python" line='line'> | ||
Line 238: | Line 228: | ||
== CircuitPython Pin Mapping for Raspberry PI Pico == | == CircuitPython Pin Mapping for Raspberry PI Pico == | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Install the Mu Editor = | = Install the Mu Editor = |