| Author |
Message |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
 Anyone using 1-wire ?
I got my 1-wire stuff from Hobby-boards today. As usual with new stuff... totally frustrated.
Can't get 1-wire viewer to run. Was going to at least see if it works. On OSX (Java) it complains that another app is using the serial port (Keyspan HS19). In WinXP/VMWare it complains that WINUSB.DLL is not installed (even though I'm using serial). After entering through the warnings, no 1-wire network found.
According to Mac profiler or the Keyspan helper app the serial port is there.
So.... anyone using 1-wire? I'd like to get a sample working before spending time to install it. My hope is to use it with Serial Bridge. My first effort is to use the leaf sensor as a water sensor.
I'm using the hub, which has the DS9097U serial adapter built in.
I'm assuming that 1-wire has to be polled for data?
TIA for any help and/or suggestions.
|
| Mon Apr 21, 2008 11:24 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
I finally got the 1-wire viewer going on a pure WinXP so I know the sensor and 1-wire itself works.
Now to make use of it.
What I'm currently in need of is a sampling of how to poll devices via Serial Bridge and Applescript.
I can probably hack the AS script I'm using for my ultra-sonic but am at a loss as to what data has to be sent to the device.
TIA if you can help.
|
| Tue Apr 22, 2008 7:14 pm |
|
 |
|
gregjsmith
Joined: Apr 01, 2003 Posts: 823 Location: Rio Rancho, NM
|
My understanding is that the DS9097U doesn't communicate via normal ASCII command. I think it uses some sort of low level serial port magic. Then again I could be wrong.
_________________ Greg In The Desert
|
| Tue Apr 22, 2008 8:38 pm |
|
 |
|
ricks
Joined: Nov 11, 2006 Posts: 120 Location: Reno, NV
|
gregjsmith wrote:My understanding is that the DS9097U doesn't communicate via normal ASCII command. I think it uses some sort of low level serial port magic. Then again I could be wrong.
All 1-wire networks require a bus master to control the "low level" communications on the network. Gregjsmith is correct, as the DS9097U is a "simple" 1-wire adapter that electrically connects the 1-wire network to the computer, requiring the computer to act as the bus master through the TMEX software (or similar). Look at the Wikipedia entry for 1-wire for more info on what the bus master (the PC in this case) has to do.
For serial bridge/applescript, you'll need an external bus master that acts as an interpreter, so to speak. You communicate with the external bus master through simple commands over the serial port, while the bus master takes care of the complicated "low level" communications with the 1-wire bus and sensors. These types of external bus masters are sold by the same companies that sell other 1-wire gear.
There has been previous discussion about 1-wire here.
Rick
|
| Tue Apr 22, 2008 11:08 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
Looks like I misjudged this big-time.
Thought I had done all the research. Rats, more food for the white elephant box.
|
| Tue Apr 22, 2008 11:26 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
Found a 'smart' DS9097U equivalent at http://www.ibuttonlink.com/link45.aspx
It'll either salvage or it will be more food for the white elephant.
|
| Wed Apr 23, 2008 11:19 am |
|
 |
