Downloading, Editing, & Installing Libraries
In his thread,
Newbie after some advice for initial build, lhw455 raises issues that tends to stymie newbies. I know that was true for me. An edited version of what I wrote at that thread might help others.
On 10/14/2015, this post was updated.
About
Arduino Libraries, with focus on
ALL libraries needed by the Gateway & End Nodes in this project:
Gateway node sketch says
Basic DHT node sketch says
#include <RFM69.h>
#include <RFM69.h>
#include <SPI.h>
#include <SPI.h>
#include <Ethernet.h>
#include <DHT.h>
#include <PubSubClient.h> All mean "insert supplementary library program code."
Arduino sketches "#include" additional programming code from
libraries, which are standardized code to help us use particularly add-on devices like RFM69 transceivers & Ethernet Shields. They are text files which may be opened, viewed, & edited with a text editing application.
When an Arduino sketch (like Gateway or End Node) "include" a library file, the Arduino IDE will NOT compile the sketch unless that file is in the right place on your computer. Library files are stored in TWO places on a computer: 1) Your path version of C:\Users\[user name]\Documents\Arduino\libraries 2) With the Arduino IDE files at your path like "C:\Program Files (x86)\Arduino\libraries".
The Gateway sketch, RFM_MQTT_GW_24_pub4.ino, & the End Node sketches (like DHT) contain the note: "// RFM69 Library by Felix Rusu - felix@lowpowerlab.com
// Get the RFM69 library at:
github.com/LowPowerLab/RFM69" ... that means ...
The
RFM69 Library provides the RFM69.h library file that the Arduino IDE expects to be available.
Download the library zip file at
github.com/LowPowerLab/RFM69/archive/master.zip & extract where you can find it.
Then you must put that collection of files where the IDE can find it:
It will be your path that looks something like
C:\Users\[your user name]\Documents\Arduino\libraries\RFM69
The collection of files which include RFM69.h must be in that ...\libraries folder named RFM69
You'll probably need to rename a folder from RFM69-master to RFM69.
The Gateway sketch, RFM_MQTT_GW_24_pub4.ino, also includes the note:
"// -
Interrupts are disabled during ethernet transactions in w5100.h (Ethernet library)
// (See harizanov.com/2012/04/rfm12b-and-arduino-ethernet-with-wiznet5100-chip/)"
That means
important edits are needed in the w5100.h & Ethernet.h library files...
---------------------------------------------------------------
Summarizing & narrowing down the harizanov.com ... info for our project's purposes:
in the
New release duplex gateway thread
CompuTourist posted the following on Feb 19, 2015 at 10:45am
Yes, replace: [Papa: find these lines in w5100.h]
#else
inline static void initSS() { DDRB |= _BV(2); };
inline static void setSS() { PORTB &= ~_BV(2); };
inline static void resetSS() { PORTB |= _BV(2); };
#endif
with: [Papa: actually
ADD what I put in blue bold face below]
#else
inline static void initSS() { DDRB |= _BV(2); };
inline static void setSS() {
cli(); PORTB &= ~_BV(2); };
inline static void resetSS() { PORTB |= _BV(2);
sei(); };
#endif
-------------------------------------------------
According to my limited understanding, (in the bold faced additions above) cli() turns off interrupts briefly & sei() turns them back on. This is supposed to improve transmissions between RFM69 transceivers, preventing drop outs, & I found that true.
Maybe you wonder "Where & how do I make those changes in w5100.h?"
w5100.h is a library file needed for the Arduino Ethernet Shield that is part of the Gateway.
w5100.h comes with the Arduino IDE in the Ethernet library & is at your Windows (or comparable Linux) path of "C:\Program Files (x86)\Arduino\libraries\Ethernet\src\utility\w5100.h"
Hint: In order to edit & re-save w5100, you'll probably need to shut down the Arduino IDE & possibly reboot your computer because the Arduino IDE / Gateway sketch "lock" the file.
Once you find the w5100.h file, open it with a text editor (like notepad), make the 2 additions noted above (in bold face for visibility, not in your file) & re-save w5100.h. As noted, these changes seem to improve the reliability of the RFM69 transceivers' transmissions.
Added 1/1/2017: From what I see, for w5100.h changes to be used,
also edit Ethernet.h, at your Windows (or comparable Linux) path of "C:\Program Files (x86)\Arduino\libraries\Ethernet\src Line 5 of Ethernet.h is //#include "w5100.h" which means do NOT include w5100.h. So
delete "//" at the start of line 5 to activate the include. Save the changed Ethernet.h file. P.S.
pato found that for some IDE versions, to avoid an error, we may need to edit the Ethernet.h line to this:
#include "utility\w5100.h"
Added 9/23/2018 for more recent versions of Arduino IDE / w5100.h: Apparently the w5100.h code has changed. See
this lewishollow post, for where to add cli(); & sei(); for current versions. (
Still needed as of Oct. 19, 2021.)
Added Oct. 19, 2021 for recent versions of Arduino IDE / Ethernet.h / w5100.h: no need to change Ethernet.h because Ethernet.cpp has #include "utility/w5100.h"
To get the PubSubClient library, go to github.com/knolleary/pubsubclient/tags Under the latest release version (currently v1.9.1), click on one type of compressed file, zip (probably) or tar.gz & save the file where you can find it (maybe Downloads). With a compressed file utility (like WinZip or 7-Zip) extract the download to where you can find it. Say you download & extract v1.9.1. You get a top folder called pubsubclient-1.9.1. Inside it are 2 more folders, PubSubClient (the most important) & tests, & README. Rename README to README.txt or README.rtf so you can more easily open it. Move the tests folder into the PubSubClient folder. Copy or move the PubSubClient folder into Documents\Arduino\libraries\
Similarly, download
DHT library (for the DHT11 temperature & humidity sensor) at github.com/adafruit/DHT-sensor-library/archive/master.zip. Rename the folder from DHT-sensor-library-master to DHT. Copy or move that folder into Documents\Arduino\libraries\
The
SPI library comes with the Arduino IDE install.