Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6d2ba04
Move stm32f4xx_hal_can.c to stmhal directory
HenrikSolver Jan 21, 2015
437817e
Dont lockup the HAL when trying to send a message when all
HenrikSolver Jan 21, 2015
755e909
Make it possible to have timeout = 0 when sending a message.
HenrikSolver Jan 21, 2015
62a3a28
py: Set compiler scope before folding constants so error messages work.
dpgeorge Mar 1, 2015
47538cc
tests: Add test for micropython const feature when it has a SyntaxError.
dpgeorge Mar 1, 2015
b753009
stmhal: Add I2S2EXT and I2S3EXT constants to stm module.
dpgeorge Mar 1, 2015
81e661f
travis: Add automated coverage testing using coveralls.
dpgeorge Mar 1, 2015
18fd7e8
README.md: Change coveralls badge from travis-testing to master branch.
dpgeorge Mar 1, 2015
2af921f
tests: Add tests for op special meths, ubinascii, complex.
dpgeorge Mar 2, 2015
a2e3838
py: Clean up and comment out unused functions in mpz.
dpgeorge Mar 2, 2015
565da3f
stmhal: Enable MICROPY_PY_ARRAY_SLICE_ASSIGN.
dpgeorge Mar 2, 2015
9f142f0
py: For inline assembler, add bcc_n and bcc_w ops.
dpgeorge Mar 2, 2015
96e37d3
tests: Add tests for inline assembler beq_n and beq_w ops.
dpgeorge Mar 2, 2015
db1e10d
py: Use SMALL_INT creation macro in builtin sum.
dpgeorge Mar 2, 2015
24ffb8e
tests: Add tests for builtins: all, any, sum, abs.
dpgeorge Mar 2, 2015
67c5f89
py: In inline assembler, fix branch out-of-range error reporting.
dpgeorge Mar 2, 2015
fe3da09
tests: Use range as iterable instead of list comprehension.
dpgeorge Mar 2, 2015
f2a8895
tests: Add basics test for gc module.
dpgeorge Mar 2, 2015
9be0d59
drivers: Add onewire driver and ds18x20 temperature sensor driver.
dpgeorge Mar 3, 2015
803264b
py: Guard against redef of nlr_push with DEBUG + MICROPY_NLR_SETJMP.
stinos Mar 3, 2015
25f1264
tests: Skip special math fun tests when math module exists but not funs.
stinos Mar 3, 2015
086a761
tests: Add tests for boundmeth; and bignum cmp, unary, float, error.
dpgeorge Mar 3, 2015
9c5cabb
py: Give error for duplicate label in inline assembler.
dpgeorge Mar 3, 2015
3665d0b
py: Simplify some inline-assembler error messages, but retain meaning.
dpgeorge Mar 3, 2015
dc79097
py: In inline assembler, reset labels on code-size pass.
dpgeorge Mar 3, 2015
72ddcfd
tests: Skip basics/boundmeth1.py for native emitter.
dpgeorge Mar 3, 2015
00ac70f
Move stm32f4xx_hal_can.c to stmhal directory
HenrikSolver Jan 21, 2015
3970aa6
Dont lockup the HAL when trying to send a message when all
HenrikSolver Jan 21, 2015
22fe8a7
Make it possible to have timeout = 0 when sending a message.
HenrikSolver Jan 21, 2015
c78d140
Rebase upstream/master
HenrikSolver Mar 3, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ before_script:
- sudo apt-get install -y python3.4 python3 gcc-4.7 gcc-multilib gcc-arm-none-eabi qemu-system mingw32
# For teensy build
- sudo apt-get install realpath
# For coverage testing
- sudo pip install cpp-coveralls

script:
- make -C minimal test
Expand All @@ -25,8 +27,17 @@ script:
- make -C cc3200 BTARGET=bootloader BTYPE=release
- make -C windows CROSS_COMPILE=i586-mingw32msvc-

- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests)
- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests --emit native)
# run tests without coverage info
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests)
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests --emit native)

# run tests with coverage info
- make -C unix CC=gcc-4.7 coverage
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests)
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests --emit native)

after_success:
- (cd unix && coveralls --root .. --build-root . --gcov $(which gcov-4.7) --gcov-options '\-o build-coverage/' --include py --include extmod)