|
gregjsmith
Joined: Apr 01, 2003 Posts: 823 Location: Rio Rancho, NM
|
I will be interested to see how that works out for you. I purchased a HA7E but found programming it was almost like programming in machine language.
_________________ Greg In The Desert
|
| Wed Apr 23, 2008 8:49 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
Got my ibutton link today. Still somewhat beyond me but at least it seems closer. Been trying to run this sample via screen (serial terminal prog) but some of the coding screws up screen somewhat. I was able to read serial number, etc.
Now all I have to do is try to create an applescript for SerialBridge per this example from the Link manual.
- Code: Select all
Appendix B – 1-Wire Communications Examples The sequence for reading a DS18B20 temp sensor via The LINK is straightforward: 1. Issue a 1-wire reset (r). 2. Enter byte mode (b) and address the ROM by sending 0x55 followed by the ROM address in reverse byte order (that is, if the discovered id is E60000003DA0E128 you would address it as 28E1A03D000000E6). 3. Send the convert command 44. 4. Exit byte mode <CR>. 5. Wait at least 900ms for the conversion to complete. 6. Issue a 1-Wire reset (r). 7. Enter byte mode (b) and address the ROM as before. 8. Send the read command 0xBE. 9. Send two read commands as FFFF. The returned data will contain the temperature reading in Intel (little-endian) order as a 16-bit signed int. 10. Exit byte mode (CR). The returned value will be in 1/16 deg C increments. So a return value of 5701 represents 0x0157, or 343 in decimal. Dividing by 16 gives us 21.4 degrees C, or 70.6 degrees F. Mind the sign bit, or values below freezing will appear to be unusually warm by several thousand degrees. Debugging hint: The power up default of the 18B20 is 85 degrees C (185 degrees F). Look carefully if you receive this value. This might indicate that a convert has never been executed by this device. It is possible to address a 18B20 and NOT have enough power available for it to execute a convert.
I'm just testing with a temp sensor. Hopefully it will be an easy migration to moisture and leaf sensors.
I'm hoping that an AppleScript expert can lend a helping hand (again).
TIA
|
| Thu May 01, 2008 8:46 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
I hacked a mess together:
- Code: Select all
-- Sample stand-alone script for Serial Bridge. -- -- This script illustrates how to send commands to Serial Bridge to: send serial -- data, wait for serial data, and read serial data. -- -- This is an independent script and shows how raw commands can be used to -- control an open connection. You can also modify a connection's attachment -- script, which Serial Bridge automatically launches when the connection is -- opened, by pressing the "Edit Script..." button inside the connection window. -- Depending on your application you might need an independent script like this -- example, a Serial Bridge managed attachment connection script, or both. -- -- The property conncectionName must be set to the name of the connection -- you want to control. By default, Serial Bridge calls the first one "New -- Connection". The connection name is always the folder name in which the -- database settings file resides. -- -- 2005-03-29 Original. (Matt Bendiksen) -- 2005-04-01 Improved termination of concurrent connection events. (Matt Bendiksen)
----------- -- Change "New Connection" below to match the serial connection you want to control: property connectionName : "New Connection" ----------- tell application "Serial Bridge" ----------------------------------------------------------------------------- send to source connectionName string "r" wait for data from source connectionName to count 1 set singleChar to read string from source connectionName log "first reset reply = " & singleChar using type "Sample" send to source connectionName string "f" wait for data from source connectionName to count 18 set restOfString to read string from source connectionName log "device address = " & restOfString using type "Sample" send to source connectionName string "r" wait for data from source connectionName to count 1 set singleChar to read string from source connectionName log "reset reply 1 = " & singleChar using type "Sample" send to source connectionName string "b55282BCB5B010000E544" wait for data from source connectionName to count 20 set Char20 to read string from source connectionName log "char20 reply = " & Char20 using type "Sample" send to source connectionName byte 13 send to source connectionName string "r" wait for data from source connectionName to count 1 set singleChar to read string from source connectionName log "reset reply 2 = " & singleChar using type "Sample" send to source connectionName string "b55282BCB5B010000E5BEFFFFFFFFF" wait for data from source connectionName to count 24 timeout after 6000 set restOfString to read string from source connectionName log "result = " & restOfString using type "Sample" --set TempString to "BEFFFF4B467FFF0410F4" -- This line is used for diagnostic use only set TempString to "BE50054B46" --set temperature to 99 --getTemperatureFromSensorData(TempString) set theData to TempString --try set hundredsHex to (ASCII number (character 5 of theData)) - 48 -- ASCII (48) is "0", (49) is "1" etc if hundredsHex > 9 then set hundredsHex to hundredsHex - 7 -- ASCII "distance" between 9 and A set tensHex to (ASCII number (character 6 of theData)) - 48 if tensHex > 9 then set tensHex to tensHex - 7 set unitsHex to (ASCII number (character 3 of theData)) - 48 if unitsHex > 9 then set unitsHex to unitsHex - 7 set fractionHex to (ASCII number (character 4 of theData)) - 48 if fractionHex > 9 then set fractionHex to fractionHex - 7 set temperature to (hundredsHex * 256 + tensHex * 16 + unitsHex + fractionHex / 16) if temperature is greater than 3000 then set temperature to temperature - 4096 --calculates temperature in Celsius set temperature to (round 10 * (32 + temperature * 9 / 5)) / 10 -- converts Celsius to Fahrenheit log "Temp reading = " & temperature end tell
---------------------------------------------------------------------------------- on getTemperatureFromSensorData(theData) -- this script returns Fahrenheit temp rathar than celsius --This script extracts the temperature from the returned data string (e.g. "BE52014B467FFF0E10FF") --and converts the temperature (Celsius) from a hexadecimal number to a decimal number, and --then converts the temperature to Fahrenheit. Temperature data is contained in characters -- 5, 6, 3, and 4 of the data string, in that order.(the temp in the example is 015.2 degrees Hex or 21.125 dec) -- degrees are characters 5, 6 and 3 (the integer part, in that order) and the fraction is character 4 -- the temperature is a two byte signed integer (so -0.0625 degree C is represented as FFFF) -- to convert hex to decimal is easiest with the scripting addition "24U Hex OSAX" from 24U Software, -- but it can be done without: try set hundredsHex to (ASCII number (character 5 of theData)) - 48 -- ASCII (48) is "0", (49) is "1" etc if hundredsHex > 9 then set hundredsHex to hundredsHex - 7 -- ASCII "distance" between 9 and A set tensHex to (ASCII number (character 6 of theData)) - 48 if tensHex > 9 then set tensHex to tensHex - 7 set unitsHex to (ASCII number (character 3 of theData)) - 48 if unitsHex > 9 then set unitsHex to unitsHex - 7 set fractionHex to (ASCII number (character 4 of theData)) - 48 if fractionHex > 9 then set fractionHex to fractionHex - 7 set temperature to (hundredsHex * 256 + tensHex * 16 + unitsHex + fractionHex / 16) if temperature is greater than 3000 then set temperature to temperature - 4096 --calculates temperature in Celsius set temperature to (round 10 * (32 + temperature * 9 / 5)) / 10 -- converts Celsius to Fahrenheit return temperature on error the error_message number the error_number set temperature to 180 return temperature end try end getTemperatureFromSensorData
The getTemperatureFromSensorData(theData) function is for reference only as I couldn't get it to work as a function. Here is what I get: - Code: Select all
Sample first reset reply = P
Sample device address = -,E50000015BCB2B28
Sample reset reply 1 = P
Sample char20 reply = 55282BCB5B010000E544 Sample reset reply 2 = P
Sample result = 55282BCB5B010000E5BE50054B46 Script Temp reading = 185.0
Of course the Temp reading is wrong.
50054B46 is what should be the temps reading but of course it needs conversion.
Still a ways from success and I may still just scrap this 1-wire stuff and chalk it up to a bad decision.
Edit: After more research/reading I find that the temp reading of 185 may actually be correct if/when no conversion has taken place. This leads me to believe that the 44 may not be seen correctly by the device.
Last edited by hwitten on Sat May 03, 2008 11:55 pm, edited 1 time in total.
|
| Fri May 02, 2008 9:38 pm |
|
 |
