cpetrich / counterfeit_DS18B20

How to tell original from fake DS18B20 temperature sensors.
Apache License 2.0
595 stars 50 forks source link

raspberry pi version #18

Open pabloandresm opened 3 years ago

pabloandresm commented 3 years ago

Very nice investigation and code.

It is a shame that there is no C or Python code for Raspberry Pi. If yould be a very nice too have.

thanks

cpetrich commented 3 years ago

ok, point taken...

hurra commented 3 years ago

You probably can check the serial number with

hexdump -v -e '7/1 "%02x-" 1/1 "%02x" "\n"' /sys/devices/w1_bus_master1/<family-id>/id
leahneukirchen commented 2 years ago

For the Raspberry Pi Pico, you can use the following CircuitPython script:

import board
from adafruit_onewire.bus import OneWireBus
ow_bus = OneWireBus(board.GP16)
print('-'.join(["%02x" % i for i in devices[0].rom]))
scruss commented 2 years ago

And this in MicroPython for the Raspberry Pi Pico/RP2040, assuming pin 16 as above:

# print hex IDs of all ds18x20 sensors found on a pin
from machine import Pin
from onewire import OneWire
from ds18x20 import DS18X20

ds = DS18X20(OneWire(Pin(16)))

for i, sensor in enumerate(ds.scan()):
    print(i, ":", '-'.join(["%02x" % j for j in sensor]))

Other implementations might use something like Pin('PE0') to define a pin.

cpetrich commented 3 months ago

I've copied a Python code fragment in issue https://github.com/cpetrich/counterfeit_DS18B20/issues/20#issuecomment-2005291905 That could be used as a basis for porting the arduino code to Python.