« Turtorial Examples for RpiZero-MicroPython | トップページ | Turtorial Examples for Maixduino-MicroPython(MaixPy) »

2020年3月11日 (水)

Turtorial Examples for CC3200-MicroPython

2020/3/11

Turtorial Examples for CC3200-MicroPython

CC3200

LaunchPad CC3200 WiFi pinout
Ti/swru372c.pdf
Ti/cc3200.pdf

I2C pinout:

P1_xx Func
P1_01(3.3V) VCC
P1_09(P01/GP10) SCL
P1_10(P02/GP11) SDA
P2_xx Func
P2_20(GND) GND

SPI pinout:

P1_xx Func
P1_01(3.3V) VCC
P1_07(P05/GP14) CLK
P2_xx Func
P2_20(GND GND
P2_18(P08/GP17) CS
P2_15(P07/GP16) MOSI(DOUT)
P2_14(P06/GP15) MISO(DIN)

GPIO pinout:

P1_xx Func
P1_01(3.3V) VCC
P1_05(P61/GP06) GPIO
P1_08(P62/GP07) GPIO
P2_xx Func
P2_20(GND) GND
P2_19(P18/GP28) GPIO
P2_18(P08/GP17) CS
P2_15(P07/GP16) MOSI(DOUT)
P2_14(P06/GP15) MISO(DIN)
P2_12(P55/GP01) GPIO
P2_11(P15/GP22) GPIO

decimal numbers not supported

>>> a = 0.123 Traceback (most recent call last): File "<stdin>", line 1 SyntaxError: decimal numbers not supported >>>

Pin/GPIO

from machine import Pin # Orange LED - D6(GP10) on board gp10_out = Pin('GP10', mode=Pin.OUT) gp10_out.value(1) gp10_out.value(0) # Green LED - D5(GP11) on board gp11_out = Pin('GP11', mode=Pin.OUT) gp11_out.value(1) gp11_out.value(0)
from machine import Pin # SW2 GPIO22 # SW3 GPIO13 # make GP22 an input with the pull-up enabled gp22_in = Pin('GP22', mode=Pin.IN, pull=Pin.PULL_UP) gp22_in() # get value, 0 or 1 on SW2 # make GP13 an input with the pull-up enabled gp13_in = Pin('GP13', mode=Pin.IN, pull=Pin.PULL_UP) gp13_in() # get value, 0 or 1 on SW3

SW control LED

from machine import Pin ledOrange = Pin('GP10', mode=Pin.OUT) ledGreen = Pin('GP11', mode=Pin.OUT) sw2 = Pin('GP22', mode=Pin.IN, pull=Pin.PULL_UP) sw3 = Pin('GP13', mode=Pin.IN, pull=Pin.PULL_UP) while True: ledOrange.value(sw2()) ledGreen.value(sw3())

PWM

# make LEDs off from machine import Pin # Orange LED - D6(GP10) on board gp10_out = Pin('GP10', mode=Pin.OUT) gp10_out.value(0) # Green LED - D5(GP11) on board gp11_out = Pin('GP11', mode=Pin.OUT) gp11_out.value(0) # from machine import Timer # timer 3 in PWM mode and width must be 16 buts tim = Timer(3, mode=Timer.PWM, width=16) # enable channel A @1KHz with a 1.55% duty cycle tim_a = tim.channel(Timer.A, freq=1000, duty_cycle=0155) # p1(GP10): Orange LED on board # enable channel B @1KHz with a 30.55% duty cycle tim_b = tim.channel(Timer.B, freq=1000, duty_cycle=3055) # p2(GP11): Green LED on board

ADC

from time import sleep_ms # p57 GP2 a#0 # p58 GP3 a#1 # p59 GP4 a#2 # p60 GP5 a#3 # read value, 0-4095 from machine import ADC adc = ADC() a0in = adc.channel(pin='GP2') a1in = adc.channel(pin='GP3') a2in = adc.channel(pin='GP4') a3in = adc.channel(pin='GP5') while True: print('p57:'+str(a0in())) print('p58:'+str(a1in())) print('p59:'+str(a2in())) print('p60:'+str(a3in())) print('============') sleep_ms(1000)

SPI

SDCard(動作確認無し、ピン配置からの推測)

# SDCard from machine import SD, Pin import os # clock pin, cmd pin, data0 pin # 以下の2つの設定のうち1つを使用する # 設定#1 sd0_clk = Pin('GP10', mode=Pin.ALT, alt=6) sd0_cmd = Pin('GP11', mode=Pin.ALT, alt=6) sd0_dat0 = Pin('GP15', mode=Pin.ALT, alt=8) # 設定#2 sd0_clk = Pin('GP16', mode=Pin.ALT, alt=8) sd0_cmd = Pin('GP17', mode=Pin.ALT, alt=8) sd0_dat0 = Pin('GP15', mode=Pin.ALT, alt=8) sd = SD(pins=(sd0_clk, sd0_cmd, sd0_dat0) # SD0_CLK(SCL) SD0_CMD(MOSI) SD0_DAT0(MISO) os.mount(sd, '/sd')

another SPI sample:
see NeoPixel(are using SPI)

I2C

from machine import Pin, I2C scl0 = Pin('GP10', mode=Pin.ALT, alt=1) sda0 = Pin('GP11', mode=Pin.ALT, alt=1) i2c = I2C(0, scl=scl0, sda=sda0) i2c.scan() # [24, 65] (ボード上の以下のデバイスのアドレスが返る) # BMA222 (加速度センサ) 24(0x18) # TMP006 (温度センサ) 65(0x41)

RTC

from machine import RTC rtc = RTC() # init with default time and date rtc = RTC(datetime=(2020, 3, 11, 0, 21, 0, 0, None)) # init with a specific time and date print(rtc.now())

NeoPixel

module install:

git clone https://github.com/JanBednarik/micropython-ws2812.git cd micropython-ws2812 Patch ws2812.py to ws2812_cc3200.py as follows: patch#1: import pyb -> import machine as pyb patch#2: self.spi = pyb.SPI(spi_bus, pyb.SPI.MASTER, baudrate=3200000, polarity=0, phase=1) -> self.spi = pyb.SPI(spi_bus,baudrate=3200000, polarity=0, phase=1) patch#3: self.spi.send(self.buf) -> self.spi.write(self.buf) Put it in /flash ampy put ws2812_cc3200.py

demo sample:

# connect the following pin to DIN of nexpixels # P2_15(P07/GP16) (if spi_bus=0) from ws2812_cc3200 import WS2812 chain = WS2812(spi_bus=0, led_count=4) data = [ (255, 0, 0), # red (0, 255, 0), # greenp (0, 0, 255), # blue (85, 85, 85), # white ] chain.show(data)

Networking

以下の部分は自分のWiFi環境に合わせて変更すること:
MYSSID = "your_ssid"
MYKEY = "your_passwd"

IPを静的に与えるサンプルにもなっているので IPがかち合っていれば、IPも変更すること。

CC3200_starwars.py

MYSSID = "your_ssid" MYKEY = "your_passwd import machine from network import WLAN # configure the WLAN subsystem in station mode (the default is AP) wlan = WLAN(mode=WLAN.STA) # go for fixed IP settings wlan.ifconfig(config=('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8')) #wlan.scan() # scan for available networks wlan.connect(ssid=MYSSID, auth=(WLAN.WPA2, MYKEY)) while not wlan.isconnected(): pass print(wlan.ifconfig()) #========================================== # Star Wars ASCII Art (python3) import socket addr_info = socket.getaddrinfo("towel.blinkenlights.nl",23) addr = addr_info[0][-1] s = socket.socket() s.connect(addr) while True: data = s.recv(500) print(str(data, 'utf8'), end='') #=============================================

starwarsのASCII_Artのアニメが表示されればOKとなる。

Peformace Test

performanceTestCC3200.py

# Peformace Test for CC3200 from machine import RTC rtc = RTC(datetime=(2020, 2, 9, 10, 11, 0, 0, None)) def performanceTest(): secs = rtc.now()[5] endTime = secs + 10 count = 0 while rtc.now()[5] < endTime: count += 1 print("Count: ", count) performanceTest()

以上

|

« Turtorial Examples for RpiZero-MicroPython | トップページ | Turtorial Examples for Maixduino-MicroPython(MaixPy) »

linux」カテゴリの記事

MicroPython」カテゴリの記事

CC3200」カテゴリの記事

コメント

この記事へのコメントは終了しました。