after_failure:
- (cd tests && for exp in *.exp; do testbase=$(basename $exp .exp); echo -e "\nFAILURE $testbase"; diff -u $testbase.exp $testbase.out; done)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Build Status][travis-img]][travis-repo]
[![Build Status][travis-img]][travis-repo] [![Coverage Status][coveralls-img]][coveralls-repo]
[travis-img]: https://travis-ci.org/micropython/micropython.png?branch=master
[travis-repo]: https://travis-ci.org/micropython/micropython
[coveralls-img]: https://coveralls.io/repos/micropython/micropython/badge.png?branch=master
[coveralls-repo]: https://coveralls.io/r/micropython/micropython?branch=master

The Micro Python project
========================
Expand Down
7 changes: 6 additions & 1 deletion docs/library/pyb.CAN.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,18 @@ Methods

Return value: buffer of data bytes.

.. method:: can.send(send, addr, \*, timeout=5000)
.. method:: can.send(send, addr, \*, timeout=0)

Send a message on the bus:

- ``send`` is the data to send (an integer to send, or a buffer object).
- ``addr`` is the address to send to
- ``timeout`` is the timeout in milliseconds to wait for the send.
If timeout is 0 the message is placed in a buffer in one of three hardware
buffers and the method returns immediately. If all three buffers are in use
an exception is thrown. If timeout is not 0, the method waits until the
message is transmitted. If the message can't be transmitted within the
specified time an exception is thrown.

Return value: ``None``.

Expand Down
104 changes: 104 additions & 0 deletions drivers/onewire/ds18x20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""
DS18x20 temperature sensor driver for MicroPython.

This driver uses the OneWire driver to control DS18S20 and DS18B20
temperature sensors. It supports multiple devices on the same 1-wire bus.

The following example assumes the ground of your DS18x20 is connected to
Y11, vcc is connected to Y9 and the data pin is connected to Y10.

>>> gnd = Pin('Y11')
>>> gnd.init(Pin.OUT_PP)
>>> gnd.low()

>>> vcc = Pin('Y9')
>>> vcc.init(Pin.OUT_PP)
>>> vcc.high()

>>> d = DS18X20(Pin('Y10'))

Call read_temps to read all sensors:

>>> result = d.read_temps()
>>> print(result)
[20.875, 20.8125]

Call read_temp to read the temperature of a specific sensor:

>>> result = d.read_temp(d.roms[0])
>>> print(result)
20.25

If only one DS18x20 is attached to the bus, then you don't need to
pass a ROM to read_temp:

>>> result = d.read_temp()
>>> print(result)
20.25

"""

from onewire import OneWire

class DS18X20(object):
def __init__(self, pin):
self.ow = OneWire(pin)
# Scan the 1-wire devices, but only keep those which have the
# correct # first byte in their rom for a DS18x20 device.
self.roms = [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28]

def _select_rom(self, rom):
if rom:
self.ow.select_rom(rom)
else:
self.ow.skip_rom()

def read_temp(self, rom=None):
"""
Read and return the temperature of one DS18x20 device.
Pass the 8-byte bytes object with the ROM of the specific device you want to read.
If only one DS18x20 device is attached to the bus you may omit the rom parameter.
"""
ow = self.ow
ow.reset()
self._select_rom(rom)
ow.write_byte(0x44) # Convert Temp
while True:
if ow.read_bit():
break
ow.reset()
self._select_rom(rom)
ow.write_byte(0xbe) # Read scratch
data = ow.read_bytes(9)
return self.convert_temp(rom[0], data)

def read_temps(self):
"""
Read and return the temperatures of all attached DS18x20 devices.
"""
temps = []
for rom in self.roms:
temps.append(self.read_temp(rom))
return temps

def convert_temp(self, rom0, data):
"""
Convert the raw temperature data into degrees celsius and return as a float.
"""
temp_lsb = data[0]
temp_msb = data[1]
if rom0 == 0x10:
if temp_msb != 0:
# convert negative number
temp_read = temp_lsb >> 1 | 0x80 # truncate bit 0 by shifting, fill high bit with 1.
temp_read = -((~temp_read + 1) & 0xff) # now convert from two's complement
else:
temp_read = temp_lsb >> 1 # truncate bit 0 by shifting
count_remain = data[6]
count_per_c = data[7]
temp = temp_read - 0.25 + (count_per_c - count_remain) / count_per_c
return temp
elif rom0 == 0x28:
return (temp_msb << 8 | temp_lsb) / 16
else:
assert False
Loading