-
I want to use the DSB1820 Onewire temperature sensor to read the temp and send the data to Sigfox.
How do I import the ds18x20 module? I am getting the error:Traceback (most recent call last): File "<stdin>", line 2, in <module> ImportError: no module named 'ds18x20'I have pasted the ds18x20.py into the folder my other py files and project is in. Is that not where it goes?
Is it the right library for DSB1820? I got it from here.I've setup my Sipy as:
VCC = 3.3V pin
Ground = GND
Data = G17 -
@sk Could you please post a snippet of your code so we can see what the issue might be?
-
from machine import Pin from ds18x20 import DS18X20 d=DS18X20(Pin('G17', mode=Pin.OUT)) result=d.read_temps() print(result)
-
@sk where have you placed the ds18x20.py file? Normally I use this file structure for my library .py file (imports):
- /flash
- /lib
- boot.py - main.py
- /flash
-
@bucknall
How do I structure it that way. Currently when I open up a project I have all my py files in /flash i.e boot.py, main.py, ds18x20.py and my tempSensor.py are on the same folder.
-
@sk is this from your main.py or your tempSensor.py?
-
@bucknall im running from my tempsensor.py.
-
@sk Ok, when you import the module ds18x20 it should work fine if it's in the same folder as your tempSensor.py.
If you open your REPL (either in Pymakr or another tool) and type the following commands, what is your output?
import os os.listdir('/flash')This should show your the file structure of /flash
-
@bucknall I did this in my tempsensor.py file:
from machine import Pin #from ds18x20 import DS18X20 import os os.listdir('/flash') #d=DS18X20(Pin('G17', mode=Pin.OUT)) #result=d.read_temps() #print(result)Which gave this output:
Running TempSensor.py > MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>> -
@sk I think you need to either wrap the code in a print statement to see an output
print(os.listdir('/flash'))or run it from the REPL to see the output
>>> import os >>> os.listdir('/flash') -
Running TempSensor.py ['boot.py', 'sys', 'lib', 'cert', 'main.py', 'project.pymakr'] > MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>>So How can I add it to lib?
-
@sk it looks like your ds18x20.py didn't upload to the SiPy. To use the sync function in Pymakr, to copy your code over to your SiPy, you need to first create a project.
Once you're got a new project, if you create a folder called 'lib' and place the ds18x20.py into this folder and then press sync, it should put it into the lib folder!
-
@bucknall
Ok so I made a new project called 'TempSensor' and in the same folder of this project I made another folder called 'lib'.
Inside lib folder I pasted the ds18x20.py, onewire.py and onewire.diff libraries.
Then in the project folder I made boot.py:from machine import UART import os import machine uart = UART(0, 115200) os.dupterm(uart)and main.py:
import os import pycom from machine import Pin #from ds18x20 import DS18X20 print(os.listdir('/flash')) pycom.rgbled(0x000000) # rblack #d=DS18X20(Pin('G17', mode=Pin.OUT)) #result=d.read_temps() #print(result) machine.idle()Then I synced and then ran my program and this is the output:
Running main.py ['__init__.py', 'sys', 'lib', 'cert', 'TempSensor.py', 'main.py', 'boot.py', 'project.pymakr'] > MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>>As you can see the library is still not there. But if I go
print(os.listdir('/flash/lib'))The output says its there:
Running main.py ['ds18x20.py'] > MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>>Why doesn't it show the onewire.py/diff?
-
@bucknall
Ok all libraries seem to be in the right place now. My main.py:import os import pycom from machine import Pin from ds18x20 import DS18X20 #pycom.rgbled(0x000000) # rblack d=DS18X20(Pin('G17', mode=Pin.OUT)) result=d.read_temps() print(result) machine.idle()My output however gives this error:
Syncing the project with the SiPy. Please wait... Successfully synced! MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>> Running main.py Traceback (most recent call last): File "<stdin>", line 8, in <module> File "/flash/lib/ds18x20.py", line 47, in __init__ File "/flash/lib/onewire.py", line 246, in scan File "/flash/lib/onewire.py", line 274, in _search File "/flash/lib/onewire.py", line 148, in write_byte NameError: name 'pin_lalue' is not defined > MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>>"pin_lalue" isn't in any of my files or libraries? Why is it looking for something that doesn't exist?
-
I've also followed this pycom Onewire DS18X20 tutorial but the output is again looking for something that doesn't exist:
Running main.py Traceback (most recent call last): File "<stdin>", line 9, in <module> File "/flash/lib/onewire.py", line 162, in __init__ File "/flash/lib/onewire.py", line 124, in scan File "/flash/lib/onewire.py", line 132, in _search_rom File "/flash/lib/onewire.py", line 36, in reset NameError: name 'enabXe_irq' is not defined > MicroPython v1.8.6-422-g516b861 on 2017-02-07; SiPy with ESP32 Type "help()" for more information. >>>at line 36 in the onewire library it is enable_irq(1)... not enabXe_irq. Paymkr is replacing the 'l' with 'X'???
-
use official onewire driver
https://github.com/pycom/pycom-libraries/tree/master/examples/onewire
it work for me on Wipy2.0but first check if your file is not corrupted
try compare it in text editor e.g Notepad++, Total Comander, WinMerge ...
i mean - read file e.g. throught ftp and compare with file you thing that should be stored
because i see in your error message corrupted name "enabXe_irq" which not exists in onewire driver -
0_1487543077630_onewire.py
this doesnt have enableXe_irq, I don't think its the files thats faulty. Something is wrong with my code or the order I'm doing things, I'm pretty sure, I just don't know what? -
@sk
Is this what you downloaded from board or what you have on the computer?
Previously (for me still - however less than before) there are some corruption of files stored on the board.try something like this
f = open('onewire.py', 'r+') d = f.readall() print(d)do you see some corruption in content?
Try also downloading file throught ftp - is this file same as your on the computer?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login