LowPowerLab Forum

Hardware support => Projects => Topic started by: Hacker007 on July 23, 2013, 10:50:59 PM

Title: MailBoxNotifier Moteino Project - Development Notes
Post by: Hacker007 on July 23, 2013, 10:50:59 PM
Felix's work on the Mailbox Notifier was fantastic! About three months ago, I ordered some RFM12B modules from Sparkfun and off I went.  I attached one of the modules to a PIC18 and then I was able to get it to periodically transmit a fixed packet.  Then, I discovered the MailBoxNotifier project that Felix had put together.  I could not resist.  I ordered a RaspberryPi and two R2 Moteinos.  I then proceeded to follow Felix’s directions of how to put the project together.  I also began to collaborate with one of my friends.  In the process of integrating all the pieces, my friend and I found some small problems. We want to publish the problems here so that other enthusiasts don’t have to face them.  The issues were:

1.   Wiring the Hall-Effect Sensor to the Remote Moteino

The picture in the main page for this project indicates that an NPN transistor is used to switch the Hall-Effect sensor on when taking data from it and off when not in order to save power.  The code then indicates that the pin A1 is set high to turn on the sensor and low to turn it off.  From the image, I could see that Felix wanted to implement a high-side (3.3V) switch for the sensor.  Typically, this is done with a PNP transistor (aka bipolar junction transistor or BJT) or P-CH MOSFET.  If a PNP BJT is used, then the control pin should be set low to pull current out of the base.  If an P-CH MOSFET is used instead, the control pin should also be set low to produce a positive Vgs potential.  Also, if a P-CH MOSFET is used, the MOSFET should be a logic MOSFET, meaning that it will turn on with a Vgs of about 2.5V, not the typical 10V required of the non-logic MOSFTEs to turn it on fully.
For this application, I opted to bypass the high-side switch all together (mainly because I did not have the parts on hand) and fed 3.3V power (2.5mA typical, 5 mA max) to the sensor directly from the control pin A1.  This worked just fine.
My friend and I then found that the image showing the connections to the Hall-Effect sensor was incorrect.  The image showed pin 2 to be the sensor output and pin 3 to be ground.  Actually, for the UA package (the one received in the order), the sensor output is pin 3 and ground is pin 2.  With the sensor wired as shown on the figure, the sensor’s open drain MOSFET’s body diode is always conducting and therefore prevents the output from going higher than 0.3V or 0.7V.  After correcting our wiring, the sensor’s output was able to change state with the presence and absence of the magnet as expected.
 
2.   Programming the Moteinos

My friend and I then had trouble programing the Moteinos with the appropriate Remote Sensor and Gateway sketches.  Because of our unfamiliarity with the Arduinos, we did not know which board to select in the IDE in order to complete the programming process.  Felix helped us out and pointed to a link that indicated that the UNO was the board type to choose for the Moteino.  This was not obvious to us.  We believe that the sketches should have a comment to indicate this important issue.

3.   Finding the name of the RaspberryPi Serial Port

This took some trial and error detective work by my friend.  Following the process of elimination, he found that it was the ttyAMA0 device.

4.   Preventing the RaspberryPi getty app from conflicting with our Python script

My friend came to the rescue on this issue.  While testing the Python script, he noticed that every once in a while, the script would crash and generate an error message.  The error indicated that the ttyAMA0 serial port was temporarily unavailable. My friend searched for the error message in Google and found information about how to prevent the getty app in the RaspberryPi from using the serial port all together.  We found the indicated file (/etc/inittab) and commented the offending line as shown below:
#Spawn a getty on RaspberryPi serial line
#T0:23:respawn:/sbin/getty –L ttyAMA0 115200 vt100  My friend commented-out this line
Once we did this, the Python script stopped crashing. 

5.   Adding our Python script to the rc.local file in the RaspberryPi

The last step for us was to find a way to invoke the Python script from the /etc/init.c/rc.local file on the RaspberryPi.  The rc.local is similar to the autoexec.bat on a PC and is the file where the user tells Linux what processes to run from power-up.  I added the following line as shown below. 
Part of the file omitted for clarity….
Case “$1” in
   Start)
   sudo python /home/[i/GarageNotifier/GarageNotifier.py   I added this line
   ;;
   Restart|reload|force-reload)
sudo python /home/[i/GarageNotifier/GarageNotifier.py  I added this line
   ;;
Part of the file omitted for clarity….
This worked like a champ.  I wanted to do this in case the RaspberryPi lost power and had to re-boot.  If it did, the system would be up and running in a jiff.

I also wanted to mention that I modified the use of the project by attaching the Remote Moteino to my garage door instead of the mailbox.  This way, I could see when the garage door was opened and closed.  I wanted to have this capability in order to help me remember if I had closed the door or not or if someone else had left it open.  I plan to add another Moteino to the system for our mail box shortly. 
Overall, this was a great project and my hat goes off to Felix for a job well done!