Page 1 of 1

[SOLVED]onewire library converting ow.scan() output to an integer

Posted: Thu Oct 12, 2017 2:23 pm
by rpi_nerd
I've been playing around with the onewire library to read the keycode on my iButton (DS1995L-F5+) When I get the keycode from ow.scan() it gives me the output:

Code: Select all

bytearray(b'\n$\xb9\x1a\x00\x00\x00~') 
How to I convert the output to an integer?

Re: onewire library converting ow.scan() output to an integer

Posted: Thu Oct 12, 2017 5:11 pm
by deshipu

Re: onewire library converting ow.scan() output to an integer

Posted: Thu Oct 12, 2017 6:02 pm
by rpi_nerd
Got it now, the links you posted helped.

The problem surrounded around the variable that I stored the result of ow.scan() becoming a list object that resulted in errors when I tried to convert it, so I needed to copy the array to another variable. Once that was done, I was able to use int.from_bytes and I got an integer output!

Code: Select all

from machine import Pin
import onewire
dw onewire.OneWire(Pin(0))
data = ow.scan()
data2=data[0]
int.from_bytes(data2, 'big')
Now I want to find how to store data on it (the datasheet states it has 2KB of storage)