nrf: Remove really old examples
These examples rely on machine and pyb modules, so they have to get. Leaving 3 BLE examples that also rely on those modules, but can be fixed to use CP's modules.
This commit is contained in:
parent
9c08db55ff
commit
deec17e4fe
@ -1,35 +0,0 @@
|
||||
"""
|
||||
|
||||
Example for pca10040 / nrf52832 to show how mount
|
||||
and list a sdcard connected over SPI.
|
||||
|
||||
|
||||
Direct wireing on SD card (SPI):
|
||||
______________________________
|
||||
| \
|
||||
| 9. | NC | \
|
||||
| 1. | ~CS | |
|
||||
| 2. | MOSI | |
|
||||
| 3. | GND | |
|
||||
| 4. | VCC3.3| |
|
||||
| 5. | SCK | |
|
||||
| 6. | GND | |
|
||||
| 7. | MISO | |
|
||||
| 8. | NC | |
|
||||
| |
|
||||
---------------------------------
|
||||
"""
|
||||
|
||||
import os
|
||||
from machine import SPI, Pin
|
||||
from sdcard import SDCard
|
||||
|
||||
def mnt():
|
||||
cs = Pin("A22", mode=Pin.OUT)
|
||||
sd = SDCard(SPI(0), cs)
|
||||
os.mount(sd, '/')
|
||||
|
||||
def list():
|
||||
files = os.listdir()
|
||||
print(files)
|
||||
|
@ -1,15 +0,0 @@
|
||||
import time
|
||||
from machine import PWM, Pin
|
||||
|
||||
def pulse():
|
||||
for i in range(0, 101):
|
||||
p = PWM(0, Pin("A17", mode=Pin.OUT), freq=PWM.FREQ_16MHZ, duty=i, period=16000)
|
||||
p.init()
|
||||
time.sleep_ms(10)
|
||||
p.deinit()
|
||||
|
||||
for i in range(0, 101):
|
||||
p = PWM(0, Pin("A17", mode=Pin.OUT), freq=PWM.FREQ_16MHZ, duty=100-i, period=16000)
|
||||
p.init()
|
||||
time.sleep_ms(10)
|
||||
p.deinit()
|
@ -1,50 +0,0 @@
|
||||
# This file is part of the MicroPython project, http://micropython.org/
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2017 Glenn Ruben Bakke
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE
|
||||
|
||||
import time
|
||||
from machine import PWM, Pin
|
||||
|
||||
class Servo():
|
||||
def __init__(self, pin_name=""):
|
||||
if pin_name:
|
||||
self.pin = Pin(pin_name, mode=Pin.OUT, pull=Pin.PULL_DOWN)
|
||||
else:
|
||||
self.pin = Pin("A22", mode=Pin.OUT, pull=Pin.PULL_DOWN)
|
||||
def left(self):
|
||||
p = PWM(0, self.pin, freq=PWM.FREQ_125KHZ, pulse_width=105, period=2500, mode=PWM.MODE_HIGH_LOW)
|
||||
p.init()
|
||||
time.sleep_ms(200)
|
||||
p.deinit()
|
||||
|
||||
def center(self):
|
||||
p = PWM(0, self.pin, freq=PWM.FREQ_125KHZ, pulse_width=188, period=2500, mode=PWM.MODE_HIGH_LOW)
|
||||
p.init()
|
||||
time.sleep_ms(200)
|
||||
p.deinit()
|
||||
|
||||
def right(self):
|
||||
p = PWM(0, self.pin, freq=PWM.FREQ_125KHZ, pulse_width=275, period=2500, mode=PWM.MODE_HIGH_LOW)
|
||||
p.init()
|
||||
time.sleep_ms(200)
|
||||
p.deinit()
|
@ -1,213 +0,0 @@
|
||||
# This file is part of the MicroPython project, http://micropython.org/
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2017 Glenn Ruben Bakke
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE
|
||||
|
||||
# MicroPython controller for PowerUp 3.0 paper airplane
|
||||
# https://www.poweruptoys.com/products/powerup-v3
|
||||
#
|
||||
# Examples is written for nrf52832, pca10040 using s132 bluetooth stack.
|
||||
#
|
||||
# Joystick shield pin mapping:
|
||||
# - analog stick x-direction - ADC0 - P0.02/"A02"
|
||||
# - buttons P0.13 - P0.16 / "A13", "A14", "A15", "A16"
|
||||
#
|
||||
# Example usage:
|
||||
#
|
||||
# from powerup import PowerUp3
|
||||
# p = PowerUp3()
|
||||
|
||||
import time
|
||||
from machine import ADC
|
||||
from machine import Pin
|
||||
from ubluepy import Peripheral, Scanner, constants
|
||||
|
||||
def bytes_to_str(bytes):
|
||||
string = ""
|
||||
for b in bytes:
|
||||
string += chr(b)
|
||||
return string
|
||||
|
||||
def get_device_names(scan_entries):
|
||||
dev_names = []
|
||||
for e in scan_entries:
|
||||
scan = e.getScanData()
|
||||
if scan:
|
||||
for s in scan:
|
||||
if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME:
|
||||
dev_names.append((e, bytes_to_str(s[2])))
|
||||
return dev_names
|
||||
|
||||
def find_device_by_name(name):
|
||||
s = Scanner()
|
||||
scan_res = s.scan(500)
|
||||
|
||||
device_names = get_device_names(scan_res)
|
||||
for dev in device_names:
|
||||
if name == dev[1]:
|
||||
return dev[0]
|
||||
|
||||
class PowerUp3:
|
||||
def __init__(self):
|
||||
self.x_adc = ADC(1)
|
||||
|
||||
self.btn_speed_up = Pin("A13", mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
self.btn_speed_down = Pin("A15", mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
self.btn_speed_full = Pin("A14", mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
self.btn_speed_off = Pin("A16", mode=Pin.IN, pull=Pin.PULL_UP)
|
||||
|
||||
self.x_mid = 0
|
||||
|
||||
self.calibrate()
|
||||
self.connect()
|
||||
self.loop()
|
||||
|
||||
def read_stick_x(self):
|
||||
return self.x_adc.value()
|
||||
|
||||
def button_speed_up(self):
|
||||
return not bool(self.btn_speed_up.value())
|
||||
|
||||
def button_speed_down(self):
|
||||
return not bool(self.btn_speed_down.value())
|
||||
|
||||
def button_speed_full(self):
|
||||
return not bool(self.btn_speed_full.value())
|
||||
|
||||
def button_speed_off(self):
|
||||
return not bool(self.btn_speed_off.value())
|
||||
|
||||
def calibrate(self):
|
||||
self.x_mid = self.read_stick_x()
|
||||
|
||||
def __str__(self):
|
||||
return "calibration x: %i, y: %i" % (self.x_mid)
|
||||
|
||||
def map_chars(self):
|
||||
s = self.p.getServices()
|
||||
|
||||
service_batt = s[3]
|
||||
service_control = s[4]
|
||||
|
||||
self.char_batt_lvl = service_batt.getCharacteristics()[0]
|
||||
self.char_control_speed = service_control.getCharacteristics()[0]
|
||||
self.char_control_angle = service_control.getCharacteristics()[2]
|
||||
|
||||
def battery_level(self):
|
||||
return int(self.char_batt_lvl.read()[0])
|
||||
|
||||
def speed(self, new_speed=None):
|
||||
if new_speed == None:
|
||||
return int(self.char_control_speed.read()[0])
|
||||
else:
|
||||
self.char_control_speed.write(bytearray([new_speed]))
|
||||
|
||||
def angle(self, new_angle=None):
|
||||
if new_angle == None:
|
||||
return int(self.char_control_angle.read()[0])
|
||||
else:
|
||||
self.char_control_angle.write(bytearray([new_angle]))
|
||||
|
||||
def connect(self):
|
||||
dev = None
|
||||
|
||||
# connect to the airplane
|
||||
while not dev:
|
||||
dev = find_device_by_name("TailorToys PowerUp")
|
||||
if dev:
|
||||
self.p = Peripheral()
|
||||
self.p.connect(dev.addr())
|
||||
|
||||
# locate interesting characteristics
|
||||
self.map_chars()
|
||||
|
||||
def rudder_center(self):
|
||||
if self.old_angle != 0:
|
||||
self.old_angle = 0
|
||||
self.angle(0)
|
||||
|
||||
def rudder_left(self, angle):
|
||||
steps = (angle // self.interval_size_left)
|
||||
new_angle = 60 - steps
|
||||
|
||||
if self.old_angle != new_angle:
|
||||
self.angle(new_angle)
|
||||
self.old_angle = new_angle
|
||||
|
||||
def rudder_right(self, angle):
|
||||
steps = (angle // self.interval_size_right)
|
||||
new_angle = -steps
|
||||
|
||||
if self.old_angle != new_angle:
|
||||
self.angle(new_angle)
|
||||
self.old_angle = new_angle
|
||||
|
||||
def throttle(self, speed):
|
||||
if (speed > 200):
|
||||
speed = 200
|
||||
elif (speed < 0):
|
||||
speed = 0
|
||||
|
||||
if self.old_speed != speed:
|
||||
self.speed(speed)
|
||||
self.old_speed = speed
|
||||
|
||||
def loop(self):
|
||||
adc_threshold = 10
|
||||
right_threshold = self.x_mid + adc_threshold
|
||||
left_threshold = self.x_mid - adc_threshold
|
||||
|
||||
self.interval_size_left = self.x_mid // 60
|
||||
self.interval_size_right = (255 - self.x_mid) // 60
|
||||
|
||||
self.old_angle = 0
|
||||
self.old_speed = 0
|
||||
|
||||
while True:
|
||||
|
||||
time.sleep_ms(100)
|
||||
|
||||
# read out new angle
|
||||
new_angle = self.read_stick_x()
|
||||
if (new_angle < 256):
|
||||
if (new_angle > right_threshold):
|
||||
self.rudder_right(new_angle - self.x_mid)
|
||||
elif (new_angle < left_threshold):
|
||||
self.rudder_left(new_angle)
|
||||
else:
|
||||
self.rudder_center()
|
||||
|
||||
# read out new speed
|
||||
new_speed = self.old_speed
|
||||
|
||||
if self.button_speed_up():
|
||||
new_speed += 25
|
||||
elif self.button_speed_down():
|
||||
new_speed -= 25
|
||||
elif self.button_speed_full():
|
||||
new_speed = 200
|
||||
elif self.button_speed_off():
|
||||
new_speed = 0
|
||||
else:
|
||||
pass
|
||||
|
||||
self.throttle(new_speed)
|
@ -1,210 +0,0 @@
|
||||
# This file is part of the MicroPython project, http://micropython.org/
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2016 Glenn Ruben Bakke
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
"""
|
||||
MicroPython Seeedstudio TFT Shield V2 driver, SPI interfaces, Analog GPIO
|
||||
Contains SD-card reader, LCD and Touch sensor
|
||||
|
||||
The pca10040 pin layout is used as reference.
|
||||
|
||||
Example usage of LCD:
|
||||
|
||||
from seeedstudio_tft_shield_v2 import ILI9341
|
||||
|
||||
lcd = ILI9341(240, 320)
|
||||
lcd.text("Hello World!, 32, 32)
|
||||
lcd.show()
|
||||
|
||||
Example usage of SD card reader:
|
||||
|
||||
import os
|
||||
from seeedstudio_tft_shield_v2 import mount_tf
|
||||
|
||||
tf = mount_tf()
|
||||
os.listdir()
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
import framebuf
|
||||
|
||||
from machine import SPI, Pin
|
||||
from sdcard import SDCard
|
||||
|
||||
def mount_tf(self, mount_point="/"):
|
||||
sd = SDCard(SPI(0), Pin("A15", mode=Pin.OUT))
|
||||
os.mount(sd, mount_point)
|
||||
|
||||
class ILI9341:
|
||||
def __init__(self, width, height):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.pages = self.height // 8
|
||||
self.buffer = bytearray(self.pages * self.width)
|
||||
self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
|
||||
|
||||
self.spi = SPI(0)
|
||||
# chip select
|
||||
self.cs = Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
# command
|
||||
self.dc = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
|
||||
# initialize all pins high
|
||||
self.cs.high()
|
||||
self.dc.high()
|
||||
|
||||
self.spi.init(baudrate=8000000, phase=0, polarity=0)
|
||||
|
||||
self.init_display()
|
||||
|
||||
|
||||
def init_display(self):
|
||||
time.sleep_ms(500)
|
||||
|
||||
self.write_cmd(0x01)
|
||||
|
||||
time.sleep_ms(200)
|
||||
|
||||
self.write_cmd(0xCF)
|
||||
self.write_data(bytearray([0x00, 0x8B, 0x30]))
|
||||
|
||||
self.write_cmd(0xED)
|
||||
self.write_data(bytearray([0x67, 0x03, 0x12, 0x81]))
|
||||
|
||||
self.write_cmd(0xE8)
|
||||
self.write_data(bytearray([0x85, 0x10, 0x7A]))
|
||||
|
||||
self.write_cmd(0xCB)
|
||||
self.write_data(bytearray([0x39, 0x2C, 0x00, 0x34, 0x02]))
|
||||
|
||||
self.write_cmd(0xF7)
|
||||
self.write_data(bytearray([0x20]))
|
||||
|
||||
self.write_cmd(0xEA)
|
||||
self.write_data(bytearray([0x00, 0x00]))
|
||||
|
||||
# Power control
|
||||
self.write_cmd(0xC0)
|
||||
# VRH[5:0]
|
||||
self.write_data(bytearray([0x1B]))
|
||||
|
||||
# Power control
|
||||
self.write_cmd(0xC1)
|
||||
# SAP[2:0];BT[3:0]
|
||||
self.write_data(bytearray([0x10]))
|
||||
|
||||
# VCM control
|
||||
self.write_cmd(0xC5)
|
||||
self.write_data(bytearray([0x3F, 0x3C]))
|
||||
|
||||
# VCM control2
|
||||
self.write_cmd(0xC7)
|
||||
self.write_data(bytearray([0xB7]))
|
||||
|
||||
# Memory Access Control
|
||||
self.write_cmd(0x36)
|
||||
self.write_data(bytearray([0x08]))
|
||||
|
||||
self.write_cmd(0x3A)
|
||||
self.write_data(bytearray([0x55]))
|
||||
|
||||
self.write_cmd(0xB1)
|
||||
self.write_data(bytearray([0x00, 0x1B]))
|
||||
|
||||
# Display Function Control
|
||||
self.write_cmd(0xB6)
|
||||
self.write_data(bytearray([0x0A, 0xA2]))
|
||||
|
||||
# 3Gamma Function Disable
|
||||
self.write_cmd(0xF2)
|
||||
self.write_data(bytearray([0x00]))
|
||||
|
||||
# Gamma curve selected
|
||||
self.write_cmd(0x26)
|
||||
self.write_data(bytearray([0x01]))
|
||||
|
||||
# Set Gamma
|
||||
self.write_cmd(0xE0)
|
||||
self.write_data(bytearray([0x0F, 0x2A, 0x28, 0x08, 0x0E, 0x08, 0x54, 0XA9, 0x43, 0x0A, 0x0F, 0x00, 0x00, 0x00, 0x00]))
|
||||
|
||||
# Set Gamma
|
||||
self.write_cmd(0XE1)
|
||||
self.write_data(bytearray([0x00, 0x15, 0x17, 0x07, 0x11, 0x06, 0x2B, 0x56, 0x3C, 0x05, 0x10, 0x0F, 0x3F, 0x3F, 0x0F]))
|
||||
|
||||
# Exit Sleep
|
||||
self.write_cmd(0x11)
|
||||
time.sleep_ms(120)
|
||||
|
||||
# Display on
|
||||
self.write_cmd(0x29)
|
||||
time.sleep_ms(500)
|
||||
self.fill(0)
|
||||
|
||||
def show(self):
|
||||
# set col
|
||||
self.write_cmd(0x2A)
|
||||
self.write_data(bytearray([0x00, 0x00]))
|
||||
self.write_data(bytearray([0x00, 0xef]))
|
||||
|
||||
# set page
|
||||
self.write_cmd(0x2B)
|
||||
self.write_data(bytearray([0x00, 0x00]))
|
||||
self.write_data(bytearray([0x01, 0x3f]))
|
||||
|
||||
self.write_cmd(0x2c);
|
||||
|
||||
num_of_pixels = self.height * self.width
|
||||
|
||||
for row in range(0, self.pages):
|
||||
for pixel_pos in range(0, 8):
|
||||
for col in range(0, self.width):
|
||||
compressed_pixel = self.buffer[row * 240 + col]
|
||||
if ((compressed_pixel >> pixel_pos) & 0x1) == 0:
|
||||
self.write_data(bytearray([0x00, 0x00]))
|
||||
else:
|
||||
self.write_data(bytearray([0xFF, 0xFF]))
|
||||
|
||||
def fill(self, col):
|
||||
self.framebuf.fill(col)
|
||||
|
||||
def pixel(self, x, y, col):
|
||||
self.framebuf.pixel(x, y, col)
|
||||
|
||||
def scroll(self, dx, dy):
|
||||
self.framebuf.scroll(dx, dy)
|
||||
|
||||
def text(self, string, x, y, col=1):
|
||||
self.framebuf.text(string, x, y, col)
|
||||
|
||||
def write_cmd(self, cmd):
|
||||
self.dc.low()
|
||||
self.cs.low()
|
||||
self.spi.write(bytearray([cmd]))
|
||||
self.cs.high()
|
||||
|
||||
def write_data(self, buf):
|
||||
self.dc.high()
|
||||
self.cs.low()
|
||||
self.spi.write(buf)
|
||||
self.cs.high()
|
||||
|
@ -1,27 +0,0 @@
|
||||
# NOTE: Modified version to align with implemented I2C API in nrf port.
|
||||
#
|
||||
# Examples usage of SSD1306_SPI on pca10040
|
||||
#
|
||||
# from machine import Pin, SPI
|
||||
# from ssd1306 import SSD1306_SPI
|
||||
# spi = SPI(0, baudrate=40000000)
|
||||
# dc = Pin.board.PA11
|
||||
# res = Pin.board.PA12
|
||||
# cs = Pin.board.PA13
|
||||
# disp = SSD1306_SPI(128, 64, spi, dc, res, cs)
|
||||
#
|
||||
#
|
||||
# Example usage of SSD1306_I2C on pca10040
|
||||
#
|
||||
# from machine import Pin, I2C
|
||||
# from ssd1306_mod import SSD1306_I2C_Mod
|
||||
# i2c = I2C(0, Pin.board.PA3, Pin.board.PA4)
|
||||
# disp = SSD1306_I2C_Mod(128, 64, i2c)
|
||||
|
||||
from ssd1306 import SSD1306_I2C
|
||||
|
||||
class SSD1306_I2C_Mod(SSD1306_I2C):
|
||||
|
||||
def write_data(self, buf):
|
||||
buffer = bytearray([0x40]) + buf # Co=0, D/C#=1
|
||||
self.i2c.writeto(self.addr, buffer)
|
Loading…
Reference in New Issue
Block a user