A project I’ve been hacking on for a while is a self-contained 1-wire to IPv6 bridge based on an Atmel AVR ATmega644 and the ENC28J60 Ethernet controller from Microchip.

1-wire: is a serial bus from Dallas Semiconductor/Maxim that only requires 1 data line, there are a number of cheap sensors and other devices for this bus. The strength of this bus is not its speed but that it supports large ranges (up to 300 meters).
Also, each 1-wire device has a permanent unique 64-bit serial number.

IPv6: Insanely large address space. It’s common to use a 64-bit netmask for site networks so that EUI-64 based addresses can be used for auto configuration. This leaves 64-bit for the node address – do you see where this is going now… :)

Yes..I’ve built a device that assigned each 1-wire device it’s connected to its own IPv6 address. Why? you ask, mostly because I can.

Hardware

As mentioned above, the device is based on an AVR ATmega644. It has 64KB of flash memory for program code and 4KB of RAM. It’s running on its built-in oscillator at 8MHz. The ENC28J60 Ethernet chip is connected to the AVR using SPI. The rest of the hardware is mostly for power distribution and management.

The PCB was manufactured by BatchPCB, cheap service but a bit slow turn-around time.

Populated PCB

Unfortunately I screwed up the SPI connection but I managed to fix that with some green wires (or black wires in this case). You’ll note them in the picture above.
I also intended to run the AVR at 5V and the ethernet chip at 3.3V. This is what the quad AND-gate in the upper right
corner was for, but since I screwed up the SPI routing it’s disconnected and the whole circuit is running at 3.3V.
The ENC28J60 can only run at 3.3V, the AVR has a range from 2.8-5V and 1-wire should be ran at 5V but works at 3.3V. Hence the need for TTL voltage translation.

As for the 1-wire devices I had implemented a bus master in software that generated the require waveforms. It worked great up to about 10-15 meters. Any cable length greater than that refused to work.
This was a bit unexpected and without an oscilloscope it was more or less impossible to figure out where and how the signals got mangled. So I simply got a DS2480 1-wire line driver that generates the required signals in hardware with more precise timing.

Add-on board with a 1-wire master

Add-on board with a 1-wire master

This required an add-on board and because I didn’t want to wait for a new PCB I used a 2.54mm prototype board. With the DS2480 only available in SOIC8 packages it required some “creative” soldering :).
The DS2480 required 5V, thus It had to get its own power supply and also required level translation on the UART line between this device and the AVR. I choose an approach using MOSFETs and a few resistors for this (the TO92 packages in the picture above). This turned out to work really good and I think I’m going to use this for the SPI level translation in the next revision of the board.
The wire leaving the board on the left side leads to the 1-wire sensor devices.

The add-on board is extremely ugly. But hey, it works.

Future improvements for the next revision

  • Use of external crystal at 16MHz instead of internal 8MHz clock.
  • Use MOSFETs for 3.3-5 V translation. Need to test it at 16MHz before manufacturing a PCB though.
  • Obviously fix all PCB errors :)
  • All SMD parts (resistors and voltage regulators) to shrink PCB size even more.
  • Better power distribution. I was a bit too conservative with the decoupling capacitors resulting in some weird power problems (fixable with some caps)
  • Create a real add-on board

I’ll publish the PCB CAD files when the next revision is complete.

Software

The only small IPv6 stack I know of is the uIPv6 stack in the Contiki operating system created by Adam Dunkel et al. This is unfortunately only available together with Contiki and not as a stand alone package as the originally uIP (IPv4) stack.

Contiki is a great operating system, but when you only have 4KB of RAM it becomes a bit heavy weight. So I broke out the uIPv6 stack from Contiki and made it run stand alone and ported in to AVR. I also ported the web server application from Contiki and made it run on AVR. As I wanted to use multiple IPv6 addresses I also had to add support for IP aliases to the uIPv6 stack.

Since the uIPv6 was integrated with Contiki it used the Contiki process model which it self is based on “proto-threads” (another thing invented by Adam Dunkel). I felt that this didn’t fit so I turned all processes into a polling mode instead. So one has to call a set of polling functions from the main application loop or from timers.

The other major parts of the code are drivers for ENC28J60, DS2480 and DS1820.

Software
1-wire devices
30 second polling interval with auto-discovery of new devices.
Each device is assigned its own IPv6 address, requires a /64 network to be available.
Webserver
Integrated web server makes it possible to visit each address. An XML file with the latest sensor reading is returned. An “age timestamp” is also provided which makes it possible to determine how old the reading is.

Currently, with 5 1-wire devices connected it uses about 3KB of RAM.

In-action

I only have temperature sensors connected at the moment. If you happen to have an IPv6 capable connection you can access the sensors through a web browser.

2001:16d8:ffe5:002:2894:eaf6:100:0c7
2001:16d8:ffe5:002:28c1:b4f6:100:035
2001:16d8:ffe5:002:2809:aef6:100:0ca
2001:16d8:ffe5:002:28c5:a5f6:100:058
2001:16d8:ffe5:002:2813:caf6:100:050

(If you don’t have IPv6 you should get it, or you can view graphs based on the sensor values at lindberg.tl instead).

