Long serial connection

cpedw

Senior Member
I plan to measure 5 temperatures using a 14M2 and 5 DS18B20s. I want to display the measurements on an AXE131 OLED so I want to send serial data from the 14M2 to the 18M2 in the AXE131.

My slight concern is that the display is about 5m from the measurements. The cable will be carrying power to the 14M2 as well as data back to the 18M2 so I was thinking of using plain 3 core cable.

Does this call for anything special in the cabling or type of serial transfer?
Will the standard N2400 baud rate be suitable?

Derek
 

lbenson

Senior Member
Probably will work. I've done 5V serial over 25 feet of cheap dollar store 3-wire mini-stereo cable, and 50 feet of 3V3 serial over Cat 5 (though not with a picaxe).
 

hippy

Technical Support
Staff member
I also would have expected it to work but the proof is in the doing. I would probably try two-core screened cable or stereo, two single-core screened cable.

The biggest issue with a long cable is interference pickup. If you get a glitch and that gets passed to the OLED it could completely scramble the display until a full power-cycle.. So, once working, it would be worth considering tweaking the 18M2 AXE131 firmware so it can receive packets of data with a checksum. That would also allow you to run at lower baud rates to improve reliability. The baud rate and transfer will be slower but the display update should be faster, even quicker than stock AXE131 firmware.

You could also supply a serial returned character to indicate "failed", "got it", and " done it, ready for next packet" indication. Or just a digital signal rather than serial.

Cat 5, telephone or alarm cable, might be best there for the extra core.
 

oracacle

Senior Member
you could use CAT 5 and send the signals of twisted pairs. Better still, use shielded CAT6. The bonus of CAT 6 is it has a separator between the pairs reducing cross talk which is helpful if you plan on send power and return signals.
You could also look into how to calculate CRC, ben eater on you tube has a couple of good videos on it, although his tend to be more hardware based than software - could be an interesting addition to the project if you go hardware based, but I see any obvious reason why it couldn't be done in software.
 

Eng460

Member
I am wondering if it might be better to put the 14M2 close to your display so that the wiring is not an issue, and have the long wire from the sensors to the 14M2.

As I understand it the DS18B20’s are intended to be used daisy chained on three wires (even 2 is possible, but I prefer three), and I suspect they are well set up to handle longer distances, to gather data from around a building or similar.

I like the DS1820B as it has so many useful features if you need them, (but I just need a high temperature one)! I haven’t yet tried it over large distances, more than a couple of metres, but I would expect it to work all around the house for example.

The cable for the temperature sensors will only be carrying power for one of them at a time, and it is a very low power requirement.

Eng460
 

Eng460

Member
I used one core for plus 5 V, one for 0 V, and the third one for data. All the sensors are in parallel and the Picaxe talks to each one in turn by serial number using the one data wire for all the connected devices. Each one has a unique serial number. Only three cores needed for more sensors on the loop than I can imagine ever needing, and only one pin of your Picaxe unless you want to save power by turning off the 5 V when not reading.

There is a Pic application note which gives the code to identify which ones are connected, but I thought that was too hard, and did not want to use up so much of my programme space to try and translate the method to Basic, and it still does not tell you where each one is. I just did the little Picaxe routine to return the serial number to the computer with sertxd, and labelled each one. Attached the label to the three Core wire near the device for future identification.

Then Picaxe can call each one by its serial number and it is not hard to display the temperatures linked to suitable screen names. Section 2 with all the program language instructions is your friend, along with section 3.

Eng460
 

cpedw

Senior Member
I used one core for plus 5 V, one for 0 V, and the third one for data. All the sensors are in parallel and the Picaxe talks to each one in turn by serial number using the one data wire for all the connected devices. Each one has a unique serial number. Only three cores needed for more sensors on the loop than I can imagine ever needing, and only one pin of your Picaxe unless you want to save power by turning off the 5 V when not reading.

There is a Pic application note which gives the code to identify which ones are connected, but I thought that was too hard, and did not want to use up so much of my programme space to try and translate the method to Basic, and it still does not tell you where each one is. I just did the little Picaxe routine to return the serial number to the computer with sertxd, and labelled each one. Attached the label to the three Core wire near the device for future identification.

