Jump to content

NLCbanner2024.jpg.2478be509670e60c2d6efd04834b8b47.jpg

Observatory Environment Instrumentation


Gina

Recommended Posts

I suppose I might be able to take the DS2408.h code and work out how to drive this device using the library but it's tricky and unknown territory so would much appreciate any help - please :)

Link to comment
Share on other sites

  • Replies 77
  • Created
  • Last Reply

With more searching I found a post on the Arduino Forum in German but with a sketch to read the DS2408 just using the 1-wire library.  This compiled and uploaded without error but when I open the Serial Monitor nothing just a blank window.  This is the sketch

#include <OneWire.h>void ReadAndReport(OneWire* net, uint8_t* addr) {   uint8_t buf[13];  // Put everything in the buffer so we can compute CRC easily.  buf[0] = 0xF0;    // Read PIO Registers  buf[1] = 0x88;    // LSB address  buf[2] = 0x00;    // MSB address  net->write_bytes(buf, 3);  net->read_bytes(buf+3, 10);     // 3 cmd bytes, 6 data bytes, 2 0xFF, 2 CRC16  net->reset();  if (!OneWire::check_crc16(buf, 11, &buf[11])) {    Serial.print("CRC failure in DS2408 at ");    return;  }  Serial.print("Digital = ");  // First 3 bytes contain command, register address.  Serial.println(buf[3], BIN);}OneWire net(12); void setup(void) {  Serial.begin(9600);}void loop(void) {  byte addr[8];   if (!net.search(addr)) {    //Serial.print("No more addresses.\n");    net.reset_search();       return;  }   if (OneWire::crc8(addr, 7) != addr[7]) {    //Serial.print("CRC is not valid!\n");    return;  }   if (addr[0] != 0x29) {    //PrintBytes(addr, 8);    //Serial.print(" is not a DS2408.\n");    return;  }   ReadAndReport(&net, addr);  delay(2000);}
Link to comment
Share on other sites

Taking the sketch that used only the OneWire library I added a Println("Test"); to the code in varios places to see where the code was failing to act like a breakpoint.  This showed me that the sketch wasn't finding the DS2408 address.  Then I went to the OneWire library to see if I could sort out what was happening.  I had mistaken the word "net" as a command whereas it was a variable - various examples in the OneWire library description let me to this answer.  It also taught me a bit more about the Arduino coding structure :)  The problem was that I had the wrong Arduino pin number - yep - that simple :D  With the right pin put into the code, the sketch worked :)

Now I'm getting a cuppa before moving on to more testing and tidying up code... :)

Link to comment
Share on other sites

Well, I've worked out how to read the PIO data but not write to the DS2408 as yet nor operate the strobe (RSTZ).  The latter need a write to the DS2408 to set RSTZ as strobe otherwise it's a reset input.  Pity the DS2408 library access code doesn't compile ATM I can't see any way of making it work but I'll keep thinking...

It might be possible to continuously read the PIO lines and use 4 for data with 1 as a "data available" signal and another as "first value" but that is very inefficient and tricky to get the timing to work.  Using 5 PIO lines as data with 1 to indicate first character of the string would be alright but I would like to get the strobe working and use interrupts.

May take a short break from this as my brain is beginning to hurt :D

Link to comment
Share on other sites

