Arduino Forum

Development => Other Software Development => Topic started by: Coding Badly on Jul 05, 2011, 10:10 am

Title: 1-Wire Slave
Post by: Coding Badly on Jul 05, 2011, 10:10 am

There have been a few brief discussions of a 1-Wire slave library.  I'd like to revisit the idea.  Some topics to get us started...

1. 1-Wire slave should be available for which processors / boards?

2. Is there any reason to support 1 MHz processor speed?

3. Is it possible for an AVR processor to run from "parasitic power"?

4. Do you think you would have any use for a 1-Wire slave library?
Title: Re: 1-Wire Slave
Post by: robtillaart on Jul 05, 2011, 04:22 pm
Quick answers

Quote
1. 1-Wire slave should be available for which processors / boards?

- keep it as portable as possible, use "timing tables" like in NewSoftSerial.

Quote
2. Is there any reason to support 1 MHz processor speed?

- maybe low energy mode?

Quote
3. Is it possible for an AVR processor to run from "parasitic power"?

- don't know; but it could look from the outside as if it was (mimicing)

Quote
4. Do you think you would have any use for a 1-Wire slave library?

- Yes if I could simulate 1 Wire devices with it. I needed a simulator for a few DS18B20's a few months ago so I could test various temperature levels (solved otherwise)
- 1-wire devices have an unique ID, which is useful for identifying a specific board.

2 cents,
Rob
Title: Re: 1-Wire Slave
Post by: 5volt on Jul 07, 2011, 04:01 pm

1. 1-Wire slave should be available for which processors / boards?

As posted by robtillaart, it should be portable. If you have to choose a board to start with, Uno.


2. Is there any reason to support 1 MHz processor speed?

I wouldn't use it but I guess it might be interesting to some people.


3. Is it possible for an AVR processor to run from "parasitic power"?

I don't know if it is possible but it would be useful. Having said that I wouldn't list it as a top priority.


4. Do you think you would have any use for a 1-Wire slave library?

Yes.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 07, 2011, 09:06 pm

Follow-up...

2. Is there any reason to support 1 MHz processor speed?  Yes but it is not possible.  Atmel claims 2.17 MHz is the minimum.  I have not done the math but I believe that number is based on no other interrupts occurring (no millis, no Serial).

5. Are you willing to give up one PWM pin for a 1-Wire slave library?

6. Is there any reason to support multiple 1-Wire devices from a single processor?

7. How do you plan to generate serial numbers?
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 08, 2011, 11:50 am

There have been a few brief discussions of a 1-Wire slave library.  I'd like to revisit the idea.  Some topics to get us started...

1. 1-Wire slave should be available for which processors / boards?

Awesome.  I found this googling "AVR one wire slave".  +1 on a 1-Wiire slave lib.
My list: Same as your core list (ATTiny45/85, ATTiny2313/4313).  My main issue is network comms with low pin count devices.  I'm using TWI/I2C but at present I have to give up /RESET pin to use as I/O, but need to recover its use.  1 wire would be perfect, half duplex master/slave is fine and it would drop me from 4 wire to 3 wire connection which would be great.  Board would be DIY as shown in your Arduino Tiny thread.
 
Quote

2. Is there any reason to support 1 MHz processor speed?

Not for my applications, using 8 MHz internal or 16 MHz external.

Quote

3. Is it possible for an AVR processor to run from "parasitic power"?

This would be cool, but not essential for my present app as I need sufficient local power to run other things anyway. May be cool for networked low power sensor apps.

Quote

4. Do you think you would have any use for a 1-Wire slave library?

Definitely.  I hope this moves forward, I think the need is there and it would compliment your work on Arduino Tiny core.
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 08, 2011, 12:04 pm
Quote

5. Are you willing to give up one PWM pin for a 1-Wire slave library?

Yes.

Quote

6. Is there any reason to support multiple 1-Wire devices from a single processor?

Yes, networking of multiple addressable slaves on a bus.  If you mean multiple addresseable slaves on a single processor, I do not have a need at present.

Quote

7. How do you plan to generate serial numbers?

Ideally over the 1-wire bus, else program in.
Title: Re: 1-Wire Slave
Post by: 5volt on Jul 08, 2011, 12:48 pm
Quote

5. Are you willing to give up one PWM pin for a 1-Wire slave library?

Yes

Quote

6. Is there any reason to support multiple 1-Wire devices from a single processor?

I guess you mean have multiple "vitual" 1-wire devices on the same slave board. E.g. slave_device_1 and slave_device_2 on the same board connected to another board/unit that operates as a master.

It would be interesting to simulate multiple temperature sensors without using one CPU each. It would also be nice read two analog signals and make them availabe as two separate devices on the 1-wire bus even if they are on same board.

Overall, a great idea but not a high priority one.
Title: Re: 1-Wire Slave
Post by: robtillaart on Jul 08, 2011, 01:28 pm
Quote
5. Are you willing to give up one PWM pin for a 1-Wire slave library?

yes,

Quote
6. Is there any reason to support multiple 1-Wire devices from a single processor?

agree  5Volt's reply;
- mapping of multiple sensors, DS18B20, or other
- mapping of multiple 1-wire EEPROM
- mapping of SPI devices on 1-wire
- mapping 6 Analog lines on six 1-wire devices
- mix of devices above

Quote
7. How do you plan to generate serial numbers?

maybe use a UUID??  => - http://www.famkruithof.net/uuid/uuidgen - as base to derive the serial number from.

Q: is 1-wire patented?
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 08, 2011, 07:12 pm
Quote
Quote
7. How do you plan to generate serial numbers?

Ideally over the 1-wire bus, else program in.


I don't understand.  Please clarify.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 08, 2011, 07:14 pm
Quote
Quote
2. Is there any reason to support 1 MHz processor speed?

Not for my applications, using 8 MHz internal or 16 MHz external.


Tuned 8 MHz internal oscillator?
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 08, 2011, 07:17 pm
Quote
Quote
6. Is there any reason to support multiple 1-Wire devices from a single processor?

I guess you mean have multiple "vitual" 1-wire devices on the same slave board. E.g. slave_device_1 and slave_device_2 on the same board connected to another board/unit that operates as a master.


Exactly.  Multiple "virtual" devices.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 08, 2011, 08:35 pm
Quote
maybe use a UUID??  => - http://www.famkruithof.net/uuid/uuidgen - as base to derive the serial number from.


Hmm.  Interesting choice.  Thanks.

Quote
Q: is 1-wire patented?


Impossible to tell from the internet what the legal ramifications are.

This is a common rumor (which has apparently been publicly refuted by a Dallas Semiconductor representative)...
http://www.buoy.com/pipermail/1-wire-software-development/2004-November/000163.html

This fellow claims the patent is indefensible due to prior art but he does not address at least one specific claim in the patent...
http://www.imagerzone.com/ForumsPro/viewtopic/t=4458/view=next.html

This is the most reference information I could find...
http://dics.voicecontrol.ro/process_mails/arata_discutia/129197/Implementing_1-wire_slaves.html

At least 1-Wire device was on the market (Apr 1, 1998) more than a year before the patent filing date (Jul 22, 1999).  That alone should have prevented the patent office from granting the patent.

The PIC folks don't seem to be too concerned...
http://www.microchip.com/forums/tm.aspx?high=&m=454169&mpage=1#454678
http://www.picbasic.co.uk/forum/showthread.php?t=9192&page=1
http://www.picbasic.co.uk/forum/showthread.php?t=6840&page=1
http://www.embeddedrelated.com/usenet/embedded/show/76371-1.php

This is claimed to be an official statement from Dallas Semiconductor...
http://www.1wire.org/index.html?target=p_142.html&lang=en-us

There are several companies selling 1-Wire slave devices that don't seem to have any association with Dallas Semiconductor.

What I do know is that each of us can do whatever we want so long as it is only for "personal use".
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 09, 2011, 02:56 pm

Quote
Quote
7. How do you plan to generate serial numbers?

Ideally over the 1-wire bus, else program in.


I don't understand.  Please clarify.



Not fully formed as an idea, but I was thinking along the lines of a base S/N that would be recognized as unprogrammed.  The master could then query slave, recognize the base number as a new node on the network, and assign it a new S/N.  I imagine this functionality could be accomplished a number of other ways, so not a hard requirement in my mind.
Title: Re: 1-Wire Slave
Post by: robtillaart on Jul 09, 2011, 05:34 pm

