+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 18

Thread: Junebug 1-wire DS18S20 test using Swordfish BASIC

  1. #1
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default Junebug 1-wire DS18S20 test using Swordfish BASIC

    Here's the code in Swordfish BASIC, it's basically the example that's found in the help file. I've adapted to work using the Junebugs CON4 connector (designed for 1-wire devices and more)
    After programming you have to disable the programmer and enable the UART tool in the PICkit2 software. DIP switchs 1-3 off and 4,5 on.

    Code:
    // Junebug 1-Wire test (using example found in Swordfish help menu)
    Device = 18F1320
    Clock = 8
    Config OSC = INTIO2, WDT = OFF            // Use the Internal Oscillator
    Include "ow.bas"
    Include "convert.bas"
    Include "usart.bas"
    // on find event handler...
    Event OnFind()
       Dim Index As Byte
       USART.Write("FAMILY $", HexToStr(SearchFamily,2))
       USART.Write(" ($",HexToStr(SearchID(7),2),")")
       USART.Write(" ($")
       For Index = 6 to 0 step -1
         USART.Write(HexToStr(SearchID(Index),2))
       Next
       USART.Write(")",13,10)
    End Event 
    // working variables...
    Dim DeviceCount As Byte   
    // program start...
    osccon = $72
    high(porta.3)       // power DS18S20
    SetBaudrate(br9600)
    SetPin(PORTA.4)
    DeviceCount = Search(owSearchROM, OnFind)
    USART.Write(DecToStr(DeviceCount), " device(s) found", 13, 10)
    end
    
    Hook up a DS18S20 to CON4 (the flat side faces the reset button) and pressing reset displays this in the UART tool.
    FAMILY $10 ($90) ($0008016029C610)
    1 device(s) found
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/


  2. #2
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Here's some pics:
    Junebug 1-wire DS18S20 test using Swordfish BASIC-18b20sm.jpg
    Since I didn't build my Junebug from a kit I didn't have the fancy 3 pin socket for CON4. Instead I cut up an 8-pin machine pin IC socket and soldered 3 pins of it in there. In the end it's the exact same thing, only less finished looking on one end.
    Junebug 1-wire DS18S20 test using Swordfish BASIC-pickit.jpg
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  3. #3
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default

    The "fancy 3 pin socket" is just an inline machine connector cut down. Same as yours

    You can control RA3 depending on VDD, GND, float or even analog VR2 can be switched in.

    I like the rocker switch I'll have to find some.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  4. #4
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    The "fancy 3 pin socket" is just an inline machine connector cut down. Same as yours
    Hahaha! I spent a lot of time digging thru Digikey's site trying to find those. No joy.

    I like the rocker switch I'll have to find some.
    Digikey GH7176-ND
    Last edited by futz; 12th January 2008 at 08:29 PM.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  5. #5
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Ok, I'm trying to read my 18B20 with Gramo's code that I modified a bit for Junebug, and I'm getting nothing happening. Any ideas what I'm doing wrong?
    Code:
    Device = 18F1320
    Clock = 8
    Config OSC = INTIO2, WDT = OFF            // Use the Internal Oscillator
    Include "DS18B20.bas"
    Include "convert.bas"
    Include "usart.bas"
    
    Dim 
       TempA As ShortInt,
       TempB As Word
    
    OSCCON = $72
    High(PORTA.3)       // power DS18S20
    SetBaudrate(br9600)
    SetPin(PORTA.4)
    
    if DS18B20.Find Then
        While true
          Convert
          GetTemp(TempA, TempB)
          USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), " C", 13, 10)
          DelayMS(1000)
        Wend   
    Else
        USART.Write("No device found", 13, 10)
    EndIf
    
    End
    
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  6. #6
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default

    Same here, the DS18B20 must be different enough from the DS18S20. Might be fun just to fix the module and make an 18S20 module. Their GLCD KS0107 module is also disfunctional, doesn't work with my KS0107 or Oshonsofts simulated KS0107. Text modes work but graphics functions don't.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  7. #7
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by blueroomelectronics
    Same here, the DS18B20 must be different enough from the DS18S20. Might be fun just to fix the module and make an 18S20 module.
    The DS18B20 module works fine. I just didn't understand how to use it. David Barker (Swordfish Developer) has posted an article on the Wiki that explains it very nicely.

    Here's working code for Junebug and DS18B20 You will have to modify the sensor address data to suit your own 18B20:
    Code:
    Device = 18F1320
    Clock = 8
    Config OSC = INTIO2, WDT = OFF
    Include "DS18B20.bas"
    include	"convert.bas"
    Include "USART.bas"
    
    const Sensor_A(8) as byte = ($28, $00, $7c, $46, $01, $00, $00, $10)
    
    // display a sensor value...
    sub DisplaySensor(byrefconst pID() as byte)
       dim TempA as shortint
       dim TempB as word
       RomID = pID
       Convert
       GetTemp(TempA, TempB)
       USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), "C",13,10)
    end sub
    
    // program start...
    osccon = $72
    high(PORTA.3)
    SetBaudrate(br9600)
    SetPin(PORTA.4)
    while true
       DisplaySensor(Sensor_A)
       delayms(1000)
    wend
    
    END
    
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  8. #8
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default

    The 18B20 module has a hardcoded $28 device ID, but I'll try your code with my 18S20 ($10)
    Puddles of fun. What do you think of Swordfish? Have you seen my posting about getting it to program and run the Junebug directly using PK2CMD.exe?
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  9. #9
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by blueroomelectronics
    After programming you have to disable the programmer and enable the UART tool in the PICkit2 software. DIP switchs 1-3 off and 4,5 on.
    I just leave switches 1-3 on and it works fine. Got tired of constantly switching em back and forth and just tried it with them in tutor position.

    When I flip back to MPLAB I have to get the programmer to reconnect. It re-downloads the OS every time (have no idea why). Then I can reprogram as usual.

    When I flip from MPLAB back to the PICkit2 program I have to (if I didn't remember to before) shut off the UART Tool and Check Communication once before turning the UART Tool back on.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  10. #10
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by blueroomelectronics
    What do you think of Swordfish?
    I like it. It needs to have better error reporting though. The error messages often don't even give you a vague idea of what the actual problem is. Those niceties will come as it improves though.

    Have you seen my posting about getting it to program and run the Junebug directly using PK2CMD.exe?
    Ya, I've got that set up but I'm comfy using MPLAB still. Does the SF editor have any really awesome advantages?
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  11. #11
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default

    Ok then try trick #2 use the PICkit2 standalone software, select program on button press, open the hex file with Autoload / burn. It will automatically reload the hexfile and burn the pic when you press the button.

    And yes the SF editor is the bees knees. One button or <F10> compile, burn & run... The module browser is excellent and it will correct the case as you type.

    Your program appear to see my 18S20 but it reports -1.28C it's not that cold, so I'll have to fix the conversions as the 18S20 is a nine bit only temperature sensor.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  12. #12
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by blueroomelectronics
    Your program appear to see my 18S20 but it reports -1.28C it's not that cold, so I'll have to fix the conversions as the 18S20 is a nine bit only temperature sensor.
    Mine was doing that (negative bullcrap numbers) until I discovered the i2c ID part of the code. Fixed that and it worked great.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  13. #13
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,709
    Blog Entries
    5

    Default

    i2c ID? you mean 1wire ID?
    PS your switches 1-5 on works fine for this...

    I've got an old side lever DIP I might try, easy on the fingers.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  14. #14
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by blueroomelectronics
    i2c ID? you mean 1wire ID?
    Ya, I guess I do!
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  15. #15
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by blueroomelectronics
    And yes the SF editor is the bees knees. One button or <F10> compile, burn & run... The module browser is excellent and it will correct the case as you type.
    I just fixed my one button compile setup (did it wrong first try) and tried it some more. That IS nice.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. Junebug 1-wire DS18S20 test using Swordfish BASIC
    By blueroomelectronics in forum Micro Controllers
    Replies: 0
    Latest: 12th January 2008, 02:51 AM
  2. Good Electronic Supply's Sites, Everyone Come On In! :P
    By Electric Rain in forum General Electronics Chat
    Replies: 44
    Latest: 27th August 2007, 11:06 PM
  3. Req: simple low drop constant current source
    By Dominique in forum General Electronics Chat
    Replies: 10
    Latest: 9th February 2006, 02:20 PM
  4. What to expect on a basic electonics test for emolyment?
    By mikrochip59 in forum General Electronics Chat
    Replies: 2
    Latest: 2nd September 2004, 07:20 PM
  5. Switcher CAD III help
    By zachtheterrible in forum General Electronics Chat
    Replies: 6
    Latest: 1st August 2004, 01:04 AM

Tags for this Thread