SparkFun Forums 

Where electronics enthusiasts find answers.


I am trying to create a weather station with the Photon Weather Shield and no matter which example I try I keep getting an error on compile that it cannot locate the OneWire.h file. I am working through the Photon Online App and have included the OneWire library and the OneWire.h file is listed as one of the files added by the Photon app.

Using the SparkFun example including access to the Soil Temperature and moisture ports, a check of the code gives the following full compile messages:

Processing weatherstationwithsoil.ino
Checking library SparkFun_Photon_Weather_Shield_Library...
Checking library OneWire...
Checking library spark-dallas-temperature...
Installing library OneWire 2.0.3 to lib/OneWire ...
Installing library SparkFun_Photon_Weather_Shield_Library 1.1.3 to lib/SparkFun_Photon_Weather_Shield_Library ...
Installing library spark-dallas-temperature 0.0.5 to lib/spark-dallas-temperature ...
Library spark-dallas-temperature 0.0.5 installed.
Library SparkFun_Photon_Weather_Shield_Library 1.1.3 installed.
Library OneWire 2.0.3 installed.
make -C ../modules/photon/user-part all
make[1]: Entering directory '/firmware/modules/photon/user-part'
make -C ../../../user
make[2]: Entering directory '/firmware/user'
Building cpp file: src/weatherstationwithsoil.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.1.0 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../hal/src/photon/include -I../hal/src/photon/wiced/security/BESL/host/WICED/ -I../hal/src/photon/wiced/security/BESL/include -I../hal/src/photon/wiced/security/BESL -I../hal/src/photon/wiced/security/BESL/crypto -I../hal/src/photon/wiced/WWD/include/ -I../hal/src/photon/wiced/platform/include/ -I../hal/src/photon/wiced/platform/GCC/ -I../hal/src/photon/wiced/security/BESL/supplicant/ -I../hal/src/photon/libraries/crypto -I../hal/src/photon/libraries/daemons/DNS_redirect -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -Isrc -I./libraries -Ilib/SparkFun_Photon_Weather_Shield_Library/src -Ilib/spark-dallas-temperature/src -Ilib/OneWire/src -I. -MD -MP -MF ../build/target/user/platform-6-msrc/weatherstationwithsoil.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=6 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,1102 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\"" -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-6-msrc/weatherstationwithsoil.o src/weatherstationwithsoil.cpp
In file included from weatherstationwithsoil.ino:2:0:
lib/spark-dallas-temperature/src/spark-dallas-temperature.h:27:36: fatal error: ../OneWire/OneWire.h: No such file or directory
#include "../OneWire/OneWire.h"
compilation terminated.
../build/ recipe for target '../build/target/user/platform-6-msrc/weatherstationwithsoil.o' failed
make[2]: *** [../build/target/user/platform-6-msrc/weatherstationwithsoil.o] Error 1
make[2]: Leaving directory '/firmware/user'
../../../build/ recipe for target 'user' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [user] Error 2
../build/ recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2


You can see at the top of the compiler messages that the OneWire library seems to be found AND included. Any ideas what's wrong???

The code is the same as the code on the SparkFun site that adds soil temperature and moisture. In case someone wants to see the code that gives me the compiler error, here it is:

