Loading...
  Show Posts
Pages: 1 2 3 [4] 5 6 ... 13
46  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: January 05, 2007, 11:35:37 am
This program is specifically for the DS18S20P. But it is probably easier to get a non P(arasite) version working. To avoid misunderstandings let's start with the DS18S20P  connections.

GND and Vdd to GND, Dq to pin 6 AND  to pin 7 AND via a 4k7 resistor to +5V on arduino board.


Thanks to yerg2k to get me started and jims to get me thinking.
Comments are welcome.

Code:
/* DS18S20P Temperature chip i/o
 * ---------------
 *
 * See http://pdfserv.maxim-ic.com/en/ds/DS1820-DS1820S.pdf for the datasheet.
 *
 * (copyleft) 2006 by Derek Yerger - Free to distribute freely.
 * (sorry Derek, great inspiration but I rewrote it completely)
 *  heavily modified by bigengineer
 * inspired by: http://microsyl.com/
 * and Dallas 1-wire datasheets
 *
 */
#define DQ 7  //data pin
#define PU 6  //separate pin for pull up
#define pin13 13
#define VERSION 01

void setup(void)
{
  // initialize inputs/outputs
  // start serial port
  pinMode(DQ,INPUT);
  pinMode(PU,INPUT);
  pinHigh();
  Serial.begin(9600);
}
byte reset()
{
  pinLow();
  delayMicroseconds(500);
  pinIn();
  delayMicroseconds(70);
  if (digitalRead(DQ) == LOW)
  {
    delayMicroseconds(500);
    return(1);
  }
  return(0);
}
void WriteByte(byte data)
{
  byte i;
  for(i=0;i<=7;i++)
  {
    pinLow();
    if (data & 0x01) //write 1
    {
      delayMicroseconds(7);
      pinIn();
      delayMicroseconds(70);      
    }
    else //write 0
    {
      delayMicroseconds(70);
      pinIn();
      delayMicroseconds(7);
    }
    data>>=1;
  }
}
void convertTemp()
{
  byte i;
  byte data = 0x44;
 
  for(i=0;i<=7;i++)
  {
    pinLow();
    if (data & 0x01) //write 1
    {
      delayMicroseconds(7);
      pinIn();
      delayMicroseconds(70);      
    }
    else //write 0
    {
      delayMicroseconds(70);
      pinIn();
      delayMicroseconds(7);
    }
    data>>=1;
  }
  pullupHigh(); //pull pin 6 high for the conversion
  delay(750); //conversion time is 750 milliseconds
  pullupIn(); //switch off pin 6
  pinIn();
}
byte readByte()
{
  /* timing is critical here. But timing values are different
   * from the datasheets. These values are found by trial & error.
   * The delay's should be somewhere around 15 uS.
   */
  byte data=0;
  byte i;
  byte bit;
  for(i=0;i<8;i++)
  {
    pinLow();
    delayMicroseconds(1); // > 2 doesn't work
    pinIn();
    delayMicroseconds(1); // >5 doesn't work
    bit = digitalRead(DQ) & 0x01;
    data >>= 1;
    if (bit) data |= 0x80;
    delayMicroseconds(50); //doesn't seem to be necessary
  }
  return(data);
}

void pinHigh()
{
  pinMode(DQ,OUTPUT);
  digitalWrite(DQ,HIGH);
}
void pinLow()
{
  pinMode(DQ,OUTPUT);
  digitalWrite(DQ,LOW);
}
void pinIn()
{
  pinMode(DQ,INPUT);
  //pullupIn(); //om de resistor pull-up te laten werken
}

void pullupHigh()
{
  pinMode(PU,OUTPUT);
  digitalWrite(PU,HIGH);
  digitalWrite(pin13, HIGH);
}
void pullupLow()
{
  pinMode(PU,OUTPUT);
  digitalWrite(PU,LOW);
  digitalWrite(pin13, LOW);
}
void pullupIn()
{
  pinMode(PU,INPUT); //necessary for resistor pull-up
  digitalWrite(pin13, LOW);
}

void readRom()
{
  byte j;
  byte pad[9];

  reset();
  WriteByte(0x33);
  for(j=0;j<8;j++)
  {
    pad[j] = readByte();
  }
  for(j=0;j<8;j++)
  {
    Serial.print(pad[j], HEX);
    Serial.print(" ");
  }
  Serial.println("read rom");
}
void readScratchpad()
{
  byte j;
  byte pad[9];
  int msb,lsb;

  WriteByte(0xBE);
  for(j=0;j<9;j++)
  {
    pad[j] = readByte();
  }
  for(j=0;j<9;j++)
  {
    Serial.print(pad[j], HEX);
    Serial.print(" ");
  }
  Serial.print("read scratchpad  ");
  msb = pad[1];
  lsb = pad[0];
  if (msb <= 0x80)lsb = lsb/2;
  msb = msb & 0x80;
  if (msb >=0x80) lsb = (~lsb)+1;
  if (msb >=0x80) lsb = lsb/2;
  if (msb >=0x80) lsb = ((-1)*lsb);
  Serial.print("T =  ");
  Serial.print(lsb);
  Serial.print(" ");
    
}
void loop(void)
{
  readRom();
  reset();
  WriteByte(0xCC);
  convertTemp();
  reset();
  WriteByte(0xCC);
  readScratchpad();
  Serial.print("version: ");
  Serial.println(VERSION);
   delay(1000);                 // Lets not flood.
}

[edit]changed typo that cosinekitty discovered[/edit]
47  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: January 05, 2007, 11:00:47 am
 smiley YES YES