DSC00664 DSC00661
21 Responses to “1-wire meets IPv6”
  1. KiLaHuRtZ says:

    I am very interested in building a few of these. I see in your last comment you were in the process of re-designing the circuit to be more effecient. I was woncering if you had a schematic and/or a bill of materials you could post. Also, I was looking to connect up to 16 DS18S20’s to a single unit. Seeing 5 sensors plus the base system use 3 out of 4KB of RAM, would an ATmega1284P be a suitable upgrade?

  2. CuriousCat says:

    Interesting! Does it mean that all the ethernet’s TX- TX+ RX- RX+ are multiplexed into one wire somehow? If we had a pair of this device with an infrared circuit, can two PCs working like peer-to-peer wirelessly?

  3. anonymous says:

    teh sensors are offfliiiiiiiineeeee

  4. Ken Flack says:

    Doyou know of any ‘low Cost” design for a IP V4 Standard Etherenet (One Ethernet address) to one wire interface controller.

    Should have a web server/data logger for sensor data… incl..

    Thanks

    Ken

    P.S. I absolutely love your design….

  5. frederic says:

    Hi Frederik,

    I’ve just taken a look at your code and can see that you have disabled IRQ mode.

    I suppose, like me, you had problems in this mode. Are you able to use this mode now ?
    If yes, I should be happy to know your trick :)

    Frederic

    PS : Nice project. I do similar things at owbox.com, especialy internet of things

  6. fli says:

    @Quirinius

    I’m not sure about the RAM in the tuxgraphics hardware.
    The stack it self should run with 2K RAM, but for any (half) serious application you
    probably want 4K.

  7. Quirinius says:

    Wow, that’s cool!

    And BTW: your temperatures are also very low. ;-)

    Can the uIPv6 run on the tuxgraphics hardware?

  8. Nuno Gonçalves says:

    James:

    You could use a laser(or anything else). But 1-wire bus have 2 advantages:
    -very low cost(for bus wire and devices).
    -parasite power. You can hang thermometers(ex) on the 1-wire bus and they can “steal” power from the bus.

    For a wireless approach maybe you should look for ZigBee.

  9. Nuno Gonçalves says:

    Great! Great! Great!

    About your problems with 1-wire bus lengths over 15m, did you account for the bus capacitance? Were you using a simple open-drain uC output with a pull-up resistor?
    For such long buses you will need higher currents to pull the bus up! There are several Dallas semiconductors AN covering that.

    You can decrease the pull-up resistor value(up to half the current drain capability of the uC when in drain mode, otherwise you will be getting problems for push-down phase).
    You can switch to a push-pull output.
    You can add an active driver with a BJT/FET.

    Last option can achieve very long distances.

  10. James says:

    Instead of the single wire could you transmit via a modulated laser beam?

  11. Daniel Klein says:

    This is very cool! Could you look at my website (and specifically http://www.klein.com/thermd/ and http://www.klein.com/thermd/thermd.cgi) and let me know if you think we could work together? I’d be very interested in getting a copy of your system and seeing how easily it could be expanded to read other DalSemi sensors. What would you say the cost of a unit would be (ignoring your development costs – what could I buy a “kit” for?

  12. fli says:

    @nave.notnilc:

    Probably too much to justify what it’s doing. It was mostly just for fun and sort of a proof-of-concept project.

  13. Erik Johansson says:

    someguy at hackaday said ethersex has implmented OpenVPN as well as ipv6.

  14. nave.notnilc says:

    What would you say the net cost was for this project?

  15. Brad says:

    You win the internets. I’m looking at hooking an AVR up to the network for SNTP requests, and I’ve got an allergy to IPv4-only systems. w00t.

  16. fli says:

    I’ve never used Teredo tunneling.

    If you can reach http://ipv6.google.com then you should be able to reach the sensors too.

  17. jimy says:

    From ipv4 lan with Teredo Tunneling I will see the sensors ?

  18. fli says:

    @jimy

    No they are working fine. Verified ping6 from a remote looking glass site, 0% packet loss.

    But you don’t seem to be IPv6 enabled, your comment was posted from an IPv4 address but this site is IPv6 capable. If you were IPv6 capable your post should have originated from an IPv6 address.

  19. jimy says:

    Hi,

    Is there know issue with temperature sensors because I can not see the link from Opera browser?

    Thank you in advance.

  20. dan says:

    Cool! You make a great work man.

    I am started with IPV6 today so please help me.

    1)Please let me know if you have a small test project to test ping for example. Also can you send me your full project IPv6+ENC28J60 Web server ?

    I work with Keil compiler and have now issues with some missing files so I want your full project no only SVN code. Also please include in your SVN code main() function file.

    2)Can I test ipv6 in any network or should I have a Ipv6 server/IPv6 gateway?

    3) If I can ping6 ipv6.google.com so I can ping a ipv6 device?

    4) Can I test only PC and ipv6 device with a cross cable ?

    Thanks.

  21. John Mann says:

    This is really cool! I really want to collect temperature / rainfall / water tank stats using IPv6.
    [ I'm the IPv6 evangelist at work. ]

    I was hoping to use real Contiki + uIPv6.
    Did you ever compile Contiki + uIPv6 + your ENC28J60 code?
    How big was it?

    AVR Ravens looked good, but they need a PC for 6lowpan wireless wired IPv6 gateway.

    I was hoping to build something using Arduino-like hardware and ENC28J60 daughter board.
    http://moderndevice.com/index.shtml or http://www.seeedstudio.com/depot/seeeduino-v328-fully-assembled-p-439.html
    http://www.futurlec.com.au/Mini_Ethernet.jsp

    Or port IPv6 bits back to ATmega328 + ENC28J60 Web server
    http://www.tuxgraphics.org/electronics/200905/embedded-tcp-ip-stack.shtml
    http://www.tuxgraphics.org/electronics/200906/home-climate-control.shtml
    http://shop.tuxgraphics.org/electronic/detail_avrwebserver_smd4.html

    But if you have already done it that’s teriffic. I’m interested in (un-)assembled boards, kits, whatever.

    Moore’s law will make AVRs big enough for IPv6 … unless ARM chips running Linux get cheap enough first!

  22.