I've been examining the DS2408 library and it all looks reasonable form what I know (probably not that much :D) and the code to call the declaraiions in DS2408.h looks right.  I wondered if it needed a reboot to finalise the library installation but tried that and it didn't make any difference :(  I would really like to get this going because I think it will do what I want.  I wonder if it's worth trying installing it again.

A bit later - nope - no joy :(

Looked at the directory structure and noticed the other DS* libraries were in folders of their own name so renamed "arduino_ds2408_master" to DS2408, restarted the IDE and tried again - no change - so I tried commenting out the "#include <DS2408.h>" line and tried compiling - absolutely exactly the same errors.  So the library is not being recognised :(

Link to comment
Share on other sites

Found this which is applicable :-

ERRORS you may see caused by Library problems: When you try to Verify (Compile) an Arduino sketch you may see error messages like these:
  • Ultrasonic_Serial.pde:1:24: error: Ultrasonic.h: No such file or directory
  • Ultrasonic_Serial:4: error: 'Ultrasonic' does not name a type
If you are seeing errors like those, it means a Library the sketch needs cannot be found. This is probably because you never downloaded the needed library, or it was installed incorrectly. Here, we'll try to explain this Library Stuff!

The "does not name a type" is exactly the error I'm getting which confirms what I thought.  OTOH The library shows in the library list as per :-

Which Libraries do I have Installed?? You can check on which libraries have been installed in your Arduino IDE:
Click on Sketch and hover over Import Library. You will see a list like this (right) of the libraries you have installed. NOTE: The Libraries at the top, before the horizontal bar are Libraries that come pre-installed with every Arduino IDE. Below that are "Contributed" libraries that you have installed.

This shows the DS2408 library is installed.

I don't know - the IDE shows the library as installed but the sketch can't find it :(  I'm foxed :(  Guess I'll have an eearly night - too late to swap to another project tonight.  Maybe I'll think of something else to try tomorrow.  If not I'm shelving this project for a while...

Link to comment
Share on other sites

After a lot more searching and reading web sites including several threads in the Arduino Forum the error I was getting was almost always due to a wrong directory structure.  Apparently, this occurs when installing libraries from GitHub.  They install a containing folder containing the library folder and a *.RST file.  Arduino IDE needs a structure where the libraries folder contain folders containing the *.cpp and *.h files and an examples folder - NOT having an additional layer.  I copied the DS2408 folder from the ZIP file directly into the libraries folder and put the DS2408.rst file in the examples folder.  The example sketch not compiles, uploads and runs correctly :)

PHEW!!!

Link to comment
Share on other sites

Found this snippet of code to set RSTZ to strobe mode :-

OneWire net(54);net.reset();net.select(addr);net.write(0xcc); //command to write to registersnet.write(0x8d); //select the control status registernet.write(0x00);net.write(0b00000100); //set RSTZ mode to STRB//the colde now is optional, but since there is no error checking while setting status registers, it's important to read them backnet.reset();net.select(addr);net.write(0xf0);net.write(0x8d);net.write(0x00);byte reg0x8d = net.read();if (!(reg0x8d & 0b100)) { Serial.println("Writing to status register went wrong");}//now you can write to the output latches using PIO WRITE command (0x5a)
Link to comment
Share on other sites

With a break in the rain I've been out to my observatory to check it.  No wet has got into the building but the pump had stopped and the water underneath was right up above the bottom of the beams.  The pump needed a good knock to get it to go but then ran alright and has now emptied the hole.  Put the rock back on top and it's now slurping away pumping out the gradually accumulating water ever minute or two.  I need to get the framework done to mount the two pumps and get the reserve pump installed and piped out over the bank.  I also really want to get the water level meter working.

Link to comment
Share on other sites

I've replaced the pump with the new one screwed to a piece of wood and weighted down with small pieces of rock.  I estimate the pump is about 50mm above where the other one was.  I also used the new pipe I bought - 4m of proper bilge pump pipe (non-kink) and this reaches beyond the west end of the building and out over the bank towards my neighbour's field.  I can see the end of the pipe from the house so will be able to see the outflow when we get the next downpour.

Link to comment
Share on other sites

On the coding front, I tried the code to use the RSTZ as probe but it didn't work :(  I think I need to work out and write down all the one-wire library calls.  Then I should be able to work out the code to do anything with any 1-wire device.  The DS2408 library doesn't do what I want.  Maybe I'll create my own library for the DS2408 to simplify other uses I shall have for it.  I may be using this chip in other parts of the weather station such as where Maxim have discontinued the devices I'm currently using.

Link to comment
Share on other sites

The general sequence seems to be :-

  1. Tell onewire which pin is used for the 1-wire network
  2. Search for addresses
  3. Do CRC check
  4. Write device address to use
  5. Write register to access
  6. Read or write register

There are probably variations and maybe short cuts.

I shall be testing this out shortly.  Maybe I see the light at the end of the tunnel :D  All this has been somewhat brain straining!!

This web page seems to give some more info :)  And there's the Arduino onewire page too.

Link to comment
Share on other sites

I guess I'm making gradual progress with this though very very slowly :D  ATM I feel that all my projects have either ground to a halt or making little progress :(  Of course, the weather doesn't help but I seem to be having more than usual trouble getting my brain round things.  I keep thinking of that advert about "moving to the woods and becoming a full-time off-grid spoon whittler"...

Link to comment
Share on other sites

Hi Gina,

I know just how you feel! I have just gone through a similar period of complete frustration when I couldn't seem to make any headway at all. I felt as if I had totally lost touch with astronomy and imaging - the things I want to do - and was drowning in a sea of electronic ignorance, where nothing I tried to do worked.

However, although I'm still not properly up to speed, I now at least wake up with a few ideas again and now at least feel as if I have a roadmap of how to get to where I need to be. So, it's January, it's wet and horrid weather and one's glass looks more half-empty rather than half-full. But spring will come, electrons will be made to do what they're supposed to do and - dare I say it - progress will be made. So, keep at it! I think spoon whittling's loss will be amateur astronomies gain.

Regards, Hugh

Link to comment
Share on other sites

Oh, thank you for that Hugh :)  I'm glad it's not just me - not that I'd wish it onto anyone else, of course.  But how you were feeling is exactly how I'm feeling.  My astro gear wont work either :(  I'll try to hang in there and hope I find my enterprising spirit again soon.  And good luck for your continuing recovery too :)

Link to comment
Share on other sites

A coding here we go ....

From the OneWire library site.

Basic Usage

  1. OneWire myWire(pin) - Create the OneWire object, using a specific pin. Even though you can connect many 1 wire devices to the same pin, if you have a large number, smaller groups each on their own pin can help isolate wiring problems. You can create multiple OneWire objects, one for each pin.
  2. myWire.search(addrArray) - Search for the next device. The addrArray is an 8 byte array. If a device is found, addrArray is filled with the device's address and true is returned. If no more devices are found, false is returned.
  3. myWire.reset_search() - Begin a new search. The next use of search will begin at the first device.
  4. myWire.reset() - Reset the 1-wire bus. Usually this is needed before communicating with any device.
  5. myWire.select(addrArray) - Select a device based on its address. After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.
  6. myWire.skip() - Skip the device selection. This only works if you have a single device, but you can avoid searching and use this to immediatly access your device.
  7. myWire.write(num); - Write a byte.
  8. myWire.write(num, 1); - Write a byte, and leave power applied to the 1 wire bus.
  9. myWire.read() - Read a byte.
  10. myWire.crc8(dataArray, length) - Compute a CRC check on an array of data.
Link to comment
Share on other sites

Here is an example taken from the web site showing use of the OneWire library to access the DS18B20 digital thermometer.  I plan to modify this example to try to access the DS2408.

#include <OneWire.h>/* DS18S20 Temperature chip i/o */OneWire  ds(10);  // on pin 10void setup(void) {  Serial.begin(9600);}void loop(void) {  byte i;  byte present = 0;  byte data[12];  byte addr[8];    if ( !ds.search(addr)) {    Serial.print("No more addresses.\n");    ds.reset_search();    delay(250);    return;  }    Serial.print("R=");  for( i = 0; i < 8; i++) {    Serial.print(addr[i], HEX);    Serial.print(" ");  }  if ( OneWire::crc8( addr, 7) != addr[7]) {      Serial.print("CRC is not valid!\n");      return;  }    if ( addr[0] != 0x10) {      Serial.print("Device is not a DS18S20 family device.\n");      return;  }  // The DallasTemperature library can do all this work for you!  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("P=");  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();}

Since the < code > authorised view doesn't use sensible colours msking it hard to read, here it is in plain text directly copied from the OneWire library web site:-

//

//#include <OneWire.h>/* DS18S20 Temperature chip i/o */OneWire  ds(10);  // on pin 10void setup(void) {  Serial.begin(9600);}void loop(void) {  byte i;  byte present = 0;  byte data[12];  byte addr[8];    if ( !ds.search(addr)) {    Serial.print("No more addresses.\n");    ds.reset_search();    delay(250);    return;  }    Serial.print("R=");  for( i = 0; i < 8; i++) {    Serial.print(addr, HEX);    Serial.print(" ");  }  if ( OneWire::crc8( addr, 7) != addr[7]) {      Serial.print("CRC is not valid!\n");      return;  }    if ( addr[0] != 0x10) {      Serial.print("Device is not a DS18S20 family device.\n");      return;  }  // The DallasTemperature library can do all this work for you!  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("P=");  Serial.print(present,HEX);  Serial.print(" ");  for ( i = 0; i < 9; i++) {           // we need 9 bytes    data = ds.read();    Serial.print(data, HEX);    Serial.print(" ");  }  Serial.print(" CRC=");  Serial.print( OneWire::crc8( data, 8), HEX);  Serial.println();}
Link to comment
Share on other sites

For testing I have two pins on an Arduino Uno connected to separate 1-wire networks.  Each network has just one 1-wire device on it.  Pin 7 has the DS2408 and pin 8 has a DS18B20.  The test code above is for the DS18S20 whereas my device is a DS18B20,  Now the DS18S20 has a family code of 10hex whereas the DS18B20 has a family code of 28hex.  Unsurprisingly the code above when run on pin 8 1-wire net reports that the device is NOT a DS18S20.  Change the test to 28 and we get

R=28 55 43 C4 3 0 0 AF P=1 FE 0 4B 46 7F FF 2 10 8A  CRC=8A
No more addresses.

The temperature data is contained in the P= hex code and would need decoding to read the values in human terms.  But this doesn't concern me ATM - the code has successfully found the device and read its data.  This RAW code data reading could be applied to any device and the actual values obtained by decoding the hex code.

Breaking this down :-

OneWire  ds(8);  // on pin 8  This creates an instance of a 1-wire object for pin 8 and called it "ds"

And this part looks at the first hex data value for the address and compares it with 28 - the family code for the DS18B20.

  if ( addr[0] != 0x28) {
      Serial.print("Device is not a DS18B20 family device.\n");
      return;

Link to comment
Share on other sites

As I sort this out I am going to proceed very slowly, one step at a time making sure I understand each step.  With very little knowledge of the innards of OneWire I need to do this so as not to be overwhelmed by it.

The above code is for the DS18B20 but I'm particularly interested in the DS2408 - the DS18B20 has a library that works well enough and contains all the decoding wanted to extract the temperature.  The DS2408 library is very crude and simple in comparison and doesn't do what I want.  So I now want to modify the code to read and write to the DS2408.

So let's take the first chunk of code :-

post-13131-0-58213100-1453412293.jpg

We create an instance of a 1-wire device, call it "ds" and attach it to pin 7.  Next is simply setting up the Serial Monitor communication.  In the loop we declare some byte array variables then search the 1-wire net on pin 7 for devices.  I have set a delay of 10000ms = 10s to give time to copy the text for repeating display.

In this next section we will print out the device address in hex, check the CRC and the address family.

post-13131-0-19098300-1453413311_thumb.j

Note that I am still checking for the DS18B20 family, which this isn't so the Serial Monitor will tell us this but also what the address actually is and we know that the first 2 hex digits are the family code.

Result :-  The sketch compiles, uploads and runs :)  The Serial Monitor reports :-

R=29 80 A5 18 0 0 0 C Device is not a DS18B20 family device.
No more addresses.

This has successfully read the DS2408 device address and the result code tells us the falily code is 29hex.

Link to comment
Share on other sites

Next stage is to work out the command code and register address or whatever to read the PIO data.  I need to study the data sheet and see if I can understand it.  Maybe it will help if I study the DS18B20 data sheet and see how things correspond.  The DS2408 is a much more complicated device with many more commands and registers.

Think I'll take a break now and resume this tomorrow.  I think I've made some progress today but it's slow going :D

Link to comment
Share on other sites

Partly working - pushed button on P2 for the second set of data.  I've highlighted the changed data.  :)

R=29 80 A5 18 0 0 0 C  CRC=FB
P=1 FF 4 FF 0 0 0 88 FF FF  CRC=13
No more addresses.
R=29 80 A5 18 0 0 0 C  CRC=13
P=1 FF 4 FF 4 0 0 88 FF FF  CRC=C
No more addresses.

But then it didn't change back when I released the push button.  Investigating...

This is the code I added to read the PIO data :-

post-13131-0-97739600-1453456045_thumb.j

Link to comment
Share on other sites

I've compared the DS18B20 code with the DS2408 and there's really no comparison.  The DS18B20 has only a couple of registers and one command tells it to read the temperature.  Following that with reading a register is all that's required to read the temperature data.  The rest of the library is devoted to converting the hex data to numerical.  The only extra is the ability to change the resolution by writing to one register but that isn't contained in the OneWire example.

For the DS2408 I need to work out not only the Read PIO Data which seems to be the command F0h and tell it it read the PIO register which is 88h but which data bits are which etc.  What I thought would work doesn't :(  Wondering if I'm "losing it" :(

Link to comment
Share on other sites

This coding problem is going on too long - maybe I need a change of tack... 

The small pump hasn't arrived today as expected but when it does, I shall need to control it.  Yes, I can do that with the Arduino I'm using to read the water level but I think I really need to be able to tell what's happening remotely (ie. indoors when it's raining cats and dogs).  I think I'm going to have to shelve the DS2408 idea for now and get back to it later so I'm thinking of going back to using a DS2438 to send the water level data over the 1-wire bus.  I really need to get one of my projects working or I shall be giving up electronics etc. altogether :(  I'm doing quite well with my art (currently watercolour painting but I'm thinking of diverging into acrylics) and I could put more time into that - it's certainly more relaxing than wondering why things don't work!!!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.