Here is a method to development a Dallas 1-Wire, single bus powered, temperature sensor network. The MatchRom command is required to address the individual sensors in the network. Here is the link on how to readout individual 64 bit ROM codes: https://sourceforge.net/p/gcbasic/discussion/579125/thread/8fb0ca75/#6044/35f9
The example should be expandable to other 1-Wire devices. Using the family device code, as in the example, identifies the handling of the two DS18B20 devices, from the single DS18S20 device.
Edit: Put back "end sub" of OWoutRom subroutine which was left out during initial cut and paste. GCBasic had still managed to put a "Return" in without it during compile.
'This is an example for reading out three networked Dallas 1-wire Temp Devices.'Thenetworkisusingbuspowerandinclude(2)DS18B20,and(1)DS18S20.'The 64 bit ROM codes have been manually read, and tables developed to use MATCHROM command.'KS2/22/2014'Chip model, Oscillator frequency FOSC#chip 18f26k22,8#config OSC=INTIO67'Setup4bitLCD#defineLCD_IO4#defineLCD_DB4PORTB.4#defineLCD_DB5PORTB.5#defineLCD_DB6PORTB.6#defineLCD_DB7PORTB.7#defineLCD_RSPORTC.5#defineLCD_RWPORTC.6#defineLCD_EnablePORTC.7'#include <NewReadtemp.h> '#defineds18b20'#define OWDevice ds18b20 '#defineReadTemp_9Bits'Want to read 1/2 degree resolution'makeuseoftheReadTemp_Neg(True)FlagfornegativetemperaturesDimDummyReadAsWordDimHighLowAsWordDimOWTempNetAsword#defineDQPortA.2#defineSkipRom204'0xCC (204) Command for addressing all devices simultaneously#define MatchRom 85 '0x55'(085)Command for master to identify a specific slave code'FunctionCommandsforfor1-WireDS18S20#defineConvertT68'0x44 (68) Protocol for Single Temp Conversion#define ReadScratch 190 '0xBE(190)ProtocolforReadScratchpadMain:
Forcount=1to3DummyRead=OWTempNetIfcount=1ThenLocate0,0Ifcount=2Thenlocate0,8Ifcount=3ThenLocate1,0IfReadTemp_Neg=True&DummyRead<>0ThenPrint"-"ElsePrint" "EndifIf(DummyRead/2)<100ThenPrint" "Print(DummyRead/2)'Print whole number from 9 bit format If DummyRead.0 = 1 Then Print ".5 " Else Print ".0 " End If Print "C "Next'wait2sgotoMain'-----SUBS-----------------------------------------Sub MasterRST 'Masterresetlowforminimum480usDirDQInDirDQOutSetDQOffwait5010usDirDQIn'HiZ the bus line for reading presence pulseend subSub PPulse 'Masterreceivepresencepulsewait70usDirDQInwait430usendsubfunctionOWTempNetMasterRSTPPulseOWoutMatchRomOWoutRomOWoutConvertTMasterRead_TimeSlots'start polling for response from device MasterRST PPulse OWout MatchRom OWoutRom OWout ReadScratch OWin16 'readfirsttwobytesfromscratchpadIfHighLow.15=1Then'Test for sign bit ReadTemp_Neg = True If DevFamily = 40 Then HighLow = HighLow / 8 end if OWTempL = HighLow 'SplitwordintobytessobytesizeOWTempH=HighLow_H'assembler operations can be used comf OWTempL 'InvertLowbytebitsintheRegisterincfOWTempL'Add One to Low byte to turn into 2'scomplimentcomfOWTempH'Invert High byte bits OWTempNet = OWTempL 'ReassemblebytesbackintowordOWTempNet_H=OWTempHgotoNegNumElseReadTemp_Neg=FalseEndifIfDevFamily=40Then'Check for DS18B20 Devices OWTempNet = HighLow / 8 'Makea9bitresultElseOWTempNet=HighLow'Its a DS1820 or DS18S20 device End ifNegNum:end functionsub MasterRead_TimeSlots #IfDEF PAR Set ReadTemp_Pullup On #EndIf #IFNDEF PAR 'startmasterreadtimeslotsuntilds18x20returnsa"1"DodirDQoutSetDQOffwait4usDirDQInwait7usIfDQ=1ThenExitDowait60us'minimum 60 us time slots between reads Loop #ENDIF #IfDEF PAR wait 750 ms 'Needapprox.750msforfullconversionSetReadTemp_PullupOff#EndIfendsubSubOWin16(OUTHighLowasWord)HighLow=0Forbits=1to16RotateHighLowRight'The one wire devices xmit data LSB first Dir DQ Out Set DQ Off 'StartReadtimeslotwait4usDirDQIn'Release bus for one wire Reception wait 7 us If DQ On Then Set HighLow.15 1 'Mustreadbuswithin15usslotIfDQOffThenSetHighLow.150wait50usNextendsubSubOWoutRomForEightBytes=1to8Ifcount=1ThenReadTableSensorOne,EightBytes,SerialNumIfcount=2ThenReadTableSensorTwo,EightBytes,SerialNumIfcount=3ThenReadTableSensorThree,EightBytes,SerialNumIfEightBytes=1ThenDevFamily=SerialNum'Print DevFamily 'Print" "EndifOWoutSerialNumNextendsubSubOWout(Command)#NRForClocks=1to8DirDQOutSetDQOffwait3us'Need to release bus within 15 us If Command.0 On then Dir DQ In End if wait 60 us Dir DQ In 'HiZthebusifstillpulledlowwait3usROTATECommandRight'The one wire devices xmit data LSB first Nextend subSub OWinRomFor EightBytes = 1 to 8 For Clocks = 1 to 8 Rotate RxData Right 'TheDS18s20wantsdataLSBfirstDirDQOutSetDQOff'Read time slot wait 4 us Dir DQ In 'Releasebusforonewiretransmissionwait7usIfDQOnThenSetRxData.71IfDQOffThenSetRxData.70wait50usNextNextendsubTableSensorOne163712822808092EndTableTableSensorTwo402484797300161EndTableTableSensorThree40405152300194EndTable
Last edit: kent_twt4 2014-02-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I see a nRF24L01 have you gotten that to work yet?
would you like a pcb that works with that and a few other parts?
I sent some to Hugh and Evan. PM me if you want a 8/14/18/20 pin + LCD board
or a soic-28 + usb board
Last edit: ofuzzy1 2014-02-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For a brief period of time, got a single channel RX/TX NRF24L01P pair working. Sadly when I tried to resurrect the project last year, it had seemed communication was lost ... :(. I had updated GCBasic during this time, tried going back to previous version, still no go. Was running these off a 9V battery and a wall wart, and that could have been the problem too.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is a method to development a Dallas 1-Wire, single bus powered, temperature sensor network. The MatchRom command is required to address the individual sensors in the network. Here is the link on how to readout individual 64 bit ROM codes: https://sourceforge.net/p/gcbasic/discussion/579125/thread/8fb0ca75/#6044/35f9
The example should be expandable to other 1-Wire devices. Using the family device code, as in the example, identifies the handling of the two DS18B20 devices, from the single DS18S20 device.
Edit: Put back "end sub" of OWoutRom subroutine which was left out during initial cut and paste. GCBasic had still managed to put a "Return" in without it during compile.
Last edit: kent_twt4 2014-02-26
Here's a pic, two sensors in the freezer...brrrr.
Nice work!
I see a nRF24L01 have you gotten that to work yet?
would you like a pcb that works with that and a few other parts?
I sent some to Hugh and Evan. PM me if you want a 8/14/18/20 pin + LCD board
or a soic-28 + usb board
Last edit: ofuzzy1 2014-02-26
Thanks, hope someone finds it useful.
For a brief period of time, got a single channel RX/TX NRF24L01P pair working. Sadly when I tried to resurrect the project last year, it had seemed communication was lost ... :(. I had updated GCBasic during this time, tried going back to previous version, still no go. Was running these off a 9V battery and a wall wart, and that could have been the problem too.
I have started another link. https://sourceforge.net/p/gcbasic/discussion/579125/thread/fe297d38/#d2b3 to share the nRF24L01 information.