Quote
Not fully formed as an idea, but I was thinking along the lines of a base S/N that would be recognized as unprogrammed.  The master could then query slave, recognize the base number as a new node on the network, and assign it a new S/N.  I imagine this functionality could be accomplished a number of other ways, so not a hard requirement in my mind.

Think there is a bootstrap problem in this. How can the server acces the client without address. eg there are 2 or more devices without S/N which one to address.

The solution could be a "voting market". Imagine an unproggrammed(UP) client device just calls on the bus "is there any nr 12, if so let him speak or silence forever"?
if another device has nr 12 it responds, and the UP device tries another/next number.
if no device responds the device can use nr 12.

If multiple devices call on the bus, the numbers passing by will not be used (skipped) except by the original sender, so if one shouts "12?" the next UPdevice shouts "13?" etc.
To prevent devices shout at the same time a random interval is used between shouts.


Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 11, 2011, 08:33 am

@MGeo: Reply #9 was a question for you...
http://arduino.cc/forum/index.php/topic,65706.msg483782.html#msg483782

At 16 MHz, the worst case time in the millis interrupt service routine is 7.3125 microseconds.  Because of the latency the millis ISR can introduce, occasionally a write-one will start past the end of the write synchronization pulse (6 microseconds) but the write-one should still start before the sample point (15 microseconds).  Which raises a few more questions...

8. What do you plan to turn into a 1-Wire slave device?  (e.g. I want to make a servo controllable through 1-Wire)

9. Which libraries do you intend to use?

10. Do you plan to make use of any interrupts?

11. On your slave device, would crippling millis / micros cause problems?  Consider this question carefully.  There are potentially hidden implications (like delay not working).

12. In your 1-Wire master code, do you read and verify the CRC?  Do you discard responses with an invalid CRC?
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 14, 2011, 11:12 am


@MGeo: Reply #9 was a question for you...
http://arduino.cc/forum/index.php/topic,65706.msg483782.html#msg483782


Sorry, missed that.  Yes tuned RC if needed.
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 14, 2011, 11:19 am

8. What do you plan to turn into a 1-Wire slave device?  (e.g. I want to make a servo controllable through 1-Wire)
9. Which libraries do you intend to use?
10. Do you plan to make use of any interrupts?
11. On your slave device, would crippling millis / micros cause problems?  Consider this question carefully.  There are potentially hidden implications (like delay not working).
12. In your 1-Wire master code, do you read and verify the CRC?  Do you discard responses with an invalid CRC?


8. I am trying to use a 1-Wire slave lib to communicate with actautors and sensors over a 3 wire bus (power, gnd, signal).
9. I do not have that fully developed, but an I2C master lib running on a 1 wire slave will be needed to talk to I2C sensors so I can get them on the 1-wire bus.  I think the actuators and sensors will in general make minimal use of libraries, but rather serve as a flexible way to add them to an arduino based master that would add higher level functionality.
10. I general yes, for timing on servo loops and sensor interfaces.
11. Not a problem, it is an expected concession.  I can handle delays direct.
12. Yes, I plan to.

Thanks for your consideration.
George
Title: Re: 1-Wire Slave
Post by: pwillard on Jul 16, 2011, 05:53 am
This is very interesting to me...

I'm looking to replace the obsolete 1-wire counter.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 16, 2011, 08:51 am
9. I do not have that fully developed, but an I2C master lib running on a 1 wire slave will be needed to talk to I2C sensors so I can get them on the 1-wire bus.


It appears Maxim has at least one product that may do what you want...
http://www.maxim-ic.com/app-notes/index.mvp/id/3684

Have you investigated or used an I2C 1-Wire bridge like the Maxim one?


Quote
Thanks for your consideration.


Thank you for your answers.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 16, 2011, 08:56 am
8. I am trying to use a 1-Wire slave lib to communicate with actautors and sensors over a 3 wire bus (power, gnd, signal).


What value do you plan to use for the 1-Wire family code?
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 16, 2011, 08:58 am
I'm looking to replace the obsolete 1-wire counter.


Part number?


I believe these are the relevant open questions...

1. 1-Wire slave should be available for which processors / boards?

5. Are you willing to give up one PWM pin for a 1-Wire slave library?

6. Do you have a need for multiple (virtual) 1-Wire devices on a single board?

7. How do you plan to generate 1-Wire serial numbers?

9. Which Arduino libraries do you intend to use?

10. Do you plan to make use of any interrupts?

11. On your slave device, would crippling millis / micros cause problems?  Consider this question carefully.  There are potentially hidden implications (like delay not working).

12. In your 1-Wire master code, do you read and verify the CRC?  Do you discard responses with an invalid CRC?


If you don't mind, please reply with answers.
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 16, 2011, 11:41 am
I was not aware of Maxim I2C 1-Wire bridge.  This could work for some sensors (ones that do not need post processing such as temp compensation, linearization, etc).  Thanks for the tip.  Would not help for actuators of course.

On family code I do not have a plan yet and am open for suggestion.
Title: Re: 1-Wire Slave
Post by: pwillard on Jul 16, 2011, 04:09 pm
Quote
Part number?


My weather station project uses multiple DS2423. I've already lost one to in-service failure.  Family Code: "1D"

http://pdfserv.maxim-ic.com/en/ds/DS2423.pdf (http://pdfserv.maxim-ic.com/en/ds/DS2423.pdf)



Quote
1. 1-Wire slave should be available for which processors / boards?


Prefer  tiny45, mega48, mega88, tiny26, tiny2313 in order of precedence (tiny45 being most preferred)

Quote
5. Are you willing to give up one PWM pin for a 1-Wire slave library?


Absolutely, yes.

Quote
6. Do you have a need for multiple (virtual) 1-Wire devices on a single board?


Not a requirement

Quote
7. How do you plan to generate 1-Wire serial numbers?


Hard Coded in EEPROM is fine.  Maybe an external program can be used to generate the EEPROM  number data.



Quote
9. Which Arduino libraries do you intend to use?

LCD, SPI, not sure.

Quote
10. Do you plan to make use of any interrupts?

Possibly.

Quote
11. On your slave device, would crippling millis / micros cause problems?  Consider this question carefully.  There are potentially hidden implications (like delay not working).


Delay() should be avoided anyway.  Though loss of accurate mS/uS timing could be problematic.

Quote
12. In your 1-Wire master code, do you read and verify the CRC?  Do you discard responses with an invalid CRC?


I would prefer to check CRC data to validate 1-wire data


Title: Re: 1-Wire Slave
Post by: robtillaart on Jul 16, 2011, 04:38 pm
Quote
10. Do you plan to make use of any interrupts?

Would be nice to make counters for RoundsPerMinute counters,

you config pulses per rotation PPR in a register and you have

PPR 16 bit?
ROTATIONS register 32 bit
POSITION register  16 bit (counter from 0..PPR)





Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 18, 2011, 08:11 am

A question for everyone...

13. Do you use Standard mode, Overdrive mode, or both?
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 18, 2011, 11:08 am
I am targetting overdrive mode speeds.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 20, 2011, 06:34 am
Prefer  tiny45, mega48, mega88, tiny26, tiny2313 in order of precedence (tiny45 being most preferred)


Clock speed?

Crystal or oscillator?



Would be nice to make counters for RoundsPerMinute counters,

you config pulses per rotation PPR in a register and you have

PPR 16 bit?
ROTATIONS register 32 bit
POSITION register  16 bit (counter from 0..PPR)


A tachometer / encoder device?


I am targetting overdrive mode speeds.


Bad news.  Overdrive will be later.  The response to a master-read has to be within 1.0 microseconds.  That's about 16 machine instructions (a small overrun would probably be OK).  I suspect it will work but I want to pin down the other "high risk" implementation details before tackling the complexity of an assembly language interrupt service routine.
Title: Re: 1-Wire Slave
Post by: MGeo on Jul 26, 2011, 11:52 am

Bad news.  Overdrive will be later.  The response to a master-read has to be within 1.0 microseconds.  That's about 16 machine instructions (a small overrun would probably be OK).  I suspect it will work but I want to pin down the other "high risk" implementation details before tackling the complexity of an assembly language interrupt service routine.


OK thanks.

