MicroView and Phoenard Arduino Forum
Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment   Page 1 of 2      1   2   Next
naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #1 
Hey Guys,

I am a 100% noob to programming and really hoped the arduino would get me into it.  I still feel that way but am just extremely busy at work these days and will never get to my coding project.

I bought the microview and ds18b20 temperature sensor because I want to monitor the temperature in my aquarium.  

I know most of you coders out there could write it in your sleep so I was wondering if someone would want to write it for me and I'd be more than willing to pay.

I got the ds18b20 to work just find on my UNO using existing code on the net and using the serial monitor on my pc but this is no-where near as nice as the microview.  I guess I said that to say I understand how to wire it up and everything so I wouldn't need help there.  I just need the microview code.

Also if there is already code out there for the microview and ds18b20 combo please link it to me.  I have exhausted google looking for such code.

thanks!
Nate


MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #2 
Can you point to, or provide a copy of the sketch and library, or libraries, you used for the UNO?

What would you like to display on the MicroView's screen? Just the numerical temperature?
naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #3 

Hey MLXXXP

Thanks so much for the response.

Yeah numerical temperature is all I am looking for right now.

Here is the tutorial i used

http://bildr.org/2011/07/ds18b20-arduino/
(the code is at the bottom of that link)

Also this is the version of ds18b20 i have
https://www.adafruit.com/products/381


Thanks!!
-Nate

MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #4 
Try this sketch for starters. I don't have a DS18B20, so I can't fully test the code. If it works and you'd like to add more features, such as a flashing warning if the temperature goes outside a certain range, we can work on it.

Note that the font used doesn't include a minus sign, so negative numbers will be displayed with a blank in front of the value, where the minus sign should be. I'm guessing this won't be a problem for use as an aquarium thermometer. [wink]


#include <MicroView.h>
#include <OneWire.h>

int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin);  // on digital pin 2

void setup() {
  uView.begin();
}

void loop() {
  float temperature = getTemp();

  if (temperature != -1000) {
    uView.clear(PAGE);
    uView.setFontType(2); // 10 X 16 "seven segment" numeric font
    uView.setCursor(8,15);
    uView.print(temperature, 1); // display with one decimal place
    uView.display();
  }

  delay(500); //just here to slow down the output so it is easier to read
}

void diplayMessage(const char *message) {
  uView.clear(PAGE);
  uView.setFontType(0); // 5 X 7 font
  uView.setCursor(0,7);
  uView.print(message);
  uView.display();
  delay(2000);
  uView.clear(PAGE);
  uView.display();
  delay(200);
}

float getTemp() {
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      diplayMessage("CRC is\nnot valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      diplayMessage("Device notrecognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

 
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
 
  ds.reset_search();
 
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
 
  return TemperatureSum;
}
naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #5 
Thanks!!!!!!!!!!!!!!!!!! ill try it tonight and see what happens ;-)
naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #6 
Hey there,

So i got it wired up and and the code uploads to the microview with no errors.

But all i get is "CRC is not valid!" and "device not recognized" flashing on the screen.

I do see these messages in your code but not sure what they mean [smile]

if ( OneWire::crc8( addr, 7) != addr[7]) {
diplayMessage("CRC is\nnot valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
diplayMessage("Device notrecognized");
return -1000;
}

 

thanks,
-Nate

MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #7 
I get those messages because I don't actually have a DS18B20 to connect. The messages probably indicate that the DS18B20 isn't wired properly or is connected to the wrong input pin.

Unless you change it, the sketch expects you to connect the sensor output to Arduino Pin 2, which on the MicroView is physical Pin 11. Is that how you've wired it?

See the Pin Configuration diagram here for more information.
naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #8 
My man!

It works!!  You were correct i was using the physical pin and not the arduino pin.

Is there a quick way to get the output in Fahrenheit instead of Celsius?
MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #9 
Quote:
Originally Posted by naterad
Is there a quick way to get the output in Fahrenheit instead of Celsius?

Change line:
  float temperature = getTemp();

to:
  float temperature = getTemp() * 9/5 + 32;


naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #10 
Dude you are so awesome!!

Thank you so much for getting this working for me.  It is perfect.

If you are up for it i have another tweak id like to do to it.

I also have this   http://www.hobbyist.co.nz/?q=interfacing-relay-modules-to-arduino

The reason behind buying this is you cannot trust aquarium heaters by the temperature dials they have them, so i was hoping instead of worrying about if my heaters are accurate i would just have them turn on if the temperature from the ds18b20 goes below a certain temp then relay 1 and 2 would turn on which my heaters are plugged into and then when the temp gets to a certain degrees turn the relays off.

For example:
relay 1 and 2 on if temp < 77F
relay 1 and 2 off if temp > 79F

Thoughts?

Thanks again bud!
-Nate
MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #11 
Quote:
Originally Posted by naterad
If you are up for it i have another tweak id like to do to it.


This isn't to hard to add, but I've become a bit busy now, so it may be a few days before I can find the time to make the changes and properly test them, if that's OK with you.

naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #12 
Oh man take your time!  Just be able to digitally see my temperature is way better than before ;-)
MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #13 
OK, I've added code to control heater relays. The pins for the relays are 3 and 5 (MicroView physical pins 12 and 13) but you can change them near the start of the sketch, if you wish. You also can set the heater on and off temperatures there.

I've also added a "temperature out of range" alert feature. You set the alert threshold temperatures near the start of the sketch, like the others. If the temperature goes below AlertLowTemp or above AlertHighTemp, the display will be flashed by inverting the pixels, with a TOO LOW! or TOO HIGH! message added.

I've put the code on GitHub at https://github.com/MLXXXp/MicroViewThermostat

Again, I don't have a DS18B20 to test with, so let me know if you have any problems.
naterad

Junior Member
Registered:
Posts: 15
Reply with quote  #14 
This works!!!

I wired it up just now and tested with the warmth of my hand vs a glass of water and the relays and messages were spot on!  Thank you so much!!!

I love the addition of flashing, and telling me if the relays are on or off as well.

MLXXXp your turn around time and getting it right on the 1st try amazes me.  Now I need to go back and read through the code and start learning something [smile]

I would love to compensate you for your time if you want.  Please send me your paypal address ;-)
MLXXXp

Avatar / Picture

Senior Member
Registered:
Posts: 75
Reply with quote  #15 
Quote:
Originally Posted by naterad
This works!!!

That's good to hear [thumb]

Quote:
Originally Posted by naterad
I love the addition of flashing, and telling me if the relays are on or off as well.

If it's important to be alerted when the temperature goes out of range (so your fish don't get cooked or frozen) you could also add a piezo speaker that would beep when the screen is flashing. It only takes one or two extra lines of code to do this using the tone() function.

Quote:
Originally Posted by naterad
MLXXXp your turn around time and getting it right on the 1st try amazes me.

Well, I didn't say that I didn't do any testing; just that I couldn't test with an actual DS18B20. I temporarily replaced the code that reads the sensor with code that reads a potentiometer, so that I could generate any simulated temperature reading that I wanted, for testing.

Quote:
Originally Posted by naterad
I would love to compensate you for your time if you want.

That's not necessary, though if it's not too much trouble to post a photo or two of your working set up, I'd like to see it. [smile]
Previous Topic | Next Topic
Print
Reply

Quick Navigation:


Create your own forum with Website Toolbox!