User manual
Simplifying the mapping of GPIO pins is only part of the power of the plaorms.py file. By having the plaorm
variable defined, you can take advantage of other special features of the various nodes:
from synapse.platforms import *
if platform == 'RF100':
sleepMode = 0
elif platform == 'RF200':
sleepMode = 1
sleep(sleepMode, 20)
On an RF200, sleep mode 0 results in a significantly higher sleep current than sleep mode 1 does. Mode 0 exists
for AT128RFA1 hardware configuraons that do not include an external ming crystal. But the RF200 does
include that crystal, so sleep mode 1 is preferred. Using a script like the one above, sleeping on either plaorm
will give the best efficiency.
The real “magic” part of this plaorm variable process is a lile more subtle than has been made evident so far.
The plaorm variable is available to Portal at compile me, rather than just being a run-me variable. So if your
SNAPpy script includes code secons condionally based on the plaorm variable, any parts that don’t apply for
the selected plaorm won’t even be included in the script loaded onto your node. This prevents incorrect code
from being run if the plaorm parameter is accidentally changed aer the code is loaded, and more importantly,
can significantly reduce the size of the image loaded into your node.
So far, the assumpon has been that the plaorm would be used only to disnguish between nodes based on
different underlying hardware. But you can set NV Parameter 41 to any value that suits your needs, and thus
have the plaorm variable be anything you like. (If you were to do so, you could sll explicitly include the GPIO
mappings by imporng synapse.RF200 or synapse.SM220 or the other appropriate mapping file to gain access to
GPIO constants for easy pin referencing.)
Defining your own plaorms could be useful in a situaon where you wanted to maintain a complete
applicaon’s code base in one source file, even though different devices used in your installaon required
different funconality.
For example, you may have different revisions of hardware connecng to your SNAP Engines, with discrepancies
in how things are connected, but wish to have only a single SNAPpy script code base to maintain. The difference
could be a simple as connecng an LED to a different pin, or making a serial connecon at a different baud rate.
Or, it could be much more complicated, where a “collectData()” funcon for one board revision makes a simple
serial connecon, while on a later board revision it makes an I
2
C connecon to harvest the appropriate
informaon.
Again, much of this could be accomplished with a user-defined NV Parameter as well. What NV Parameter 41
and the plaorm variable provide is access to this level of control at the point where your SNAPpy script is being
compiled before loading it into your node, which allows selecve control of which other SNAPpy modules are
imported into your script, and which helps reduce the code size of your script, leaving more script space for
more elaborate SNAPpy scripts.
30 SNAP® Network Operang System