20X2 as a 'serial data collector'

grim_reaper

Senior Member
Good morning.

I'm looking for a bit of advice, or hopefully someone's experience, of using a PICAXE for nothing more than tying several serial data streams together. Background information; I have several small PICAXE systems, using various chips, which monitor temperatures, switches, etc. One, for instance, monitors my aquarium temperatures and displays locally to an OLED display, another is connected to 3 PIR's in my workshop and triggers a sounder when an intruder (unauthorised child!) enters.
My most recent project has been connecting the aquarium system to my ethernet network, which works fine; it simply streams out some bytes every 10 seconds using SEROUT at T19200_16 to a cheap Taiwanese RS232 to TCP converter [quite chuffed with it!].

What I want to do now is to start integrating all the other 'sub-systems' together. Taking the workshop as a prime example - there are 3 PICAXE's, all outputting serial data (into thin air ATM), which I want to combine. This is the idea;

SCC idea.png

Obviously I plan on using the HSERIN/OUT for the ethernet side, to take advantage of the speed. The other connections will be 'standard' SERIN/OUT. The 20X2 will basically wait for inputs from all the subsystems, maybe looping through each input in sequence(?) then store any received data somewhere in RAM. At the end of the loop, the data would then be passed out to the ethernet network. Commands from the network would then be fed back into the subsystems in reverse fashion. So, my questions are...
Is this feasible? Can the 20X2 cope with checking up to 10 legs for serial inputs without missing anything?
Is there a sensible way to achieve this with interrupts?
Would I be better off using the multi-drop serial methods as described in this thread? I.e. using a smaller chip (08M2) to join a serial bus to the ethernet adapter?

Sorry if all that sounds a bit garbled and not well-thought-through, but I want to get a handle on whether it's a good idea before I start spending precious time on re-networking everything!

Thanks.
 

inglewoodpete

Senior Member
I've used a 28X2 as an I2C master, polling 8 I2C slave devices (these are 28X1s in slave mode). The master communicates with a Visual Basic application on a PC using the 28X2's hSerial port.

The 28X2 polls each of its slaves in turn, asking if there is any data to pass up to the PC. When the slave responds 'yes', the master reads the data from the slave and passes the data up to the PC. The PC can also download 'commands' and/or data to a specific slave when required.

I2C is great for interworking with multiple slave devices on one bus. However, you have the remember that only the X1 and X2 series PICAXEs can operate in slave mode.
 

hippy

Technical Support
Staff member
If you have four ( or more ) PICAXE slaves arbitrarily sending out data and a single PICAXE master trying to log all of those to create a single output stream you likely will lose data - It is like being a secretary writing down everything anyone at a meeting says; it will go okay until two or more start talking at the same time.

To make it work without losing data you need some method of making sure only one slave sends data at a time, either polling them for data in turn, or letting them indicate they have data and then choosing which is allowed to send.

You might be able to leave your slaves as they are, arbitrarily sending data, but then you will need another PICAXE between each slave and the master which can take unsolicited slave data and only pass it on to the master in the arbitrated manner described.

It can be done but can get complicated, especially if some slaves may be turned off or inactive at times or don't respond, and if there are slaves which require higher priority than others. A wired system will be easier than wireless and the simpler you can make the system the easier that will be to implement and debug and more likely to be reliable and robust.

As a prerequisite I would recommend considering the design of a digital home; having a network of light switches, door bells, temperature sensors, PIR and panic alarms, lights and relays, each with their own PICAXE ( one PICAXE per input sensor, one PICAXE per output controller ) and figuring out how to implement that so it works robustly. That will give a good foundation for what you need to do, and understanding of what the problems can be and how they can be overcome.
 

grim_reaper

Senior Member
Thanks for that hippy, nice and concise. I work with industrial control systems, so the whole philosophy is ingrained into my mind.
Regarding wired/wireless, all the AXE stuff is wired - I went with conversion to Ethernet to avoid the whole wireless serial Tx/Rx thing, since the wired Ethernet network in the workshop is just connected to my wireless network in the house via a bridge. I'm a .NET coder, so once the information is on the network I can play with it to my heart's content :D
I will definitely kick my research off in the direction of polling each slave in turn (with a short timeout to avoid offline slaves, as you mention). At the moment I'm just refining my packet definitions for the data itself. I'll post back when I have a few slaves chattering away; no doubt with some more intricate questions!
 
Top