SparkFun Photon Weather Shield basic example with soil moisture and temp
and weather meter readings including wind speed, wind direction and rain.
Joel Bartlett @ SparkFun Electronics
Original Creation Date: May 18, 2015
Based on the Wimp Weather Station sketch by: Nathan Seidle
This sketch prints the temperature, humidity, barometric pressure, altitude,
soil moisture, and soil temperature to the Seril port. This sketch also
incorporates the Weather Meters avaialbe from SparkFun (SEN-08942), which allow
you to measure Wind Speed, Wind Direction, and Rainfall. Upload this sketch
after attaching a soil moisture and or soil temperature sensor and Wetaher
Meters to test your connections.
Hardware Connections:
This sketch was written specifically for the Photon Weather Shield,
which connects the HTU21D and MPL3115A2 to the I2C bus by default.
If you have an HTU21D and/or an MPL3115A2 breakout, use the following
hardware setup:
HTU21D ------------- Photon
(-) ------------------- GND
(+) ------------------- 3.3V (VCC)
CL ------------------- D1/SCL
DA ------------------- D0/SDA
MPL3115A2 ------------- Photon
GND ------------------- GND
VCC ------------------- 3.3V (VCC)
SCL ------------------ D1/SCL
SDA ------------------ D0/SDA
Soil Moisture Sensor ----- Photon
GND ------------------- GND
VCC ------------------- D5
SIG ------------------- A1
DS18B20 Temp Sensor ------ Photon
VCC (Red) ------------- 3.3V (VCC)
GND (Black) ----------- GND
SIG (White) ----------- D4
Development environment specifics:
IDE: Particle Dev
Hardware Platform: Particle Photon
Particle Core
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful,
please buy us a round!
Distributed as-is; no warranty is given.
#include <SparkFun_Photon_Weather_Shield_Library.h>
#include <OneWire.h>
#include <spark-dallas-temperature.h>
//OneWire and DallasTemperature libraries are needed for DS18B20 Temp sensor

#define ONE_WIRE_BUS D4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

#define SOIL_MOIST A1

int WDIR = A0;
int RAIN = D2;
int WSPEED = D3;

//Run I2C Scanner to get address of DS18B20(s)
//(found in the Firmware folder in the Photon Weather Shield Repo)
DeviceAddress inSoilThermometer =
{0x28, 0x6F, 0xD1, 0x5E, 0x06, 0x00, 0x00, 0x76};//Waterproof temp sensor address

//Global Variables
long lastSecond; //The millis counter to see when a second rolls by
byte seconds; //When it hits 60, increase the current minute
byte seconds_2m; //Keeps track of the "wind speed/dir avg" over last 2 minutes array of data
byte minutes; //Keeps track of where we are in various arrays of data
byte minutes_10m; //Keeps track of where we are in wind gust/dir over last 10 minutes array of data

//We need to keep track of the following variables:
//Wind speed/dir each update (no storage)
//Wind gust/dir over the day (no storage)
//Wind speed/dir, avg over 2 minutes (store 1 per second)
//Wind gust/dir over last 10 minutes (store 1 per minute)
//Rain over the past hour (store 1 per minute)
//Total rain over date (store one per day)

byte windspdavg[120]; //120 bytes to keep track of 2 minute average
int winddiravg[120]; //120 ints to keep track of 2 minute average
float windgust_10m[10]; //10 floats to keep track of 10 minute max
int windgustdirection_10m[10]; //10 ints to keep track of 10 minute max
volatile float rainHour[60]; //60 floating numbers to keep track of 60 minutes of rain

//These are all the weather values that wunderground expects:
int winddir = 0; // [0-360 instantaneous wind direction]
float windspeedmph = 0; // [mph instantaneous wind speed]
float windgustmph = 0; // [mph current wind gust, using software specific time period]
int windgustdir = 0; // [0-360 using software specific time period]
float windspdmph_avg2m = 0; // [mph 2 minute average wind speed mph]
int winddir_avg2m = 0; // [0-360 2 minute average wind direction]
float windgustmph_10m = 0; // [mph past 10 minutes wind gust mph ]
int windgustdir_10m = 0; // [0-360 past 10 minutes wind gust direction]
float rainin = 0; // [rain inches over the past hour)] -- the accumulated rainfall in the past 60 min
long lastWindCheck = 0;
volatile float dailyrainin = 0; // [rain inches so far today in local time]

float humidity = 0;
float tempf = 0;
double InTempC = 0;//original temperature in C from DS18B20
float soiltempf = 0;//converted temperature in F from DS18B20
float pascals = 0;
float altf = 0;
float baroTemp = 0;
int soilMoisture = 0;

