Author Topic: Anyone Try 1-Wire Emulation Yet?  (Read 11899 times)

Josh47

  • Newbie
  • *
  • Posts: 19
Anyone Try 1-Wire Emulation Yet?
« on: March 24, 2013, 02:36:33 pm »
I have a project I'm thinking about starting with the Digispark, and it would involve some 1-Wire emulation to do it. I know it can probably be done because there is already code out there on the topic for a regular ATTiny45 (https://github.com/smurfix/owslave also http://robocraft.ru/blog/arduino/302.html and http://www.mcselec.com/index.php?option=com_content&task=view&id=256&Itemid=57). The last link emulating the DS2450 is what I'm shooting for in particular as they were so kind as to discontinue the product for so long now and never introduce a reasonable replacement of any kind.


So, since neither of these projects have code that would "just work" with the Digispark, I'm wondering if anyone else has tried it here yet. If not, when I do try it out I'll be sure to post/share the results.


Thanks,
Josh

RussNelson

  • Newbie
  • *
  • Posts: 23
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #1 on: March 30, 2013, 09:46:21 am »
I haven't tried it, but have found the existing code to be fairly robust. Try just compiling it and see what happens!

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #2 on: March 30, 2013, 10:01:34 am »
Unfortunately "life" is in the way of the hobby for a few weeks. I'll post an update when I get a compile done with some of the examples communicating.

kamots

  • Newbie
  • *
  • Posts: 13
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #3 on: April 16, 2013, 06:00:56 pm »
What do you mean by 1-Wire emulation? I have the Digispark talking to 1-Wire devices including a 1-Wire LCD ( see http://theforest.us/lab/ ).

I've been working with 1-Wire devices for years, so let me know how I can help you.

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #4 on: April 16, 2013, 06:19:06 pm »
Emulating here means making it act as if it is a 1-wire slave device, like the one I mentioned in the first post specifically. This can be very useful when you have an existing project and they discontinue the chip you used (my case). So, it would be powered by the 1-wire power line (not parasite) and one pin would be used as the data line (and another as ground of course).

kamots

  • Newbie
  • *
  • Posts: 13
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #5 on: April 16, 2013, 06:56:32 pm »
Ah, got it. That should be easily doable, and it helps if I read this thread more to see there are a few existing projects out there ;)

I've been surprised how much the Attiny can do, though I've already blow out the stack several times expecting just a little too much from it.

Well let me know if you need help!

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #6 on: April 27, 2013, 04:08:42 pm »
Well let me know if you need help!
Well, I may need to take you up on this offer. I have tried every "library" I can find like the ones I linked to in the OP, but none of them are working for me. Each has it's own "example" that I can get to compile and load onto the Digispark, but when I debug what is going on through a serial connection it seems nothing happens. I placed other "real" 1-Wire devices on the line and they are seen fine from my master (a LinkUSB), but it will never find my emulated chip. It is connected correctly, as I do see the line reset commands.


If you would like to help, please reply to this thread and I can share the files and what output I am seeing from my serial debugging. I'm currently working on the Russian language based library as it seems to be the most compact and is already Arduino based whereas the others all required quite a bit of tweaking to where I'm not sure if I could have screwed something up in the process.

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #7 on: April 28, 2013, 12:04:06 pm »
OK, in case anyone wants to help, attached is a version with some serial debug in it. I have my Digispark attached through some pins for serial debugging (0 and 3) and the 1-wire on pin 2. The code compiles and "runs", and when I start the master it clearly knows and starts outputting values on the serial line, it's just it never seems to actually do anything but timeout. I'm thinking this means I missed something obvious, but I have no idea what.


Thanks,
Josh

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #8 on: April 28, 2013, 02:36:20 pm »
Josh
This may sound like a stupid question ...
You do have a 4k7 pullup resistor on the one Wire device line don't you.?

One Wire and I2C are a open collector style (sometime referred to as Tri state). The idea being that they can check when to talk by seeing if the line is high, and then pulling the line down with the data they want to send.

So somewhere on the line you need a pullup resistor to the +5v (in this case) or +3v3 in some other situations.
4k7 is the recommended, but I've seen values from 2k7 to 10k that work.
The preference is to have it at the far end, although I can't actually see what difference it makes.

Mark

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #9 on: April 28, 2013, 02:54:58 pm »
You do have a 4k7 pullup resistor on the one Wire device line don't you.?

A fair question, but the master is the LinkUSB, and it pulls the data line high. It can read other 1-wire slaves on the line without any problems. If I remember the docs correctly, it uses a dynamic pull-up to compensate for line length. I don't have a scope, but the line does go high when attached, so everything seems correct. Also, since there is activity on the line, that also seems correct as the code waits for that line to drop as it should, and does.

Thanks,
Josh

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #10 on: April 28, 2013, 05:40:47 pm »
Okay
I've seen some I2C snooping devices, but nothing for OneWire, so I'm afraid a scope is the best solution.
Perhaps someone with a scope/capture device can duplicate your setup and test it for you.


Good luck, it looks like a good project.

mark

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #11 on: April 29, 2013, 12:33:12 pm »
Well, just a quick update. I'm fairly certain that it is the timings in the code that are wrong, but without a scope this is becoming somewhat futile. If anyone with a scope wants to load up a 1-Wire master on something like a full sized Arduino/etc. and then connect up to the Digispark with the code provided, that would be great. I can't figure out how to get the timings correct currently.


Thanks,
Josh

kamots

  • Newbie
  • *
  • Posts: 13
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #12 on: April 29, 2013, 07:47:07 pm »
I have a scope I can do this with. Send me the code you are trying to test and I'll load it to my Digispark and test. If you want to e-mail it, its kamots at theforest.us

Josh47

  • Newbie
  • *
  • Posts: 19
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #13 on: April 29, 2013, 07:55:03 pm »
I have a scope I can do this with. Send me the code you are trying to test and I'll load it to my Digispark and test.

Awesome! Thank you!

I'm not at my machine right now, but the code is attached in the zip file a few posts back. If you can't get that to download, let me know and I can email it to you tomorrow.

kamots

  • Newbie
  • *
  • Posts: 13
Re: Anyone Try 1-Wire Emulation Yet?
« Reply #14 on: April 29, 2013, 07:58:06 pm »
Got it, I'll give it a try in the next few days, if not tonight :)