|
gregjsmith
Joined: Apr 01, 2003 Posts: 823 Location: Rio Rancho, NM
|
Your making more progress than I did. the ibutton link looks easier to program than the HA7E. I may need to purchase one to see if I can help out.
_________________ Greg In The Desert
|
| Sat May 03, 2008 12:01 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
In principle this 1-wire stuff seems so easy but it certainly isn't, at least on OS X.
Being stupid or stubborn, or maybe both, I hacked some more at the scheme, switching to a DS2760, which is what Hobby-Boards uses for the leaf/moisture sensor. Since that's what I actually want to use I figured I might as well stick with that and then a temp sensor would probably come easy
I'm stuck at making sure the DS2760 is actually active. I read somewhere that it goes to sleep on power up so have to figure out how to wake it up or at least to check if it is sleeping as I'm not getting any values back.
I hate quitting so I'm keeping at it. Besides, it's raining out so no digging in the garden yet.
|
| Sat May 03, 2008 12:41 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
Hoping that someone can confirm I'm doing it right.
To send this via Applescript to the serial port: b552608846200000083B800<CR>
I'm using - Code: Select all
-- read temp send to source connectionName string "b5530DA8295110000D6B800" send to source connectionName byte 13
I'm not sure if a CR is sent as part of "string". I kinda think it''s a LF?
The above basically means:
b = set byte mode
55 = Match ROM
the the device serial number
B800 = recall memory page 00
and the CR and the end means to exit byte mode
TIA for confirmation that I'm doing it right or suggesting a better/correct way.
|
| Sat May 03, 2008 12:57 pm |
|
 |