Then Picaxe can call each one by its serial number and it is not hard to display the temperatures linked to suitable screen names. Section 2 with all the program language instructions is your friend, along with section 3.

Eng460
This sounds like an interesting approach. It seems I could change down to an 08M2. I looked at the DS18B20 data sheet but it will take me some time to comprehend it.

Are you able to share some code to do this? Are Section 2 and Section 3 that you refer to in the Pic app note? Can you give a link to that?

Thanks,
Derek
 

Eng460

Member
Hi Derek, it would take me quite some time to find those files, and they are nothing really clever, but I was referring to the Picaxe manuals, easily accessed via the Picaxe tab at the top of this forum page or from your Program Editor, and I used the code snippets there. I found it quite easy to adapt those snippets to what I wanted to do.

The DS1820B data sheet told me the terminal identification and useful information about the capabilities, but the Picax manual was my most important reference. The important being the read temp command.

I will have another look at the details and come back with more shortly.

Eng460
 

cpedw

Senior Member
Digging a bit deeper, I find that 1 wire has its own Picaxe commands but they only work in X parts.

Since the application does nothing apart from displaying 5 temperatures and is only powered when reading is taking place using a momentary switch, I can put up with the occasional glitch.
To reset the display, just let go of the switch. For error checking, just keep looping round reading and displaying. KISS!

Derek.

p.s. I'm still interested in 1 wire comms but probably not for this application.
 

hippy

Technical Support
Staff member
The READTEMP and READTEMP12 commands only work with a single DS18B20 per pin. The commands send out a 'whoever you are, return your data', so does not work with multiple sensors because they will all respond.

The X2 devices have the OWIN and OWOUT commands which allow individual sensors to be addressed on ta single pin, but the software is a little more complicated, and requires an X2.

It is, as noted, possible to determine the serial numbers of each sensor on a shared pin but that doesn't really help much as that won't reveal where they are placed.

That capability is more useful with a large network of sensors, where multiple PICAXE's don't know which sensors are connected and don't care, each merely sending data and serial numbers to something else which knows which each are which and where they are placed.
 

Eng460

Member
Thanks Hippy, I think you have explained my conundrum.
I found my code to return the serial number, it was so long ago that perhaps my memory has overlooked whether I actually achieved reading several devices, but simply assumed that once I had the serial number, I could specify which device to read. Sorry if I have led us all astray.

I was being lazy, working on the iPad, computer needs some update maintenance, but while I have been away, I found the code

First, to get the serial number, I used the readowsn command. This command reads all those registers specified on the DS18B20 data sheet into bite variables. The code snippet given works.

Apologies for not using the correct method for quoting code, but due to my device challenges I will have to transcribe the code.

Mod Edited : We have added the [code]...[/code] tags for you.

Code:
Initialise:
    pause 1000
    let b6=0

