A Few Notes on my First Steps with panStampsIntroduction IntroductionThis page is intended as a very quick run through on
setting up panStamps as
well as troubleshooting a few problems I had initially
with NRG on both debian
wheezy AMD64 and RaspberryPi and was originally written
in February 2015. I recently bought a few panStamps, a panStick and a shield after reading about them on the fhem forum. panStamps are small wireless modules that can be programmed using the Arduino IDE. They consume very little power and are ideal for monitoring of remote sensors etc. They are ideal for situations where running wires is either impractical or impossible. There is a lot of documentation
in the wiki and on first reading I was totally
lost. The documentation is very detailed and both example
code and sketches are provided. Do read it - and
perhaps go back and re-read it! In simple terms when a connected sensor has something to send it triggers an interrupt, waking the panStamp which then takes in, processes, and transmits that data - and goes back to sleep. What You NeedYou will need panStamps of course. Plan for one to use as a modem as well as one for each remote location - and maybe some spares to play with :) Make sure that one of your boards includes a sensor
(see the NRG
accessories), it will make your life much easier
starting out. The panStick is connected via USB and can be used for both programming the boards and connecting the modem panStamps to your computer to receive data from the others. For the RaspberryPi the RPi
shield is an alternative to a panStick, designed to be mounted on
the GPIO pins of a Raspberry Pi (all models) and
connects a modem panStamp
through the GPIO pins. Once you have decided what you need you will need to
order from the panStamp
webstore. My order arrived here in the UK within a few days.
v2 panStamps require a
different panStick and
the panStamps themselves
are now small PCBs that can be soldered to a
panStick or carrier board or used as they are.
See the wiki for more details.
Soldering notes...
The following relates to v1 panStamps, v2 require soldering
directly to a panStick
or carrier board but
the soldering technique is similar. Programming
The recommended version of the Arduino IDE is 1.6.5
and higher. The python and lagarto downloads do still require a manual install - but with the help of a script there is little to it.
Programming v2 panStamps requires a different method to v1 devices as they are no longer plug-in devices. Starting out, a panStamp should be mounted on a
carrier board. In this
way it can be programmed by placing the carrier board on the pins of a
panStick (without a
panStamp soldered to it)
and using light pressure to ensure good contact between
the two. The rest of the procedure is very much as described on the Arduino site here. Load the modem sketch, select serial/USB port then
board type as either panStamps
NRG or panStamps
AVR (v2) as well as msp430-gdb programmer for
NRG or default for
AVR. If you have purpose made antennae, attach these or
use wire whips of the appropriate length
(the length is important). Tip: Keep track of the panStamps you have programmed, it's
very difficult to tell from the outside what is on the
inside ;) Sensor PowerThe sensor board needs to be powered. Use two AA
cells, a breadboard or patch leads and connect to
VCC (+) and GND (-) (see the wiki
pinouts for your board). Modem Connection
Ideally your v2 panStamp modem will be attached to a panStick so plug this in to your computer fhemTo use with fhem
define it with something like Initially (back in February 2015) I had great
difficulty getting lagarto show my device, suspecting
both my abilities and the mixed system I am running now
on the RPi 2. So... I got out my B+, cloned my backup SD card. Same result :( Finally I re-read the lagarto wiki page. Previously I must
have overlooked the last bit and used the Doesn't reflect very well on my abilities at all :( You can also try Whichever application you use you should see traffic in the terminal window from which you started either lagarto or swapdmtgui. Now you can see your device it's a good idea to
change its address and TX interval, the first to avoid
adding a new device with the same default address, the
second to see data when you want it. Most of the sketches have a few lines of code in the setup function that toggle the LEDs to indicate that the panStamp is listening for commands. This mode usually only lasts for a few seconds. lagarto will send new address and interval settings at this point. swapdmtgui should do the same if you can see the sync notification window on screen. You can force the panStamp into sync mode either by unplugging and re-inserting the panStick to its USB socket or by pressing the reset button on the panStick. Removing power from a standalone panStamp should achieve the same result but it may need remain without power for some seconds or it may not reset. Notes:
I have had much better luck with recent versions running on a jessie Pi - and in current versions of lagarto, ZeroMQ has now been replaced with MQTT. Gas Meter ReadingIn this section I hope to describe using a panStamp to record data from my gas meter which is located outside on a flank wall. A panStamp seems an ideal solution. I have tried this on a breadboard and it was surprisingly easy. The pulsecounter sketch works for both AVR and NRG boards and will record pulses using interrupts, and add each occurrence of an interrupt to a counter. At intervals the contents of the counter are transmitted for the modem panStamp to receive. I shall be using a purpose-made pulse block but a
reed switch should work just as well. Let's take a closer look. My meter is a BK-G4 and has a small magnet
incorporated in the rightmost index wheel, the wheel
that records thousandths of a m³, so every
revolution of this wheel and resulting pulse from the
sensor should equate to one hundredth of a m³
consumed. You can easily check whether your own meter has a
magnetic wheel, simply hold a magnetic (orienteering)
compass close to it. If the needle displacement varies
as the wheel turns then it has a magnet :) I had expected the connection to be a 3.5mm jack
socket. In fact it's an RJ11 modular socket (4 wire
telephone type) and there is an additional
alarm/anti-tamper switch incorporated. If we look at the code in the pulsecounter sketch we will see that
it is designed to generate an interrupt as the voltage
is RISING on a specific pin. We connect one side of our reed switch or pulse
block to ground, the other to the interrupt pin. As the
switch is closed it pulls the pin LOW (to ground
potential) then as it opens shortly after the pin is
pulled back up to a HIGH state. Except it probably won't do that as it is set up so
far! To make things more obvious visually add a 100kΩ resistor between the interrupt pin and VCC to pull the pin HIGH. That's it. All done :) If we connect the panStamp to a couple of AA cells we should be able to start measuring gas consumption and should see the counter incrementing. I now have a new RPi 2 so here are some rather rushed Fritzing images - these and the ones for the electricity meter monitoring are of the breadboard prototypes but have now been tested and are both working..
Electricity Meter ReadingMy electricity meter is a fairly typical for a UK
model that has a flashing LED. The rate at which it
flashes depends on usage and mine indicates that it
flashes one thousand times for each kWh used. I have a TAOS TSL260
in my bits box that may make a suitable sensor. The
TSL260 generates a voltage when illuminated by IR light
- using an IR sensitive device may help to reduce
interference from other light sources - I hope. (The
package is black, not clear, as it might be for visible
light.) We can check to see if this works as we hope by
connecting it to a battery and then, with a multimeter
between GND and
OUT, see whether a
voltage registers when the LED flashes. We could use additional components to reverse this action so that it behaves exactly as the switch did - or better we can use a 100kΩ pulldown resistor between the interrupt pin and ground to pull the pin LOW so that a pulse from the TSL260 will pull the pin HIGH and trigger the interrupt. We can also change the interrupt statement in the sketch so that an interrupt is generated on FALLING ie. as the LED flash finishes. (In tests using a RISING or FALLING interrupt seems to make no significant difference.) All done again :) Connect power to the panStamp and attach the TSL260 to the meter temporarily with some 'tac' and we should see the counter incrementing.
Battery BoardsThe two sections above are only proof of concept but
they do both work on the breadboards. The battery boards arrived - I finalised my order on
Wednesday morning and it was delivered here on Saturday
morning! The battery boards themselves are about 50 x 70mm
(v1.1) and that includes the area for the single AA
cell. I set TX intervals to 60 seconds so that I could see results sooner than with the default setting. Gas counting looked good from the start but the
electricity counter appeared to be adding about three
pulses at a time. My next step is to find a weatherproof box for the
gas meter counter (the battery board enclosures have
vent holes top and bottom so not ideal for external
installation) and some means of securing the TSL260
sensor against the electricity meter window directly
above the flashing LED as well as excluding external
light interference. The two sensors have now been installed and seem to
be working as expected although I have not yet
integrated them into fhem. As noted in the caption above, the battery board has a number of
unpopulated positions for pullup resistors for the
various connection points if required. The results from fhem...
The pulsecounter
sketch increments the counter on each interrupt and the
current counter value is transmitted at the chosen
interval.
As you can see from the above image no data was received from the gas counter for some hours. There may, of course, be the odd missed transmission but the sketch has been written so that the panStamp only transmits if there has been a change in the counter value. My boiler has a pilot light so there is always some consumption but this may not be enough to use one hundredth of a cubic meter between transmissions. My fhem definition for the electricity meter pulsecounter is... define SWAP_02 SWAP 02
Note the use of the modifier difference. define E_Count_notify notify SWAP_02:E_Count:.*
{
Note the use of the ternary operator to discard any negative values that may result from a reset of the panStamp. Update after many months of running.. More panStampsI really like these devices, in case you hadn't
noticed. They are just so easy to use with the supplied
sketches as well as providing scope for more complex
applications. I have long had a plan to install temperature and
humidity sensors in each room and my intention has
always been to use 1-wire. Needless to say, it hasn't
happened, there is always something more interesting to
do than moving furniture, taking up carpets and pulling
up floorboards. My latest order has arrived and here is an image of one of the sensors made up.. .
They are each labelled as you can see with the
panStamp device address
so that I can tell them apart. The panStamp itself is held in place using a short length of 16mm plastic electrical trunking and allows air circulation to both sides of the board. The trunking and battery housing are both hot-melt glued to the sensor housing. (The hot-melt glue failed after a while, now upgraded to silicone mastic.) The results from fhem...
The timestamp is a temporary addition whilst I find the best location for one of the sensors. Later... Next project is to transfer my heating flow and
return sensors from 1-wire to a panStamp. Additional ResourcesAs I mentioned earlier, there is a wealth of
information in the panStamp wiki pages but a few other
sources may be useful. For many who have played with Arduinos before
perhaps one of these is confusion regarding pin numbers
or names. I have created my own table of panStamp pinouts to save me having to look them up each time. It may be useful to others. For those like me who still find books with real paper pages useful, I recommend The Arduino Cookbook as a very good general guide to Arduinos. The link is to a sampler so you can see a bit before you buy. Neopixels and a bit of DevelopingA lot has changed since I wrote most of this page
and there is a now a new generation of panStamps. Arduino IDE 1.6.6 has been released but it's not working here at present with panStamps so I'm still using 1.6.5. The example sketches now include a basic sketch for
using WS2812
Neopixels with NRGs.
The sketch works and lights up pixels but not in a
useful and fully controllable way at present. I wondered if an AVR
panStamp could be used as it is based on an
Atmega 328 - but of course it runs at 8MHz whereas
Arduino Uno and 5V Pro Mini are both 16MHz. Adding modified bits of my previous code into the
panStamp binouts2 sketch
seemed to be OK but of course panStamp sketches use completely
different input and output methods tied closely to
SWAP. Much of the code and methods are beyond my comfort level so it took a long, long time to take in - but I got there in the end. I'm sure many will find developing for panStamps relatively easy and be able to jump in straight away but for those like myself who are struggling this is a quick run-through of my experiences - some of my assumptions may be incorrect of course - my working life was spent building houses not code :). The first thing that struck me was that I had almost completely overlooked the importance of the <device>.xml files but in fact they are an essential part of the whole in that they define how a register is split into various fields to be used from the SWAP registers in your sketch. Once I had grasped this things became much easier As an example my sketch requires a byte for a
command (cmd), another for led index then three
separate bytes for red, green and blue values.
<device>
developer>fruit</developer> product>WS2812display</product> pwrdownmode>false</pwrdownmode> regular> reg name="PWM output 0" id="11"> endpoint name="PWM output 0" type="num" dir="out"/> /reg> reg name="Command" id="12"> endpoint name="CmdStr" type="num" dir="out"> size>5</size> /endpoint> endpoint name="cmd" type="num" dir="out"> position>0</position> size>1</size> /endpoint> endpoint name="index" type="num" dir="out"> position>1</position> size>1</size> /endpoint> endpoint name="red" type="num" dir="out"> position>2</position> size>1</size> /endpoint> endpoint name="green" type="num" dir="out"> position>3</position> size>1</size> /endpoint> endpoint name="blue" type="num" dir="out"> position>4</position> size>1</size> /endpoint> /reg> reg name="LEDs" id="13"> endpoint name="LEDs" type="num" dir="inp"> position>0</position> size>1</size> /endpoint> /reg> /regular> </device> The first register PWM output
0 is my output pin, the third, LEDs is where I place the number of
LEDs defined in the sketch (transferred back to the
application, in my case fhem but it could be lagarto or swapdmt or some other app). Note: Registers are numbered from 11 up (id="11"). Add the <device>.xml to the location of
others on your machine using a suitable name. I didn't
have a developer ID initially so used the panStamp one. Note that these two xml files may be overwritten at times from central repositories so keep copies! fhem also uses devices-local.xml which I believe gets around this but I haven't investigated/translated further so far - something for another day. Later... Example setters and
updaters are given in the
wiki docs and are relatively easily adapted,
SWAP does much of the
work for you once these are in place. In my case input is the command, sent by wireless
message from fhem, output
is the above defined pin which supplies data to the
Neopixel stick (via a level-shifter and recommended
resistor in the data line). That is sort of all there is to it - but anyone following this may still need to do a lot of reading - and head scratching too :) I am running panStamps
in fhem and fhem grabs any new device (not a
problem, just precludes the use of panStamp tools by default but, as I
mentioned earlier, setting the ignore attribute will
allow this) and although I was able to see bits of data
it wasn't until I had correctly set up <device>.xml and devices.xml that the data became
useful and meaningful. So now, how do I send commands to the panStamp from fhem? There are two SWAP
modules for specific devices as well as a generic
SWAP module available
within fhem. I'm quite pleased with myself :) Just need a new panStamp (more on the way now) and to tidy up my various bits of code to finish it all off. I'll try and summarise even more briefly...
Please let me know if I have missed anything - or misled anyone - or broken anything tidying up this page. Have fun. Reference SectionTroubleshootingOne of my AVR1 modules stopped working for some reason after working perfectly until an upload broke something. The AVR chip seemed
to be OK, I could upload and the pins worked as they
should but I could not get it to register with either
fhem or swapdmt. eepromToFactoryDefaults();
I used the template sketch for this - and now have it saved (AVR only) in case I need it in the future! NRG ProblemsMy initial purchase was limited by low stocks to a
single AVR panStamp and
a few NRGs along with
the panStick and
shield. I was able to program the AVR with no problems on my patched Arduino IDE on the Raspberry Pi. The NRG panStamps require at least an Arduino IDE 1.6 with a patch applied to enable NRG support. This patch is available from the panStamp wiki pages - and is frequently updated. After patching my 1.6 IDE on the Pi I tried an NRG board but it produced an immediate error.
So, how to program an NRG board? My desktop is debian wheezy and the wheezy Arduino IDE is only 1.0 so I thought I was stuck. Following some very helpful correspondence with Daniel from panStamp I discovered the Arduino software page has installable ready-to-run linux downloads. Somehow I'd managed to miss that completely before! The 64 bit version of 1.5.8 runs on wheezy and I
was able to program standard Arduino boards as well
as the one panStamp AVR
I have. The NRG patch is expecting glibc 2.14, debian wheezy has only 2.13. Daniel suggested building the required NRG patch from source which I found is available from https://github.com/energia/Energia/wiki/Build-Energia. Building mspgccAfter extracting the archive and taking a look
around inside, the only bit we are interested in is
in the /Energia-master/build/linux/dist/tools/
directory. The build process starts by fetching a number of
additional files and the build itself takes quite a
time. Once successfully completed all that's needed is
to copy the files created in Applying this modified patch enabled me to successfully program the NRG boards. NB. The energia sources were used exactly as extracted with no modifications whatsoever. Building mspgcc on a Pi?References to jessie on the Pi in this and the
following section relate to the system I was using on
a RPi B. Would it be possible to do the same for the Raspberry Pi I use for my Arduino programming amongst other things? My first attempt was on the Pi with the patched IDE, running jessie. The build is very long and very
slow!
On my searches I came across a
branch on the energia github repository modified
to run on a Beagle Bone Black (another ARM based
machine) that seems worth a try. Sadly this one failed at exactly the same point with the same error. Building mspgcc on Another PiThen something occurred to me... As I had managed a successful build on my desktop wheezy perhaps I could do the same on a Pi running wheezy - and I have a few of those :) As I write this I'm on the third attempt, the earlier ones failing on something missing which I've installed before the next go. Success! The build has completed! Started at 06:00 finished at 16:39 If anyone else is crazy enough to try this the
size of the build log may give an indication of
progress. I now have to transfer to the Pi running jessie
and see if it works - but I have a more pressing
task, my Pi 2 has arrived :) NB. The energia sources were used exactly as extracted with no modifications whatsoever. Raspberry Pi 2 and jessieThe next section is out of date but left in grey text for reference.
Once I received my Pi 2 I tried to move the OS from
the Pi running jessie but found I could not update
the kernel to the latest required for some
reason.
I installed standard raspbian and tried updating to jessie from there but my many attempts resulted in unusable or unbootable systems. I'm sure it will be possible/easier once the new kernel and hardware has been around for a while. So I am now back to Arduino IDE 1.0 - but I still have the Arduino debs I built on the previous jessie. Following
these instructions by Nico Hood I now have my
Arduino 1.6 debs running on raspbian wheezy on the
RPi 2 - thanks Nico :) I'm also able to use the RTC on the panStamp shield - there was no available module with the jessie I was running. My first attempt at building and uploading
NRG code to a
panStamp using my
NRG build and the Pi
failed, rather disappointing... until I realised
that I had used the wrong sketch! NB. I advise anyone following this path to proceed with caution, the RPi 2 and its adapted software are still very new. If you intend to use the jessie repositories
create a good wheezy base system on SD, include
python/largato as well, and back it up in case you
have to use it! Raspberry Pi 2 and the official raspbian jessieJust a short update (Nov 2015).. I now have a couple of Pi2s with the recently
released raspbian jessie installed. My guess is that the imported patch files do not
match the new jessie binutils and texinfo, perhaps
gcc too. Another source from Energia, energia-0101E0016-linux.tgz appears to be more recent but uses the exact same build-mspgcc script and patches - another fail. I believe all the above are based on http://sourceforge.net/projects/mspgcc/ which is now marked as obsolete and refers readers to the TI site which links to a Red Hat open source version of their code. So this is yet another source - with a difference.
The msp430-gcc-source.tar.bz2 archive is available
from the
TI site, however https://github.com/pabigot/msp430-elf
(for a long time the maintainer of mspgcc) states RTCs are now working nicely now :) I have also installed the Arduino 1.6.5 IDE from this thread on a jessie Pi2 - and just when I thought we were catching up, there is now a new 1.6.6 version, again no arm or Pi support :( The Arduino 1.6.5 IDE Boards and Library Managers
work in both the Pi and wheezy installs but, as
expected, I have had to copy across the Energia files
I built into .arduino15/packages/panstamp_nrg/tools/msp430-gcc/4.6.3/
on both systems. |
Last updated 30-01-2016 |
All trademarks referred to in this web site are the
properties of their respective owners. Trademarked
names appear throughout the content of this site.
Trademarks, and their respective owners, are not
systematically listed or marked in the text, but
nevertheless all trademarks are acknowledged. Any
trademarks or names being used are for editorial
purposes only, and to the benefit of the trademark
owner, with no intention of infringing upon that
trademark.
|