This got me wondering how Arduino OneWire lib based master could be prepared for a 1 microsecond slave response to master-read without any hardware assist.  It appears that OneWire Master lib OneWire::read_bit() code has a 3 microsecond delay for driving pin low, followed by a 9 microsecond delay at float before reading pin value.  So maybe Arduino OneWire Master lib allows more response time than the minimum listed in Dallas spec, and 1 uS is taking excess margin?

Arduino OneWire Master Lib Source --> http://www.pjrc.com/teensy/td_libs_OneWire.html

Anyway, thanks for on-going consideration.

George
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 30, 2011, 06:36 am
I am targetting overdrive mode speeds.


Do you have an Overdrive master?

Quote
This got me wondering how Arduino OneWire lib based master could be prepared for a 1 microsecond slave response to master-read without any hardware assist.


It should work fairly well on the Master.  Interrupts have to be disabled in advance.  But 1 microsecond is 16 simple machine instructions (worst case 8 machine instructions) which I believe is enough to pulse the line low and then listen for the slave's response.

Quote
It appears that OneWire Master lib OneWire::read_bit() code has a 3 microsecond delay for driving pin low, followed by a 9 microsecond delay at float before reading pin value.  


The timing in the OneWire library seems a bit odd to me.  It's definitely a different than the timing Maxim documents.  At first I thought the times were tweaked to compensate for the code before and after but that does not seem to be the case.

Quote
So maybe Arduino OneWire Master lib allows more response time than the minimum listed in Dallas spec, and 1 uS is taking excess margin?


I don't follow.

Quote
Arduino OneWire Master Lib Source --> http://www.pjrc.com/teensy/td_libs_OneWire.html


That's the Master I've been working against.

Quote
Anyway, thanks for on-going consideration.


You are welcome.  But don't hold your breath.  The day job will not stop interfering!
Title: Re: 1-Wire Slave
Post by: robtillaart on Jul 30, 2011, 08:47 am
Quote

Quote from: robtillaart on July 16, 2011, 03:38:44 PM
Would be nice to make counters for RoundsPerMinute counters,

you config pulses per rotation PPR in a register and you have

PPR 16 bit?
ROTATIONS register 32 bit
POSITION register  16 bit (counter from 0..PPR)

A tachometer / encoder device?

Yep, it is a recurring problem on the forum and developing a "smart encoder sensor" could be very interesting. The 1-wire slave Arduino connects the HW encoder to an IRQ line, the software on the 1-wire slave is configurable for the HW encoder details, like
* control register: start, stop, reset
* pulses per rotations (PPR)
* set IRQ edge (RISING/FALLING/CHANGE)
* rotations done since reset.
* position within current rotation.
* current direction of rotation [if supported in HW]
* angular velocity  [include array with last 10 pulse timestamps]



Title: Re: 1-Wire Slave
Post by: jooray on Aug 18, 2011, 11:25 pm
I just started coding similar project, just for fun (the goal is to send serial as slave to another arduino as a master). I can not seem to get the timing right though.

Do you have any ideas for testing?

I started with master library and changing it with the PIC code as an example.

I played with some iButtons and this is my first Arduino project besides lighting LEDs. :)

Thanks for doing this!
Title: Re: 1-Wire Slave
Post by: Coding Badly on Aug 19, 2011, 07:53 am
I started with master library and changing it with the PIC code as an example.


Don't do that.  You can find a ready to use well documented master library here...
http://pjrc.com/teensy/td_libs_OneWire.html

Quote
I just started coding similar project, just for fun


You have a perverse sense of "fun"!   ;)

Quote
Do you have any ideas for testing?


Work in very tiny increments.  Create code that can reliably detect a Reset.  Add code that reliably detects the Device Present pulse.  Add code that reliably determines the end of the Reset.  Et cetera.

Quote
(the goal is to send serial as slave to another arduino as a master). I can not seem to get the timing right though.


The slave timing is definitely tricky.  I've identified three potential problems...

1. Interrupt latency.

2. Master variations.

3. Loose protocol.

Quote
I played with some iButtons and this is my first Arduino project besides lighting LEDs. :)


An eclectic set.

Quote
Thanks for doing this!


Don't thank me yet!  At the rate I'm going we all may expire before I finish.

This is not very Arduino friendly but I suspect that it works well...
http://old.nabble.com/1wire-slave-codebase-%28AVR%29-td28214218.html
https://github.com/smurfix/owslave
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jul 23, 2012, 02:20 pm
Did you take a look at this?

http://robocraft.ru/blog/arduino/302.html

Google will help you to translate.
Title: Re: 1-Wire Slave
Post by: Coding Badly on Jul 23, 2012, 07:02 pm

I had not seen that.  Thank you for the tip.
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jul 25, 2012, 11:15 am


I had not seen that.  Thank you for the tip.


Not for that i've seen that few days ago, i'am looking too, to get an emulation of an 1-Wire Slave, this looks like the most simple projekt, for other typs of devices the libary must expand in my opinion, bevor i've seen that i was thinking about an interrupt driven lib, in combination with an final state maschine but this would be to complex. But this modified lib looks nice maybe with some extra code for different typs of devices and "jump marks" it can be an solution for 1-Wire Slaves. So that you tell the lib what it is and only the conf or informations would be set in the Sketches.

B.R.

Markus
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 15, 2013, 12:09 pm
It's about time to move some dust.

Moving from this http://robocraft.ru/blog/arduino/302.html (http://robocraft.ru/blog/arduino/302.html) way there to this https://digistump.com/board/index.php/topic,887.0.html (https://digistump.com/board/index.php/topic,887.0.html). Thanks to all that Guys what they did.

I was able to start this. Files in the Attachment.

DS18B20_Slave.ino                        --> the Slave in Arduinostyle
OneWireSlave.cpp/.h                    --> the library for it
(did not work on Due or Teensy 3)

DS18x20_Temperature_edited.ino   --> an little edited Version of Paul Stoffregen's File from the last OneWirelib (2.2)

The Arduino pretend on with the DS18B20_Slave to be an DS18B20 with an temp of 155°C (clearly above the capabilities of the DS18B20 (125)) parasite powered. But under heavy duty.

What didn't work is the DallasTemperature Library from Miles Burton there are some problems with reset_search and the reset at the end of some parts.

Code: [Select]
// reads the device's power requirements
bool DallasTemperature::readPowerSupply(uint8_t* deviceAddress)
{
 bool ret = false;
 _wire->reset();
 _wire->select(deviceAddress);
 _wire->write(READPOWERSUPPLY);
 if (_wire->read_bit() == 0) ret = true;
 _wire->reset();     --> this line is not good fore the cloned DS18B20 without it works
 return ret;
}


May someone can help drive this forward to getting an working and universal library. Perhaps an interrpt driven Initiaization Timing can bring success but I'm not an expert for that.

This is really experimental. Nothing is convenient on this.

Pictures below:
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 15, 2013, 12:15 pm
1st the Hardware
Black-Board an Vinciduino, Powered by an supply
Blue-One an Arduino Nano Powered by USB
And 3 real DS18B20 Powered from the Nano external.

2nd the Serial from the Nano
4 DS18B20
The last is the Arduino-Slave what you can see parasite Powered and burning@155°C
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 15, 2013, 05:44 pm
Surprise to my self.

Now an expedition into interrupts.

Quick an dirty with interruptsroutine for recognizing the Master Tx Reset Pulse...

But now the  DallasTemperature Library from Miles Burton works too, for it on the other side, and recognize it as well.
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 15, 2013, 10:36 pm
Some improvement with support for the 44h command and set the "power supply" from the outsite the library.

Code: [Select]

ds.attach44h(temper);

-----------------------------------------

void temper() {
  scratchpad[1] = scratchpad[1] + 1;
  ds.setScratchpad(scratchpad);
}


Sometimes the "Slave did something wrong think he didn't get the Master reset.

Code: [Select]
ROM = 28 AD DA CE 0F 00 11 5B
  Chip = DS18B20
  Data = FF FF FF FF FF FF FF FF FF  CRC=C9
  Powersupply = Parasite Powered
  Temperature = -0.06 Celsius, 31.89 Fahrenheit


All FF so there is some miss.

New added:
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 18, 2013, 07:49 pm
Now support for Teensy 3.0 and Arduino Due added.

For proper work with the T3 some changes must be done:

Add this on the void setup()
Code: [Select]
pinMode(12, INPUT);