int count = 0;

// volatiles are subject to modification by IRQs
volatile long lastWindIRQ = 0;
volatile byte windClicks = 0;
volatile unsigned long raintime, rainlast, raininterval, rain;

//Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor
Weather sensor;

void update18B20Temp(DeviceAddress deviceAddress, double &tempC);//predeclare to compile

//Interrupt routines (these are called by the hardware interrupts, not by the main code)
void rainIRQ()
// Count rain gauge bucket tips as they occur
// Activated by the magnet and reed switch in the rain gauge, attached to input D2
raintime = millis(); // grab current time
raininterval = raintime - rainlast; // calculate interval between this and last event

if (raininterval > 10) // ignore switch-bounce glitches less than 10mS after initial edge
dailyrainin += 0.011; //Each dump is 0.011" of water
rainHour[minutes] += 0.011; //Increase this minute's amount of rain

rainlast = raintime; // set up for next event

void wspeedIRQ()
// Activated by the magnet in the anemometer (2 ticks per rotation), attached to input D3
if (millis() - lastWindIRQ > 10) // Ignore switch-bounce glitches less than 10ms (142MPH max reading) after the reed switch closes
lastWindIRQ = millis(); //Grab the current time
windClicks++; //There is 1.492MPH for each click per second.

void setup()
// DS18B20 initialization
sensors.setResolution(inSoilThermometer, TEMPERATURE_PRECISION);

pinMode(WSPEED, INPUT_PULLUP); // input from wind meters windspeed sensor
pinMode(RAIN, INPUT_PULLUP); // input from wind meters rain gauge sensor

pinMode(SOIL_MOIST_POWER, OUTPUT);//power control for soil moisture
digitalWrite(SOIL_MOIST_POWER, LOW);//Leave off by defualt

Serial.begin(9600); // open serial over USB

// Make sure your Serial Terminal app is closed before powering your device
// Now open your Serial Terminal, and hit any key to continue!
Serial.println("Press any key to begin");
//This line pauses the Serial port until a key is pressed
while(!Serial.available()) Spark.process();

//Initialize the I2C sensors and ping them

/*You can only receive acurate barrometric readings or acurate altitiude
readings at a given time, not both at the same time. The following two lines
tell the sensor what mode to use. You could easily write a function that
takes a reading in one made and then switches to the other mode to grab that
reading, resulting in data that contains both acurate altitude and barrometric
readings. For this example, we will only be using the barometer mode. Be sure
to only uncomment one line at a time. */
sensor.setModeBarometer();//Set to Barometer Mode
//baro.setModeAltimeter();//Set to altimeter Mode

//These are additional MPL3115A2 functions the MUST be called for the sensor to work.
sensor.setOversampleRate(7); // Set Oversample rate
//Call with a rate from 0 to 7. See page 33 for table of ratios.
//Sets the over sample rate. Datasheet calls for 128 but you can set it
//from 1 to 128 samples. The higher the oversample rate the greater
//the time between data samples.

sensor.enableEventFlags(); //Necessary register calls to enble temp, baro ansd alt

seconds = 0;
lastSecond = millis();

// attach external interrupt pins to IRQ functions
attachInterrupt(RAIN, rainIRQ, FALLING);
attachInterrupt(WSPEED, wspeedIRQ, FALLING);

// turn on interrupts
void loop()
//Keep track of which minute it is
if(millis() - lastSecond >= 1000)

lastSecond += 1000;

//Take a speed and direction reading every second for 2 minute average
if(++seconds_2m > 119) seconds_2m = 0;

//Calc the wind speed and direction every second for 120 second to get 2 minute average
float currentSpeed = get_wind_speed();
//float currentSpeed = random(5); //For testing
int currentDirection = get_wind_direction();
windspdavg[seconds_2m] = (int)currentSpeed;
winddiravg[seconds_2m] = currentDirection;
//if(seconds_2m % 10 == 0) displayArrays(); //For testing