Identify:
    readowsn 1    ;DS18B20 data leg is connected to pin 1, please check the pin limitations         
                           ;for your device in section 2
    pause 1000
    if b6=0 go to identify
    if b6=$FF then initialise
    sertxd (“Family “,#b6,13,10)
    pause 1000
    sertxd (“Ser. no. “,#b12,#b11,#b10,#b9,#b8,#b7,13,10)
    pause 1000
    sertxd (“CRC value “,#b13,13,10)

Measure:
    readtemp 1,b2
    pause 1000
    sertxd (Temperature is now “,#b2,13,10)
    pause 1000
    readtemp12, 1 w2
    pause 1000
    b5=w2/$10
    b4=w2//$10*$10+10*10/256
    sertxd (High res temp is “,b5,”.”,#b4,13,10)
    pause1000

Checktemp:
    readtemp12 ,w0
    pause 1000
    if w0=w2 go to checktemp
    goto measure
Lots of 1 second pauses avoid timing issues due to temperature processing and sertxd execution times. Program is not time critical so avoid issues.

I see that I used goto’s which are not recommended. I will have to try and update the code to better practice.
The check temp routine just keeps looking for a temperature change before going through the routine again.

I copied out the window with the sertxd output as follows (and pasted it at the end of the program as a rem.

Family 40

Ser. No. 001109114112

CRC value 206

Temp is now 19

High Res Temp is 19.12 C

Please don’t ask me to explain the formula for b4 in the high res temp section, it was well over ten years ago.

As all devices have a different serial number yours will differ. I swapped to a different DS18B20 then ran the program again to get the next one.

So the next step is to use the serial number to read one device when many are connected.

Now my old memory is defeating me, and I can’t find my code, but a quick look at section 2 indicates that it is necessary to read the one wire tutorial available as a download from the Picaxe site, and use the one wire protocol to select the device to be read and take the reading. The DS18B20 device is used in section 2 as the example for one wire.

PS, I see that Hippy has replied while I was searching. Thanks Hippy. So more code required, but is it possible on an X2?

Now 11 pm here. No time tomorrow, but it looks like I will have to read that one wire tutorial later in the week, if only to straighten out my own memory.

MJM460
 
Last edited by a moderator:

Eng460

Member
Well lots of unproductive searching later,

I have found data sheets for the one wire system from TI and from DS,

I have found that there is a clear intent that multiple devices can be installed on just two or three wires, and individually addressed by their serial number. However it is not clear to me whether the distance limitation is 5 or 125 metres. Possibly 5 for the two wire, parasitic powered method and longer for three wires, but I am not sure,

I have searched the Picaxe site for the one wire tutorial mentioned in each of the three commands that address one wire devices, but can’t find the tutorial. Can anyone suggest a link to this document?

I have found methods using other chips but that would be a whole different project, so not relevant here. Nothing that gets me close to implementing this on Picaxe unfortunately.

So I think that leaves me at last convinced that I am mistaken in my belief that I had actually done it. Obviously I did explore reading the serial number, and have used a single device for temperature measurement on several projects. I discovered the intent, but never actually completed that last step. My apologies.

So back to the original post, I still suggest making the long wires between the Picaxe and the temperature sensors, and using five data pins for five devices as as already been suggested. I would also recommend running plus 5 V in addition to the ground and signal wires for each one. Of course using a multi core cable, probably just Cat 5, there are enough cores for +5V ground and several signal wires, all in the same core. It means you are not limited to X2 devices, just need one with sufficient input pins.

Thank you for inserting the code tags, I did not appreciate that I could do that for typed text, and not only for text copied from the program editor. Another thing learned.

Eng460
 

Hemi345

Senior Member
Many years ago, a friend and I designed a 1wire sensor network to monitor server cabinets in a datacenter at work. It used a few different 1wire devices on custom PCBs: DS28EA00 for temperature, DS2438 to read analog Honeywell humidity sensors, and DS2406 for LED status indicators. I used a 20X2 with the OW commands and a single wire (plus power and ground). This worked really well with many meters of cable between each sensor PCB. It appears I have lost the more mature programs I had written, but found the following in my "testcode" folder that talks to two of the 1wire devices:

Code:
#picaxe 20x2
#no_data
#no_table

symbol OW_NET = b.0
SYMBOL PIO_Latch    = b2
SYMBOL Chan_Info      = b0
SYMBOL   myctr       = b14

;BIT 7     BIT 6     BIT 5     BIT 4     BIT 3     BIT 2     BIT 1     BIT 0 
;ALR     IM         TOG     IC         CHS1     CHS0     CRC1     CRC0

;1-wire mode: %0000
;% bit3 bit2 bit1 bit0
; Bit 3    apply strong pullup after data
; Bit 2    bit mode (receive 1 bit rather than 8 bits (1 byte))
; Bit 1    reset pulse sent after data
; Bit 0    reset pulse sent before data

main:
    ;DS2406 ROM ID
    b6 = 18
    b7 = 67
    b8 = 164
    b9 = 161
    b10 = 0
    b11 = 0
    b12 = 0
    b13 = 167
    Chan_Info = 0
    sertxd ("Initializing DS2406...",13,10)
    OWOUT OW_Net, %1000, ($55, b6, b7, b8, b9, b10, b11, b12, b13)
    pause 100
    sertxd ("Done.",13,10)
    inc myctr
    sertxd (#myctr, " Configure PIO and report channel info byte.",13,10)
    if myctr > 3 then
        OWOUT OW_Net,%0001,($55, b6, b7, b8, b9, b10, b11, b12, b13,$F5,%10101100,$FF)
    else
        OWOUT OW_Net,%0001,($55, b6, b7, b8, b9, b10, b11, b12, b13,$F5,%10100100,$FF)
    endif
    OWIN  OW_Net,%0000,(Chan_Info) ;do i need to send reset after the data??
    sertxd ("Channel info byte: ",#Chan_Info,13,10)
    ;OWOUT OW_Net, %0011, ($55, b6, b7, b8, b9, b10, b11, b12, b13)
    ;else
    ;    OWOUT OW_Net,%1000,($55, b6, b7, b8, b9, b10, b11, b12, b13,$F5,%00101100,$FF)
    ;endif
    ;OWOUT OW_Net, %1001, ($55, b6, b7, b8, b9, b10, b11, b12, b13)
    pause 1000
;goto main
;#rem
    ;DS2438 ROM ID
    b6 = 38
    b7 = 143
    b8 = 215
    b9 = 111
    b10 = 1
    b11 = 0
    b12 = 0
    b13 = 1
    sertxd ("Initializing DS2438...")
    OWOUT OW_Net, %1000,($55, b6, b7, b8, b9, b10, b11, b12, b13)
    OWOUT OW_Net, %0001,($55, b6, b7, b8, b9, b10, b11, b12, b13, $4E, $00)
    ; send  reset before, 
    pause 100
    sertxd ("Done.",13,10)
    sertxd ("Sending Temperature conversion request...")
    OWOUT OW_Net, %0001,($55, b6, b7, b8, b9, b10, b11, b12, b13, $44)    
    ; send reset before, $55 = match ROM, S/N for device, then convert T
    pause 100
    sertxd ("Done.",13,10)
    sertxd ("Sending Voltage conversion request...")
    OWOUT OW_Net, %0001,($55, b6, b7, b8, b9, b10, b11, b12, b13, $B4)
    ; send reset before, $55 = match ROM, S/N for device, then convert V
    pause 100
    sertxd ("Done.",13,10)
    sertxd ("Sending recall from memory to scratchpad request...")
    OWOUT OW_Net, %0001,($55, b6, b7, b8, b9, b10, b11, b12, b13, $B8, $00)    
    ; send reset before, $55 = match ROM, S/N for device, then recall from memory to scratchpad
    pause 100
    sertxd ("Done.",13,10)
    sertxd ("Reading from scratchpad memory...",13,10)
    OWOUT OW_Net, %0001,($55, b6, b7, b8, b9, b10, b11, b12, b13, $BE, $00)
    ; send reset before, $55 = match ROM, S/N for device, then read from scratchpad
    OWIN OW_Net, %0000,(b19,b20,b21,b22,b23)
    sertxd ("Values pulled from scratchpad page 0 are:",13,10)
    sertxd ("Status: ",#b19,", Temp: ",#b21,".",#b20, "C, ADC: ",#b23 , ".", #b22,"V",13,10)
    sertxd ("Finished",13,10)
    pause 5000
goto main
;#endrem
 

Eng460

Member
Thank you so much Premelec for those links.

Also thank you Hemi345 for that code example, I will certainly learn more from that.

I have found Westy’s tutorial and it is on my summer reading.

Clearly like Hippy said, it can be done (on an X2 part) but it requires a “ bit” more coding. I suspect it is beyond my present skill level, but it won’t hurt me to do some heavy reading. I always learn something from others code examples.

Progress won’t be quick as I won’t have access to my computer for a while now, computers are not compatible with beaches anyway, but lots of reading and some trials when time allows. We will see.

But in the mean time, it’s one data pin per device for me.

I hope that Cpedw can now successfully complete the project. Looking forward to updates.


Eng460
 
Top