Silicon ChipThe PICAXE, Pt.6: Data Communications - July 2003 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Digital TV is a complete failure
  4. Feature: RFID Tags - How They Work by Peter Smith
  5. Feature: Solar Power For Caravans & Motor-Homes by Collyn Rivers
  6. Project: Smart Card Reader & Programmer by Peter Smith
  7. Project: PowerUp: Turns Peripherals On Automatically by John Clarke
  8. Product Showcase
  9. Order Form
  10. Project: A "Smart" Slave Flash Trigger by Jim Rowe
  11. Weblink
  12. Project: A Programmable Continuity Tester by Trent Jackson
  13. Project: The PICAXE, Pt.6: Data Communications by Stan Swan
  14. Project: Updating The PIC Programmer & Checkerboard by Peter Smith
  15. Vintage Radio: The "Jelly Mould" STC 205 Mantel/Table Receiver by Rodney Champness
  16. Back Issues
  17. Notes & Errata
  18. Market Centre
  19. Advertising Index
  20. Book Store
  21. Outer Back Cover

This is only a preview of the July 2003 issue of Silicon Chip.

You can view 27 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "PowerUp: Turns Peripherals On Automatically":
  • PowerUp PCB pattern (PDF download) [10107031] (Free)
  • Panel artwork for the PowerUp (PDF download) (Free)
Items relevant to "A "Smart" Slave Flash Trigger":
  • Smart Slave Flash Trigger PCB [13107031] (AUD $10.00)
  • "Smart" Slave Flash Trigger PCB pattern (PDF download) [13107031] (Free)
  • Panel artwork for the "Smart" Slave Flash Trigger (PDF download) (Free)
Items relevant to "A Programmable Continuity Tester":
  • Programmable Continuity Tester PCB [04207031] (AUD $7.50)
  • Programmable Continuity Tester PCB pattern (PDF download) [04207031] (Free)
  • Panel artwork for the Programmable Continuity Tester (PDF download) (Free)
Articles in this series:
  • PICAXE: The New Millennium 555? (February 2003)
  • PICAXE: The New Millennium 555? (February 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)

Purchase a printed copy of this issue for $10.00.

