1wire devices

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: 1wire devices

Post by dhylands » Wed Mar 04, 2015 9:52 pm

mattyb wrote:This is the first time I've needed to install a driver on the micropython. How does one do so?
While on the topic, how does one install a python library?
Just copy the files onto either the internal flash, or an sdcard.

After copying the files, wait for about 5 seconds, and then at the REPL, press Control-D to soft-reset the pyboard. The pyboard should then be able to see the files.

I normally do my testing this way, and copy my test file. I then execute it by doing:

Code: Select all

import test_file
which will then load and run test_file.py. You cold also do execfile('test_file.py').

Just remember that anytime you make any changes to the filesystem from the host, you need to do a Control-D, or the pyboard will be using stale data. Disclaimer - I use linux, and that's what I do under linux. The behaviour might be slightly different with another OS.

Alex Limonov
Posts: 1
Joined: Fri Feb 13, 2015 8:12 pm

Re: 1wire devices

Post by Alex Limonov » Mon Apr 06, 2015 8:59 pm

I'm getting an error with the read_temp function. Whenever I try to read_temp off of a single device without specifying the device rom, I get this error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "main.py", line 15, in print_temp
  File "ds18x20.py", line 73, in read_temp
TypeError: 'NoneType' object is not subscriptable
It seems like the the default rom doesn't work for the convert_temp function on line 73 because it's expecting a hex value. Is there a workaround for this? I've tried to hardcode a default hex rom, but it doesn't work as expected.

This is the main I have running the print_temp function:

Code: Select all

from pyb import Pin
from ds18x20 import DS18X20

gnd = Pin('Y11')
gnd.init(Pin.OUT_PP)
gnd.low()
        
vcc = Pin('Y9')
vcc.init(Pin.OUT_PP)
vcc.high()

d = DS18X20(Pin('Y10'))

def print_temp():
	result = d.read_temp()
	print(result)
Thank you!

JasonHildebrand
Posts: 7
Joined: Thu Jan 29, 2015 4:03 am

Re: 1wire devices

Post by JasonHildebrand » Tue Apr 07, 2015 2:47 pm

Looks like a bug - according to the docs your code should work.

Until this is fixed, try this instead:

Code: Select all

result = d.read_temp(d.roms[0])
This will read the temperature of the first sensor.

JimTal001
Posts: 176
Joined: Thu Jul 30, 2015 4:59 pm

Re: 1wire devices

Post by JimTal001 » Thu Jul 30, 2015 7:58 pm

Any resolution on the bug mention by JasonHildebrand?

Thanks

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: 1wire devices

Post by Damien » Thu Jul 30, 2015 10:12 pm

JimTal001 wrote:Any resolution on the bug mention by JasonHildebrand?
I just fixed it. See the latest driver.

QuaakHaak
Posts: 8
Joined: Wed May 18, 2016 4:14 am

Re: 1wire devices

Post by QuaakHaak » Tue Aug 16, 2016 4:42 am

Hi All,

I followed the instructions with Micropython Latest on a Pyboard v1.1, sourced the OneWire.py & DS18x20.py from the github account as per the instructions above.

My module to read the Temp from a single sensor is:

Code: Select all

'''
Read DS18x20 Temp Sensor(s)
'''

# Import modules
from pyb import Pin
from ds18x20 import DS18X20

# Set GND
gnd = Pin('Y11')
gnd.init(Pin.OUT_PP)
gnd.low()

# Set VCC
vcc = Pin('Y9')
vcc.init(Pin.OUT_PP)
vcc.high()

# Set SENSOR(s)
d = DS18X20(Pin('Y10'))

# If DS18x20 n = 1
def print_temp():
    # result = d.read_temp()
    result = d.read_temp(d.roms[0])
    print(result)
Connect the Pyboard, copy across the OneWire & DS18x20 files, open a Picocom session, Ctrl-D to be safe.

Then copy across the "gettemp" module written as above, Ctrl-D, then execfile('gettemp.py') but there is no result.

If I type in at the Micropython prompt, the following two lines, I get a valid result.

Code: Select all

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

What is wrong with the 'gettemp' module? Or am I not calling it the correct way?

QuaakHaak
Posts: 8
Joined: Wed May 18, 2016 4:14 am

Re: 1wire devices

Post by QuaakHaak » Tue Aug 16, 2016 8:54 am

This afternoon, I have even updated the Firmware, remade the onewire.py & ds1820.py scripts and then the 'gettemp.py' ... exactly the same result.

The last section, is the issue:

Code: Select all

# If DS18x20 n = 1
def print_temp():
#  result = d.read_temp(d.roms[0]) <== commented out as a break point
#  print(result) <== commented out as a break point

# EOF

Post Reply