Download Print this page

Raspberry Pi Pico Python SDK Manual page 37

A micropython environment for rp2040 microcontrollers

Advertisement

Raspberry Pi Pico Python SDK
 23
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 24
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 25
# THE SOFTWARE.
 26
#
 27
# Sample code sections
 28
# ------------ SPI ------------------
 29
# Pin Map SPI
 30
#
 31
#
 32
#
 33
#
 34
#
 35
#
 36
#
 37
#
 38
# for CS, D/C and Res other ports may be chosen.
 39
#
 40
# from machine import Pin, SPI
 41
# import sh1106
 42
 43
# spi = SPI(1, baudrate=1000000)
 44
# display = sh1106.SH1106_SPI(128, 64, spi, Pin(5), Pin(2), Pin(4))
 45
# display.sleep(False)
 46
# display.fill(0)
 47
# display.text('Testing 1', 0, 0, 1)
 48
# display.show()
 49
#
 50
# --------------- I2C ------------------
 51
#
 52
# Pin Map I2C
 53
#
 54
#
 55
#
 56
#
 57
#
 58
#
 59
#
 60
#
 61
# Pin's for I2C can be set almost arbitrary
 62
#
 63
# from machine import Pin, I2C
 64
# import sh1106
 65
#
 66
# i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
 67
# display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c)
 68
# display.sleep(False)
 69
# display.fill(0)
 70
# display.text('Testing 1', 0, 0, 1)
 71
# display.show()
 72
 73
from
 74
import
 75
import
 76
 77
 78
# a few register definitions
 79 _SET_CONTRAST
 80 _SET_NORM_INV
 81 _SET_DISP
 82 _SET_SCAN_DIR
 83 _SET_SEG_REMAP
 84 _LOW_COLUMN_ADDRESS
 85 _HIGH_COLUMN_ADDRESS = const(0x10)
Using a SH1106-based OLED graphics display
- 3v - xxxxxx
- Vcc
- G
- xxxxxx
- Gnd
- D7 - GPIO 13
- Din / MOSI fixed
- D5 - GPIO 14
- Clk / Sck fixed
- D8 - GPIO 4
- CS (optional, if the only connected device)
- D2 - GPIO 5
- D/C
- D1 - GPIO 2
- Res
- 3v - xxxxxx
- Vcc
- G
- xxxxxx
- Gnd
- D2 - GPIO 5
- SCK / SCL
- D1 - GPIO 4
- DIN / SDA
- D0 - GPIO 16
- Res
- G
- xxxxxx
CS
- G
- xxxxxx
D/C
micropython
import
const
utime
as
time
framebuf
= const(0x81)
= const(0xa6)
= const(0xae)
= const(0xc0)
= const(0xa0)
= const(0x00)
36

Advertisement

loading
Need help?

Need help?

Do you have a question about the Pico Python SDK and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Pico seriesPico 2