Shop OBEX P1 Docs P2 Docs Learn Events
One-wire device control — Parallax Forums

One-wire device control

What code can I use to communicate a Propeller 1 with one-wire devices?

Sincerely,

Discovery

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2022-01-28 00:37

    Attached is the object I use, written by Cam Thompson.

    -Phil

  • RIP Cam. You are missed.

  • I wrote a 1-wire object, too (it uses a Cam's CRC code; the rest is mine). I double-check all is well with a little DS1822 demo program.

  • Thank you.
    I use the one-wire interface on BS2s which is really simple but I need more programming space. I will graduate to the Propeller 1.
    The code looks difficult to use compared to BS2 basic.

    Sincerely,

    Discovery

  • JonnyMacJonnyMac Posts: 8,918
    edited 2022-01-29 00:57

    It's really not. Give yourself a few days to learn Spin, and take things easy. What you'll find is that once you adapt to the new syntax, many things are really easy because the resources of the Propeller are so much greater than on the Stamp. Again, be patient with yourself and take it easy. Anything new is scary and looks difficult -- you'll get past that, and you'll get plenty of assistance in these forums when you need it. If you post a BS2 program, many of us can show you how to port it to the P1.

  • I agree with Jon about the simplicity. As an example, here's my driver for the MAX31820 1-Wire temperature sensor:

    {{
    ─────────────────────────────────────────────────
    File: MAX31820.spin
    Version: 1.0
    Copyright (c) 2018 Bueno Systems, Inc.
    See end of file for terms of use.
    
    Author: Philip C. Pilgrim  
    ─────────────────────────────────────────────────
    
    Call start first to establish pin number. Allow a second or so between calling convert
    and reading the new data.
    
    }}
    
    OBJ
    
      ow    : "OneWire"
    
    PUB start(pin)
    
       ow.start(pin)
    
    PUB convert
    
      ow.reset
      ow.writeByte($cc)
      ow.writeByte($44)
    
    PUB tempF100 : temp
    
      temp := tempC100 * 9 / 5 + 3200 
    
    PUB tempC100 : temp
    
      ow.reset
      ow.writeByte($cc)
      ow.writeByte($be)
      byte[@temp][0] := ow.readByte
      byte[@temp][1] := ow.readbyte
      ~~temp
      temp := temp * 100 / 16
    
    {{
    
    ┌──────────────────────────────────────────────────────────────────────────────────────┐
    │                           TERMS OF USE: MIT License                                  │                                                            
    ├──────────────────────────────────────────────────────────────────────────────────────┤
    │Permission is hereby granted, free of charge, to any person obtaining a copy of this  │
    │software and associated documentation files (the "Software"), to deal in the Software │ 
    │without restriction, including without limitation the rights to use, copy, modify,    │
    │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    │
    │permit persons to whom the Software is furnished to do so, subject to the following   │
    │conditions:                                                                           │                                            │
    │                                                                                      │                                               │
    │The above copyright notice and this permission notice shall be included in all copies │
    │or substantial portions of the Software.                                              │
    │                                                                                      │                                                │
    │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   │
    │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         │
    │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    │
    │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION     │
    │OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE        │
    │SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                │
    └──────────────────────────────────────────────────────────────────────────────────────┘
    }}  
    

    -Phil

  • Maybe you are right!

    Would you suggest a good or excellent tutorial from which I can learn spin?

    Discovery

  • Would you suggest a good or excellent tutorial from which I can learn spin?

    Try this:

    http://people.scs.carleton.ca/~lanthier/teaching/COMP4807/Notes/3 - SpinLanguageAndPropBotProgramming.pdf

    -Phil

  • Okay Phil,
    This looks good. Now I will go to school.

    Discovery

  • Thank you very much. I am overwhelmed.

    Sincerely,

    Discovery

  • That's a really nice resource, Phil! Did you put that together for your students?

    Paul

  • That's a really nice resource, Phil! Did you put that together for your students?

    No, I just found it online.

    -Phil

  • I hope someday soon we can see such a great resource such as this for P2.
    Jim

  • Has anyone used a parasitic-powered EEPROM?

    I want to read and eventually write to a DS24B33 that's embedded in a device.
    The DS24B33 is a newer version of the DS2433, and I am guessing that the DS2431 and DS2432 are similar.

Sign In or Register to comment.