MORE FUN WITH THE PICAXE – PART 6 ‘Stringing’ Along With The PICAxe by Stan Swan Would you believe this month we are going to use a piece of wet string for data communication between two PICAXE08s? Or even a ring of kids holding hands? And we might even try adding radio! Read on – and be amazed . . . T he so-far-unused Pin 0, normally switchable as either the programming input or an output pin, has revealed itself capable of versatile double duty. When a high impedance piezo sounder was connected to this pin, it was found that programming downloads to the “08” would still pass as normal, with the piezo also conveniently “burbling” as the program went past. Not only is this a useful audible assurance, (unless you’re working late at night!), but the piezo remains capable of sound output as desired, without having to swap the I/O leads. Consequently it’s recommended that sound outputs be now normally generated at Pin 0, since this conveniently frees up other I/O pins for more demanding work Sounds, LED flashing, A-D conversion, timing, pulsing, and motor control all for under $5! As if their appeal so far wasn’t enough, PICAXE-08’s also come with full-featured serial data communications capabilities. Sacre bleu – it’s almost like learning your kids are talented at cricket, calculus and cooking! As we have discovered over the past few months, these little “kids” are extremely talented. Unlike kids, though, they are very cheap to train and use. Not only that, they don’t know the difference between work and play! But, at 2400 bps, it’s not very fast – OK, maybe your kids aren’t that hot tidying up their bedrooms either? However such data speeds are more than enough for digital data control over simple wired links and show merit for short range wireless control and telemetry too. Even when wound back to 300 bits per second (perhaps for reliability), valuable data acquisition of temperatures/security/voltages/control signals and the like can occur. Such variables may only need updating every few seconds (even hours?) – it’s not as if you’re downloading MP3s from the web at ADSL speeds! In today’s wide-bandwidth data communications age, when Firewire, Wi-Fi, Bluetooth, ADSL and even regular USB entrance us with speed and seamless connectivity, plain RS-232 may seem as quaint as Morse code. Yet Recommended Standard #232, dating from 1960s room-filling computers, still remains the core tech- How long is a piece of (wet) string? Long enough to transmit and receive data communications from one PICAXE to another. Fair dinkum – wet string really does work! 74  Silicon Chip www.siliconchip.com.au nique for linking diverse electronic communications and terminal equipment, especially when raw speed is not an issue. Modems, navigational aids, data loggers, CNC milling machines, programmable devices, instruments and the like often still depend on inter-device protocols detailing speeds, bits per character, stop and parity. Such well known cryptic expressions as 9600E71 (9600 bps, Even Parity, 7 bits per character, 1 Stop bit) inform both ends of a serial comms link of the protocols expected, much as sports teams must follow prescribed rules. (If one team plays basketball while the other plays soccer then of course little sense will occur). RS-232 voltages should strictly be ±15V, with “1” being negative and “0” positive. These wide swings may have to be provided by the ubiquitous MAX232 IC, as was the case in one of the PICAXE applications shown last month. However, the PICAXE swing of 5V is usually sufficient. Classic serial D9/25 data cables may use diverse data flow control voltages, presented over extra wires at RTS (Ready To Send), CTS (Clear To Send), DTR (Data Terminal Ready). Phew, rest easy ladies and gentleman – FWR on these (Finished With Engines?) – bare bones data links can be done over just a 2 wire connection (signal line and ground return). In fact “08”s have shown themselves to have such robust input features that almost any electrical 2-wire link could be viable, with the theoretical “50 foot” (~15m) serial cable limit trivial. Junk box wires, 100 metre lengths of twin core bell wire, capacitors, or even (wait for it!) damp natural string (!) have all delivered the data for me. The upper wired link impedance is thought to be some 1MΩ, which roughly approximates the resistance of dry skin. Ever conscious of electrical safety with impressionable youngsters and with adult “terminals” at each end, I’ve even had a chain of young kids holding hands passing RS232 data, (perhaps the kids had palms damp with the excitement!). Quick DMM soil conductivity tests here in coastal New Zealand, showed some 10kΩ resistance with a ten metre probe separation, implying a single www.siliconchip.com.au Yes, our “standard” PICAXE circuit has changed this month – and not only ’cos there’s two of ’em! We’re also permanently connecting the piezo to I/O port 0 (pin 7). Why? Because we can! Here’s the protoboard wiring for the transmitter shown above. The receiver is basically indentical but does not have the LED, switch nor associated resistors. July 2003  75 BASIC PROGRAM LISTINGS (This can also be downloaded from http://picaxe.orconhosting.net.nz) RX.BAS ‘PICAXE-08 serial INPUT data control link for July 2003 SiChip article V 1.0 15/5/03 ‘Needs matching output program & hardware at sender PICAXE for receiver piezo control ‘Connect piezo to PICAXE-08 pin 0 - ref article for use as programming feedback too. ‘2 wires between units only - data on pin 4 linking both & simple ground return ‘Inputs such high impedance that even damp string (~ 1MOhm) may be used as conductor! ‘Variable b0= sender switch status (0=off/low,1=on/high) with 10k pulldown resistor ‘NB -serial link decoding overheads may mean time delays (?)-easily *pause* tweaked. ‘Via Stan. SWAN (MU<at>W,New Zealand) => s.t.swan<at>massey.ac.nz <= ‘——————————————————————————————————— ‘ Lines beginning ‘ are program documentation & may be ignored if need be. ‘ Program available for web download => www.picaxe.orconhosting.net.nz/rx.bas ‘——————————————————————————————————— state: ‘ procedure to serial data read sender switch state serin 4,n2400,b0 ‘ set up serial input on pin 4 & wait for b0 value if b0 =1 then fastbeep ‘ check b0 & jump to fastbeep if =1(ON) else continue slowbeep: sound 0,(80,20) pause 1000 goto state ‘ slow beep routine when switch is low (OFF) ‘ 20 ms lazy beep to piezo attached direct to pin 0 ‘ 1 sec delay (may need altering to synch. ?) ‘ return to serial link switch reading input fastbeep: sound 0,(100,10) pause 250 goto state ‘ fast beep routine when switch is high (ON) ‘ 10 ms higher pitched urgent beep to pin 0 piezo ‘ 1/4 sec delay ( may also need altering ?) ‘ return to serial link switch reading input TX.BAS ‘PICAXE-08 serial OUTPUT data control link for July 2003 SiChip article. V 1.0 15/5/03 ‘Needs matching input program & PICAXE hardware at receiver unit for sender control ‘Connect status check LED via 220 Ohm dropper R & toggle switch Pin 0 with pulldown R ‘Simple 2 wire data link can be greatly extended or even replaced with damp string ! ‘Variable b0= switch status ( 0=off/low, 1=on/high ) with 10k pulldown resistor ‘Pause times at sender may need tweaking to synch. with receiver - decoding o’heads ? ‘Via Stan.SWAN (MU<at>W, New Zealand) => s.t.swan<at>massey.ac.nz <= ‘——————————————————————————————————— ‘Lines beginning ‘ are program comments etc & may be ignored if need be ‘Program available for web download => www.picaxe.orconhosting.net.nz/tx.bas ‘——————————————————————————————————— state: serout 4,n2400,(b0) if pin1=1 then fastbeep ‘ procedure to serial data send local switch status ‘ setup & 2400bps send b0 value as serial output pin 4 ‘ if local switch is on/high jump to fastbeep slowbeep: b0=0 pulsout 2, 5000 pause 2000 goto state ‘ lazy slowbeep if switch is off (0) ‘ set switch status variable b0=0 ‘ pulse attached LED at pin 2 for local confirmation ‘ 2 sec. delay (may need altering for synch ?) ‘ loop back to switch status routine fastbeep: b0=1 pulsout 2,5000 pause 500 goto state ‘ fastbeep urgent routine if switch is on (1) ‘ assign switch status variable b0=1 ‘ pulse attached LED at pin 2 for local confirmation ‘ 1/2 sec. delay (may also need altering for synch ?) ‘ loop back to switch reading routine 76  Silicon Chip wire earth return (SWER) data link could be viable; perhaps over many kilometres to suit moist region farms (unused electric fences perhaps?) What I am trying to say here is that just about anything conductive but safe is worth a try. How about a waterfilled plastic hose, with connections to the brass fittings? NB: 240V mains wiring is of course so unsafe when meddled with that it should never even be considered! You won’t do any harm and you may be surprised at what you can get away with! Syntax: Bit rates can be 300, 600, 1200 or 2400 bps, true (T) or inverted (N). Picaxe serial commands are capable of sophisticated data qualification too, needed perhaps for LCD driving. At a basic level, suitable for this month’s article, the syntax is just Serial output: output pin, T/N & bit rate, (data,data,…) Example: serout 2,N2400,(b1) This sends variable b1 (and others?) through pin 2 at 2400bps, inverted polarity Serial input: input pin, T/N & bit rate, data, data,… Example: serin 4,T300,b2 This receives one byte of data (true polarity, 300bps) at pin 4 and stores the data as variable b2. Incidentally, the program stops and waits until this prescribed data is received. An important further aspect of serial reception, only too well known in classic comms. theory (recall buffered 16550 UARTs?), is that data may be missed or jumbled if the busy receiver is “distracted” with another task or program loop. Wireless data receivers may also need a few milliseconds (typically 5) turn-on time as well. Sender delays, “wake up” junk variables, sync bytes (with predetermined data), reduced data rates or even refined recipient program routines may be needed to cope. Mmm– does it all seem very like your kids on reluctant kitchen duty again? The program(s): Since two “08s” are used, it’ll help if two PCs are available for independent editing. One will of course suffice (using minimised screens) but you’ll need a clear head to avoid confusing www.siliconchip.com.au Readily-available (and cheap!) 433MHz LIPD transmitters and receivers make a great way to link two PICAXE datacomms setups. The transmitter (left) and receiver (right) are shown here almost life size the programs, cables and controllers! It’ll also help if you use consistent titles – local/sender/transmitter/tx/A and remote/recipient/receiver/rx/B perhaps ? The setup here uses a simple switch, whose status is shown also by a local LED flash, to control remote speaker beep rates and tones. When on, this switch just connects the positive rail (~5V) to input pin 1, which then reads a “1” to the program. At switch off (read as 0), this then unconnected pin 1 may randomly “float” between 0-1 values, since it’s not strictly connected to anything. A high value “pull down” resistor (~10kΩ) solves this by providing a weak but firm connection to the ground rail. The opposite effect may be organised, if needed, with a similar “pull up” resistor to the positive supply. Flicking the switch on just instructs the remote PICAXE to sound its piezo more urgently and at a higher tone. Pauses at each end can easily be ad- justed (ex. pause 500 = ½ sec delay) to give LED & sounder synching. Of course a further data link could have been added, perhaps for the remote to “handshake” signal back to the local unit about its state and thus regulate and control the data flow. Just a one way (simplex) wiring has been set up initially to help avoid your possible “which is which” confusion and allow minimalist (wired) links. Wireless linking An appealing extension of this circuit uses prebuilt hybrid 433.29MHz UHF radio control modules at each end. These quite cheap and readily-available devices were apparently developed for licence-free radio controlled garage door opening, with SMD circuitry on the SAW transmitter (Surface Acoustic Wave – a kind of enhanced piezo oscillator) small enough to fit in a key-chain and generate a few millwatts, even with a near flat (2-12V) battery. And here’s the proof of the pudding. OK, so here it’s only over a few centimetres but it could be many hundreds of metres with suitable antennas. The scanner at rear is simply monitoring the 433.29MHz data stream. www.siliconchip.com.au The sensitive receiver is slightly larger, and needs a steadier supply (4.5V-5.5V) – it’d normally be indoors of course supplied from the mains via a plugpack and 7805 perhaps. They often pair with Holtek encoder/ decoder ICs but seem almost made for wireless Picaxe linking, since their convenient “serial data in” (Tx) and “serial data out” (Rx) pins almost beg for action! PICNIK protoboard construction proved simple, with supply wiring and data pins a breeze to connect. The only code changes related to data rates being lowered to 300 and made true (T) – N did not turn on the transmitter. Pins on each module allow a 50Ω antenna too, perhaps resonant quarter-wave uprights (~175mm wire slightly coiled for compactness). To help initial set up a scanner or other radio receiver capable of covering 433.29MHz may greatly assist -you’ll hear a scratchy ASK (Amplitude Shift Keying) wideband signal as the data goes out. Naturally range was of keen interest and even with the simple antenna strong line-of-sight signals were deJuly 2003  77 The 433MHz receiver and transmitter in place on the protoboard in the PICNIK box. We’re not attempting to show any wiring for these because every manufacturer uses a different pinout! Suffice to say that you feed data from the transmitter PICAXE port4; (pin 3) in to the data in pin on the 433MHz transmitter and take data out to PICAXE receiver from the data out pin on the 433MHz receiver. Now that’s pretty straightforward, isn’t it! References and parts suppliers . . . (also refer to previous months articles) 1. Many web sites have valuable insights into the last 200 years (semaphore to cellular!) of data communication techniques and “brick walls “. The lucid “ Brief History of Datacomms.”– www. k12.hi.us/~telecom/datahistory.html is typical. 2. Wireless data modules from Computronics, WA (type TWS/RWS) www.computronics.com.au or Commlinx, Tas (type TLP/RLP) www.commlinx.com.au ~A$8 each, but pinouts may vary. 3. Tx/Rx module datasheets via Reynolds Electronics (Rentron USA ) www.rentron.com, or Laipac Technology (Canada) - www.laipac.com 4.Oatley Electronics (NSW)- www. oatleyelectronics.com sell more sophisticated UHF data units (ref. June 2003 Silicon Chip article ), as do Chipcon – www.chipcon.com 5. LIPD (Low Interference Potential Device) regulations - www.acma.gov.au 7. Author’s ever-updating “08” web page – www.picaxe.orconhosting.net.nz, shows simple 433MHz antenna suitable longer range DIY wireless data links. 78  Silicon Chip tected at 100 metres. A simple directional Yagi UHF antenna at each end could push such links to a few km! Indoor ranges of some 30m, influenced of course by building materials (especially reinforced concrete), would normally nicely cover a suburban property (and maybe next door, although that is probably not legal). Receiver “settling” time, as outlined earlier, proved an issue however. Data often was missed by the receiver busy on task execution, and considerable preamble “massaging”, perhaps by longer gaps between data (200mS ?) or pull up resistors may be needed for links as reliable as the wired ones. It’s recommended that you wrestle with these tweaks yourself, since PICAXE workarounds are so easy to cut and try that you may be rewarded with immense insights into such classic datacomms frustrations as noise and receiver overload. A possible application, with PICAXE-08s at both ends, relates to “keeping your dog in the yard”. A small transmitting collar module could wake up (via the “sleep” command) and send a data pulse every 5 seconds or so to the nearby receiver. Decoding software, suitably set up to remain silent when pulses were correctly received, would sound an alert only when this pulse train was absent, presumably because the sender had “jumped the fence” and moved out of range. Visions of lively beeps signalling “Fido’s out again” of course arise! Such wandering animals, vehicles, or bags etc could maybe then be located by simple radio direction finding (RDF) if still nearby, with your listening unit then switched to a “find Fido“ mode. Several coded senders could even be monitored and identified by just a single receiver – coloured winking LEDs or varying tone/duration beeps would give specific ID. Such “fail safe” circuits have wide application but the opposite function offers productivity too. Aside from short range emergency location (avalanche rescue perhaps?), consider an approaching bus fitted with a data sender, coded for perhaps the route number, so that a suitable alert is triggered as the bus drew closer to the stop. Intending passengers could then be ready to board before the bus drew up, with obvious time saving benefits all round- it may also encourage public transport use. Even your mum’s handbag might get fitted with such a sender, so as to alert “Yikes – mum’s almost home –tidy up the kitchen fast “ as she approaches! SC Stay tuned. NEXT MONTH: Memory, LCD driving and program economising You think that by now we’d be done, With “08s” exhausting their fun, But the darlings of course, Still have to do Morse!, Before their big brothers can run. www.siliconchip.com.au