Author Topic: OneWire Library - Does an RFDuino version exist? I can't get it to work.  (Read 307 times)

jjv

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Hi,

I have an original RFDuino (RFD22102) and I'm trying to get it to read a ds18b20 temperature sensor over the one wire interface.  I am using the arduino 1.8.3 IDE and have the RFDuino updated to the lastest firmware.

I first tried accessing the ds18b20 with a normal Arduino using the 'official' OneWire library 2.3.3 https://github.com/PaulStoffregen/OneWire .  This worked fine, I can read the temperature.  I then used the same circuit and same code (except for changing the pin number) on the RFDuino and it compiled fine but it was not able to find any devices on the bus.  I don't have an oscilloscope but it seems the data pin is just sitting at 1.1 volts.

I then found this post on this forum.
http://forum.rfduino.com/index.php?topic=103.msg3912;topicseen#msg3912

This person had some 'hacked' one wire code that was created from the version 2.2 of the 'official' one.  It was to fix compile issues.  I didn't have issues compiling the 2.3.3 one but I figured I'd give it a try.  It did not produce different results.  I even tried it with older versions of the arduino IDE.

People clearly are getting one wire to work with RFDuino.  Is there something I'm missing?  Is there a hidden RFDuino version of One Wire library I should be using?

Thanks,

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Don't know of any special one-wire library. But this script I used to test the 18B20 uses the 2.3.3 onewire library and it is still working with Arduino 1.8.1 and RFduino library 2.3.3.

I am using RFduino Pin2. The VCC for the 18B20 is the RFduino 3V pin. There is a 4.7K ohm from pin2 to the RFduino 3V pin. Do not use 5V  with RFduino.

Code: [Select]
#include <OneWire.h>
#include <RFduinoBLE.h>

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library
// Thomas Olson Modified to send data via RFduino BLE.

OneWire  ds(2);  // on pin 10 (a 4.7K resistor is necessary)

void setup(void) {
 // Serial.begin(9600);
    RFduinoBLE.advertisementData = "temp";
    RFduinoBLE.deviceName = "DS18B20";
  // start the BLE stack
  RFduinoBLE.begin();
}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
 
  if ( !ds.search(addr)) {
  //  Serial.println("No more addresses.");
   // Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
 
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
 
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad

 // Serial.print("  Data = ");
 // Serial.print(present, HEX);
 // Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  //  Serial.print(data[i], HEX);
   // Serial.print(" ");
  }
//  Serial.print(" CRC=");
 // Serial.print(OneWire::crc8(data, 8), HEX);
 // Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  /*Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
  */
    RFduinoBLE.sendFloat(celsius);
}
« Last Edit: July 17, 2017, 04:41:27 PM by tolson »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Just downloaded the OneWire library from the Github link you provided to compare just in case I had mods in my copy of the library. Looks like they are exactly identical. So here is output using the Github fresh install.

Only modification was to change
OneWire ds(10);
to
OneWire ds(2);

Here is the output to the Serial Monitor. Notice the temperature going up as I apply my finger to the ds18b20.

Code: [Select]

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 33 0 0 0 FF FF 1F 48 70  CRC=70
  Temperature = 25.50 Celsius, 77.90 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 33 0 0 0 FF FF 20 48 45  CRC=45
  Temperature = 25.50 Celsius, 77.90 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 33 0 0 0 FF FF 4 48 BF  CRC=BF
  Temperature = 25.50 Celsius, 77.90 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 35 0 0 0 FF FF 6 48 BD  CRC=BD
  Temperature = 26.50 Celsius, 79.70 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 37 0 0 0 FF FF 1F 49 3B  CRC=3B
  Temperature = 27.50 Celsius, 81.50 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 38 0 0 0 FF FF 45 49 51  CRC=51
  Temperature = 28.00 Celsius, 82.40 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 38 0 0 0 FF FF 28 49 82  CRC=82
  Temperature = 28.00 Celsius, 82.40 Fahrenheit
No more addresses.


ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 33 0 0 0 FF FF 1F 48 70  CRC=70
  Temperature = 25.50 Celsius, 77.90 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 33 0 0 0 FF FF 20 48 45  CRC=45
  Temperature = 25.50 Celsius, 77.90 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 33 0 0 0 FF FF 4 48 BF  CRC=BF
  Temperature = 25.50 Celsius, 77.90 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 35 0 0 0 FF FF 6 48 BD  CRC=BD
  Temperature = 26.50 Celsius, 79.70 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 37 0 0 0 FF FF 1F 49 3B  CRC=3B
  Temperature = 27.50 Celsius, 81.50 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 38 0 0 0 FF FF 45 49 51  CRC=51
  Temperature = 28.00 Celsius, 82.40 Fahrenheit
No more addresses.

ROM = 10 C1 D1 6 0 0 0 C9
  Chip = DS18S20
  Data = 1 38 0 0 0 FF FF 28 49 82  CRC=82
  Temperature = 28.00 Celsius, 82.40 Fahrenheit
No more addresses.