Two Picaxes talking to each other

Wow, I seem to be asking a lot of questions lately… Let me know if I become a question “ho”… At any rate, I am working on the serout and serin commands to get 2 picaxes to talk to each other, I can’t seem to find a schematic in any of the manuals. Has anyone done this? If so, do I need any resistors? Pull-up, pull-down or otherwise?

I’ve done it with 3…you

I’ve done it with 3…you don’t need pullup or pull down, but I do use (10k)resistors as the connection wire. Just make sure your grounds are tied if you use different power supplies.

 

http://www.hippy.freeserve.co.uk/picaxeio.htm

this guy has great info on serial interfacing.

This is another very helpful link. I use this method in my setup. This uses the interupts to avoid serin lockup.

http://www.hippy.freeserve.co.uk/picaxesi.htm

You’re in luck!

I don’t beleive this! I just finished my test with 3 picaxe chips on 1 line. Only 1 minute ago. I thought I’d check the new posts… and there’s your question.

I use 08M chips because they have fully configurable input/outputs. That means you can change an input pin and use it with the serout command and the serin command. That cannot be done with any other picaxe chip.

But I also found a way to have a picaxe 28 communicate with 2 pins over the same line.

I just finished this so you’l have to wait a few minutes for the schematic and the pseudo code.

Schematics

SerialBus.jpg

I use a 22K resistor to pull the data line High.

The top two chips in the drawing use 1 pin for serial communication. This pin (pin4) is defined as an input. An interrupt will be triggered when the line is pulled low (low 4)by one of the other picaxes ; indicating they want to talk.

The interrupt routine starts the serin command on pin4 and wait for the message to arrive. In my test program it is a 4 byte message.the first byte is a dummy (27) followed by a number identifying the chip that the message is intended for. Followed by two bytes that contain the message (in this case a word variable that sets a delay-time for a blinking led)

After receiving (or sending) a message, all chips set the interrupt again and make pin4 an input.

The third/bottom picaxe 08M simulates a picaxe 28X1. It uses 1 pin as output only and keeps it high. i use a 4K7 resistor for that pin, because it must be small enough to send serial data and large enough to enable the other picaxes to pull the line low.

When the "fake" picaxe 28X1 wants to talk it pulls down the line with the output pin, waits for 50 milliseconds and starts to talk. It is important that this output pin is high whenever this picaxe is not talking. Otherwise it will keep the line low and make all the other chips wait indefinately for a message that will never come.

Finally. The fake 28X1 listens on a regular input pin. This can be done using the same interrupt routine as the 08M's use.

 

In my test setup the two pins on the bottom chip are used the other way around (ie. pin 4 is output and pin 2 is input) but swapping them made the drawing better.

Anyway. I was going to get some sleep and write a walkthrough with my code tomorrow, but I had to post a quick summary when I saw your post.

Code for one of the chips

symbol chipid=0 'we give this chip number 0

symbol serpin = 4
symbol talkbutton = pin4
symbol seraddr = b3 'address of serial device

symbol LED = 2
symbol blinkspeed = w0

init:
input serpin 'pin 4 is an input
blinkspeed = 300
w2=200
seraddr=1
gosub talk 'make chip1 blink at rate 200
main:
high LED
pause blinkspeed
low LED
pause blinkspeed

if blinkspeed > 500 then 'reset the other chip
'lets talk to chip1
seraddr=1
w2=75
gosub talk
seraddr=2 'and chip2
gosub talk
end if
goto main

talk:
setint off
if talkbutton=1 then
low serpin
pause 50
serout serpin, N2400,(27,seraddr,b4,b5)
endif
input serpin
setint 0,%00010000 'interrupt on pin4 when low
return
interrupt:
’ someone wants to talk
serin serpin,N2400,(27),seraddr, b4,b5 'b4 and b5 => w2
if seraddr=chipid then 'they are talking to us!
blinkspeed=w2
end if
setint 0,%00010000 'interrupt on pin4 when low
return

Thanks guys!

What a fantastic website we have here… Ask a question and boom goes the dynamite! I still a bit amazed that Mint and I seem to be working on the same problem at the same time! --Not to mention similar ideas about many smaller picaxes each doing their own task. At any rate, thanks again and I will post my results and findings as I get to them. Please respond in kind --Mint, I really want to see this “bank” of 08’s you got going in action!