Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions terkin/device.py
Expand Up @@ -243,10 +243,8 @@ def add(item=''):
add('=' * len(title))

# Machine runtime information.
if self.platform_info.vendor == self.platform_info.MICROPYTHON.Pycom:
frequency = machine.freq() / 1000000
else:
frequency = machine.freq()[0] / 1000000
frequency = machine.freq() / 1000000

Comment on lines -246 to +247
Copy link
Member

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.

Copy link
Collaborator Author

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.

add('CPU freq {} MHz'.format(frequency))
add('Device id {}'.format(self.device_id))
add()
Expand Down
14 changes: 12 additions & 2 deletions terkin/drivers/ds18x20.py
Expand Up @@ -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__)

Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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:
Expand Down
17 changes: 14 additions & 3 deletions terkin/lib/hx711.py
Expand Up @@ -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__)

Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


self.initialized = False

Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!


log.info('HX711 power up')
self.pSCK.value(False)
Expand Down
4 changes: 2 additions & 2 deletions terkin/network/wifi.py
Expand Up @@ -558,8 +558,8 @@ def read(self):

if platform_info.vendor == platform_info.MICROPYTHON.Vanilla:
stats = {}
stats['system.wifi.channel'] = self.station.config('channel')

# only in AP mode
#stats['system.wifi.channel'] = self.station.config('channel')
try:
stats['system.wifi.rssi'] = self.station.status('rssi')
except:
Expand Down
18 changes: 16 additions & 2 deletions terkin/sensor/core.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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 make setup again to get both drivers into dist-packages as onewire_native.py vs. onewire_python.py.

self.scan_devices()

except Exception as ex:
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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')
Expand Down