-->
Page 1 of 1

DS18B20 Onewire

PostPosted: Wed Mar 09, 2016 3:38 am
by al555bike
Hi,
I'm new to this forum.
I just got a NodeMCU (ESP-12E) and am programming it with the Arduino IDE.
The module reads analogue data and sends it to thingspeak without problem. However when I try and add a DS18B20 onewire sensor to a digital pin I get an error at compile that I don't understand.
The error is:
In file included from C:\Users\Al\OneDrive\Arduino\ESP8266_DS18B20_temperature_sensor_REST\ESP8266_DS18B20_temperature_sensor_REST.ino:16:0:

C:\Program Files (x86)\Arduino\libraries\OneWire/OneWire.h:108:2: error: #error "Please define I/O register types here"

#error "Please define I/O register types here"

I got this code from the web and have stripped out all the wireless lines to try and isolate the problem. My code should now only print to screen. I use these onewire sensors a lot and the NodeMCU is great for small projects.
Can anyone help please.
Thanks
Code: Select all#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2  // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

float oldTemp;
void setup() {
  Serial.begin(115200);   
  oldTemp = -1;
}

void loop() {
  float temp; 
  do {
    DS18B20.requestTemperatures();
    temp = DS18B20.getTempCByIndex(0);
    Serial.print("Temperature: ");
    Serial.println(temp);
  } while (temp == 85.0 || temp == (-127.0));
 
  if (temp != oldTemp)
  {
    oldTemp = temp;
  } 
    delay(1000);
}

Re: DS18B20 Onewire

PostPosted: Thu Mar 10, 2016 1:42 am
by gjlawran
I am currently running a NodeMCU Devboard (v1) with a DS18B20 - however I used this code

https://github.com/ok1cdj/ESP8266-LUA/t ... Thingspeak using LUA and Esplorer

rather than Arduino IDE.

This tutorial is also good if you are interested in trying out LUA as an alternative

https://bigdanzblog.wordpress.com/2015/ ... ture-data/

Re: DS18B20 Onewire

PostPosted: Thu Mar 10, 2016 3:18 am
by leenowell
If you search for the error message in OneWire.h (probably on line 108), you should see what the issue is. I suspect it requires you to #define some values in your code to be picked up at compile time. If not defined it does a #error to display the compile time message you see.

The necessary #defines will need to be made either in your ino or a header file that is included BUT it must be before you include OneWire.h

Re: DS18B20 Onewire

PostPosted: Thu Mar 10, 2016 4:08 am
by al555bike
Apologies for replying to my own post, but I got it working. problem was I had lost the reference to the board in the IDE. Not sure how it happened but in any event it now works well.