Xbee and Picaxe

sunburnt63

New Member
Thanks to a previous thread, I am now trying to connect my picaxe18X with an Xbee module. I had a few questions pertaining to some code that was shown as an example though.

Code:
start:

symbol BAUD=T4800_4 'baud rate for comms (either set xbee to run at 4.8k or double picaxe speed using setfreq m8)
setfreq m8
symbol XBEEdataoutPIN=4'output 4 is used to send data to the XBee
symbol XBEEdatainPIN=7'input 7 is used to recieve data from the XBee

'power up xbee

high 7'take XBee RESET pin high
high XBEEdataoutPIN'take XBee DATA IN pin high
high 6'take XBee SLEEP pin high

main:

high 5'turn onboard relay on
high portc 1'turn onboard led on
serout XBEEdataoutPIN,BAUD,("Relay and LED on")

pause 1000

low 5'turn on board relay off
low portc 1'turn onboard led off
serout XBEEdataoutPIN,BAUD,("Relay and LED off")

pause 1000

goto main
According to the Picaxe manual2 for BASIC commands it says to use the N(inverted signals) for the Baud rate. However, in the picaxe tutorial for connecting to Xbee, they use a T(true) signal. It says to use the N signal when using simple resistor interfaces which I think I am using since I will not be including the MAX232 interface. However, it seems that the interface used in parts of the tutorial are simple resistor interfaces, but they still use the T signal. Is there any reason for the discrepancy, or does it not really matter which you use?

I am also confused about the baud they chose because they use T4800_4, and then setfreq m8. isn't T4800_4 supposed to be used at 4MHz, not 8? wouldn't T4800_8 be correct? I guess this all boils down to me being confused about BAUDMODE for the serin / serout commands. Thanks for the insight!
 

Dippy

Moderator
I can't speak for PICAXE + XBee kits specifically as I've never used one, but XBee requires a negative-going serial i.e. it idles high.
And the signal should idle high when no data is being transmitted.

You should be able to see from the BASIC Manual (serout) which syntax you need.
And look at the notes concerning the True polarity when using it the first time.

Note XBee default baud rate is 9600.
 

hippy

Ex-Staff (retired)
The XBee requires a Txxxx baud rate for both transmit and receive. It's a 3V3 device so needs resistors to get the transmit signal down from 5V the PICAXE puts out to 3V3 the XBee accepts as input. This is a potential divider on the PICAXE output as opposed to the non potential divider used for download interface to the PICAXE input. The 3V3 output from the Xbee can drive a suitable 5V PICAXE input directly.

I'm not sure about the baud rate chosen in the code you posted; stick to the advice in the XBee datasheet and use a Txxxx baud rate appropriate for the baud rate you have it configured for.
 

ciseco

Senior Member
Hi,

Dont worry about inversion or not, side issue. It's running at 8Mhz (double speed) and 4800bps (max speed of the software comms commnd "SEROUT")to give you 9600bps (what a stock out the wrapper an xbee is otherwise you'd have to set the speed of the xbee, more hassle than 1 line of code believe me).

It's the almost the simplest code you can write, i've stripped it further for you to the absolute minimum.

Simply chose an output, here my code uses output 4 on the 28x1 connect this to DIN on the XBee, Input 7 to DOUT, no resistors just wire them up.

YOU MUST RUN BOTH PICAXE and XBee at 3.3v! otherwise you'll damage XBee. Also on a 28x1 and others the ST inputs like more voltage, so hippy is right for some but not all PICAXE's. Again run at 3.3v you'll not need to worry. Not got a 3.3v regulator, no worries 2 x 1.2v rechargables will do you (about 3v with good charge).

Here's the code

main:
serout 4,T4800_4,("testing")
pause 1000
goto main

Job done, you are transmitting, you just need something to recieve with.


Miles

Tell you what, I've been meaning to do it for ages, I'll document getting one PICAXE to send to another over a pair of XBee,s and a way of dealing with proper level shifting for those who like staying at 5v. Give me till lunch and I'll post a link to it
________
video review
 
Last edited:

sunburnt63

New Member
I have 2 XBee's. One for Transmitting, and the other for receiving. They are hooked up to a picaxe 14M and 18X respectively. I am trying to send a number across the wireless link, and if it is detected at the receiver, turn on another output. Thank you for this code, but is this really all I need? I have the XBee's connected to power and GND, as well as inputs/outputs for the DIN/DOUT.

main:
serout 4,T4800_4,("testing")
pause 1000
goto main

For example, don't I need the setfreq m8 command to match baud rates? sorry if I am being thick, but I just want this to work. Cheers!
 

hippy

Ex-Staff (retired)
You either need to configure the XBee to operate at a default baud rate the PICAXE works at, or adjust baud rate and use SETFREQ to operate the PICAXE at the desired baud rate.

The following will allow a PICAXE to transmit at 9600 baud using an XBee -

#Picaxe 18X
Symbol TX_PIN =?
SetFreq M8
High TX_PIN
Do
Pause 2000
SerOut TX_PIN, T9600_8, ( b0 )
b0 = b0 + 1
Loop

A corresponding receiver will receive at 9600 from another XBee and display the value of data received on the Programming Editor's Terminal display ...

#Picaxe 18X
Symbol RX_PIN = ?
SetFreq M8
Do
SerIn RX_PIN, T9600_8, b0
SerTxd( "Rxd = ", #b0, CR, LF )
Loop
 

Dippy

Moderator
Xbee is just about the simplest RF device out there.
9600 baud by default.

Are you running PICAXE and XBee at ~3V?

If not post your circuit BEFORE you plug it all in.
 
Top