Shop OBEX P1 Docs P2 Docs Learn Events
Question about Jm_ds1822_demo — Parallax Forums

Question about Jm_ds1822_demo

lockadoclockadoc Posts: 115
edited 2014-09-03 18:32 in Propeller 1
I am working on a project that needs to display the Temperature of Four DS18B20 chips, I have the method working with one chip. Using JM_Ds1822_demo. I have 4 chips connected to ports 0,1,2,3 and they all work one at a time. Is there a example somewhere that I see how it polls the four different addresses then displats them on the Serial Terminal?
My end goal is to get them to display on something like the _ML_GraphicsDemo.

Thanks for any heads up that you can give me.
Billy S.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-08-31 18:54
    Hey Billy S.

    It would be easier for people to help you if you provide links to the objects in question.

    What does "_ML_GraphicsDemo" look like? How is the data displayed now?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-08-31 21:44
    The easy way would be to use four instances of the object. This will cost you an extra three cogs but otherwise the PASM section of the code would need to be modified to read from multiple sensors.

    I've attached code which "should" read from four sensors. I don't have any DS1822 sensors to test it with.

    This is what the output of my "test" version with dummy data looks like.
    DS1822 Demo
    
    sensor[0] SN: 0000000000000000
    temperature[0] = 10.1000°C
                     50.1800°F
    
    
    sensor[1] SN: 0000000000000000
    temperature[1] = 10.1000°C
                     50.1800°F
    
    
    sensor[2] SN: 0000000000000000
    temperature[2] = 10.1000°C
                     50.1800°F
    
    
    sensor[3] SN: 0000000000000000
    temperature[3] = 10.1000°C
                     50.1800°F
    

    I need to quit procrastinating and get back to my own program.
  • lockadoclockadoc Posts: 115
    edited 2014-09-01 17:54
    Thanks for the input, But when I try to load it I get an error on line 115 of
    EXPECTED ","
    the books I have Don't give me a clue as how to correct it.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-09-01 19:42
    lockadoc wrote: »
    Thanks for the input, But when I try to load it I get an error on line 115 of
    EXPECTED ","
    the books I have Don't give me a clue as how to correct it.

    You're right. I thought for sure I had test compiled it. Sorry about that.

    I added a "sensorIndex" parameter to a lot of the methods, including "readsn".

    Line 115 should be:
          readsn(sensorIndex, serialNumberPtr)            ' read the serial #
    

    The version attached to this post does compile but I'm not sure it really works. The main thing I wanted to show is how to use multiple instances of an object. Instead of the one wire object only being used once, it's now used four times.
    obj
    
      term : "Parallax Serial Terminal"
      ow[SENSORS_IN_USE]   : "jm_1-wire"
    
    
    

    Since "SENSORS_IN_USE" was defined as 4, there are are four instances of the "ow" object. These objects are accessed by using "ow[0]" through "ow[3]".

    Rather than having a number to define the instance you could have different aliases for the object.
    obj
    
      term : "Parallax Serial Terminal"
      ow  : "jm_1-wire"
      oneWire  : "jm_1-wire"
     sensorCom   : "jm_1-wire"
      comWire  : "jm_1-wire"
    
    
    

    IMO, it's easier to use the first technique since the object can be accessed with a variable (for example "sensorIndex").
    ow[sensorIndex].reset
    
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-09-02 12:30
    Keep in mind that 1-Wire is a multi-drop buss; unless there is a compelling reason to have more than one physical connection, then only one instance of the object is required.

    My 1-Wire object handles all the basics. If you download the data sheet for the desired part (hint, hint), you'll see that the transactions are quite easy. What I haven't yet implemented in the Propeller is a 1-Wire search, though I know it's possible because I did it with a BS2p a long time ago. Most applications know the serial numbers of the attached devices. Those can be stored in a DAT table. If you do some kind of read-back of the serial # you can save it to the EEPROM with an I2C object. Using the address of the DAT table in the EEPROM writes will mean simplify the code for subsequent uses.

    To your specific question about multiple sensors on one line -- setup the DAT table to hold four 1W serial numbers:
    dat  { sensor ids }
    
      SN0                   byte    $00, $00, $00, $00, $00, $00, $00, $00
      SN1                   byte    $00, $00, $00, $00, $00, $00, $00, $00
      SN2                   byte    $00, $00, $00, $00, $00, $00, $00, $00
      SN3                   byte    $00, $00, $00, $00, $00, $00, $00, $00
    


    You will have to use the read_sn() method -- with just one sensor connected -- to get the senor #s you're using. You need to do this four times.

    Once you have the serial numbers array populated, use the read_tca(p_sn) method to read the sensors in a simple loop:
    repeat ch from 0 to 3
        rawtemp[ch] := read_tca(@SN0 + (ch << 3))
    
  • lockadoclockadoc Posts: 115
    edited 2014-09-03 18:32
    Duane

    Thanks
    it compiled and seems to get the data.
    Now to take it apart and try to fiquire out how it works so i can expand on it.
    again thanks for the assist.

    Bill S
Sign In or Register to comment.