New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes for the ESP32 port #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
from terkin import logging | ||
from terkin.sensor import AbstractSensor | ||
from terkin.sensor.core import OneWireBus | ||
from terkin.util import get_platform_info | ||
platform_info = get_platform_info() | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -30,8 +32,16 @@ def start(self): | |
|
||
# Initialize the DS18x20 hardware driver. | ||
try: | ||
from onewire import DS18X20 | ||
self.driver = DS18X20(self.bus.adapter) | ||
if platform_info.vendor == platform_info.MICROPYTHON.Vanilla: | ||
import ds18x20 | ||
#self.driver = ds18x20.DS18X20(self.ow) | ||
# TBD there is some difference between uPy & Pycom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the adaptation code from 7330d65 will already help here? |
||
elif platform_info.vendor == platform_info.MICROPYTHON.Pycom: | ||
from onewire import DS18X20 | ||
self.driver = DS18X20(self.bus.adapter) | ||
else: | ||
raise NotImplementedError('DS18X20 is ' | ||
'not implemented on this platform') | ||
return True | ||
|
||
except Exception as ex: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
import utime | ||
from terkin import logging | ||
from machine import Pin, enable_irq, disable_irq, idle | ||
from terkin.util import get_platform_info | ||
platform_info = get_platform_info() | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -20,8 +22,16 @@ class HX711: | |
def __init__(self, dout, pd_sck, gain=128): | ||
|
||
# Define two pins for clock and data. | ||
self.pSCK = Pin(pd_sck, mode=Pin.OUT) | ||
self.pOUT = Pin(dout, mode=Pin.IN, pull=Pin.PULL_UP) | ||
if platform_info.vendor == platform_info.MICROPYTHON.Vanilla: | ||
self.pSCK = Pin(int(pd_sck[1:]), mode=Pin.OUT) | ||
self.pOUT = Pin(int(dout[1:]), mode=Pin.IN, pull=Pin.PULL_UP) | ||
elif platform_info.vendor == platform_info.MICROPYTHON.Pycom: | ||
self.pSCK = Pin(pd_sck, mode=Pin.OUT) | ||
self.pOUT = Pin(dout, mode=Pin.IN, pull=Pin.PULL_UP) | ||
else: | ||
raise NotImplementedError('HX711 is ' | ||
'not implemented on this platform') | ||
|
||
Comment on lines
-23
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
||
self.initialized = False | ||
|
||
|
@@ -202,7 +212,8 @@ def power_up(self): | |
|
||
# Unfreeze pin hold when coming from deep sleep. | ||
# https://community.hiveeyes.org/t/strom-sparen-beim-einsatz-der-micropython-firmware-im-batteriebetrieb/2055/72 | ||
self.pSCK.hold(False) | ||
if platform_info.vendor == platform_info.MICROPYTHON.Pycom: | ||
self.pSCK.hold(False) | ||
Comment on lines
-205
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks again! |
||
|
||
log.info('HX711 power up') | ||
self.pSCK.value(False) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
from machine import Pin, I2C | ||
|
||
from terkin import logging | ||
from terkin.util import get_platform_info | ||
platform_info = get_platform_info() | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -275,7 +277,13 @@ def start(self): | |
# Todo: Improve error handling. | ||
try: | ||
from onewire import OneWire | ||
self.adapter = OneWire(Pin(self.pins['data'])) | ||
if platform_info.vendor == platform_info.MICROPYTHON.Vanilla: | ||
self.adapter = OneWire(Pin(int(self.pins['data'][1:]))) | ||
elif platform_info.vendor == platform_info.MICROPYTHON.Pycom: | ||
self.adapter = OneWire(Pin(self.pins['data'])) | ||
else: | ||
raise NotImplementedError('I2C Bus is ' | ||
'not implemented on this platform') | ||
Comment on lines
-278
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes from 7330d65 might already account for that and even will handle the collision between both drivers. Remember to invoke |
||
self.scan_devices() | ||
|
||
except Exception as ex: | ||
|
@@ -328,7 +336,13 @@ def start(self): | |
""" """ | ||
# Todo: Improve error handling. | ||
try: | ||
self.adapter = I2C(self.number, mode=I2C.MASTER, pins=(self.pins['sda'], self.pins['scl']), baudrate=100000) | ||
if platform_info.vendor == platform_info.MICROPYTHON.Vanilla: | ||
self.adapter = I2C(self.number, sda = Pin(int(self.pins['sda'][1:])), scl = Pin(int(self.pins['scl'][1:])), freq=100000) | ||
elif platform_info.vendor == platform_info.MICROPYTHON.Pycom: | ||
self.adapter = I2C(self.number, mode=I2C.MASTER, pins=(self.pins['sda'], self.pins['scl']), baudrate=100000) | ||
else: | ||
raise NotImplementedError('I2C Bus is ' | ||
'not implemented on this platform') | ||
Comment on lines
-331
to
+345
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks again, that looks good! |
||
self.scan_devices() | ||
except Exception as ex: | ||
log.exc(ex, 'I2C hardware driver failed') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Is it actually just the same thing on both platforms?
Maybe it will be different on the pyboard-D. We will see that when I will try to ramp up the code again on this platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, surprised me, too. Maybe I had one weird firmware version.