The Free Site   |  vBuddy - make friends, share photos, blogs, have fun   |  Cheap Web Hosting - starting at $5

Slow Serial Data Transmission using Picaxes

This application was designed to send data out to sprinkler solenoid controllers. The control boxes are out in the field next to groups of 4-8 solenoids. A data system was needed that was extremely easy to debug (logic probe or led) and which would work over long distances.

This data protocol sends one byte  with each bit lasting 200ms over a single wire that has either 0V or 5V on it. Each control box has 5 wires - 24VAC live and earth, electronics earth, 12V and data. Electronics earth and 24VAC earth are grounded at a common point at the main controller at a large earth stake. Control boxes have local 78L05 regulators and drive 12V relays to turn on the 24VAC.

The transmitter picaxe listens to the PC serial port and waits for its address and checks a checksum. If all is valid it sends out the single byte which turns on that solenoid.

Transmitter code (picaxe 08)

main: serin 3, N1200, ("Data"), b1, b2, b3, b4, b5, b6, b12, b13
If b1 <> "T" Then main ' not an output byte
If b2 <> 6 Then main ' device number 6
Let w5 = b3 + b4 + b5 + b6
If w5 <> w6 Then main ' checksum invalid
' sprinkler number in b3. 0 to turn all off.
GoSub sendloop
GoTo main ' wait for next serin byte

sendloop: Let b0 = b3
high 2
pause 200 ' start pulse
low 2
Let b2 = 128 ' decrement amount to add
For b1 = 1 To 8
If b0 >= b2 Then outhigh
If b0 < b2 Then outlow
bytereturn: b2 = b2 / 2
pause 200
Next b1
low 2
Return

outhigh: high 2
Let b0 = b0 - b2
GoTo bytereturn

outlow: low 2
GoTo bytereturn

Receiver code

main: If pin3 = 1 Then GoTo decodebyte
Let w0 = w0 + 1
pause 10
If w0 > 18000 Then GoTo reset ' 3 min reset if no signal so always turns off. signal sent every minute
GoTo main

reset: Let w0 = 0
low 0
low 1
low 2
low 4
GoTo main

changedvalue:

' syntax is .2 secs high then 8 lots of 0.2 secs either high or low. Takes 1.8 secs to send a byte

decodebyte: pause 300 ' puts timer in middle of next bit
Let b2 = 0
Let b3 = 128
For b4 = 1 To 8
If pin3 = 0 Then GoTo skiphigh
Let b2 = b2 + b3
skiphigh: Let b3 = b3 / 2
pause 200
Next b4
' now have value in b2
If b2 = 17 Then GoTo high0 ' change values here for each sprinkler
If b2 = 18 Then GoTo high1
If b2 = 19 Then GoTo high2
If b2 = 20 Then GoTo high4
GoTo reset ' wans't for me

high0: low 1
low 2
low 4
pause 1000
high 0
GoTo counterzero

high1: low 0
low 2
low 4
pause 1000
high 1
GoTo counterzero

high2: low 0
low 1
low 4
pause 1000
high 2
GoTo counterzero

high4: low 0
low 1
low 2
pause 1000
high 4
GoTo counterzero

counterzero: Let w0 = 0
GoTo main

 

Home