Wireless problem

peatmoss

New Member
Hi,

I’m trying to get a 14m to talk to a 08m over a serial wireless link. It seems the data is corrupt on the receiving end. I’m using this 4800 baud wireless pair http://www.sparkfun.com/commerce/product_info.php?products_id=7815

Here is the transmitter code on the 14M:
Main:
b2 = 5 'test value
serout 0, N2400, ("UUUUUUUUUUUUUTW", b2)
pause 5000
goto main

And the receiver code on the 08M:
main:
serin 4, N2400, ("TW"), b2
b0 = 11
SerTxD (#b0, 13, 10)
SerTxD (#b2, 13, 10)
pause 1000
goto main

In the terminal window I get values like 251 250… for b2.
I have tried different baud rates but still get the same.

I failed to notice the 14M does not do 4800 with serout. Could it be that this module needs to be run at 4800?

Thanks,
Pete
 

moxhamj

New Member
First test - does it work with the wires joined together ie no radio link. Join pin 0 of 14M to pin 4 of the 08M?

Nothing wrong with the code. The modules will work at any baud rate up to 4800 so 300, 1200, 2400 etc will be fine.

What is the power supply and associated bypass capacitor values?
 
Last edited:

peatmoss

New Member
Dr Acula,

Thanks for for publishing your information which inspired me to do this project.

I got it working by using 4800 baud. I’m not sure why it works with 4800. The power supply is a lm317 and 100uf and .1uf caps.

Here is the transmitter code on the 14M:
Main:
b2 = 5 'test value
serout 0, N4800, ("UUUUUUUUUUUUUTW", b2)
pause 5000
goto main

And the receiver code on the 08M:
main:
setfreq m8
serin 4, N2400, ("TW"), b2 ‘here is where I thought I could not use 4800
setfreq m4
b0 = 11
SerTxD (#b0, 13, 10)
SerTxD (#b2, 13, 10)
pause 1000
goto main

Wow, this is going to be cool. Thanks!
 

manuka

Senior Member
Whoa- slow down!?

PeatMoss: Dr-A has pretty much issued a prescription, but it's perhaps worth mentioning that wireless datacomms woes can often be better handled with- YIKES- slower data rates. Even 2400bps can be too fast with swampy conditions, & often you have to step right back to 300bps. Even slower can be achieved by PICAXE UNDERclocking - how does just a few bps strike you?!
 
Last edited:

moxhamj

New Member
Great to hear it is working. Manuka is right and certainly one can get longer range by using slow baud rates - eg a few bps is essentially morse code speed and it does help troubleshooting. Manuka and I are still brainstorming various long range options - 1Mhz, 27Mhz, 433Mhz and 2.4Ghz are some of the interesting bands to play with. There are lots of modules that go about 50 metres but it gets tricky to go further and stay within the law and not upset other radio users.

Just out of interest, once you get these modules working maybe set one up sending a signal every few seconds, and take a receiver out for a bit of a walk and see how far the signal can go.

BTW, I'm not the wireless expert. My max range is 500 metres but Manuka has sent a signal right across Wellington harbour. I takes me hat off to 'im.
 
Last edited:

manuka

Senior Member
Wellington Harbour is ~10km across & allows great line of sight links from my usual eagles nest test spot on a neighbour's BBQ deck => www.usbwifi.orcon.net.nz/alfaaudit.jpg,which gets especially well used at WiFi 2.4GHz ! As radio waves increasingly behave like light as frequency increases,by UHF things are almost WYSIWYG. Obstructing vegetation & rolling terrain (as in Dr_A's Adelaide hills) can be a very wet blanket indeed. Numerous workarounds exist, but most involve a trade off between budgets, antenna sizes & -oh yes- regulations...
 

peatmoss

New Member
Wellington harbour, that’s a good distance!

Do you guys have any idea why it only works at 4800? Is it possible the module is set for 1 baud rate? I never heard of that before. On modems usually slower is better.

I’ll try some more experiments to see if I can use a slower rate. I used the CRC code from http://galia.fc.uaslp.mx/~cantocar/microcontroladores/PICAXE/PICAXE_WIRELESS_INTERFACING.HTM . I’m sending every 5 seconds 3 bytes and it gets a checksum error about 1 out of every 15 or so. This is at about 40 meters apart through a house. I’d rather have distance than speed and 300 baud would be fine.

I’ll do a range test next weekend and let you know how it goes. Also I’m driving the transmitter at 5v and it states that 12v will increase the range. I plan to switch to 12v.
 

Technical

Technical Support
Staff member
Do you guys have any idea why it only works at 4800? Is it possible the module is set for 1 baud rate? I never heard of that before. On modems usually slower is better.
4800 @ 4MHz = 2400 @ 8MHz
ie if you setfreq m8 2400 willl be doubled!
 

peatmoss

New Member
Thanks Technical. I used the code below for 4800 baud:
TX
serout 0, N4800, ("UUUUUUUUUUUUUTW",b0, b1, b2)
RX
setfreq m8
serin 4, N2400, ("TW"), b0, b1, b2
setfreq m4

For some reason this does not work:
TX
serout 0, N2400, ("UUUUUUUUUUUUUTW",b0, b1, b2)
RX
serin 4, N2400, ("TW"), b0, b1, b2

I tried other rates as well. I was thinking the TX and RX radio modules are somehow set to 4800.
 

manuka

Senior Member
PM- in haste so brief! These 433 MHz ISM OOK (On Off Keying) units usually work at whatever data rate you feed them & are not fixed. Are you mixing up the UUUUU "wakeup alerts" (ASCII 85 =10101010) with the "whatever" conditioner? The latter must match on the serout & serin of course. What are the exact models you have? Most tx will indeed run to 12V, but the rx are pretty picky at 4½-5½V I've found.

Consider a "cotanga" Yagi at both ends for range boosting => www.picaxe.orcon.net.nz/yagi433.jpg Stan
 

moxhamj

New Member
With your code snippets, it would indeed appear that these modules are fixed for 4800 baud. I can't think of any other explanation.

To boost the range the cotanga would be plan A. Then if that isn't enough, do a search for yagi 433 on google as there are lots of recipies out there for building yagis with more elements. I've used pieces of 2mm fencing wire cut to the right length and a broomstick or 20mm pvc pressure pipe. If you drill the holes the same size as the wire they don't even need to be glued in. Total cost of a yagi can be under $10 but they do take a while to build as all the bits of wire have to be the right length. You can mount the Tx/Rx units right up in the yagi in the middle of the dipole and then cut out losses from coax cable, though some attention needs to be paid to weatherproofing.

How far do you need to send a signal?
 

peatmoss

New Member
:confused:I finally got my wireless link in place and working. I have a 14m on the transmitter and a 08m on the receiver. I decided to swap out the 08m for a 14m to get the extra pins to drive a led array. I can’t get the 14m to work. It never receives any packets.

I tried calibfreq to see if the timing was off but it did not help. I'm using pin 4 (physical pin 3) for the serin.

Here is the code for the transmitter:
Code:
#Picaxe 14m
	SYMBOL  RECEIVER_CODE   = 0 ' 0 .. 15
	SYMBOL  SENDER_CODE     = 0 ' 0 .. 15
	SYMBOL  TX_PIN          = 0
	SYMBOL  TX_BAUD         = N4800
	SYMBOL  POWER_ON_PIN    = 5 'this is pin 8 - bottom right
	SYMBOL  POWER_UP_DELAY  = 500
	SYMBOL  PREAMBLE_LENGTH = 5
	SYMBOL  MAX_DATA_LENGTH = 4
	SYMBOL  PREAMBLE_BYTE   = $AA
	SYMBOL  SOM_BYTE        = $C5
	SYMBOL  EOM_BYTE        = $5C
	SYMBOL  POSTAMBLE_BYTE  = $3A
	SYMBOL  dataLength      = b0
	SYMBOL  byteNumber      = b1
	SYMBOL  bytePtr         = b2
	SYMBOL  byte1            = b3
	SYMBOL  bit             = b4
	SYMBOL  k               = b5
	SYMBOL  crc             = b6
	SYMBOL  POLYNOMIAL      = $8C

	PowerOnReset:

    MainLoop:

		GOSUB CreatePacket
		GOSUB SendPacket
		PAUSE 5000

		GOTO MainLoop

	CreatePacket:

		'first get the outside voltage b8
		readadc 4,b8
		'now get the temp b9
		ReadTemp 0, b9	' read into word

		dataLength = 2
		POKE $50,b8
		POKE $51,b9
		RETURN

	Sendpacket:

		' On entry, 'dataLength' contains the number of bytes
		' of data to send. The bytes of data are stored in SFR
		' RAM from location $50 upwards.

    CalculateCrc:

        crc = 0

        byte1 = SENDER_CODE * $10 | RECEIVER_CODE
        GOSUB CrcAdd

        bytePtr = $50

        FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byte1
          bytePtr = bytePtr+1
          GOSUB CrcAdd
        NEXT

    PowerUpTransmitter:

        HIGH POWER_ON_PIN

        PAUSE POWER_UP_DELAY

    SendPreamble:

        FOR byteNumber = 1 TO PREAMBLE_LENGTH
          SEROUT TX_PIN,TX_BAUD,(PREAMBLE_BYTE)
        NEXT


    SendStartOfMessage:

        SEROUT TX_PIN,TX_BAUD,(SOM_BYTE)

    SendReceiverAndSenderCode:

        byte1 = SENDER_CODE * $10 | RECEIVER_CODE
        SEROUT TX_PIN,TX_BAUD,(byte1)

    SendDataLength:

        SEROUT TX_PIN,TX_BAUD,(dataLength)

    SendData:

        bytePtr = $50

        FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byte1
          bytePtr = bytePtr+1
          SEROUT TX_PIN,TX_BAUD,(byte1)
        NEXT

    SendChecksum:

        SEROUT TX_PIN,TX_BAUD,(crc)

    SendEndOfMessage:

        SEROUT TX_PIN,TX_BAUD,(EOM_BYTE)

    SendPostamble:

        FOR byteNumber = 1 TO MAX_DATA_LENGTH
          SEROUT TX_PIN,TX_BAUD,(POSTAMBLE_BYTE)
        NEXT

    SentPacket:

        LOW TX_PIN
        LOW POWER_ON_PIN

        RETURN

    CrcAdd:
        FOR bit = 0 TO 7
          k = byte1 ^ crc & 1
          IF k = 0 THEN CrcAdd1
          k = POLYNOMIAL
        CrcAdd1:
          crc = crc / 2 ^ k
          byte1 = byte1 / 2
        NEXT
        RETURN
And here is the receiver code:
Code:
#Picaxe 14m
        SYMBOL  RECEIVER_CODE   = 0 ' 0 .. 15

        SYMBOL  RX_PIN          = 4
        SYMBOL  RX_BAUD         = N4800

        SYMBOL  MAX_DATA_LENGTH = 4

        SYMBOL  PREAMBLE_BYTE   = $AA
        SYMBOL  SOM_BYTE        = $C5
        SYMBOL  EOM_BYTE        = $5C
        SYMBOL  POSTAMBLE_BYTE  = $3A

        SYMBOL  dataLength      = b0
        SYMBOL  data1           = b1
        SYMBOL  data2           = b2
        SYMBOL  data3           = b3
        SYMBOL  data4           = b4
        SYMBOL  data5           = b5
        SYMBOL  data6           = b6

        SYMBOL  byteNumber      = b7
        SYMBOL  bytePtr         = b8
        SYMBOL  byte1            = b9
        SYMBOL  bit             = b10
        SYMBOL  k               = b11
        SYMBOL  crc             = b12
        SYMBOL  code            = b13

        SYMBOL  POLYNOMIAL      = $8C

    PowerOnReset:

        GOSUB ClearErrorLed

    MainLoop:

        GOSUB ReceivePacket
        GOSUB ShowPacket

        GOTO MainLoop

    ReceivePacket:

        'setfreq m8
        SERIN RX_PIN,RX_BAUD,(PREAMBLE_BYTE,SOM_BYTE), code, dataLength,data1,data2,data3,data4,data5,data6
        'setfreq m4

    CheckDataLength:

        IF dataLength < 1 THEN Failed
        IF dataLength > MAX_DATA_LENGTH THEN Failed

    CheckReceiverCode:

        byte1 = code & $0F
        IF byte1 <> RECEIVER_CODE THEN Failed

    SaveDataForUseLater:

        POKE $50,data1
        POKE $51,data2
        POKE $52,data3
        POKE $53,data4
        POKE $54,data5
        POKE $55,data6

    CheckEomByte:

        bytePtr = $50 + dataLength + 1
        PEEK bytePtr,byte1
        IF byte1 <> EOM_BYTE THEN Failed

    CheckChecksum:

        crc = 0
        byte1 = code
        GOSUB CrcAdd

        bytePtr = $50
        FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byte1
          bytePtr = bytePtr+1
          GOSUB CrcAdd
        NEXT

        bytePtr = $50 + dataLength
        PEEK bytePtr,byte1
        IF byte1 = crc THEN ReceivedPacket

    Failed:

        GOSUB SetErrorLed
        GOTO ReceivePacket

    ReceivedPacket:

        GOSUB ClearErrorLed
        RETURN

    CrcAdd:
        FOR bit = 0 TO 7
          k = byte1 ^ crc & 1
          IF k = 0 THEN CrcAdd1
          k = POLYNOMIAL
        CrcAdd1:
          crc = crc / 2 ^ k
          byte1 = byte1 / 2
        NEXT
        RETURN

    ShowPacket:

        byte1 = code / $10
        SERTXD(#byte1,"|")

        bytePtr = $50
        FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byte1
          bytePtr = bytePtr+1
          SERTXD(#byte1,"|")
        NEXT

        SERTXD($0D,$0A)
        RETURN

    SetErrorLed:
        SERTXD("BAD PACKET",$0D,$0A)
        RETURN

    ClearErrorLed:
        RETURN
Does anyone have any suggestions? I also have an 18x I may try if I can&#8217;t get it to work.

Thanks,
Pete
 

peatmoss

New Member
One thing I forgot to mention is the serin pin is tied directly to the wireless serial output. Do I need to add a 10k resistor to tie the pin low or high?

I replaced the 14m with a 08m on the same circuit board since the pinout is similar. I found the 08m works just fine. It must be a timing issue with the 14m.

Thanks,
Pete
 
Last edited:

peatmoss

New Member
I tried everything and could not get the 14m to work. It&#8217;s firmware is 9b. I swapped in a 08m and tied it serially to an 18. I can now get an additional 7 outputs. My only problem is I am out of program space. Can anyone suggest a more compact way to do the following?

IF byte1 > 50 THEN serout 2,T2400,(%01000000) EndIf
IF byte1 > 75 THEN serout 2,T2400,(%00100000) EndIf
IF byte1 > 90 THEN serout 2,T2400,(%00010000) EndIf
IF byte1 > 120 THEN serout 2,N2400,(%00001000) EndIf
IF byte1 > 150 THEN serout 2,N2400,(%00000100) EndIf

I need to add 2 more if statements to control my 7 leds. I'm using 253 bytes now.

Thanks,
Pete
 

hippy

Technical Support
Staff member
@ peatmoss : As the 'run out of memory' is in the sending 08M, if there's room in the 18, instead of deciding which bit pattern to send, you can send the byte1 value and have the 18 decode it and set the appropriate LED(s).
 

peatmoss

New Member
I finally got my wireless thunderstorm monitor finished. Thanks to everyone for their input. I’m already thinking of improvements and will be ordering more parts tomorrow.

It’s a device to wirelessly log the voltage in the atmosphere and sound an alarm when the danger of lightning is possible. It’s based on an article by Thomas Scarborough in Everyday Practical Electronics in November 2004. It uses a high input impedance op amp (TLO71) to measure the voltage between ground and about 2 meters. So far it’s been interesting to watch a graph of the daily changes.

If anyone is interested I will post a schematic and the code. I also have a .net graphing application that may be useful for other projects.

The wireless modules I used were able to easily go 100 meters with simple wire antennas, any further and I started to get a lot of checksum errors.

Thanks,
Pete
 

manuka

Senior Member
Great project- wish you'd mentioned this initially however, as we maybe could have offered more on target ideas... Thomas Scarborough (who in fact is a man of the cloth in Capetown- South Africa) & I are in touch on assorted educational electronics ideas- he'd probably have helped you directly on this. Stan
 

peatmoss

New Member
Thanks Stan. It’s great to know that you and the Reverend are friends! Let him know I really enjoyed his article. I would also be interested if he has made any changes or improvements.

Pete
 
Top