Pages: [1]   Go Down
Author Topic: Program appears to hang – Serial.print and OneWire  (Read 1295 times)
0 Members and 1 Guest are viewing this topic.
England
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My program was working, then I made some changes, and now the screen output stops part way through the loop.  

By inserting Serial.print commands I established that I could get output before ds.reset(), but not after.

I thought there was something wrong with the code, so I re-wrote the entire function.  After that, I found that the screen output stopped at ds.read().

I find that the loop is still running, because other outputs are still working, but Serial.print stops working.

So for example this code prints “1” but not “2”:

      byte response = ds.reset();
      ds.select(addr);     // select next device
      ds.write(0xBE);         // Read Scratchpad
      Serial.println("1");
      for (byte j=0;j<9;j++)  { // get data
        data[j] = ds.read();
      }
      Serial.println("2");

However, Serial.print continues to work if I insert 2 lines like this:

      byte response = ds.reset();
      ds.select(addr);     // select next device
      ds.write(0xBE);         // Read Scratchpad
      Serial.println("1");
      for (byte j=0;j<9;j++)  { // get data
      Serial.print ("j = ");                          // new line
      Serial.println (j,DEC);                       // new line
        data[j] = ds.read();
      }
      Serial.println("2");

The above code continues to print as expected.  Can anyone tell me why please, or can anyone make any suggestions?  Have I done something to upset Serial.print?  Is it a coincidence that when Serial.print stops working, it is always after a call to the OneWire library?  All suggestions gratefully received!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed a more strange behavior as follows:

Parts
1.      Arduino Duemilanove
2.      1 Dallas DS18S20
3.      1 Serial LCD from Modern Device

I run the code found on playground for OneWire  with no modifications

I connect the serial LCD on ANY arduino port Digital or Analog and from the outer space random characters appear on the LCD screen

Any ideas are welcome – any solutions much appreciated
Logged

England
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I found the cause eventually.  It was my fault of course.  :-[

I was overflowing an array.  At the top  I had

  byte data[8];

and further down I had:

        data[j] = ds.read();
      for (byte j=0;j<9;j++)  {
        data[j] = ds.read();
      }

If you have a software fault it is likely to be this or an overflow into a string using itoa for example.

I guess you will have checked the wiring to your LCD already.

If all else fails, try running example code from the LCD supplier and build on that.

Good luck!
Logged

Pages: [1]   Go Up
Jump to: