Picaxe to/from Picaxe comms over 2 wires?

Haku

Senior Member
I'm having great fun tinkering with Picaxe's initally bought an 18X to control my bike light setup with 300LED front light (code done, need to physically finish the lights), but now I'm tinkering with various inputs/outputs/communications to work out wether future projects are feasable, but I'm stuck on something:

I programmed up two 08M's to communicate to each other through serial, one way serial comms through just two wires (ground & signal) works a treat but I couldn't get two-way comms using just two wires working.

My thought on the idea was for each 08M to 'listen' to pin4 and when it goes high use SERIN on pin4, but to stop pin4 input from floating and accidentally triggering the SERIN command I had to ground it with a 10k resistor and now the serial signal doesn't work.

Does anyone else have an idea how to do two way comms with just two wires?
 

kranenborg

Senior Member
Hello Haku,

When you are doing bidirectional comms over a single line between two picaxes you need some kind of arbitration mechanism in order to decide who is allowed to send. Using a very simple diode-mixing network (search the forum for "diode-mixing") between the two nodes and an interrupt-driven "after you"-type protocol you should have some real fun in designing and realizing your own, working solution!

I myself designed and implemented a generalized form of such a network called "SerialPower"; it is a multi-drop network based on a single communication line that allows any node connected to it to communicate with any other node, irrespective of the direction and number of nodes connected. Key to it is an extra, application-independent node that generates communication timeslots on request. Whenever a node puts a message on the network, all other nodes temporarily stop with what they were doing, interpret the message and decide whether they want to do something with it. In this way a loosely-coupled distributed processing system is defined where all nodes/processes are aware of each other (in contrast to other serial protocols like i2c and SPI where slaves do not "see" each other directly and thus a single master - multiple slave topology is enforced) .

As an option you can even combine power delivery and serial communication, resulting in a true two-wire solution with network-powered nodes. You can find a full description (with a link directly in the first message) via the following link: http://www.picaxeforum.co.uk/showthread.php?t=7694

/Jurjen
 
Last edited:

moxhamj

New Member
I would thoroughly recommend kranenborg's circuit. He is our resident forum 2 wire comms expert and the circuit works very well and does the power as well as the data.
 

hippy

Ex-Staff (retired)
Two-wire serial can be done in a Master-Slave setup by simply reversing the input to output and vice-versa. Untested, but something like this ...

Code:
'                  ___
'  Master >---.---|___|---.---< Slave
'            .|.   220   .|.
'            | |         | |
'            |_|10K      |_|10K
'             |           |
'      0V >---^-----------^---< 0V 

Master:
  Pause 1000
  Do
    SerTxd( #b0 , " " )
    SerOut 4, N2400, ( b0 )
    SerIn 4, N2400, b0
  Loop

Slave:
  SerIn 4, N2400, b0
  Do
    b0 =  b0 + 1
    SerOut 4, N2400, ( b0 )
    SerIn 4, N2400, b0
  Loop
The 220R is essential. Without it, if both PICAXE sre each outputting, one high the other low, the PICAXE I/O can be destroyed. The 10K are to keep the signal lines at 0V when both PICAXE's are as input.
 
Last edited:

kranenborg

Senior Member
Hippy has proven again that he's the real expert as he provided the solution that is elegant and simplest both from the hardware and software point of view (his solution provides an "after you" solution but does not require interrupts) and still sufficient for the task. SerialPower is heavily based on hippy's expertise actually ...

In general "SerialPower" might be overkill if you have a 1 master - n slave configuration. See hippy's excellent treatise on this subject: http://www.hippy.freeserve.co.uk/picaxeio.htm#Serial_Links_Between_Picaxes or
http://www.hippy.freeserve.co.uk/picaxesi.htm

When the 1 master - n slave configuration cannot be used anymore you probably need something like SerialPower though

/Jurjen

PS Corrected first link as it is picaxe-to-picaxe comms here, not pc-to-picaxe
 
Last edited:

Haku

Senior Member
Thanks for the quick replies everyone, read them at lunchtime but didn't get a chance to reply then as I wan't near my Picaxes to do testing.

kranenborg, amazing design there, but a little over-complicated for my needs right now.
I'll give hippy's solution a try in a minute, breadboarding is so easy for concept testing.

My initial reason for wanting to do picaxe-to-picaxe communication is for remote monitoring of a solar power setup, which a picaxe should be able to do and more should I need it. Funny thing is when I ask electronics engineers about how long a cable can a serial signal be sent down they all have 'that look' on their faces when I say the cable I've already setup is about 35 meters. But I tested it with a picaxe at each end and it works a treat at 2400baud :)
 

Haku

Senior Member
Got distracted by the final of BB :eek:

I tried the circuit with the two 10k & 220 resistors and it works perfectly, both 08M's can make the signal line go high to notify the other one to get ready to receive a serial signal, then receive the signal and go back into listening mode, meaning each picaxe can do their own thing whilst still listening out for a message from the other.
Each 08M had the same code programmed into them for the test.

Thank you so much hippy :)
 

moxhamj

New Member
Re "Funny thing is when I ask electronics engineers about how long a cable can a serial signal be sent down they all have 'that look' on their faces when I say the cable I've already setup is about 35 meters."

I have just tested a picaxe to picaxe signal 1200 baud, 0/12V going 500 metres via two wires in open air. So 35metres should be fine.
 

chopperwalker

New Member
I got a 20x2 and a 08m working great. Could this (hippy's suggested circuit) be used for multiple slaves? I know I could do the code, but could you add another 08M onto it through a second 220 ohm to the master and a third 10k to ground?
 

hippy

Ex-Staff (retired)
This should work with multiple slaves. I would use 220R from the master to each slave and all I/O pins having a 10K pull-down which matches what you suggest. You have to modify the master and slave to talk to each, untested ...

Code:
Master:
  Pause 1000
  Do
    SerTxd( #b0 , " ", #b1, CR, LF )
    SerOut 4, N2400, ( [b]"S1",[/b] b0 )
    SerIn 4, N2400, b0
    SerOut 4, N2400, ( [b]"S2",[/b] b1 )
    SerIn 4, N2400, b1
  Loop

Slave1:
  SerIn 4, N2400, ( [b]"S1"[/b] ), b0
  Do
    b0 =  b0 + [b]1[/b]
    SerOut 4, N2400, ( b0 )
    SerIn 4, N2400, ( [b]"S1"[/b] ), b0
  Loop

Slave2:
  SerIn 4, N2400, ( [b]"S2"[/b] ), b0
  Do
    b0 =  b0 + [b]2[/b]
    SerOut 4, N2400, ( b0 )
    SerIn 4, N2400, ( [b]"S2"[/b] ), b0
  Loop
 

chopperwalker

New Member
I tried this last night and it worked great. I used a qualifier byte "id" just as you have in your sample. I have all the slaves in/out line as an interrupt so they do their business until the master sends the line high. All begin to listen and if their ID is called they respond. All the slaves that weren't called as relieved by a serout to each from the master with a "clear serin" command.

One more question though, is it necessary for either the 08M or 20X2 to be modifying the pins through dirs or dirsC between switching from in/out? I have done the following on each side of a serout for the slaves:
Code:
	serin Master,N2400_4,(SensID),b2,b3
	let dirs = dirs | %10
	pause 100	
	if b2 = "T" or b2 = "P" or b2 = "L" then
		serout Master,N2400_4,(SensID,b2,b3,"3")
		serout LCD,T2400_4,("?n",b2,b3)
	endif
	pause 100
	let dirs = dirs | %10
	let dirs = dirs ^ %10
 

hippy

Ex-Staff (retired)
is it necessary for either the 08M or 20X2 to be modifying the pins through dirs or dirsC between switching from in/out?
Electrically it's not absolutely required ( the 220R's should protect the chips ) but the pins of all slaves should be made inputs and ideally immediately after the SERIN.

There's no need to make the pins output as SEROUT will ensure that happens. To turn the pins into inputs you can use the following ...

dirs = dirs &/ %0001000

and rather nicely for the 20X2 ....

dirsX = 1 << Master ^ dirsX
 

inglewoodpete

Senior Member
hippy's circuit has a 10k resistor at each end on the serial link. When using a series resistor of only 220r, you would only need one 10k pull-down (I suggest at the nominated 'master' device). The same would apply where multiple picaxes are networked.
 
Top