CubeCell: OneWire Library

This is it, it is just running the initialisation function for the DS18B20, then calling F0 to do a search, the chip should respond with it’s ID…

void setup() {
  pinMode(GPIO6, OUTPUT);
  digitalWrite(GPIO6,LOW);
  pinMode(GPIO0,OUTPUT_PULLUP);
  digitalWrite(GPIO0,HIGH);
  Serial.begin(9600);

}

void loop() {
  Serial.println("Beginning");
  digitalWrite(GPIO0,LOW);
  delayMicroseconds(500);
  pinMode(GPIO0,INPUT);
  delayMicroseconds(60);
  delayMicroseconds(500);
  pinMode(GPIO0,OUTPUT);
  byte searchString = 0xF0;
  byte mask = 1;
  for (mask = 00000001; mask>0; mask <<=1){
    if (searchString & mask){
      //1
      digitalWrite(GPIO0,LOW);
      delayMicroseconds(10);
      digitalWrite(GPIO0,HIGH);
      delayMicroseconds(50);
      
      }
      else{
        // 0
        digitalWrite(GPIO0,LOW);
        delayMicroseconds(60);
        digitalWrite(GPIO0,HIGH);
        }
    }
    pinMode(GPIO0,INPUT);
    
  delay(20);
  pinMode(GPIO0,OUTPUT);
  digitalWrite(GPIO0,HIGH);
  
  delay(5000);
  

}

This isn’t the same code that got a result from the Uno, I was trying to mimic the actual OneWire signals that the Uno was send via the usual library.
The Uno call was using the OneWire lib.

I think I’ve found the solution. There are macros provided to directly modify the GPIO pins (CY_SYS_PINS_READ_PIN/CY_SYS_PINS_CLEAR_PIN/CY_SYS_PINS_SET_PIN/CY_SYS_PINS_SET_DRIVE_MODE). With some pointer arithmetic the OneWire library can directly use these.

There is a PR with a proposed fix.

Well done! Have you tested as well?

Just merged it.
Great work.
Hope to test it today

tested and it works like a charm.
@jokel Thank you for your great help

@rsmedia, please note that the URL provided is broken.
Thanks

Hi

Yes i know i deleted my fork.
I push all my work to the official repository now

Hi there what is the link to yur repository?

BR
/A

It is all in the official repository

Hi skipper, did you manage to get everything working with the DS18B20? - interested to se the complete code, do you have a repository avaiable

BR

/A

Hello

Ivé been looking at the new onewire files, and in the DS18xx it is a reference to “onewire ds10;” as port 10 for reading sensor, wich pinout does this refer to,? looked at onewire.h and it´s subroutines but it seems that it allocates the available GPIO port on stack or something…
Is there a way to allocate another of the GPIO pins on bord for reading data or how do this work…
Syntax?

BR
/A

use

OneWire ds(GPIO1);

to choose the pin you want.
GPIO1 is only an example

Thanks, just noticed the change in the repository :-), it says
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary) in my example file since yesterday

Sitll compiles however, whats the story on this? wich pin will it be? still GPIO1?

have a wonderful evening /A

the last change in the onewire library was a month ago.

it is just an example.
put the pin name you want into it:

OneWire ds(GPIO1); will use GPIO1
OneWire ds(GPIO0); will use GPIO0

and so on

it is up to you to choose the pin

OK, i downloaded yesterday and that reference is among the examples :slight_smile:

Still we ofcourse need to use the dallastemperature.h to not be needed to read all data direkt from the sensors, how would you adapt the below simple code to read via dallas library the sensor data

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // Start serial communication for debugging purposes
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
}

void loop(void){ 
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures(); 
  
  Serial.print("Celsius temperature: ");
  // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  Serial.print(sensors.getTempCByIndex(0)); 
  Serial.print(" - Fahrenheit temperature: ");
  Serial.println(sensors.getTempFByIndex(0));
  delay(1000);
}

Hi again guy´s, it mee :slight_smile:
Just cannot get this function to work no matter what i do, it just loops No more adresses
But if you take out the return, next step shows the ROM value of “addr” in hex, wich seems about right, im using DS18B20±ND from Digikey, wich works in all other applications - anyone that knows whats going on - and yes, pullup resistor in place, ran it both in true onewire and with 3.3 & 5V attached, no difference whatsoever

  • All you guy´s in this thread managed to get it to read this sensor last november, do you have any code to share, would be intersting to see if it compiles here

Best Regards / A

if ( !ds.search(addr)) {
Serial.println(“No more addresses.”);
ds.reset_search();
delay(1000);
//return;
}

There’s a bug in platform.txt. I’ll create a pull request shortly to fix it and add a DallasTemperature example

thank you for your great help.
justg merged your request and OneWire is up and running again.

1 Like