And this on the void DS18B20() change this line
Code: [Select]
if (difference >= 380 && difference <= 800) {
to
Code: [Select]
if (difference >= 325 && difference <= 500) {

Thanks to Paul.

For the Due the Sample must be changed read this page about the interrupts.

http://arduino.cc/en/Reference/AttachInterrupt (http://arduino.cc/en/Reference/AttachInterrupt)

Update:

Allowing to set resolution from Master or per command from slave side
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 25, 2013, 12:45 pm
Some new Sketches to play with for the 1-Wire-Slave:

1nd Analogread for temper

2st Serial in for temper
Title: Re: 1-Wire Slave
Post by: ilevans on Oct 31, 2013, 09:58 pm
I have been playing around with your libraries for programming an ATTiny85 at 8Mhz but find that it is failing to detect the 0x44 - Convert Temperature when sent. The 0xBE - Read Scratchpad  works only from your sample master and not from my program with nearly identical code that works with DS18B20 temperature sensors.

My master program detects, converts DS18B20 temperature sensors without any problem.

Not having an oscilloscope I am at a loss as to where the problem may be. I am assuming a timing issue but am not sure where to look next.

Any ideas would be most welcome.

Ian
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Nov 01, 2013, 10:34 am

I have been playing around with your libraries for programming an ATTiny85 at 8Mhz but find that it is failing to detect the 0x44 - Convert Temperature when sent. The 0xBE - Read Scratchpad  works only from your sample master and not from my program with nearly identical code that works with DS18B20 temperature sensors.

My master program detects, converts DS18B20 temperature sensors without any problem.

Not having an oscilloscope I am at a loss as to where the problem may be. I am assuming a timing issue but am not sure where to look next.

Any ideas would be most welcome.

Ian


I have there some newer version may that will help..., let me know
Title: Re: 1-Wire Slave
Post by: ilevans on Nov 04, 2013, 03:36 am
Thank you. I will give them a try.
Title: Re: 1-Wire Slave
Post by: ilevans on Nov 04, 2013, 10:29 am
I am receiving the following errors when compiling

. . ./OneWireSlave.h:133:4: error: #error "Not an Interrupt Pin"
. . ./OneWireSlave.h:134:4: error: #error "Use 2 or 3"

Any ideas?

Ian
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Nov 04, 2013, 11:41 am

I am receiving the following errors when compiling

. . ./OneWireSlave.h:133:4: error: #error "Not an Interrupt Pin"
. . ./OneWireSlave.h:134:4: error: #error "Use 2 or 3"

Any ideas?

Ian

Oh I know, the  ATTiny85 is not part in the lib can you give me the pins in the IDE where the ATTiny85 has interrupts so I can adopt it for somethink like this.

Code: [Select]
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //Arduino Mega
  #if dsslavepin == 2
  #define dsslaveassignedint 0
  #elif dsslavepin == 3
  #define dsslaveassignedint 1
  #elif dsslavepin == 18
  #define dsslaveassignedint 5
  #elif dsslavepin == 19
  #define dsslaveassignedint 4
  #elif dsslavepin == 20
  #define dsslaveassignedint 3
  #elif dsslavepin == 21
  #define dsslaveassignedint 2
  #else
  #error "Not an Interrupt Pin"
  #error "Use 2, 3, 18, 19, 20 or 21"
  #define dsslaveassignedint -1
  #endif


so your uC can be supported.
Title: Re: 1-Wire Slave
Post by: PaulS on Nov 04, 2013, 12:09 pm
Quote
Any ideas?

Use pin 2 or pin 3.
Title: Re: 1-Wire Slave
Post by: ilevans on Nov 04, 2013, 08:41 pm
Hi  Again

Interrupts are available on pins 0, 1, 2, 3, 4 and 5.
The micro-controller details and datasheet are available at the following link http://www.atmel.com/devices/ATTINY85.aspx (http://www.atmel.com/devices/ATTINY85.aspx).

I have attached the pins_arduino.h for the ATTiny

Thank you for your assistance.

Ian
Title: Re: 1-Wire Slave
Post by: ilevans on Nov 04, 2013, 09:27 pm
I added the following to OneWireSlave.h and removed a reference to "Serial" in OneWireSlave.cpp that was not commented out.

Code: [Select]
#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


Title: Re: 1-Wire Slave
Post by: ilevans on Nov 08, 2013, 10:25 pm
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
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 15, 2013, 12:20 pm

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


How often did you poll your uC to get the informations? The Problem is if the uC is too often called he would get out of sync and can't responce anymore, at the moment I have no idea for it. How fast is the ATTiny?
Title: Re: 1-Wire Slave
Post by: ilevans on Dec 15, 2013, 08:54 pm
My testing currently consists of 3 x DS18B20 Temperature Sensors and 1 ATTiny85. All slaves are running on external power.

1) All slaves are issued a Convert Temperature Command individually (0x44)
2) 750ms wait (minimum conversion time for DS18B20)
3) All slaves are Read. (0xBE)
4) 2000ms wait before polling again.

The ATTiny85 running at 8mhz, although the chip is capable of running at 20mhz with external clocking.

cheers
Title: Re: 1-Wire Slave
Post by: robtillaart on Dec 15, 2013, 09:44 pm
Quote
2) 750ms wait (minimum conversion time for DS18B20)

for 12 bits it is, for 9 bits it is substantially less...
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 16, 2013, 10:52 am

The ATTiny85 running at 8mhz, although the chip is capable of running at 20mhz with external clocking.


Crystal or internal RC?

At the moment I don't know if the Leonardo I tested it sometimes get out of step or it's a load problem, I have run it on two Teensy 3 for hours with one miss on temp conversions.

I know if I let run an Leonardo direct against an other, the on who pretends an DS18B20 can't response in time with 2 real DS18B20 in chain it works most the time, only a few "temp conversions" are dropped.
Title: Re: 1-Wire Slave
Post by: ilevans on Dec 16, 2013, 07:52 pm
Th ATTiny85 can clock internally at either 1mhz or 8mhz or externally with a crystal at 20mhz.
I run it a 8mhz.
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 16, 2013, 07:54 pm

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
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 17, 2013, 09:07 am

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?
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 17, 2013, 09:42 am

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

Code: [Select]
#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
Title: Re: 1-Wire Slave
Post by: ilevans on Dec 17, 2013, 12:12 pm
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

Title: Re: 1-Wire Slave
Post by: yoyolb on Dec 20, 2013, 02:41 pm
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.
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 20, 2013, 02:48 pm

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.
Title: Re: 1-Wire Slave
Post by: onik on Dec 20, 2013, 02:51 pm
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?
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Dec 20, 2013, 03:05 pm

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
Title: Re: 1-Wire Slave
Post by: prone on Jan 06, 2014, 02:12 pm
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?
Title: Re: 1-Wire Slave
Post by: onik on Jan 17, 2014, 09:31 am
@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.

Code: [Select]
#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;
}
Title: Re: 1-Wire Slave
Post by: gismo on Feb 13, 2014, 01:51 am

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.
Title: Re: 1-Wire Slave
Post by: christian77 on Feb 21, 2014, 07:54 am

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   :smiley-roll:)!

Christian
Title: Re: 1-Wire Slave
Post by: sanyok on Feb 21, 2014, 09:00 pm
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...
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Feb 22, 2014, 02:30 pm

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 http://www.tm3d.de/index.php/1-wire-device-mit-avr (http://www.tm3d.de/index.php/1-wire-device-mit-avr) its in german...
Title: Re: 1-Wire Slave
Post by: christian77 on Feb 24, 2014, 07:12 pm

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 http://www.tm3d.de/index.php/1-wire-device-mit-avr (http://www.tm3d.de/index.php/1-wire-device-mit-avr) 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
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Feb 26, 2014, 09:06 am

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.
Title: Re: 1-Wire Slave
Post by: ringram2077 on Mar 30, 2014, 06:40 pm
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 https://github.com/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 https://github.com/MarkusLange/OneWireSlave.

Thanks
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Mar 30, 2014, 08:27 pm

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 https://github.com/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 https://github.com/MarkusLange/OneWireSlave.

Thanks


Hi ringram,

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

Some are spezific for the Teensy 3.

BR
Markus
Title: Re: 1-Wire Slave
Post by: ringram2077 on Mar 31, 2014, 12:47 am
Here is the error list. 