|
hwitten
Joined: Dec 26, 2007 Posts: 486 Location: British Columbia
|
Some success at last.
Here are the revised script pieces. Sub call works now. Delay was the missing piece.
- Code: Select all
property connectionName : "New Connection" ----------- tell application "Serial Bridge" ----------------------------------------------------------------------------- send to source connectionName string "r" send to source connectionName string "r" wait for data from source connectionName to count 1 set singleChar to read string from source connectionName log "first reset reply = " & singleChar using type "Sample" send to source connectionName string "f" wait for data from source connectionName to count 18 set restOfString to read string from source connectionName log "device address = " & restOfString using type "Sample" send to source connectionName string "r" wait for data from source connectionName to count 1 set singleChar to read string from source connectionName log "reset reply 1 = " & singleChar using type "Sample" send to source connectionName string "b55282BCB5B010000E544" send to source connectionName byte 13 --send to source connectionName string "p44" --send to source connectionName byte 13 delay 2 wait for data from source connectionName to count 21 set Char20 to read string from source connectionName log "char20 reply = " & Char20 using type "Sample" --send to source connectionName byte 13 --delay 1 send to source connectionName string "r" wait for data from source connectionName to count 1 set singleChar to read string from source connectionName log "reset reply 2 = " & singleChar using type "Sample" send to source connectionName string "b55282BCB5B010000E5BEFFFFFFFF" wait for data from source connectionName to count 28 timeout after 6000 set restOfString to read string from source connectionName log "result = " & restOfString using type "Sample" set TempString to text 19 through 28 of restOfString set temperature to getTemperatureFromSensorData(TempString) of me log "Temp reading = " & temperature end tell
Results in: - Code: Select all
Sample result = 55282BCB5B010000E5BE78014B46 Script Temp C reading = 23.5 Script Temp F reading = 74.3 Script Temp reading = 74.3
Now to try for some success using the moisture/leaf sensor but first some garden work before the rain starts. And of course lots of cleanup after that. To say it's a hack is an understatement 
|
| Sun May 04, 2008 11:09 am |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11698 Location: Texas
|
Great -- glad it is starting to come together. You should be able to get rid of the delay by adding the timeout after argument to the wait for data verb.
Instead of this:
- Code: Select all
delay 2 wait for data from source connectionName to count 21
try this: - Code: Select all
wait for data from source connectionName to count 21 timeout after 2000
The advantage of the latter is that it will continue as soon as the 21 bytes are received (and will throw an error if they are not received after 2 seconds).
Regards,
Matt
|
| Sun May 04, 2008 11:28 am |
|
 |
|
gregjsmith
Joined: Apr 01, 2003 Posts: 823 Location: Rio Rancho, NM
|
I ordered a link45. How did you determine the address of your device?
_________________ Greg In The Desert
|
| Sun May 04, 2008 11:47 am |
|
|