Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Library writers >> OneWire library/Wiring/logistical question
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1211295154

Message started by N201LJ on 05/20/08 at 14:52:34

Title: OneWire library/Wiring/logistical question
Post by N201LJ on 05/20/08 at 14:52:34
I've modified the OneWire library in the arduino distribution to work with Wiring.  This library allows users to communicate with Dallas Semi/Maxim 1-Wire devices (e.g. DS18B20)

What's the most efficient way to contribute it to this project? (It's a little large to post directly in the forum...)

Title: Re: OneWire library/Wiring/logistical question
Post by barragan on 05/21/08 at 00:23:21
hey this is great, we can add it to the library section of the site with your credits etc, we could also host it on Wiring cvs http://wiring.org.co/source if you want as well.
Just let me know what do you want to do.

Title: Re: OneWire library/Wiring/logistical question
Post by N201LJ on 05/21/08 at 04:07:31
Thanks - happy to contribute.  I have an e-mail in to the author of the original arduino code to work out permissions.  Just want to get the attributions correct.

Title: Re: OneWire library/Wiring/logistical question
Post by N201LJ on 06/02/08 at 22:04:51
I finally finished adapting the arduino OneWire library to work with Wiring.  This library will let your sketches talk with Dallas Semiconductor/Maxim 1-wire devices (e.g. DS18B20).  

You can find this library for download and a quick example sketch at:  http://idisk.mac.com/duncan.alan-Public

If you find bugs, etc. let me know.  It seems to work in my sketches; but I have not tried it with devices other than DS18B20.

Would be happy to document on the library page of the site, if you like.

Cheers,
akd

Title: Re: OneWire library/Wiring/logistical question
Post by barragan on 06/02/08 at 23:57:52
We could either link your page or create a local version for the reference if you prefer. Also we could include the library with the Wiring distribution as well. Let me know. Thanks for doing this :)

Title: Re: OneWire library/Wiring/logistical question
Post by N201LJ on 06/04/08 at 03:36:09
You know - probably best to set up a local version, if you don't mind.  Happy to include in the distro.

Title: Re: OneWire library/Wiring/logistical question
Post by barragan on 06/04/08 at 16:06:56
cool, please send me the zip file, Iīll add it to the svn and distribution.

Title: Re: OneWire library/Wiring/logistical question
Post by N201LJ on 06/07/08 at 02:52:57
You should be able to download it here:  http://idisk.mac.com/duncan.alan-Public/OneWire.zip

akd

Title: Re: OneWire library/Wiring/logistical question
Post by barragan on 06/13/08 at 06:31:49
hi, I am integrating it into the Wiring libraries, I have a question reagarding the API,
which set of functions are part of the end user API? If all of them it would be nice to rename some of them to be consistent with the Wiring API style, for example writeBit
readBit resetSearch etc. Let me know what do you think.

   OneWire( uint8_t pin);
   uint8_t reset();
   void select( uint8_t rom[8]);
   void skip();
   void write( uint8_t v, uint8_t power = 0);
   uint8_t read();

   void write_bit( uint8_t v);
   uint8_t read_bit();
   void depower();

#if ONEWIRE_SEARCH
   void reset_search();
   uint8_t search(uint8_t *newAddr);
#endif

   static uint8_t crc8( uint8_t *addr, uint8_t len);
#if ONEWIRE_CRC16
   static unsigned short crc16(unsigned short *data, unsigned short len);
#endif


Title: Re: OneWire library/Wiring/logistical question
Post by N201LJ on 06/14/08 at 01:14:56
Sure - I can rename to make them consistent.  Before I do, is there a written standard, or is it simply lowercaseUppercase (i.e. camel case )


Title: Re: OneWire library/Wiring/logistical question
Post by barragan on 06/14/08 at 01:39:40
yes thatīs it, also verify the coherence of the naming/functions, I am not familiar with OneWire protocol so I have questions about the functions, what does select does? or skip, readBit and writeBit, search etc. in the communication process, perhaps looking at examples will make it clearer to me. Thanks for doing this.

Title: Re: OneWire library/Wiring/logistical question
Post by N201LJ on 06/14/08 at 12:29:54
OneWire::select will select a given device on the 1W bus.  Because many devices can exist on the same bus, calling select() with the ROM address of the desired device will cause it to listen to the next command.  For example, issuing the following sequence on a 1W bus that contains a DS18B20 temp sensor will start the temperature conversion:

_1W.reset();
_1W.select( rom);
_1W.write(0xBE);

OneWire::skip(), on the other hand, tells all of the devices on the bus to listen to the next command.  Essentially, it means "skip the ROM address."  It would be applicable, for example, on a bus with only one device, where you don't care about its unique ROM.

I changed the naming for read_bit to readBit, etc.  Although most users will only use the byte level routines, I left the bit routines in the public interface in case there are devices that have unique protocols that might require them.

Here's an example reading the temperature from a DS18B20 1W device:

Code:
OneWire    _1W(16);   //initiate 1W on pin 16

int read_DS18B20( byte rom[8] )
{  
   int TReading;
   byte preset = 0;
   byte i;
 
   _1W.reset();
   _1W.select( rom );
   _1W.write(0x44,1);         // 0x44 =start conversion, w/ parasite power on at end
   delay(750);
   _1W.reset();
   _1W.select( rom);
   _1W.write(0xBE);           // 0xBE = read scratchpad
   for(int i = 0; i<8; i++)
   {
       data[i] = _1W.read();
       //Serial.print(data[i]); Serial.print(" ");
   }
   TReading = (data[1] << 8) + data[0];
   return( TReading );
}

void showStatusAmbientTemp()
{
   int TReading = read_DS18B20( ROM_AMBIENT_TEMP );
   
   int signBit = TReading & 0x8000;
   if( signBit )
   {
       TReading = (TReading ^ 0xFFFF) + 1; //2's comp if negative
   }
   float TFloat = TReading * 0.0625;
   
   clearLCD();
   selectLineOne();
   serialPrintMsgByAddress( SERIAL1, MSG_AMBIENT_TEMP_1);
   selectLineTwo();
   printFloatingPoint( TFloat, signBit );
   Serial1.print("C");
   gCurrentAmbientTemp = (int) TFloat;
}


I can write up a document describing the user API and more detail around this example if that would be better...

Title: Re: OneWire library/Wiring/logistical question
Post by barragan on 08/26/08 at 06:22:05
Dear Alan, I have included the OneWire library in the repository for 0017, please check if things are ok so far. I am Still doing fixes before releasing 0017.
http://wiring.uniandes.edu.co/source/trunk/wiring/lib/OneWire/

Thanks for your help.
best,
Hernando.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.