PropBasic and One-wire

Hi Bean,
I am struggling with the load library instructions as they pertain to One-wire Read and Write.

I have serial numbers of the one-wire devices I will use so I don't need code for reading the serial numbers.

Could you supply code for writing PropBasic instructions that set the four digital outputs of the DS2450, read the four analog inputs of the DS2450, and read the temperature of the DS1820?

Sincerely,

Discovery

Comments

  • Does anyone have PropBasic code that will do the job?

    Discovery
  • I use the following BS2 code to read DS18S20 temperature devices. What equivalent PropBasic code is needed to read DS18S20 devices on my Propeller?

    '{$STAMP BS2p}
    'One-Wire serial communications to the DS18S20
    'I/O Definitions
    DQ PIN 0

    'Constants
    RdROM CON $33
    SkipROM CON $CC
    Cvrt Tmp CON $44
    RdSP CON $BE

    'Variables
    romData VAR Byte(8)
    tempIn VAR Word
    sign VAR tempIn.BIT8
    tLo VAR tempIn.LOWBYTE
    tHi VAR tempIn.HIGHBYTE
    tSign VAR Bit
    tempC VAR Word
    tempF VAR Word

    Main:
    DO
    OWOUT DQ, 1, [rdROM]
    OWIN DQ, 2, [STR romData\8]
    GOSUB Get_Temperature
    DEBUG HOME,
    "SD18S20",CR,
    "_________",CR,
    SDEC tempC, " C ",CR,
    SDEC tempF, " F "
    PAUSE 500
    LOOP

    END

    Get_Temperature:
    OWOUT DQ, 1, [SkipROM, CvrtTmp] 'Start conversion
    PAUSE 500
    OWOUT DQ, 1, [SkipROM, RdSP]
    OWIN DQ, 2, [tLo, tHi] 'Read temperature

    tSign = sign 'Save the sign bit
    tempIn = tempIn/2 'Round to whole bit
    IF tSign = 0 THEN NoNeg1
    tempIn = tempIn | $FF00 'Extend sign bits for negs

    NoNeg1:
    tempC = tempIn 'Save Celcius value
    tempIn = tempIn */ $01CC 'Multiply bu 1.8
    IF tSign = 0 THEN NoNeg2 'If negative, extend sign bit
    tempIn = tempIn | $FF00

    NoNeg2:
    tempF = tempIn + 32 'Finish C to F conversion
    RETURN

    Sincerely,

    Discovery


  • Does anyone have working one-wire Propeller Basic code for the DS18S20 temperature sensor and the DS2450 quad digital output / quad analog converter?

    Or, is there anyone with the where-with-all to write the one-wire Propeller Basic code?

    Sincerely,

    Discovery

    PS This is really important!
  • Discovery wrote: »
    Does anyone have working one-wire Propeller Basic code for the DS18S20 temperature sensor and the DS2450 quad digital output / quad analog converter?

    I don't know if there's any existing PropBasic code for that. Have you looked in the Obex for Spin objects that access that hardware? If there are some, then I can see 3 solutions for you:

    (1) Port the Spin code to PropBasic. This will require a bit of work, but would have the big advantage that (if you share the code) other PropBasic users will be able to use the libraries.

    (2) Port your code to Spin. How easy/hard this will be depends on your code, of course, but Spin isn't too hard to learn. The advantage here is that Spin is widely used and supported on the Propeller.

    (3) Port your code to Fastspin/BASIC, and use the Spin objects directly from Basic. Fastspin/BASIC is a bit different in syntax from PropBasic, so this would be work, but if your code isn't too large it might be easier than option (1).

  • tritoniumtritonium Posts: 240
    edited 2019-01-03 - 21:27:59
    Hi

    My PropBasic directory from Bean has a directory called "demos"
    in there is a file DS18B20.pbas

    at the top of this document it says

    ' Reads the temperature from a Dallas DS18B20
    ' Converts it to ascii and sends it to the PC
    ' Connect DS18B20 DQ pin to PIN 1 on the propeller
    ' Don't forget the 4.7K pullup resistor too...
    '
    DEVICE P8X32A, XTAL1, PLL16X
    etc....

    Dave
  • tritonium,

    How do I access your PropBasic directory?

    Discovery
  • PublisonPublison Posts: 10,585
    edited 2019-01-03 - 22:00:29
    This is from Dave from the third post about this topic that was deleted.
    Hi

    lookup this forum post

    http://forums.parallax.com/discussion/118611/download-propbasic-here-00-01-14-last-version-for-bst/p1


    At the bottom of first post there are zip files

    There are four files- the leftmost one is called Demos.zip



    http://forums.parallax.com/discussion/download/71912/Demos.zip

    Dave
    Infernal Machine
  • Hi

    This is from Dave from the third post about this topic that was deleted.


    How did that happen?
    Glad you caught it.

    Dave
  • tritonium wrote: »
    Hi

    This is from Dave from the third post about this topic that was deleted.


    How did that happen?
    Glad you caught it.

    Dave

    A third post was started about the same topic which is against forum rules. It was deleted.
    Infernal Machine
  • Sir or Madam,
    I am aware that you blocked my attempts to reach Bean by invoking the redundancy rule. In the beginning, Bean said that he would help as I learn PropBasic since I wanted to convert my industrial control system from BS2 controllers to Propeller controllers using PropBasic exclusively. The first of two control boards was successfully converted to a Propeller using Bean's help. He supplied the Real-Time clock PropBasic code that ran on a COG but the clock ran too fast. It was the brilliance of ersmith who realized that the WAIT addr instruction could be used to adjust the rate. Smith was absolutely correct and I was able to increase the 80_000_000 value to 80_000_700 and trim the clock to be highly accurate. The combination of Bean and ersmith solved the problem that I had no clue how to solve. I was hoping to contact Bean for help in using the Propeller one-wire commands since my system uses one of two one-wire coax lines to read my system sensors and a second one-wire coax line to control devices in the factory which include motors, heaters, etc. I tried to use the information in the PropBasic one-wire library to read temperature of a single DS18S20 using my Propeller Activity Board but everything I tried produced an error "Insufficient Number of Parameters" but as far as I can tell no additional parameters are needed for the OW-READ instruction. But things get more difficult when I need to communicate with several DS2450 Quad A/D Converter/Quad Digital Output devices that are used extensively in my system. The BS2 code is used for communication with the DS2450s and sends instructions to the chip for configuring the device to be a quad ADC or a quad DO. This code was supplied by a forum member and it works perfectly with the exception that DS2450 can only convert 8 bits and no more. The specification states that 16 bits are possible. I apologize for trying to open another forum discussion with Bean but it appears that Bean is too busy and just maybe he could provide a spark that ersmith or someone else could follow to generate the PropBasic code that I need to make the conversion.

    Discovery
  • PublisonPublison Posts: 10,585
    edited 2019-01-04 - 14:34:57
    Infernal Machine
  • Okay...thank you Publison,

    Tritonium,
    I downloaded the demo code and installed it in my program. It compiled and executed but I have no way of knowing if it reads the DS18S20 since the temperature message is output using SEROUT TX, Baud, Message and I do not have the TX Pin connected to my PC. I don't know how to do that.
    Secondly, my system uses six DS18S20 temperature sensors...how do I individually address each sensor?
    Finally, can the variable "value" be used in an IF statement to determine if the value is between 10 and 30 if in Celsius units?

    Would you have the time to look into devising the PropBasic code for reading and writing data to the DS2450 quad ADC/DO?

    Sincerely,
    Discovery
  • I inserted an IF-ENDIF statement to determine what the value of "value" was as returned by the one-wire program code. The value was between 194 and 205 and changed with finger temperature. The actual room temperature was 70F or 21C. I don't know what number base is returned by the DS18S20.

    Discovery
  • Tritonium,
    The demo program appears to read the DS18S20 as long as I divide the numerical in "value" by 10.
    So a value of 205 is actually reading a temperature of 20.5C and this value changes as I increase or decrease the temperature of the sensor. This is good.

    Discovery

  • Discovery, I can't help but wonder if you ever got around to looking at the 18S20 data sheet.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
  • Yes,
    Way back when I was working with the initial development of the BS2 software shown above. Sending control data to the DS18S20 using the PropBasic commands: OWWRITE, OWREAD, OWRESET, with the additional parameters attached appears to be far simpler than the BS2 commands.

    Now I will configure a DS2450S and attach it to the Propeller One-wire and try to send and receive data from its registers.
    Discovery
Sign In or Register to comment.