Code: [Select]
[/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]
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Mar 31, 2014, 01:00 am
A okey I see, the version on github did not contain support for the Teensy 3.1, please reload the new from github it should work now.
Title: Re: 1-Wire Slave
Post by: ringram2077 on Mar 31, 2014, 12:59 pm
Thanks for the reply. Still getting compile errors.  I got the latest GitHub files.  Here is result:

Code: [Select]
[/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\build8964515928240465406.tmp\DS18B20_Slave_Interrupt_universal_analogread_fulllib.cpp -o C:\Users\Richard\AppData\Local\Temp\build8964515928240465406.tmp\DS18B20_Slave_Interrupt_universal_analogread_fulllib.cpp.o

In file included from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:0:
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:212:2: error: #error "Please define I/O register types here"
C:\Arduino\libraries\OneWireSlave/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 C:\Arduino\libraries\OneWireSlave/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:
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:260:4: error: 'IO_REG_TYPE' does not name a type
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:261:14: 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:
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h: At global scope:
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:306:22: warning: 'static_OWS_instance' defined but not used [-Wunused-variable]code]
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Mar 31, 2014, 01:31 pm
Strange, I used the files directly from git and tested it, compiled without errors can, test if it compile for other boards from the list? What verion of teensyduino did you use?
Title: Re: 1-Wire Slave
Post by: ringram2077 on Mar 31, 2014, 01:44 pm
For the Mega 2560 I get this:
I don't see where to find version of Teensyduino but I just got it yesterday.  It does support Teensy 3.1 and will load the blink sketch.  May be I am not going about this the correct way. I got the latest onewireslave files from get hub and the ino sketch. Then simply load your ino sketch to Arduino GUI  hit Verify.  That's it.

Code: [Select]
[/Arduino: 1.0.5-r2 (Windows 7), Board: "Arduino Mega 2560 or Mega ADK"
C:\arduino-1.0.5-r2\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\arduino-1.0.5-r2\hardware\arduino\cores\arduino -IC:\arduino-1.0.5-r2\hardware\arduino\variants\mega -IC:\Arduino\libraries\OneWireSlave C:\Users\Richard\AppData\Local\Temp\build5803949998534887674.tmp\DS18B20_Slave_Interrupt_universal_analogread_fulllib.cpp -o C:\Users\Richard\AppData\Local\Temp\build5803949998534887674.tmp\DS18B20_Slave_Interrupt_universal_analogread_fulllib.cpp.o

In file included from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:35:4: error: #error "Not an Interrupt Pin"
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:36:4: error: #error "Use 2, 3, 18, 19, 20 or 21"
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:231:1: warning: "EXTERNAL" redefined
In file included from C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:7,
                from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:
C:\arduino-1.0.5-r2\hardware\arduino\cores\arduino/Arduino.h:56:1: warning: this is the location of the previous definition
DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino: In function 'void blinking()':
DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:56: warning: comparison between signed and unsigned integer expressions
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h: At global scope:
C:\Arduino\libraries\OneWireSlave/OneWireSlave.h:306: warning: 'static_OWS_instance' defined but not usedcode]
Title: Re: 1-Wire Slave
Post by: ringram2077 on Apr 01, 2014, 02:31 am
UPDATE:
Current GitHub files compile correctly for Teensy 3.1. Must have been picking up old version of onewireslave.h.  I put the current onewireslave.h file in sketch folder and referenced it there and successfully compiled.  Thanks for making changes for 3.1.
Richard
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Apr 11, 2014, 06:11 pm

UPDATE:
Current GitHub files compile correctly for Teensy 3.1. Must have been picking up old version of onewireslave.h.  I put the current onewireslave.h file in sketch folder and referenced it there and successfully compiled.  Thanks for making changes for 3.1.
Richard

No Thanks needed at all, have fun with it.

Looks like the Slave works more proper with the Teensy 3 and above may its an idea to port the timer and interrupt driven version to the Arduino to get better work with the Megas.
Title: Re: 1-Wire Slave
Post by: Punkt3 on Jun 06, 2014, 10:26 am
Hi Markus,

i tried the OneWireSlave-Library to work on an Arduino Pro Mini.
If i compiled the example DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino and i get the following errors:

In file included from DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino:3:
Eigene Dateien\Arduino\libraries\OneWireSlavemaster/OneWireSlave.h:140:4: error: #error "Not an Interrupt Pin"
Eigene Dateien\Arduino\libraries\OneWireSlavemaster/OneWireSlave.h:141:4: error: #error "Use 0, 1, 2, 3, 4 or 5"

Is there a way to get this Library working with my Arduino Pro Mini?


regards

Michael
Title: Re: 1-Wire Slave
Post by: Punkt3 on Jun 06, 2014, 10:45 am
ok - think i got it.

In the DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino i changed the dsslavepin to 1 - that worked.
The Sketch compiled.

Now i will try to test it out.

Is there anywhere a wiring scheme to connect to the 1wire-Bus?
Or will the following work:

Bus  <->  Arduino
5V    <->  5V
GND <->  GND
Data  <->  Pin1 (the pin assigned to dsslavepin)

Is this correct?


regards

Michael
Title: Re: 1-Wire Slave
Post by: Punkt3 on Jun 07, 2014, 07:24 pm
soo...update:

i wired my nano like Markus as shown in Post #36 (http://forum.arduino.cc/index.php?topic=65706.msg1279103#msg1279103).
But my nano istn listet on my 1wire-Bus.

I set Pin2 as dsslavepin - but it seems that this doesnt work.

Markus: you got your Nano running as 1wire slave - what can i do to get mine working?  :smiley-red:
Can you give me e litte hint?
Title: Re: 1-Wire Slave
Post by: ilevans on Jun 07, 2014, 10:32 pm
You will need a 4.7K ohm resister between +5v and the data line for the arduino to act as a master.
Title: Re: 1-Wire Slave
Post by: Punkt3 on Jun 07, 2014, 10:37 pm
I don't want the Arduino to act as a master.
The Arduino should act as an 1wire slave.

For testings i have an Raspberry with an 1wire bus master to which i would connect the Arduino (as slave).
The bus master works fine - tested with an normal DS18B20.

On this bus i connected the Arduino with the 1wire slave sketch - but the Arduino is not listed on the 1wire bus...
Title: Re: 1-Wire Slave
Post by: ilevans on Jun 07, 2014, 10:55 pm
Quote
For testings i have an Raspberry with an 1wire bus master to which i would connect the Arduino (as slave).
The bus master works fine - tested with an normal DS18B20.


Quote
Bus  <->  Arduino
5V    <->  5V
GND <->  GND
Data  <->  Pin1 (the pin assigned to dsslavepin)


If you are not using the Raspberry  +5v to power the Arduino it should not be connected to the Arduino +5v. You only need to connect GND and Data.
Title: Re: 1-Wire Slave
Post by: Punkt3 on Jun 07, 2014, 11:03 pm
thanks for the hint.

so far i connected only the data pin (connected to digital2) and ground pin to the Arduino.
At the moment the Arduino is powered via the usb connector.