Finally, it works. I'll do a quick clean up of the code and post it. Though I rewrote almost everything it was a hardware  >smiley-sad problem after all. I don't really understand it, maybe someone can explain it to me. There are some other issues that I found out by trial and error. So, I am not there yet, but there is a start to get 1-wire working.
48  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: January 04, 2007, 01:55:34 pm
This http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=41771&highlight=ds18s20 thread explains something about connecting the DS18S20. To it seems it is about the powered sensor. Unfortunately, because I have the DS18S20P I can't connect to it like "kartman" explains.

49  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: January 04, 2007, 11:22:19 am
Quote
The solution is to not let the external pull-up bring the pin high after the low period of the final bit of the 0x44 is written, force it high with the output driver. Then after the 750ms conversion period passes flip the pin back to an input and let the external pull-up take over.


Do you use the same pin for this? In yerg2k's code I bring the pin high immediately after the ds_writebyte(0x44) function. But it still  doesn't work. I was wondering if it maybe takes too much time to finish the ds_writebyte() function and that you are doing someting different with an additional pin.


Quote
You almost certainly have a DS18S20P on your hands.
Hmm, overlooked this one but indeed I have the DS18S20P. So far I still couldn't find what I am doing wrong. I am using the 750 uS delay after the 44h write, then pulling the pin high. Why don't I see what's going wrong?
50  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: January 03, 2007, 03:21:31 am
That's good news jims! How do you connect the DS18S20? I have a resistor between +5V and the data pin. I found this somewhere in the avrfreaks forum.
51  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: December 23, 2006, 01:16:20 pm
Quote
The datasheet isn't very clear and straightforward in describing when "Skip ROM" can be used.

No,  they mention it is possible with only one slave on the bus. See page 9 "SKIP ROM", in the DS1820 datasheet.  (you can follow your own link tot the datasheet)

I searched around on avrfreaks.net to see if there are similar problems. I couldn't find anything useful. I thought I read something about a similar problem.

Would the problem be on timing? How long will the temperature be in the scratchpad? Or would it take more time to finish writing it to the scratchpad than you wait with the while(pres=0) loop?
52  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: December 23, 2006, 10:27:28 am
Well, unfortunately it doesn't work for me either. But, at least I understand why my code didn't work.

I Keep getting the same line:
"AA 0 4B 46 FF FF C 10 87"
The only thing I changed in the code was adding a ds_reset() at the start of the loop(void). But it didn't make any difference. I tried a "read rom", (33h) command. Then the 64bit ROM code is read from the scratchpad. So, that works.
As you stated in the comment after the CONVERT (44h) command this probably doesn't work.
53  Forum 2005-2010 (read only) / Interfacing / Re: Arduino and 1-wire on: December 20, 2006, 02:25:12 pm
I tried to get a DS18S20 working but didn't get any further than the reset. That seemed to work but I never got any data from the sensor. I played around with the timing values but that didn't help me. The delayMicrosecond function seemed to work ok as far as I could measure it with my scope. So I guess filling in the delay's as mentioned in the datasheets should work.

Do you want to share your code? Or at least a read function?
54  Forum 2005-2010 (read only) / Interfacing / Re: Serial Interface with Processing and Dataflash on: March 06, 2008, 03:24:06 pm
It has been a while since I used the dataflash library. It worked for me but..... at some point I discovered that buffer 2 wasn't working. Well, the buffer worked, but storing from buffer 2 into memory didn't.

Something else: I see "lastBufferUsed%2" is that was is really in your program, with the percentage sign?

I would suggest to try to upload some know data like the alfabet or just a known sequence. If you can read this back by sending it over the serial port the problem is probably somewhere else.
55  Forum 2005-2010 (read only) / Interfacing / Re: Arduino GCode Interpreter on: March 01, 2008, 03:38:33 pm
Very nice work! Can you use 3 axis at the same time with this setup? So, do a real 3D movement? Not that it would be of any use for the reprap. But it might be nice if you could use it for a normal milling machine.

I should really start building a reprap. All these different, but very interesting, disciplines come together with it.


56  Forum 2005-2010 (read only) / Interfacing / Re: Original 8bit LCD example problems on: November 06, 2007, 04:39:18 pm
I thought it was mentioned on the forum before but I couldn't find it. My best guess is that you have to  change the int's in void pinMode(int, int) to uint8_t.
57  Forum 2005-2010 (read only) / Interfacing / Re: Help!Help! Serial portname on: November 04, 2007, 02:17:32 am
there is no need for crossposting.
58  Forum 2005-2010 (read only) / Interfacing / Re: dallas temp sensor review and help / (one wire on: September 16, 2007, 02:52:59 pm
This is a quote from jims: (2nd page of 1-wire topic)
Quote
I have the grounds connected, the DQ pin on the DS18S20P connected to the pin of the Arduino, and a 4.7kohm resistor from DQ to +5v as the pullup. It is good to connect the Vdd pin of the DS18S20P to ground also so if you get a non-parasite version (DS18S20) it will also work in parasite mode.

Try to use the sensor in parasite mode. Isn't the difference between B20 and S20 described somewhere in the datasheets?
59  Forum 2005-2010 (read only) / Interfacing / Re: Inconsistent serialprint on: September 25, 2007, 04:32:41 pm
4 characters in a loop,  just a serial.println in the loop function:
void loop()
{
Serial.println("1234");
}
Just to make sure that the connection is ok.
60  Forum 2005-2010 (read only) / Interfacing / Re: Inconsistent serialprint on: September 22, 2007, 06:40:13 pm
Did you try sending the same 4 characters in a loop? So you can see if arduino is sending exact 4 characters or that your serial terminal on the pc side messes things up. What do you use for reading? The arduino IDE?
Pages: 1 2 3 [4] 5 6 ... 13