Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
Error on using OneWire library
-
Dear All,
I started to use Sony Spresense instead of Arduino.
I am trying to use OneWire library for DS18S20 temperature
sensor.
It returns multiple errors.error: no matching function for call to 'OneWire::OneWire
candidate: constexpr OneWire::OneWire(const OneWire&)
exit status 1
void value not ignored as it ought to beEtc.
Also, please can anyone to show me an example for defining digital pins.
For example D05
is this correct?
OneWire ds(digitalPinToInterrupt (05), connect, RISING);I appreciate you kind concerns about these issues.
Thank you
Niro -
Hi @niro
It would be good if you could share both your sketch and information on where you got the library.
But anyway. The pins for the Arudino IDE used in Spresense are defined in (using Ubuntu):
~/.arduino15/packages/SPRESENSE/hardware/spresense/1.5.1/variants/spresense/pins_arduino.h
The names lookes like this:
// Digital pins - 0x0N #define PIN_D00 _DIGITAL_PIN(0) #define PIN_D01 _DIGITAL_PIN(1) #define PIN_D02 _DIGITAL_PIN(2) #define PIN_D03 _DIGITAL_PIN(3) #define PIN_D04 _DIGITAL_PIN(4) #define PIN_D05 _DIGITAL_PIN(5) #define PIN_D06 _DIGITAL_PIN(6) #define PIN_D07 _DIGITAL_PIN(7) #define PIN_D08 _DIGITAL_PIN(8) #define PIN_D09 _DIGITAL_PIN(9) #define PIN_D10 _DIGITAL_PIN(10) #define PIN_D11 _DIGITAL_PIN(11) #define PIN_D12 _DIGITAL_PIN(12) #define PIN_D13 _DIGITAL_PIN(13) #define PIN_D14 _DIGITAL_PIN(14) #define PIN_D15 _DIGITAL_PIN(15) #define PIN_D16 _DIGITAL_PIN(16) #define PIN_D17 _DIGITAL_PIN(17) #define PIN_D18 _DIGITAL_PIN(18) #define PIN_D19 _DIGITAL_PIN(19) #define PIN_D20 _DIGITAL_PIN(20) #define PIN_D21 _DIGITAL_PIN(21) #define PIN_D22 _DIGITAL_PIN(22) #define PIN_D23 _DIGITAL_PIN(23) #define PIN_D24 _DIGITAL_PIN(24) #define PIN_D25 _DIGITAL_PIN(25) #define PIN_D26 _DIGITAL_PIN(26) #define PIN_D27 _DIGITAL_PIN(27) #define PIN_D28 _DIGITAL_PIN(28) #define PIN_D29 _DIGITAL_PIN(29) #define PIN_D30 _DIGITAL_PIN(30) #define PIN_D31 _DIGITAL_PIN(31) #define PIN_D32 _DIGITAL_PIN(32) #define PIN_D33 _DIGITAL_PIN(33) #define PIN_D34 _DIGITAL_PIN(34) #define PIN_D35 _DIGITAL_PIN(35) #define PIN_D36 _DIGITAL_PIN(36) #define PIN_D37 _DIGITAL_PIN(37) #define PIN_D38 _DIGITAL_PIN(38) #define PIN_D39 _DIGITAL_PIN(39) #define PIN_D40 _DIGITAL_PIN(40) #define PIN_D41 _DIGITAL_PIN(41) #define PIN_D42 _DIGITAL_PIN(42) #define PIN_D43 _DIGITAL_PIN(43) #define PIN_D44 _DIGITAL_PIN(44) // LED - 0x4N #define PIN_LED0 _LED_PIN(0) #define PIN_LED1 _LED_PIN(1) #define PIN_LED2 _LED_PIN(2) #define PIN_LED3 _LED_PIN(3) // BUILDIN LED #define LED_BUILTIN0 (PIN_LED0) #define LED_BUILTIN1 (PIN_LED1) #define LED_BUILTIN2 (PIN_LED2) #define LED_BUILTIN3 (PIN_LED3) #define LED_BUILTIN (LED_BUILTIN0) static const uint8_t LED0 = PIN_LED0; static const uint8_t LED1 = PIN_LED1; static const uint8_t LED2 = PIN_LED2; static const uint8_t LED3 = PIN_LED3; #define PIN_PWM_0 PIN_D06 #define PIN_PWM_1 PIN_D05 #define PIN_PWM_2 PIN_D09 #define PIN_PWM_3 PIN_D03 // Analog pins - 0x8N #define PIN_A0 _ANALOG_PIN(0) #define PIN_A1 _ANALOG_PIN(1) #define PIN_A2 _ANALOG_PIN(2) #define PIN_A3 _ANALOG_PIN(3) #define PIN_A4 _ANALOG_PIN(4) #define PIN_A5 _ANALOG_PIN(5) static const uint8_t A0 = PIN_A0; static const uint8_t A1 = PIN_A1; static const uint8_t A2 = PIN_A2; static const uint8_t A3 = PIN_A3; static const uint8_t A4 = PIN_A4; static const uint8_t A5 = PIN_A5;
-
Thank you very much for your reply.
I would like to share the sketch. I downloaded the library from Arduino Manage libraries.
This is my sketch,#include <OneWire.h> //int DS18S20_Pin; int DS18S20_Pin = attachInterrupt (digitalPinToInterrupt (05), connect, RISING); //DS18S20 Signal pin on //x = digitalPinToInterrupt (D07); //attachInterrupt (x, ISR, mode); //int DS18S20_Pin = PIN_D07; //DS18S20_Pin.attach(PIN_D07); //Temperature chip i/o OneWire ds(digitalPinToInterrupt (05), connect, RISING); // on digital pin 2 void setup(void) { Serial.begin(9600); } void loop(void) { float temperature = getTemp(); Serial.println(temperature); delay(1000); //just here to slow down the output so it is easier to read } float getTemp(){ //returns the temperature from one DS18S20 in DEG Celsius byte data[12]; byte addr[8]; if ( !ds.search(addr)) { //no more sensors on chain, reset search ds.reset_search(); return -1000; } if ( OneWire::crc8( addr, 7) != addr[7]) { Serial.println("CRC is not valid!"); return -1000; } if ( addr[0] != 0x10 && addr[0] != 0x28) { Serial.print("Device is not recognized"); return -1000; } ds.reset(); ds.select(addr); ds.write(0x44,1); // start conversion, with parasite power on at the end byte present = ds.reset(); ds.select(addr); ds.write(0xBE); // Read Scratchpad for (int i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); } ds.reset_search(); byte MSB = data[1]; byte LSB = data[0]; float tempRead = ((MSB << 8) | LSB); //using two's compliment float TemperatureSum = tempRead / 16; return TemperatureSum; }
This is simple sketch given by DFRobot temperature sensor.
The information are taken from the below link,https://wiki.dfrobot.com/Waterproof_DS18B20_Digital_Temperature_Sensor__SKU_DFR0198_
I appreciate your kind support.
Thank you!