however if i tested the simple code for simulating the DS1990A - the Arduino (simulated DS1990A) is not listed in the bus list. =(
somehow i have no idea what i can do to get this setup work - but i know that it must work.
Markus got this running on an Arduino nano if i am not wrong...  :smiley-roll:
Title: Re: 1-Wire Slave
Post by: ilevans on Jun 07, 2014, 11:55 pm
I have finally got ATTiny85's working as 1-wire slaves but not using Markus' library, I used a modified version of the one wire library from Alexander Gordeev  (http://robocraft.ru/blog/arduino/302.html). I finally succeeded once I discovered I could run the ATTiny85 at 16Mhz, that was the big breakthrough.  

I now have ATTiny85s as slaves for a rain gauge and another for a humidity sensor. I am using the  PinChange Interrupt Library (https://code.google.com/p/arduino-tiny/downloads/detail?name=PinChangeInterrupt-0001.zip) so that the slaves only process one-wire commands once a One Wire Reset is detected. An LED flashes to provide visual feedback when the slave sends sensor data. Like the DS18B20 I use 0x44 as a request to calculate the sensor data and 0xBE to return the results.

I am running an Arduino as the weather station and One wire Master with Serial Communication to a computer. I had problems once I started adding multiple ATTiny85s but a 100nF decoupling ceramic capacitor across the +5v and GND lines has fixed them. My currently setup includes . . .

I have attached the modified library along with the slave code for the rain Gauge and Humidity Sensors. The Weather Station Sketch is a work in progress that I am willing to make available should anyone be interested.
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 10, 2014, 08:13 pm

thanks for the hint.

so far i connected only the data pin (connected to digital2) and ground pin to the Arduino.
At the moment the Arduino is powered via the usb connector.

however if i tested the simple code for simulating the DS1990A - the Arduino (simulated DS1990A) is not listed in the bus list. =(
somehow i have no idea what i can do to get this setup work - but i know that it must work.
Markus got this running on an Arduino nano if i am not wrong...  :smiley-roll:

Looks like I have some work to do!
Title: Re: 1-Wire Slave
Post by: Markus_L811 on Jun 11, 2014, 02:56 pm

soo...update:

i wired my nano like Markus as shown in Post #36 (http://forum.arduino.cc/index.php?topic=65706.msg1279103#msg1279103).
But my nano istn listet on my 1wire-Bus.

I set Pin2 as dsslavepin - but it seems that this doesnt work.

Markus: you got your Nano running as 1wire slave - what can i do to get mine working?  :smiley-red:
Can you give me e litte hint?


Damn it really don't work on the Arduino Nano...

ATM. I will give the external ceramic resonator from the Nano the guiltiness, the ceramic resonator isn't as accurate as the crystal resonator who is used on the Leonardo or Uno. Following this
http://jorisvr.nl/arduino_frequency.html (http://jorisvr.nl/arduino_frequency.html)

But this means the ATtiny85 with the internal RC would be more accurate than the ceramic resonator

So far so good, my Trinket response as 1-wire device with some drops on the line but works. For the next step an self calibration for the Nano and Trinket would be nice to solve the timing problems. I will try to include overdrive support

Did someone run 2 Nano's against another?
Title: Re: 1-Wire Slave
Post by: Adam84 on Jul 02, 2014, 09:06 pm
Hi guys,
Can anyone give any guidance on using this library to make an Uno a 1-wire slave. I can get the "DS18B20_Slave_Interrupt_universal_analogread_fulllib.ino" example sketch to compile and upload fine by changing the  dsslavepin (does this number refer to the actual pin or the interrupt no.?) I have another arduino with another DS18B20 and using the wire library example to get the addresses of the devices on the bus i only find the actual DS18B20. Has anyone had it working on an Uno and knows where i'm going wrong?   
Title: Re: 1-Wire Slave
Post by: wongsm7 on Jul 02, 2015, 11:50 am
Hi Markus,

Does your library work with Arduino Uno?
Title: Re: 1-Wire Slave
Post by: Youen on Aug 09, 2015, 10:44 am
I just released my library to make an Arduino board act as a 1-wire slave. You can download it here: https://github.com/neuoy/OneWireArduinoSlave (https://github.com/neuoy/OneWireArduinoSlave)

It's implemented using interrupts (everything is asynchronous, user code is notified by callbacks when bytes are received, etc.)

I've only tested it with an Arduino Uno and a DS9490R master (connected by USB to a laptop that acts as my home automation server). Works flawlessly so far in this setup, but let me know if you find bugs or can test it with other hardware setups (wether it works or not, I'm interested to know in both cases).

I was surprised how developing this kind of library is tricky, timings are sometimes as short as 3 microseconds or the master can miss bits, so debugging through Serial is not really an option, I acquired an USB oscilloscope for the occasion (very interesting project though).
Title: Re: 1-Wire Slave
Post by: -dev on Aug 09, 2015, 09:17 pm
Very nice!  It's great to see a real C++ design and clean implementation that's easy-to-read.  I've been helping someone over here (http://forum.arduino.cc/index.php?topic=333017.0), and had recently come to the conclusion that interrupts will have to be used for the exact reasons you state: 3us events.

As you said, this is definitely something that requires a 'scope or Logic Analyzer.  The nice thing about the 'scope is that you can distinguish between active highs, input mode and multiple devices driving low.  The user I am trying to help doesn't have either, and isn't very advanced in Arduino nor embedded techniques.  It has been slow going.

While I've been reluctant to dive in and implement this, I have started on something.  After looking at the timings and existing implementations, I was just starting to look at External Interrupts, Pin Change Interrupts and even the Input Capture.  So thanks a million for this very "timely" post.  ;)

Were you thinking about extending this to other types/numbers of 1-wire devices, or are you at the "good enough for me" stage?

BTW, have you seen Cosa (https://github.com/mikaelpatel/Cosa)?  There are a few stylistic similarities, and I mean that as a compliment.

Cheers,
/dev
Title: Re: 1-Wire Slave
Post by: Youen on Aug 09, 2015, 10:23 pm
Nice to see it can be useful to others :-)

Right now, it is indeed in a "good enough for me" stage. The goal was to provide a low level implementation only, because high level considerations (emulating specific devices such as temperature sensors or whatever) have a much larger scope, beyond what I can provide and support as a hobby, and also these are (somewhat) less difficult problems to solve. But it's open source, so anyone can expand on it. Also, that doesn't mean I won't try to fix the bugs that are reported, if any :-)

I didn't heard of Cosa, but it seems interesting, I'll take a look, thanks.

About timing issues, I also tried with an active wait, and it was just a little bit slower, but I think it can work too. However, you really have to use 100% of the CPU to do just that, poll the pin state in a loop, and pull low as soon as you detect the edge (so you need to know if you're going to pull low before starting the loop, to avoid too many instructions in between). So in my experience, interrupts are indeed more adequate to the task (a bit faster, and also less risk to miss an edge since the edge detection is hardware). Not sure how all these things will work (or not) on other boards though.
Title: Re: 1-Wire Slave
Post by: milimilo on Aug 28, 2015, 05:01 pm
Hello Youen

Thank you very much for your lib.

My project is this one, and of course doesn't work:
I have an home automation zwave device that can read DS18B20 1Wire sensors. I would like to use my Arduino UNO to send some value through this zwave module.

May you give me a simple example of code that sends a value when pressing a simple button?

I'm blocked trying to give your library a value to send (using your demo .ino ...).

Sorry for my completely noob question (i am really new to Arduino and totally off the computing universe) and thank you very much for your help!
Title: Re: 1-Wire Slave
Post by: ColinR on Aug 30, 2015, 04:32 am
The example does not seem to compile for ATTiny85:

In file included from ATTiny1WireSlave.ino:2:0:
E:\Docs\code\avr\arduino projects\libraries\OneWireArduinoSlave/LowLevel.h: In member function 'void Pin::attachInterrupt(void (*)(), int)':
E:\Docs\code\avr\arduino projects\libraries\OneWireArduinoSlave/LowLevel.h:113:3: error: 'EIFR' was not declared in this scope
   EIFR |= (1 << INTF0); // clear any pending interrupt (we want to call the handler only for interrupts happending after it is attached)
   ^
Title: Re: 1-Wire Slave
Post by: ColinR on Aug 30, 2015, 06:01 am
I've gone through and replaced the offending items using the ATTiny85 and ATMega328 datasheets, namely:

EIFR --> GIFR
TCCR1B --> TCCR0B
WGM12 --> WGM02
TIMSK1 --> TIMSK

There may have been one more.

I don't know enough about the register functions to know where I have not gotten this right, but I definitely do not have a functioning example at the moment. The Tiny doesn't take down the bus, and have another device on there for a sanity check, so the bus and adapter are up. Just no ATTiny slave.

Colin
Title: Re: 1-Wire Slave
Post by: ColinR on Aug 30, 2015, 07:53 pm
I have finally got ATTiny85's working as 1-wire slaves but not using Markus' library, I used a modified version of the one wire library from Alexander Gordeev  (http://robocraft.ru/blog/arduino/302.html). I finally succeeded once I discovered I could run the ATTiny85 at 16Mhz, that was the big breakthrough. 

I now have ATTiny85s as slaves for a rain gauge and another for a humidity sensor. I am using the  PinChange Interrupt Library (https://code.google.com/p/arduino-tiny/downloads/detail?name=PinChangeInterrupt-0001.zip) so that the slaves only process one-wire commands once a One Wire Reset is detected. An LED flashes to provide visual feedback when the slave sends sensor data. Like the DS18B20 I use 0x44 as a request to calculate the sensor data and 0xBE to return the results.

<<snip>>

I could not get this to work. I had to all sorts of library moving, and eventually a type definition conflict with 'boolean'. I renamed all instances in the libraries to 'myboolean' and resolved the conflict, but still no device on the bus.

You did not mention how you set the clock to internal 16MHz. The typical ATTiny board profiles for the Arduino IDE do not have a 16MHz internal option. Instead, I set up the Adafruit Trinket 16MHz definition and enabled as described here: https://learn.adafruit.com/introducing-trinket/16mhz-vs-8mhz-clock

Still, no love.

Colin
Title: Re: 1-Wire Slave
Post by: milimilo on Sep 01, 2015, 11:02 am
Would this project be possible? :

- a keypad identifies a user with a code
- the accepted user code is send through 1Wire (as a DS18B20) to a 1Wire receiver that can only read a DS18B20

All of this on an Arduino UNO.

Thank you for your help
Title: Re: 1-Wire Slave
Post by: Youen on Sep 01, 2015, 09:19 pm
Hello Youen

Thank you very much for your lib.

My project is this one, and of course doesn't work:
I have an home automation zwave device that can read DS18B20 1Wire sensors. I would like to use my Arduino UNO to send some value through this zwave module.

May you give me a simple example of code that sends a value when pressing a simple button?

I'm blocked trying to give your library a value to send (using your demo .ino ...).

Sorry for my completely noob question (i am really new to Arduino and totally off the computing universe) and thank you very much for your help!
If I understand correctly, the zwave thing does not matter here, things would be exactly the same if you wanted to talk to a classical 1-wire master?

So what you want to do is emulate a DS18B20 sensor. For that, you need to understand the specific protocol of this device, you can look at this document for example : http://www.adafruit.com/datasheets/DS18B20.pdf, check the section "DS18B20 FUNCTION COMMANDS"

For a very basic operation, you'll need to understand the temperature conversion command, and how to send the response (which happens after the "read scratchpad" command, two bytes of the scratchpad are used to transmit the temperature). However, if your zwave device, which acts as a master, always sends configuration, or performs other operations, you might need to implement that part of the protocol as well.

Once you understand the protocol, implementing it with my library should be straightforward : as in the sample, you initialize the library with the device ROM (which may or may not be an official ROM number, but must have the correct family code), and register the event callback. This callback is a function that you write yourself, and will be called each time something happens (a byte is received, an error occurs, etc.). Then you'll need to react to the various commands that can be sent to a DS18B20 ("begin temperature conversion" and "read scratchpad" being the most important).

Communicating with your development PC using the serial port of the Arduino should help you in the process of understanding what happens in your program (so that you can see what command you have received, etc.)
Title: Re: 1-Wire Slave
Post by: aivs on Oct 17, 2015, 02:00 pm
Hi, if you show how to emulate the DS18B20, it will be great!
Title: Re: 1-Wire Slave
Post by: aivs on Oct 18, 2015, 10:23 pm
I'm trying to implement DS18B20 with OneWireArduinoSlave library.
First problem - I need to respond to the master reset. How to do it?
From documentation:
"When the DS18B20 detects
this rising edge, it waits 15µs to 60µs and then transmits a presence pulse by pulling the 1-Wire bus low
for 60µs to 240µs."

I do so, but it not works:
Code: [Select]

void owReceive(OneWireSlave::ReceiveEvent evt, byte data) {
switch (evt) {
   // Detect Reset on bus
   case OneWireSlave::RE_Reset:
       Serial.println("Reset");
       _delay_us(60);
       pinMode(2, OUTPUT);
       digitalWrite(2, HIGH);
       _delay_us(200);
       digitalWrite(2, LOW);
   case OneWireSlave::RE_Byte:
     // Read Scratchpad [BEh] command
     if (data == 0xBE) {
      Serial.println("Scratchpad command");
     }
OneWire.write(&acknowledge, 1, NULL);

break;

default:
}


Arduino slave receives Reset, so in console I see "Reset".
Title: Re: 1-Wire Slave
Post by: Youen on Oct 21, 2015, 08:54 pm
I've seen your message on github, and I think you've already solved this particular issue, but just in case I'll answer the question anyway: the library handles the reset procedure, so you don't have to implement that part of the DS18B20 protocol.

The library listens for the reset signal, then sends the presence, and responds to the search ROM procedure as well. This is entirely automatic, and performed as a background task. In fact, you can completely ignore the RE_Reset event, you probably don't need it in your case.

It will then receive bytes (automatic as well), and call owReceive for each byte received. Also, you don't need to read or set the pin mode directly, and that would probably interfere with what the library is doing.

Finally, as I said on github but it might be usefull for other readers here as well, you should avoid any long operation in owReceive, such as waiting, performing serial communication, etc. The default serial speed is 9600bps, which means to send "Reset" it will take 4167 micro seconds. At this point, you've probably already missed everything you hoped to receive.

What you can do, however, is store what you receive in a global variable, and when you detect that variable has changed in your main loop, write to the serial port from the main loop. This way, you don't block other background tasks. Don't forget to mark the variable as volatile, since it's going to be modified from an interrupt handler (owReceive is always called from an interrupt handler).
Title: Re: 1-Wire Slave
Post by: aivs on Oct 25, 2015, 12:06 pm
@Youen Big thanks for the library!
I created a DS18B20 Emulator based on OneWireArduinoSlave (https://github.com/neuoy/OneWireArduinoSlave) library, it's really very easy!



Code: [Select]

#include "Arduino.h"
#include "LowLevel.h"
#include "OneWireSlave.h"

// Defines to access to Low and High bytes
#define Lo(x)   ((x) & 0xFF)
#define Hi(x)   (((x)>>8) & 0xFF)

// This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support)
// On Arduino Uno, you can use pin 2 or pin 3
Pin oneWireData(2);

// This is the ROM the arduino will respond to, make sure it doesn't conflict with another device, 0x28 - DS18B20 identificator
const byte owROM[] = {0x28, 0xF2, 0x27, 0xD6, 0x04, 0x00, 0x00, 0x3D};

// 0 - Low Byte Temperature
// 1 - High Byte Temperature
// 2-7 - reserved
// 8 - CRC8
byte SCRATCHPAD[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x00};

// This function will be called each time the OneWire library has an event to notify (reset, error, byte received)
void owReceive(OneWireSlave::ReceiveEvent evt, byte data);

void setup() {
// Setup the OneWire library
OneWire.setReceiveCallback(&owReceive);
OneWire.begin(owROM, oneWireData.getPinNumber());
}

void loop() {
delay(100); 
  int temperature = 25;
 
  // Add temperature to the SCRATCHPAD
  if (temperature > 99)  temperature = 99;
  if (temperature < -55) temperature = -55;
  if (temperature >= 0) {
    SCRATCHPAD[0] = Lo(temperature*16);
    SCRATCHPAD[1] = Hi(temperature*16);
  }
  else {
    SCRATCHPAD[0] = Lo(temperature*16);
    SCRATCHPAD[1] = Hi(temperature*16) | 0xF8;
  }
  // Add CRC8 to the SCRATCHPAD
  SCRATCHPAD[8] = OneWire.crc8(SCRATCHPAD,8);
 
cli();//disable interrupts

sei();//enable interrupts
}

void owReceive(OneWireSlave::ReceiveEvent evt, byte data) {
switch (evt) {
    case OneWireSlave::RE_Reset:
      break;
    case OneWireSlave::RE_Byte:
      // Read Scratchpad [BEh] command
      if (data == 0xBE) {
        // Send SCRATCHPAD 9 byte with temperature and CRC
        for (byte i = 8, j = 1; j<=9; i--, j++) {
          OneWire.write(&SCRATCHPAD[i], j, NULL);
          //Serial.print(5);
        }
      }
      break;
    case OneWireSlave::RE_Error:
  break;
  default:
;
}
}
Title: Re: 1-Wire Slave
Post by: aivs on Nov 06, 2015, 09:40 pm
I don't know why, but with some devices previous code didn't work. But with ROM from real DS18B20 all works fine, so in this code I use ROM from real device and send brightness at request.

Code: [Select]
#include "Arduino.h"
#include "LowLevel.h"
#include "OneWireSlave.h"

// Defines to access to Low and High bytes
#define Lo(x)   ((x) & 0xFF)
#define Hi(x)   (((x)>>8) & 0xFF)

// This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support)
// On Arduino Uno, you can use pin 2 or pin 3
Pin oneWireData(2);
#define brightnessPin 0

// This is the ROM the arduino will respond to, make sure it doesn't conflict with another device, 0x28 - DS18B20 identificator
const byte owROM[] = {0x28, 0xF2, 0x27, 0xD6, 0x05, 0x00, 0x00, 0x96};


// 0 - Low Byte Temperature
// 1 - High Byte Temperature
// 2-7 - reserved
// 8 - CRC8
byte SCRATCHPAD[] = {0x00, 0x00, 0x4B, 0x46, 0x7F, 0xFF, 0x05, 0x10, 0x00};

int brightness = 0;

// This function will be called each time the OneWire library has an event to notify (reset, error, byte received)
void owReceive(OneWireSlave::ReceiveEvent evt, byte data);

void setup() {
// Setup the OneWire library
OneWire.setReceiveCallback(&owReceive);
OneWire.begin(owROM, oneWireData.getPinNumber());
  Serial.begin(9600);
}

void loop() {
  Serial.print("brightness=");
  Serial.println(brightness);
  delay(5000);
 
cli();//disable interrupts

sei();//enable interrupts
}

void owReceive(OneWireSlave::ReceiveEvent evt, byte data) {
switch (evt) {
    case OneWireSlave::RE_Reset:
      break;
    case OneWireSlave::RE_Byte:
      // Start measuring brightness
      if (data == 0x44) {
        brightness = analogRead(brightnessPin);     
        // Add brightness to the SCRATCHPAD
        SCRATCHPAD[0] = Lo(brightness*16);
        SCRATCHPAD[1] = Hi(brightness*16);
        // Add CRC8 to the SCRATCHPAD
        SCRATCHPAD[8] = OneWire.crc8(SCRATCHPAD,8); 
      }
   
      // Read Scratchpad [BEh] command
      if (data == 0xBE) {
        // Send SCRATCHPAD 9 byte with brightness and CRC
        for (byte i = 8, j = 1; j<=9; i--, j++) {
          OneWire.write(&SCRATCHPAD[i], j, NULL);
        }
      }       
      break;
    case OneWireSlave::RE_Error:
  break;
  default:
;
}
}
Title: Re: 1-Wire Slave
Post by: milimilo on Nov 19, 2015, 05:29 pm
@Youen
Thank you for your answer.
Title: Re: 1-Wire Slave
Post by: Blocktalkers on Nov 20, 2015, 05:44 am
Hi, I am trying to port the one wire libraries from Arduino to ATTiny85. My sketch, which just returns addresses of all slaves on the line, works on Arduino Uno Master - Uno Slave combination. But when I program the same sketch with .cpp and .h files into the ATtiny85 slave at 8MHz internal clock or 1MHz internal clock, I don't get the addresses as intended on my serial monitor. What might be the problem? I am using only ds.init(rom) and ds.waitForRequest(false) functions in my sketch.
Title: Re: 1-Wire Slave
Post by: abc2006 on Nov 24, 2015, 12:05 pm
Hi,
i read this thread highly interested, because i want to make my Water-Counter one-Wire-accessable with an Arduino Nano and the DS9490R. I tried both Sources, from Post #102 and #105, but the device does not appear in the List of my OW-Server (Linux Ubuntu).

Then i put a Serial.println("RESET"); in the RESET-Part of the

> case OneWireSlave::RE_Reset:

This produces 8 RESET-Entries in my Serial Console (one for every native DS18B20 that i'm using on my BUS).

So the Uno recognizes the Signal from the Controller.
I also put another Serial.print in the RE_Byte-Part, but after Reading Post #103, i wondered if this could be my Problem.

But the original Program without any changes also does not work.

I could remove my Arduino Uno out of my Productive environment for testing, but i don't really belive it would solve my problem.

Can you help? Any suggestions?
Thanks

Stephan
Title: Re: 1-Wire Slave
Post by: Blocktalkers on Nov 30, 2015, 08:19 pm
There have been a few brief discussions of a 1-Wire slave library.  I'd like to revisit the idea.

3. Is it possible for an AVR processor to run from "parasitic power"?

Hi, has anybody found a way to parasitically power the ATtiny85 slaves? I got it working for 1-Wire using Markus' library, but parasitic power requires the use of two pins - Tx and Rx.

Any suggestions would be very helpful.

Thanks
Title: Re: 1-Wire Slave
Post by: palsbo on Feb 06, 2016, 03:33 pm
Hi

I have not been succesful in getting this (the code included in the post - #58) to work.
I am using Arduino IDE 1.6.7 and programming the ATtiny85 (8Mhz) with Arduino Nano.

The code compile but no response from the 1-wire. Code in later in this topic will not compile.

Any suggestions are appreciated.
Erik
Title: Re: 1-Wire Slave
Post by: palsbo on Feb 28, 2016, 04:03 pm
I am trying to get the source in post #59 to work on an ATtiny85, running 8Mhz.
It compiles and upload (using Arduino 1.6.7), but I cannot  see the device (on OWFS).
ATtiny lib is version 1.0.1 by David A Melis (http://highlowtech.org/?p=1695);

What am I doing wrong?
Title: Re: 1-Wire Slave
Post by: Coolbert on Mar 11, 2016, 09:03 pm
Hello, I implemented the code posted in #104 and  #105 on two arduino nano, one master and second one slave. The command sent by master (i.e. 0xBE, 0x44) is correctly received by slave. But the communication in the other direction fails, the data received by master do no comply with those sent by the slave.

Another problem occures during device search. The arduino slave can't be found if alone on the bus. But with an original DS18B20 on the bus, all devices were recognized (incl. arduino slave).

I replaced the Nano slave by a mega 2560 without any improvement.


Any idea what's going wrong?

regards,
CB

Title: Re: 1-Wire Slave
Post by: hjfabius on Mar 20, 2016, 12:12 am
Hi,
    I'm trying using the 1-Wire Slave Library and I'm really far to make it working.

I've a master that it's able to read a DS18B20 without any problem.
When I replace it with the Arduino Slave, it does not work (Reset signal is recognized but master does not receive the address).

I replaced the library with this one (https://github.com/Shagrat2/OneWireHub) and it works like a charm, so the wiring is ok.

I suspect the reason why the 1-Wire Slave Library does not work is related timing.
In the implementation i noted:

Code: [Select]

const unsigned long ResetMinDuration = 480;
const unsigned long ResetMaxDuration = 900;
const unsigned long PresenceWaitDuration = 30;
const unsigned long PresenceDuration = 300;
const unsigned long ReadBitSamplingTime = 25;
const unsigned long SendBitDuration = 35;

that are used by
Code: [Select]

void OneWireSlave::setTimerEvent_(short delayMicroSeconds, void(*handler)())



In my case, I'm using and Arduino Pro Mini 3.3V that is running 8MHz.  I suspect that the above settings are related to 16MHz arduino.


Could you confirm that the implementation is frequency dependent?
If it's the case does anyone have the setting for 8MHz?

Thanks
hjfabius
Title: Re: 1-Wire Slave
Post by: Youen on Mar 20, 2016, 09:29 am
There is indeed a risk that any change on the arduino hardware results in timing issues. Most of the code should be independent of the microcontroller frequency (it counts microseconds, not ticks), but even then, if instructions are executed slower maybe you'll need to adjust by waiting a little less here and there, if at all possible.

There is also a part that is clearly dependent on frequency: the timer configuration. It is currently configured for 16MHz, and halving that frequency will double all timer durations. The timer is used when an event must happen after a predetermined time, rather than on an input pin state change (i.e. reset detection and bit reading).

The relevant line is probably this one:
tccr1bEnable_ = (1 << WGM12) | (1 << CS11) | (1 << CS10); // turn on CTC mode with 64 prescaler
which is used to configure the timer in function setTimerEvent_

You'll need to check the documentation of your microcontroller to find how to set the prescaler to 32 instead of 64. I should probably replace this code by a portable timer library if I find one...

To debug this kind of "fast" communications (with timings of a few microseconds), you might need a digital oscilloscope (I would probably not have managed to get it to work on my Uno without one), since you can't debug by logging to the serial port (too slow). I've bought mine for about $50 (second hand), it connects to the computer through USB to visualize data.
Title: Re: 1-Wire Slave
Post by: Youen on Mar 25, 2016, 09:48 am
For those interested with using my library with an ATTiny, you might find what you want in ntruchsess fork (https://github.com/ntruchsess/OneWireArduinoSlave/tree/DS2890_attiny). Don't know the status (probably work in progress), but apparently he is working on it.