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

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
rpi_nerd
Posts: 17
Joined: Sat Jul 29, 2017 2:05 pm

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

Postby rpi_nerd » Thu Oct 12, 2017 2:23 pm

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?
Last edited by rpi_nerd on Thu Oct 12, 2017 6:03 pm, edited 1 time in total.


rpi_nerd
Posts: 17
Joined: Sat Jul 29, 2017 2:05 pm

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

Postby rpi_nerd » Thu Oct 12, 2017 6:02 pm

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)


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests