3

(coco) #1
FORGE

computer board and the sensor of a couple of metres
works fine.


SOFTWARE
The simplest way to program ESP8266 boards like the
NodeMCU is via the Arduino IDE. The core Arduino IDE
package must be extended with a board manager to
work with the ESP8266. Many sketches and libraries
developed for the Arduino series of computers can be
used on the ESP8266 – a huge advantage, given the
wealth of Arduino applications. The sketch (Arduino
program) relies on a library written to access the
TLS2561 sensor by the people at SparkFun. Setting
up the Arduino IDE and loading the SparkFun library is
described in the box on page 106.


HANDLING THE SOLAR SENSOR
First attach the libraries needed for the WiFi, the solar
sensor, and the I^2 C interface.


#include <SparkFunTSL2561.h>
#include <Wire.h>

Next, enter the calibration for the sensor. The
number, 3000, in the code is for indoor light for initial
investigation. Once you have calibrated your sensor,
change this to suit.


float solcalib=1000.0/3000;

Tell the ESP8266 how the I^2 C hardware is connected.
#define SDA 0 // GPIO0 / D3
#define SCL 2 // GPIO2 / D4

Create an instance of the light sensor and set the
highest reading that will be likely.


SFE_TSL2561 light;
const float solarMax = 1000.0;
This next section is run once from the main setup
function and collects together all the instructions
required to set up the solar sensor.


void setup_solarirradiance() {

boolean gain = 0;
unsigned int sitime;
unsigned char time = 0; // time 13.7
milliseconds
light.begin(); // Initialize the
TSL2561
delay(1000);
light.setPowerUp();
}

The following function is used to take readings from
the sensor.
float reading_totalsolar() {
unsigned int sdata0, sdata1;
const float error =9999.0;
if (light.getData(sdata0,sdata1))
{
return solcalib*sdata0;
}
else
{
return error;
}
}

NODEMCU PHONE HOME
Setting up the WiFi on an ESP8266 device is
straightforward, but you will have to enter details of your
WiFi network to make this section work. In particular,
you will need to enter the network name in the ssid
variable and the network password in password. The
other settings may should suit most networks, but if
your router has a different IP address or the address
192.168.0.186 is already assigned, you will need to
change the other settings.
(If you are unsure what IP address your router has,
try using the incredibly useful, free smartphone app,
Fing, to see all the devices on your WiFi network and
their IP addresses.)
#include <ESP8266WiFi.h>

const char* ssid = “********”; // Wi-Fi network
const char* password = “*****”;// Wi-Fi password
IPAddress ip(192,168, 0, 186); // static IP
IPAddress gateway(192,168,0,1); // router IP
IPAddress subnet(255,255,255,0);

Figure 1
ESP8266 website
for solar data

526


Solar Irradiance
FSD 10000 W/m/m
Free download pdf