XBee wireless with I/O expander schematic

cianyd

New Member
I've just ordered the parts to build this circuit, which is basically a wireless control system with a security mechanism.

This is my first schematic slash original circuit design. I'm not very used to electronics so any help with this circuit would be great. I still don't fully understand how resistors work, and chose the values based on what i've seen others using.

The main components are an XBee-PRO wireless module, (2x) Picaxe 18X microprocessors, and (2x) MCP23017 I/O expanders. The entire circuit runs on 3.3v.

The main Picaxe 18X is connected to the XBee-PRO wireless module to communicate with other control boxes. It is also interfaced with two MCP23017 I/O expanders, providing a total of 32 inputs and outputs which are in turn connected to 16 input NO momentary push buttons and 16 output LEDs.

The security part of the system has its own Picaxe 18X connected to a 12-digit keypad, along with two input NO momentary push buttons and two output LEDs. It has a one way connection to the main Picaxe 18X which it uses to enable and disable the entire system.

Any suggestions/corrections? Cheers guys!! :)

http://www.getbweb.com/stuff/controlsch.gif

 

hippy

Ex-Staff (retired)
It looks okay to me on a brief examination, with the following comments -

1) It's wise to add some 100nF capacitors across the +V/0V rails, one per chip, one near the XBee and one near PSU input.

2) With the PSU being 3V3 there is no need for the voltage dividers between the PICAXE and XBee.

3) You need 4K7 pull-ups on the SCL and SDA lines for I2C.

I haven't otherwise checked the XBee interface wiring ( cannot remember what it should be ). It has a capability to control a LED when communicating with another and another to show signal strength. It would be a good idea to connect those as well so it can be used and tested in loop-back mode ( without a PICAXE ). Adding a 3-pin molex link which selects XBee Transmit input between PICAXE output and XBee Receive output would also be helpful for that.
 

cianyd

New Member
Cheers hippy, much appreciated :)

Ive done all the modifications you suggested. I'll do a breadboard prototype once all the parts arrive. Now for the waiting game.
 

profmason

Member
Xbee

You might want to look at my quickie writeup on using the Xbee with a picaxe. You will probably want to put a couple of LEDS on the status indicators of the XBee so you can see if it is getting the transmission.
http://profmason.com/?p=414
The Xbees are great parts! I ended up using them as part of my computer vision platform.
good luck!
 

cianyd

New Member
Cheers profmason, you article pointed out a simple thing I hadn't planned for straight away which is that I didn't realise the XBee needs to be set to run at 2400bps.

I'll post up here once i've put everything together.

Thanks again!
 

cianyd

New Member
Anyone know how to use these MCP23017 chips?

I've spent a solid 8 hours trying to get them to work with no luck, searched the forum but nothing works so i'm back to square one.

All i'm trying to do is set both B banks to inputs for the switches and both A banks to outputs for the LEDs.

Any help appreciated!
 
profmason - your documentation could not have come at a better time!!!!! I am starting to embark on my next robot which I wanted to incorporate Xbees, but I wasn't quite sure exactly how to do it... I can't thank you enough for taking the time to document your efforts! Very much appreciated!!!!!

Steve
 

BCJKiwi

Senior Member
Re MCP23017
Not used these myself - used MCP23016 instead.

However there are plenty of references and code snippets on the forum

Just search for;
MCP23017
 

cianyd

New Member
I read every thread on both the 23016 and 23017 and couldn't get any working code out of my understandings.

This is what I have so far, which isn't working..

main:
i2cslave %01000000,i2cslow,i2cbyte
writei2c $10,($00) 'makes all GPB pins outputs
writei2c $13,(%11111111) ' turn on all GPB outputs
writei2c $00,($255) 'makes all GPA pins inputs
writei2c $06,($255) 'makes all GPA pins have pullups (switches are attached)
goto main

Anyone?
 

cianyd

New Member
I also added a 4k7 resistor going to the positive rail from the 23017's RESET pin as someone mentioned in one of the threads. Was this the right thing to do?
 

BCJKiwi

Senior Member
There is an absolute mine of information regarding i2c on this website.
This
http://i2c-bus.org/Typical-I2C-Bus-Setup.537.0.html
link is to the page with the specific requirements for the physical connections.

The 4k7 pullup resistors (Rp on the diagram) are critical to ensure the bus behaves properly - note there should be only one set for the entire bus regardless of how many devices you have on the bus - usually located somewhere near the microprocessor. The resistors are critical but not the value. Lower values (have seen down to 1K8 referred to) will enable the bus to switch between states faster but 4k7 is the norm.

The Rs and Cc Cs components do not need to be added - they represent the inherent factors in the circuit but the Rp resistors do need to be added.

Also I have found the bus needs to be tidy with all connections made and all devices powered - i.e no loose wires on your breadboard for the i2c bus.

The thread;
How to control a MCP23017 16 bit I/O Extender
seemed the most relevant to me.

I have included a sample working code snippet in the code snippets section entitled
MCP23016 I/O expander driving LEDs PICAXE 28X1 hi2c sample code
The MCP23017 is a bit more complicated but you should get the general idea from this.

Trust this helps.
 
Last edited:

lbenson

Senior Member
One gotcha that I ran into with i2c was that the device I was using (4K eeprom 24LC32) failed if I just started right in on it at the beginning of the program. I had to insert a pause (I think I used 500ms), and then all worked perfectly. I also put a "pause 10" between writes.
 

cianyd

New Member
I2c Programming

Managed to work it out myself. Here is some test code, complete with comments:

init:

symbol highLED = b0
highLED = %11111111

pause 500
i2cslave %01000000,i2cslow,i2cbyte 'Communicate chip1
writei2c $0A,(%00000000) 'Set IOCON(A) Bank = 0
writei2c $0B,(%00000000) 'set IOCON(B) Bank = 0
writei2c $00,(%11111111) 'All IODIR(A) = Input
writei2c $01,(%00000000) 'All IODIR(B) = Output

main:

readi2c $12,(b1)

if b1 = %10000000 then sw1 'activate sw1 code
if b1 = %01000000 then sw2 'activate sw2 code
if b1 = %11000000 then multitap

goto main

sw1:
writei2c $13,(%00000001) 'sw1 GPIO(B) pin1 = high

goto main

sw2:
writei2c $13,(%00000010) 'sw2 GPIO(B) pin2 = high
goto main

multitap:
writei2c $13,(%00000000) 'All GPIO(B) pins = high (0)
pause 200

goto main

This is used together with my schematic in the first post of this thread for i2c MCP20317 in conjuction with the PicAxe 18x chip.
 
Last edited:
Top