Let's Make Robots!

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?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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!



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

    input serpin     'pin 4 is an input
    blinkspeed = 300
    gosub talk   'make chip1 blink at rate 200
    high LED
    pause blinkspeed
    low LED
    pause blinkspeed

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

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



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.

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. 

I've been reading the manuals a lot on this subject as I wanted BoozeBot to have a lot of picaxes doing things like driving servos, monitoring sensors etc.

I'd put a 1K resistor between the pins of different chips. This way on powerup, before the pins have been configured there is no chance of damage. This is actually suggested somewhere in one of the manuals concerning digital I/O pins.

During serial communication, the resistors will have no effect as the pin on one side will be an output and the other will be an input.

No pull ups or downs should be required as the output pin (serial tx) will either be high or low.

Because chips like the 14M don't have a timeout command for serial in, they'll wait forever and do nothing else including driving servo outputs.I was going to set them up as slaves where they sit and wait for an instruction from a master, do it, and if neccessary send a response back. Then sit and wait for the next instruction.

Because I want to use multiple slaves and one master (a 28X1 or 40X1), I was going to use qualifiers to call each slave device by name.

check the second link in my post. It has a technique for using the interupt to avoid serin lockup for the most part.

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.



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.