You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
tests: Add a suite of tests specifically for the pyboard.
In tests/pyb is now a suite of tests that tests the pyb module on the pyboard. They include expected output files because we can't run CPython on the pyboard to compare against. run-tests script has now been updated to allow pyboard tests to be run. Just pass the option --pyboard. This runs all basic, float and pyb tests. Note that float/math-fun.py currently fails because not all math functions are implemented in stmhal/.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
accel = pyb.Accel()
|
||||
print(accel)
|
||||
accel.x()
|
||||
accel.y()
|
||||
accel.z()
|
||||
accel.tilt()
|
||||
accel.filtered_xyz()
|
||||
@@ -0,0 +1 @@
|
||||
<Accel>
|
||||
@@ -0,0 +1,10 @@
|
||||
from pyb import ADC
|
||||
from pyb import Pin
|
||||
|
||||
adc = ADC('X22')
|
||||
print(adc)
|
||||
|
||||
adc.read()
|
||||
|
||||
buf = bytearray(100)
|
||||
adc.read_timed(buf, 500)
|
||||
@@ -0,0 +1 @@
|
||||
<ADC on X22 channel=13>
|
||||
@@ -0,0 +1,8 @@
|
||||
dac = pyb.DAC(1)
|
||||
print(dac)
|
||||
dac.noise(100)
|
||||
dac.triangle(100)
|
||||
dac.write(0)
|
||||
dac.write_timed(bytearray(10), 100, mode=pyb.DAC.NORMAL)
|
||||
pyb.delay(20)
|
||||
dac.write(0)
|
||||
@@ -0,0 +1 @@
|
||||
<DAC>
|
||||
@@ -0,0 +1,6 @@
|
||||
ext = pyb.ExtInt('X1', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
|
||||
ext.disable()
|
||||
ext.enable()
|
||||
print(ext.line())
|
||||
ext.swint()
|
||||
ext.disable()
|
||||
@@ -0,0 +1,2 @@
|
||||
0
|
||||
line: 0
|
||||
@@ -0,0 +1,23 @@
|
||||
from pyb import I2C
|
||||
|
||||
i2c = I2C(1)
|
||||
i2c2 = I2C(2)
|
||||
|
||||
i2c.init(I2C.MASTER, baudrate=400000)
|
||||
print(i2c.scan())
|
||||
i2c.deinit()
|
||||
|
||||
# use accelerometer to test i2c bus
|
||||
|
||||
accel_addr = 76
|
||||
|
||||
pyb.Accel() # this will init the bus for us
|
||||
|
||||
print(i2c.scan())
|
||||
print(i2c.is_ready(accel_addr))
|
||||
|
||||
print(i2c.mem_read(1, accel_addr, 7, timeout=500))
|
||||
i2c.mem_write(0, accel_addr, 0, timeout=500)
|
||||
|
||||
i2c.send(7, addr=accel_addr)
|
||||
i2c.recv(1, addr=accel_addr)
|
||||
@@ -0,0 +1,4 @@
|
||||
[]
|
||||
[76]
|
||||
True
|
||||
b'\x01'
|
||||
@@ -0,0 +1,28 @@
|
||||
from pyb import LED
|
||||
|
||||
for i in range(4):
|
||||
print(LED(i+1))
|
||||
|
||||
for i in range(4):
|
||||
LED(i+1).on()
|
||||
pyb.delay(10)
|
||||
for i in range(4):
|
||||
LED(i+1).off()
|
||||
pyb.delay(10)
|
||||
for i in range(4):
|
||||
LED(i+1).toggle()
|
||||
pyb.delay(10)
|
||||
for i in range(4):
|
||||
LED(i+1).intensity(0)
|
||||
|
||||
for i in range(256):
|
||||
LED(4).intensity(i)
|
||||
if LED(4).intensity() != i:
|
||||
print('fail', i)
|
||||
pyb.delay(1)
|
||||
for i in range(256):
|
||||
LED(4).intensity(255 - i)
|
||||
pyb.delay(1)
|
||||
|
||||
for i in range(4):
|
||||
LED(i+1).off()
|
||||
@@ -0,0 +1,4 @@
|
||||
<LED 1>
|
||||
<LED 2>
|
||||
<LED 3>
|
||||
<LED 4>
|
||||
@@ -0,0 +1,29 @@
|
||||
from pyb import Pin
|
||||
|
||||
p = Pin('X1')
|
||||
print(p)
|
||||
print(p.name())
|
||||
print(p.pin())
|
||||
print(p.port())
|
||||
|
||||
p = Pin('X1', Pin.IN, Pin.PULL_UP)
|
||||
#p = Pin('X1', Pin.IN, pull=Pin.PULL_UP)
|
||||
print(p.value())
|
||||
|
||||
p.init(p.IN, p.PULL_DOWN)
|
||||
#p.init(p.IN, pull=p.PULL_DOWN)
|
||||
print(p.value())
|
||||
|
||||
p.init(p.OUT_PP)
|
||||
p.low()
|
||||
print(p.value())
|
||||
p.high()
|
||||
print(p.value())
|
||||
p.value(0)
|
||||
print(p.value())
|
||||
p.value(1)
|
||||
print(p.value())
|
||||
p.value(False)
|
||||
print(p.value())
|
||||
p.value(True)
|
||||
print(p.value())
|
||||
@@ -0,0 +1,12 @@
|
||||
<Pin A0>
|
||||
A0
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
@@ -0,0 +1,42 @@
|
||||
# basic tests of pyb module
|
||||
|
||||
import pyb
|
||||
|
||||
# test delay
|
||||
|
||||
pyb.delay(-1)
|
||||
pyb.delay(0)
|
||||
pyb.delay(1)
|
||||
|
||||
start = pyb.millis()
|
||||
pyb.delay(17)
|
||||
print((pyb.millis() - start) // 5) # should print 3
|
||||
|
||||
# test udelay
|
||||
|
||||
pyb.udelay(-1)
|
||||
pyb.udelay(0)
|
||||
pyb.udelay(1)
|
||||
|
||||
start = pyb.millis()
|
||||
pyb.udelay(17000)
|
||||
print((pyb.millis() - start) // 5) # should print 3
|
||||
|
||||
# other
|
||||
|
||||
pyb.disable_irq()
|
||||
pyb.enable_irq()
|
||||
|
||||
print(pyb.freq())
|
||||
|
||||
print(pyb.have_cdc())
|
||||
|
||||
pyb.hid((0, 0, 0, 0)) # won't do anything
|
||||
|
||||
pyb.rng()
|
||||
|
||||
pyb.sync()
|
||||
|
||||
print(len(pyb.unique_id()))
|
||||
|
||||
pyb.wfi()
|
||||
@@ -0,0 +1,5 @@
|
||||
3
|
||||
3
|
||||
(168000000, 168000000, 42000000, 84000000)
|
||||
True
|
||||
12
|
||||
@@ -0,0 +1,6 @@
|
||||
from pyb import RTC
|
||||
rtc = RTC()
|
||||
print(rtc)
|
||||
rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
|
||||
pyb.delay(1000)
|
||||
print(rtc.datetime()[:7])
|
||||
@@ -0,0 +1,2 @@
|
||||
<RTC>
|
||||
(2014, 1, 1, 1, 0, 0, 1)
|
||||
@@ -0,0 +1,16 @@
|
||||
from pyb import Servo
|
||||
|
||||
servo = Servo(1)
|
||||
print(servo)
|
||||
|
||||
servo.angle(0)
|
||||
servo.angle(10, 100)
|
||||
|
||||
servo.speed(-10)
|
||||
servo.speed(10, 100)
|
||||
|
||||
servo.pulse_width(1500)
|
||||
print(servo.pulse_width())
|
||||
|
||||
servo.calibration(630, 2410, 1490, 2460, 2190)
|
||||
print(servo.calibration())
|
||||
@@ -0,0 +1,3 @@
|
||||
<Servo 1 at 1500us>
|
||||
1500
|
||||
(630, 2410, 1490, 2460, 2190)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user