1-Wire Slave

Th ATTiny85 can clock internally at either 1mhz or 8mhz or externally with a crystal at 20mhz.
I run it a 8mhz.

ilevans:
Th ATTiny85 can clock internally at either 1mhz or 8mhz or externally with a crystal at 20mhz.
I run it a 8mhz.

May the internal RC is not accurate enough for it

ilevans:
More testing today and the library is working as expected. Yeah!!

I still have a problem that it stops responding after awhile, That is a strange one but I have a starting point with working communications.

thanks

Btw. did you make some other changes anyway, may can you post you Sketch?

ilevans:
I added the following to OneWireSlave.h and removed a reference to "Serial" in OneWireSlave.cpp that was not commented out.

#elif defined(__AVR__)	//ATTiny

#if dsslavepin == 0
  #define dsslaveassignedint 0
  #elif dsslavepin == 1
  #define dsslaveassignedint 1
  #elif dsslavepin == 2
  #define dsslaveassignedint 2
  #elif dsslavepin == 3
  #define dsslaveassignedint 3
  #elif dsslavepin == 4
  #define dsslaveassignedint 5
  #elif dsslavepin == 5
  #else
  #error "Not an Interrupt Pin"
  #error "Use 0, 1, 2, 3, 4 or 5"
  #define dsslaveassignedint -1
  #endif




The 0x44 is working. The 0xBE is not.
After a short while running it no longer is detected by the master does not detect the 0x44.

My program that uses the library does not use any interrupts. Another chip does all the work and communicates using an interruptable shiftIn style communications to pass data to the OWSlave chip. An LED on the second chip informs me that the 0x44 was received and the userdefined function executed. Only 0xFFFF's are reported as being read from the scratchpad.

Ian

Did someone know the rest of the "defined" for the other Arduino Modells so I can maybe complete it better

Hi,

I have attached the sketches I have been testing with for the chips on the slave side. I have kept as much vanilla as possible until debugged. (I am currently selling our house so am not getting time to debug at present)

Counter.ino - sketch to just count pulses on the counter pin and send the count to OWSerial.ino when the trigger pin goes high.
LED flashes to indicate trigger and pulses.
OWSerial.ino - slave sketch. Acts as a DS18B20 returning the count rather than temperature ( 1 pulse = 1/16 degree)
OneWireSlave.cpp - Your library with mods identified previously
OneWireSlave.h - Your library with mods identified previously

Counter.ino (4.89 KB)

OWSerial.ino (3.17 KB)

OneWireSlave.cpp (21.8 KB)

OneWireSlave.h (9.51 KB)

Hello,

I own an Arduino Due and I am very interested in your project (for home automation).
I needed to replace 'cli()' and 'sei()' instructions by 'noInterrupts()' and 'interrupts()'.
Then, it seems to work fine (only few testings so far in front of my Raspberry PI).

I have several DS18B20 for temperature measurement, and was interested by DS2423 for water consumption measurement (to share the same wires between all probes and my Raspberry PI). Since DS2423 is discontinued, I plan to use software emulation for this device.

Do you plan to adapt your code to emulate this one ?

In any case, thank you for your contribution.

Lionel.

yoyolb:
Since DS2423 is discontinued, I plan to use software emulation for this device.

Do you plan to adapt your code to emulate this one ?

Yes I'm looking foward to it, at first without the overdrive support but yes it's the next step maybe in the next weeks, can you please post what you have changed so I can adopt it.

Hi,

I'm a total newbie when it comes to Arduino, but I'm researching the possibility of emulating a DS1990A or similar on Arduino. The aim is to receive serial data from another device, take the necessary data (which would fit in the 48bit ROM serial number) and rewrite it as an iButton ROM ID. Then the virtual DS1990A would be set present and the attached device would read the ROM and process the serial number further, at which point the virtual iButton could be made not present and rewritten based on new incoming data.

The reason for this is that both of the existing devices have limited I/O capabilities, and this is basically the only feasible way to transmit data from one to the other.

Is this possible with the current library, or reasonable at all, in your opinion?

onik:
Hi,

I'm a total newbie when it comes to Arduino, but I'm researching the possibility of emulating a DS1990A or similar on Arduino. The aim is to receive serial data from another device, take the necessary data (which would fit in the 48bit ROM serial number) and rewrite it as an iButton ROM ID. Then the virtual DS1990A would be set present and the attached device would read the ROM and process the serial number further, at which point the virtual iButton could be made not present and rewritten based on new incoming data.

The reason for this is that both of the existing devices have limited I/O capabilities, and this is basically the only feasible way to transmit data from one to the other.

Is this possible with the current library, or reasonable at all, in your opinion?

