mikaelpatel / Arduino-OWI

One Wire Interface (OWI) library for Arduino
https://mikaelpatel.github.io/Arduino-OWI/
62 stars 14 forks source link

Which example emulates the function of several one-wire devices? #8

Closed adamaero closed 5 years ago

adamaero commented 5 years ago

I don't know if it's appropriate to ask here, but does the Arduino Slave emulate 1-Wire devices: https://github.com/mikaelpatel/Arduino-OWI/tree/master/examples/Slave/Arduino

(I would like to simulate some 1-wire devices with an Arduino Mega to a datalogger. Maybe I'm confusing different types of emulation.)

mikaelpatel commented 5 years ago

@adamaero Did you have a look at the DS18B20 emulation? https://github.com/mikaelpatel/Arduino-OWI/blob/master/examples/Slave/DS18B20/DS18B20.ino. The Slave::OWI class https://github.com/mikaelpatel/Arduino-OWI/blob/master/src/Slave/OWI.h gives that basic support for creating emulation of 1-Wire devices. There is limited support for matching multiple ROM address, device families, etc, but possible.

adamaero commented 5 years ago

Wow, you are quick.

I don't understand it very well. I've never heard of things like cyclic redundancy check. So it doesn't involve a TX pin, but an analog pin (A0) that simulates temperatures?

How do I set different temperatures to be simulated? Is that what the 85, 75, 70 C is doing (in the DS18B20.ino)?

Thank you for your time.

mikaelpatel commented 5 years ago

@adamaero The example emulation of DS18B20 uses an analogRead() of pin A0, https://github.com/mikaelpatel/Arduino-OWI/blob/master/examples/Slave/DS18B20/DS18B20.ino#L44. The value read is mapped from 0..1023 to -128.00..127.75 C, 10-bits resolution, according to the DS18B20 temperature format. Pin D7 is used for 1-Wire, https://github.com/mikaelpatel/Arduino-OWI/blob/master/examples/Slave/DS18B20/DS18B20.ino#L32. The DS18B20 device has a low and high temperature threshold for alarms (70..75 C). The device has also a power-on default value (85 C). To simulate different temperatures connect a potentiometer to A0. Or if you are doing pure testing of a logger you could simply skip the analogRead() etc and return a fixed value (but then you will need to read about number representation on the DS18B20). Emulating a 1-Wire device requires a lot of understanding of the protocol, timing, number representation, etc. The library helps you implement the functionality.

adamaero commented 5 years ago

For the libraries

include "OWI.h"

include "Slave/OWI.h"

How do I know which to put in the same folder when they're the same name? (Since without having them in the same folder, I get the error: "No such file or directory".)

mikaelpatel commented 5 years ago

@adamaero Is this a question about how to install a library? Or something specific for the original issue? Or maybe a question about refactoring the original directory structure of the OWI library?

adamaero commented 5 years ago

It's probably not specific. I'll spend more hours trying to figure it out... I either have to move https://github.com/mikaelpatel/Arduino-OWI/blob/master/examples/Slave/DS18B20/DS18B20.ino or the three .h libraries, to run DS18B20.ino without errors, right?

mikaelpatel commented 5 years ago

@adamaero Would be easier to understand if you would tell me what is your goal, what you want to achieve. In general you should install the library, run the examples to get to know the library, copy an example sketch to your Arduino folder and then continue to develop it or start to develop your own sketch. Do not change library code if you do not intend to contribute with a Pull Request. There is no need to move library code around. Have you read how to install an Arduino library?

adamaero commented 5 years ago

I am trying to run that example: DS18B20.ino

mikaelpatel commented 5 years ago

@adamaero Master or Slave version on what Arduino? What is you setup? Arduino IDE version, compiler, host machine, etc?

mikaelpatel commented 5 years ago

@adamaero Any error/warnings from the compiler? Any changes made? How did you install the library? Why do you think you should move files to get it to work?

mikaelpatel commented 5 years ago

@adamaero Seems like we have moved away from the initial issue. If you do not object I will close this issue. Thanks for your interest in this library and good luck with your project.