//Check to see if this is a gust for the minute
if(currentSpeed > windgust_10m[minutes_10m])
windgust_10m[minutes_10m] = currentSpeed;
windgustdirection_10m[minutes_10m] = currentDirection;

//Check to see if this is a gust for the day
if(currentSpeed > windgustmph)
windgustmph = currentSpeed;
windgustdir = currentDirection;

if(++seconds > 59)
seconds = 0;

if(++minutes > 59) minutes = 0;
if(++minutes_10m > 9) minutes_10m = 0;

rainHour[minutes] = 0; //Zero out this minute's rainfall amount
windgust_10m[minutes_10m] = 0; //Zero out this minute's gust

//Get readings from all sensors
//Rather than use a delay, keeping track of a counter allows the photon to
// still take readings and do work in between printing out data.
//alter this number to change the amount of time between each reading
if(count == 5)
count = 0;
void printInfo()
//This function prints the weather data out to the default Serial Port
switch (winddir)
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
Serial.print("No Wind");
// if nothing else matches, do the
// default (which is optional)

Serial.print(" Wind_Speed:");
Serial.print(windspeedmph, 1);
Serial.print("mph, ");

Serial.print(rainin, 2);
Serial.print("in., ");

Serial.print("F, ");

Serial.print("%, ");

Serial.print("F, ");

Serial.print("hPa, ");
//The MPL3115A2 outputs the pressure in Pascals. However, most weather stations
//report pressure in hectopascals or millibars. Divide by 100 to get a reading
//more closely resembling what online weather reports may say in hPa or mb.
//Another common unit for pressure is Inches of Mercury (in.Hg). To convert
//from mb to in.Hg, use the following formula. P(inHg) = 0.0295300 * P(mb)
//More info on conversion can be found here:
// ... ersion.pdf

//If in altitude mode, print with these lines

Serial.print("F, ");

Serial.println(soilMoisture);//Mositure Content is expressed as an analog
//value, which can range from 0 (completely dry) to the value of the
//materials' porosity at saturation. The sensor tends to max out between
//3000 and 3500.
void getSoilTemp()
//get temp from DS18B20
update18B20Temp(inSoilThermometer, InTempC);
//Every so often there is an error that throws a -127.00, this compensates
if(InTempC < -100)
soiltempf = soiltempf;//push last value so data isn't out of scope
soiltempf = (InTempC * 9)/5 + 32;//else grab the newest, good data
void getSoilMositure()
/*We found through testing that leaving the soil moisture sensor powered
all the time lead to corrosion of the probes. Thus, this port breaks out
Digital Pin D5 as the power pin for the sensor, allowing the Photon to
power the sensor, take a reading, and then disable power on the sensor,
giving the sensor a longer lifespan.*/
soilMoisture = analogRead(SOIL_MOIST);
digitalWrite(SOIL_MOIST_POWER, LOW);

void update18B20Temp(DeviceAddress deviceAddress, double &tempC)
tempC = sensors.getTempC(deviceAddress);
//Read the wind direction sensor, return heading in degrees
int get_wind_direction()
unsigned int adc;

adc = analogRead(WDIR); // get the current reading from the sensor

// The following table is ADC readings for the wind direction sensor output, sorted from low to high.
// Each threshold is the midpoint between adjacent headings. The output is degrees for that ADC reading.
// Note that these are not in compass degree order! See Weather Meters datasheet for more information.

//Wind Vains may vary in the values they return. To get exact wind direction,
//it is recomended that you AnalogRead the Wind Vain to make sure the values
//your wind vain output fall within the values listed below.
if(adc > 2270 && adc < 2290) return (0);//North
if(adc > 3220 && adc < 3299) return (1);//NE
if(adc > 3890 && adc < 3999) return (2);//East
if(adc > 3780 && adc < 3850) return (3);//SE