Should be. Look at the Tech-paper from the DS1990A what it needed I think it only response it ID so far after all

I need something similar as Onik for an access control system:
1 device that

  • acts as multiple 1-Wire Masters, i.e. to read iButtons (and RFID with 1-Wire emulation) from multiple doors, and possibly other input like Wiegand or other serial information.
  • acts as a 1-Wire Slave to pass on the combination of token ID + door ID to another 1-Wire Master (existing an working) that handles all authentication.

I'm also new to Arduino and my first question is: which Arduino should I buy and is most likely to work for this purpose?

@onik: did you make any progress?

prone:
@onik: did you make any progress?

Yes, in fact I did. First there was a delivery delay on my Arduino board, and then the Serial side of the app had to be redesigned, but finally I got to work on the 1wire side.

I cobbled together a little test sketch for transmitting a ROM generated from user input, and verified it with OneWireViewer and an USB adapter (DS9490R). The code attached works, but only if the board is not attached to the reader when starting the viewer, otherwise it doesn't recognize the 1-wire net. I had one crash, but this may be due to the app itself, not the Arduino side.

#include <OneWireSlave.h>;

const int OW_TX_PORT = 13;

unsigned char rom[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
OneWireSlave ds(OW_TX_PORT);

int checkRom();
int sendRom();
int resetValues();

void setup() {
  pinMode(OW_TX_PORT, OUTPUT);
  Serial.begin(9600);
  Serial.println("* Setup done");
}

void loop() {
  Serial.println("**Input RFID tag (in hex, 4 bytes):");
  while (Serial.available() < 8) {
    delay(10);
  }
  if (checkRom() == 0) {
    Serial.println("***RFID valid for ROM, calculating CRC and sending...");
    Serial.print("****");
    Serial.print((int)rom[0]);
    Serial.print((int)rom[1]);
    Serial.print((int)rom[2]);
    Serial.print((int)rom[3]);
    Serial.print((int)rom[4]);
    Serial.print((int)rom[5]);
    Serial.print((int)rom[6]);
    Serial.println((int)rom[7]);
    sendRom();
  } else {
    Serial.println("\n**Invalid character.");
    resetValues();
  }
  do {
    Serial.read();
  } while (Serial.available());
}

int checkRom() {
  unsigned char data[8];
  unsigned char validValues[22] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'};
  for (int i = 0; i < 8; i++) {
    Serial.print(Serial.peek());
    data[i] = Serial.read();
    boolean matchFound = false;
    for (int j = 0; j < (sizeof(validValues) / sizeof(validValues[0])); j++) {
      if (data[i] == validValues[j]) {
        matchFound = true;
      }
    }
    if (!matchFound) {
      return 1;
    }
  }
  Serial.println("");
  charToHex(data);
  return 0;
}

void charToHex(unsigned char chars[]) {
  int values[8];
  for (int i = 0; i < 8; i++) {
    switch (chars[i]) {
      case '0':
        values[i] = 0;
        break;
      case '1':
        values[i] = 1;
        break;
      case '2':
        values[i] = 2;
        break;
      case '3':
        values[i] = 3;
        break;
      case '4':
        values[i] = 4;
        break;
      case '5':
        values[i] = 5;
        break;
      case '6':
        values[i] = 6;
        break;
      case '7':
        values[i] = 7;
        break;
      case '8':
        values[i] = 8;
        break;
      case '9':
        values[i] = 9;
        break;
      case 'a':
      case 'A':
        values[i] = 10;
        break;
      case 'b':
      case 'B':
        values[i] = 11;
        break;
      case 'c':
      case 'C':
        values[i] = 12;
        break;
      case 'd':
      case 'D':
        values[i] = 13;
        break;
      case 'e':
      case 'E':
        values[i] = 14;
        break;
      case 'f':
      case 'F':
        values[i] = 15;
        break;
    }
    if (i % 2 == 0) {
      values[i] = values[i] * 16;
    }
    Serial.print("Value ");
    Serial.print(i);
    Serial.print(":");
    Serial.println(values[i]);
  }

  rom[3] = (values[0] + values[1]);
  rom[4] = (values[2] + values[3]);
  rom[5] = (values[4] + values[5]);
  rom[6] = (values[6] + values[7]);
}

int sendRom() {
  ds.init(rom);
  ds.setPower(PARASITE);
  ds.waitForRequest(false);
  return 0;
}

int resetValues() {
  rom[0] = 0x01;
  rom[1] = 0x00;
  rom[2] = 0x00;
  rom[3] = 0x00;
  rom[4] = 0x00;
  rom[5] = 0x00;
  rom[6] = 0x00;
  rom[7] = 0x00;
}

ilevans:
Hi,

I have attached the sketches I have been testing with for the chips on the slave side. I have kept as much vanilla as possible until debugged. (I am currently selling our house so am not getting time to debug at present)

Counter.ino - sketch to just count pulses on the counter pin and send the count to OWSerial.ino when the trigger pin goes high.
LED flashes to indicate trigger and pulses.
OWSerial.ino - slave sketch. Acts as a DS18B20 returning the count rather than temperature ( 1 pulse = 1/16 degree)
OneWireSlave.cpp - Your library with mods identified previously
OneWireSlave.h - Your library with mods identified previously

This sounds interesting. I have a similar project counting pulses with an Attiny and needing to communicate the pulse count with another device. After reading this thread and the sketches, it's not so clear to me. OWSerial is the slave device as you mention above, but it uses getdata() and MyShiftIn() ..it's reading data in? And Counter has MyShiftOut(). I think I'm misunderstood...Shouldn't the slave device be sending data when the master asks for it?

Anyway, I'd like to try to use this code with my ATtiny85 @ 8mhz and not sure how to start. Currently, I'm using Timer0 (PB2/Pin7/T0/Timer0/Counter0/TCNTO) with an external source to count upwards and that's working. I have to use Pin7/PB2 for this to count the external signal. Now, I'd like the the master device to get the count(with overflows accounted for). It'll only be two bytes from the ATtiny85 to the master device. Any ideas would be appreciated.

In the meantime, I'll continue wrapping my head around the code.

ilevans:
Hi,

I have attached the sketches I have been testing with for the chips on the slave side. I have kept as much vanilla as possible until debugged. (I am currently selling our house so am not getting time to debug at present)

Counter.ino - sketch to just count pulses on the counter pin and send the count to OWSerial.ino when the trigger pin goes high.
LED flashes to indicate trigger and pulses.
OWSerial.ino - slave sketch. Acts as a DS18B20 returning the count rather than temperature ( 1 pulse = 1/16 degree)
OneWireSlave.cpp - Your library with mods identified previously
OneWireSlave.h - Your library with mods identified previously

Hello,

I am also interested in a 1-Wire slave based on ATtiny85.
I would like to measure three times the light/brightness outside (East, South, West) with a LDR or photodiode and transfer the measured values with 1-Wire.
Unfortunately I didn't find any single 1-wire chip for light measurement therefore the ATtiny85 might be an alternative.

I am a newbie with Arduino, but I know that it is possible to program an ATtiny85 with the Arduino IDE.
How can I integrate the files and code above into the IDE? Do I just have to copy it into a sketch?
Is somewhere a webpage where I can download the latest version of the code?

Many thank for your help (for this beginners questions :roll_eyes:)!

Christian

just for discussion,

I would like to try something similar,
I want to integrate dht22 temperature and humidity sensor to 1-wire network. Usually humidity devices for 1-wire based on some other sensors, like Honeywell HIH-3605, cause they provide data using analog pin, and it can be connected to ds2438, but having program slave based on attiny85 looks more interesting for me:)
I experimenting with usb9097 bus master, bought on ebay from China, and Arduino Due for, and code in this thread doesn't seem to work out of box, in OneWireViewer slave device appear for a second and then disappear, and it harms other 1-wire devices connected to net: ds18b20 doesn't report temperature until arduino is disconnected. I believe, there's some issue with timings.
I have idea to rewrite lib to make it fully interrupt-based, cause as for me, delayMicroseconds() in several places look ugly. Also, I have idea to refactor it to split to different classes bus-access code and device logic implementation, since I would like to be able to register two virtual 1-wire devices using 1 chip (as long as my dht22 reports both temperature and humidity, why don't simulate 2 simple devices?). The issue is only that I'm just learning microcontrollers development, I have big experience of desktop "corporate" development on different technologies, but during research of this code I learned there are so many caveats...

sanyok:
just for discussion,

I would like to try something similar,
I want to integrate dht22 temperature and humidity sensor to 1-wire network. Usually humidity devices for 1-wire based on some other sensors, like Honeywell HIH-3605, cause they provide data using analog pin, and it can be connected to ds2438, but having program slave based on attiny85 looks more interesting for me:)
I experimenting with usb9097 bus master, bought on ebay from China, and Arduino Due for, and code in this thread doesn't seem to work out of box, in OneWireViewer slave device appear for a second and then disappear, and it harms other 1-wire devices connected to net: ds18b20 doesn't report temperature until arduino is disconnected. I believe, there's some issue with timings.
I have idea to rewrite lib to make it fully interrupt-based, cause as for me, delayMicroseconds() in several places look ugly. Also, I have idea to refactor it to split to different classes bus-access code and device logic implementation, since I would like to be able to register two virtual 1-wire devices using 1 chip (as long as my dht22 reports both temperature and humidity, why don't simulate 2 simple devices?). The issue is only that I'm just learning microcontrollers development, I have big experience of desktop "corporate" development on different technologies, but during research of this code I learned there are so many caveats...

Yes the timing is a challenge. I would like to see an fully interrupt-based version, I only modify the Resetpulse detection and added an functions to read commands, there is an DS emulation on the web that based on interrupt and timer tm3d.de - geniale 1-Wire Sensoren und mehr its in german...

Markus_L811:
Yes the timing is a challenge. I would like to see an fully interrupt-based version, I only modify the Resetpulse detection and added an functions to read commands, there is an DS emulation on the web that based on interrupt and timer tm3d.de - geniale 1-Wire Sensoren und mehr its in german...

I am just starting with Arduino. Do I understand right that this is not a code which can be loaded with the Arduino IDE?
Is it possible to convert it into Arduino code?

Best regards,

Christian

christian77:
I am just starting with Arduino. Do I understand right that this is not a code which can be loaded with the Arduino IDE?
Is it possible to convert it into Arduino code?

Best regards,

Christian

Yes it's doable for sure, but there are some thinks that have to be looked good at because it hat to work on all Arduino's.

Hello
I have been looking for information for onewire slave. This thread looks interesting but I am not sure I understand how to implement this. If the code is .ino file does that mean I can compile and load from Arduino GUI ?? I also looked at the code on GitHub (from Markus GitHub - MarkusLange/OneWireSlave ) that has .ino files for what appears to be Teensy devices. I have not been able to get that compile with Arduino. I currently have Arduino Mega 2560 and a Teensy 3.1. I would really appreciate someone explaining how to use the various versions listed here and at GitHub GitHub - MarkusLange/OneWireSlave.

Thanks

ringram2077:
Hello
I have been looking for information for onewire slave. This thread looks interesting but I am not sure I understand how to implement this. If the code is .ino file does that mean I can compile and load from Arduino GUI ?? I also looked at the code on GitHub (from Markus GitHub - MarkusLange/OneWireSlave ) that has .ino files for what appears to be Teensy devices. I have not been able to get that compile with Arduino. I currently have Arduino Mega 2560 and a Teensy 3.1. I would really appreciate someone explaining how to use the various versions listed here and at GitHub GitHub - MarkusLange/OneWireSlave.

Thanks

Hi ringram,

can you explain or show what for errors you get? This one should work on all

DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino

Some are spezific for the Teensy 3.

BR
Markus

Here is the error list.

[/Arduino: 1.0.5-r2 (Windows 7), Board: "Teensy 3.1"
C:\arduino-1.0.5-r2\hardware\tools\arm-none-eabi\bin\arm-none-eabi-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mcpu=cortex-m4 -DF_CPU=96000000 -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -mthumb -nostdlib -D__MK20DX256__ -DTEENSYDUINO=118 -fno-rtti -felide-constructors -std=gnu++0x -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\arduino-1.0.5-r2\hardware\teensy\cores\teensy3 -IC:\Arduino\libraries\OneWireSlave C:\Users\Richard\AppData\Local\Temp\build8616894812382935706.tmp\DS18B20_Slave_Interrupt_universal_analogread_fulllib.cpp -o C:\Users\Richard\AppData\Local\Temp\build8616894812382935706.tmp\DS18B20_Slave_Interrupt_universal_analogread_fulllib.cpp.o 

In file included from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:0:
OneWireSlave.h:212: error: #error "Please define I/O register types here"
OneWireSlave.h:231:0: warning: "EXTERNAL" redefined [enabled by default]
In file included from C:\arduino-1.0.5-r2\hardware\teensy\cores\teensy3/wiring.h:33:0,
                 from C:\arduino-1.0.5-r2\hardware\teensy\cores\teensy3/WProgram.h:15,
                 from C:\arduino-1.0.5-r2\hardware\teensy\cores\teensy3/Arduino.h:1,
                 from OneWireSlave.h:7,
                 from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:
C:\arduino-1.0.5-r2\hardware\teensy\cores\teensy3/core_pins.h:711:0: note: this is the location of the previous definition
In file included from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:0:
OneWireSlave.h:260: error: 'IO_REG_TYPE' does not name a type
OneWireSlave.h:261: error: 'IO_REG_TYPE' does not name a type
DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino: In function 'void blinking()':
DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:56:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In file included from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:0:
OneWireSlave.h: At global scope:
OneWireSlave.h:306:22: warning: 'static_OWS_instance' defined but not used [-Wunused-variable]code]