Answer the question
In order to leave comments, you need to log in
How to correctly read the serial number of IButton?
At work, I needed to read a lot of serial numbers from iButton. It is necessary to read all 16 characters from the key. To solve the problem, I decided to use arduino nano. I read several articles about the 1-ware protocol. there were no questions. There were no questions about the program either. I used this code:
#include "<"OneWire.h">"
OneWire ds(4);
byte addr[8];
void setup() {
Serial.begin(9600);
}
void loop() {
if (ds.search(addr)){
for(int i=7; i>-1; i--){
Serial.print(addr[i],HEX);
Serial.print(" ");}
Serial.println();
ds.reset_search();
}
}
The code works, but it doesn't read the numbers exactly as it should. For example, the number 01 reads as 1.00 as 0 I understand why this happens, but how to fix it, no. Tell me please
Answer the question
In order to leave comments, you need to log in
If (addr[i] <0x10) Serial.print("0");
Serial.print(addr[i],HEX);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question