Onewire and DS18B20

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Onewire and DS18B20

Post by Roberthh » Wed May 18, 2016 7:22 pm

It's '\x00' followed by the letter '4', 9 bytes in total.
If a byte contains a printable character, it's printed as such, and not the hex code.

nui_de
Posts: 40
Joined: Fri Oct 23, 2015 3:27 pm

Re: Onewire and DS18B20

Post by nui_de » Wed May 18, 2016 9:00 pm

I was not aware of that (so simple :mrgreen: ) , maybe I just could have counted the bytes and
notice that one is missing.
Many thanks for your comment.

Ridley Walker
Posts: 19
Joined: Thu Jun 25, 2015 1:04 am

Re: Onewire and DS18B20 instal on pyboard ver1

Post by Ridley Walker » Tue Jul 26, 2016 5:17 pm

Anyone here willing to help me install the drivers for the ds18b20 ?
Yes, i have looked at several sources - at least one of which is touted as simple.
Well, not to me, they are not. I am a complete noob and the only reason i
have got the pyboard running is because it came pre loaded ( Big shout out to
Damien and Co.) I have purchased 8266 and Teensy boards also, but have
given up on them - temporarily, i hope.
I have the pyboard ver.1 and have been able to get a simple resistor / thermistor
string sensing temperature and controlling a GPIO pin. If push comes to shove,
i suppose even this simple arrangement will serve in my application

I have just received some ds18b20 chips and want to get working.
I just do not have the background knowledge to use the information i have found
here to install the drivers

Brunus
Posts: 5
Joined: Sat Oct 15, 2016 8:02 am

Re: Onewire and DS18B20 instal on pyboard ver1

Post by Brunus » Sat Oct 15, 2016 1:41 pm

[quote="Ridley Walker"]Anyone here willing to help me install the drivers for the ds18b20 ?[/quote]
It's perhaps and old message but while there was no answer...
It's pretty simple, you just have to follow the documentation to : first, upgrade the WiPy firmware, then connect the FTP space of the WiPy to put the driver in the FTP diretory flash/lib.
Then from the console you will be able to import it.

Brunus
Posts: 5
Joined: Sat Oct 15, 2016 8:02 am

Re: Onewire and DS18B20

Post by Brunus » Fri Oct 21, 2016 11:10 am

Hill all,
I can't manage to make it work.
I use the latest firmware on a WiPy 1.3, the onewire lib is installed and can import it, I have a waterproof DS18B20 sensor.
The data cable is connected on the GP2 and there is a 4K7 pull up between the cable of the sensor and GP2.
I tried to connect the sensor both on GP1 and GP3 (ground and VCC) or GND and 3V3.

Like :
sensor data > 4K7 > GP2
sensor GND > GP1
Sensor + > GP3

and

sensor data > 4K7 > GP2
sensor GND > GND
Sensor + > 3V3

No device and no temperature.

Does someone could send a pic of a working connexion please ?

My sensor is working, I can read temperatures with an Arduino micro-controler.

Thanks for any help.

Miguel
Posts: 20
Joined: Fri Sep 09, 2016 7:53 am

Re: Onewire and DS18B20

Post by Miguel » Thu Oct 27, 2016 5:15 am

Hello!

I use probably the same waterproof DS18B20 as you do and it works without any problems on my Wipy. I have even tried connecting two sensors at once.

Wipy Sensor
3V3 -> red (VCC)
G10 -> yellow (DATA)
GND -> black (GND)

Pull-up resistor 4k7 is connected between VCC and DATA.

Code: Select all

import onewire
from machine import Pin

ds = onewire.DS18X20(onewire.OneWire(Pin('GP10')))
print('devices:', ds.roms)
print('temperatures:', ds.read_temps())
Hope this helps.

Michal

Miguel
Posts: 20
Joined: Fri Sep 09, 2016 7:53 am

Re: Onewire and DS18B20

Post by Miguel » Thu Oct 27, 2016 11:00 am

Another tip for Brunus - use Robert's firmware with disabled multithreading:

https://github.com/robert-hh/Shared-Stu ... mcuimg.bin

Otherwise it won't work (testing with stock firmwares 1.8.4 and 1.8.5 fails for me).

Michal

Brunus
Posts: 5
Joined: Sat Oct 15, 2016 8:02 am

Re: Onewire and DS18B20

Post by Brunus » Fri Oct 28, 2016 11:00 am

Miguel wrote:Another tip for Brunus - use Robert's firmware with disabled multithreading:

https://github.com/robert-hh/Shared-Stu ... mcuimg.bin

Otherwise it won't work (testing with stock firmwares 1.8.4 and 1.8.5 fails for me).

Michal
It works ! \o/
Thank you so much Miguel !

Sincerely, Brunus

Brunus
Posts: 5
Joined: Sat Oct 15, 2016 8:02 am

Re: Onewire and DS18B20

Post by Brunus » Mon Nov 21, 2016 1:44 pm

Hi all,
I have a coding problem while playing with the DS18B20.
I want to activate/deactivate a relay if temperature is above or under 30°C.

I have two version of the code opening or closing a relay while reading the temperature, both versions are starting with :

Code: Select all

import time
import onewire
from machine import Pin
ds = onewire.DS18X20(onewire.OneWire(Pin('GP10')))
print('devices:', ds.roms)
print('temperatures:', ds.read_temps())
relay = Pin('GP5', Pin.OUT, Pin.PULL_UP)
Then I need a loop...

This code works, but it's not what I wanna do :

Code: Select all

while(True):
	temp = ds.read_temps()
	print (temp[0])

	if temp[0] > 3000 and relay.value() is 0:
		print('relay up')
		relay.toggle()
		
		// I do this only to test this version of this code, I don't need it if the code is working like I want
		time.sleep(5)

	if relay.value() is 1:
		print('relay down')
		relay.toggle()

	time.sleep(2)
This code should works but it never enter in the 2nd condition.
When I add the test on the temperature in the 2nd condition, the programme ignore this condition.

Code: Select all

while(True):
	temp = ds.read_temps()
	print (temp[0])

	if temp[0] > 3000 and relay.value() is 0:
		print('relay up')
		relay.toggle()
		
	if temp[0] < 3000 and relay.value() is 1:
		print('relay down')
		relay.toggle()

	time.sleep(2)
There is no error casted by this code above but it's not working, it's printing the good values for temp., but it never enter the 2nd condition and I can't figure out why.

If someone see what I did wrong, it would help me a lot.
Thanks for any answer.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Onewire and DS18B20

Post by pythoncoder » Tue Nov 22, 2016 7:56 am

If you look at the docs http://docs.micropython.org/en/latest/w ... e.Pin.html for the WiPy you will see that the return value of Pin.value() is undefined for output pins. You should therefore write something like:

Code: Select all

value = False
relay.value(value)
while(True):
   temp = ds.read_temps()
   print (temp[0])
   if temp[0] > 3000 and not value:
      print('relay up')
      value = True
      relay.value(value)
      
   if temp[0] < 3000 and value:
      print('relay down')
      value = False
      relay.value(value)

   time.sleep(2)
Peter Hinch
Index to my micropython libraries.

Post Reply