if(adc > 3570 && adc < 3650) return (4);//South
if(adc > 2790 && adc < 2850) return (5);//SW
if(adc > 1580 && adc < 1610) return (6);//West
if(adc > 1930 && adc < 1950) return (7);//NW

return (-1); // error, disconnected?
//Returns the instataneous wind speed
float get_wind_speed()
float deltaTime = millis() - lastWindCheck; //750ms

deltaTime /= 1000.0; //Covert to seconds

float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4

windClicks = 0; //Reset and start watching for new wind
lastWindCheck = millis();

windSpeed *= 1.492; //4 * 1.492 = 5.968MPH

/* Serial.println();

void getWeather()
// Measure Relative Humidity from the HTU21D or Si7021
humidity = sensor.getRH();

// Measure Temperature from the HTU21D or Si7021
tempf = sensor.getTempF();
// Temperature is measured every time RH is requested.
// It is faster, therefore, to read it from previous RH
// measurement with getTemp() instead with readTemp()

//Measure the Barometer temperature in F from the MPL3115A2
baroTemp = sensor.readBaroTempF();

//Measure Pressure from the MPL3115A2
pascals = sensor.readPressure();

//If in altitude mode, you can get a reading in feet with this line:
//float altf = sensor.readAltitudeFt();

getSoilTemp();//Read the DS18B20 waterproof temp sensor
getSoilMositure();//Read the soil moisture sensor

//Calc winddir
winddir = get_wind_direction();

//Calc windspeed
windspeedmph = get_wind_speed();

//Calc windgustmph
//Calc windgustdir
//Report the largest windgust today
windgustmph = 0;
windgustdir = 0;

//Calc windspdmph_avg2m
float temp = 0;
for(int i = 0 ; i < 120 ; i++)
temp += windspdavg;
temp /= 120.0;
windspdmph_avg2m = temp;

//Calc winddir_avg2m
temp = 0; //Can't use winddir_avg2m because it's an int
for(int i = 0 ; i < 120 ; i++)
temp += winddiravg;
temp /= 120;
winddir_avg2m = temp;

//Calc windgustmph_10m
//Calc windgustdir_10m
//Find the largest windgust in the last 10 minutes
windgustmph_10m = 0;
windgustdir_10m = 0;
//Step through the 10 minutes
for(int i = 0; i < 10 ; i++)
if(windgust_10m > windgustmph_10m)
windgustmph_10m = windgust_10m;
windgustdir_10m = windgustdirection_10m;

//Total rainfall for the day is calculated within the interrupt
//Calculate amount of rainfall for the last 60 minutes
rainin = 0;
for(int i = 0 ; i < 60 ; i++)
rainin += rainHour;
Hi again:

I've found online that there was a problem in the Dallas-temperature library that leads to this error, which was reported more than two years ago. However, I could not find anyone saying that they found a fix for it. However, I saw a couple of comments that said "Why not just switch to the DS18B20 library instead". I would do so in a heart beat, but I don't know what all I would need to change in the code to make that switch.

Can anyone walk me through the changes I would need to make to the code I posted above to read the soil temperature from the temperature probe connected to the 3 SoilTemp pins on the SparkFun WeatherShield for the Photon?

I also would like to get the Soil Moisture to a moisture sensor attached to the SoilMoisture pins on the same shield. This is supposed to be in the code I borrowed, but I'm not sure it is correct.


Hey Jproehl. Sorry for the delay in response here.

I regret to say that this cold is a bit on the old side and needs an update, however, prioritizing an update for the code will probably take time. I will submit to our engineering department to look into updating the code for this product to prevent issues such as what you are experiencing from happening. I am sure the code worked flawlessly back in 2015.

As for compiling new code to get your project working, I regret to inform you that this is not really a service SparkFun offers our forum users or customers. I bet you would have a better chance of getting help if you posted on the Arduino forums as their community is much more active when it comes to everything Arduino related:

I hope this helps. Please let us know how else we may be of assistance.