Arduino controller build thread

Coding the arduino is simple and straight forward. You will have fun with this build, and with a little ingenuity and careful thinking you can program this thing to do anything. If you want to expand your I/O you can also add a muxshield for about $23 which adds 48 I/O.
 
These just came in. May rig up the LCD and temp sensor a little later to test.

mu2amyna.jpg



Sent from my iDevice.
 
Nice!

For those interested in starting on something like this, I've found these tutorials a great place to get some basics down: Tutorial 01 for Arduino: Getting Acquainted with Arduino - YouTube

Granted I've taken a couple of programming classes back in the day, but these are still fairly simple to follow.

Can't wait to see how this turns out, Josh.

Brandon
 
Got the temp probe wired up. Still very beta. I've been fight the cold/flu. When I get some time tonight I'll cost code.

9anyhegy.jpg


The temp is real time.


Sent from my iDevice.
 
Quick and dirty copy paste of code. Need to clean it up a bit.

Code:
#include <OneWire.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>


#define I2C_ADDR    0x3F  // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7


int n = 1;


LiquidCrystal_I2C	lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
OneWire ds(10); //temp sensor on pin 10


void setup()
{
  lcd.begin (20,4);
  Serial.begin(9600);
  
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();                   // go home
  lcd.print("Temp:");  
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print("Middle TN Reef Club");  
  lcd.setCursor ( 0, 2 );        // go to the next line
  lcd.print("TheJoshDavis");
  lcd.setCursor ( 0, 3 );        // go to the next line
  lcd.print("myReef Controller");
  lcd.setCursor ( 0, 4 );        // go to the next line
//   lcd.print("Iteration No: ");
}


void loop()
{
  // Backlight on/off every 3 seconds
  //lcd.setCursor (14,3);        // go col 14 of line 3
  //lcd.print(n++,DEC);
  //lcd.setBacklight(LOW);      // Backlight off
  //delay(3000);
  //lcd.setBacklight(HIGH);     // Backlight on
  //delay(3000);
  
   byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }


  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();
 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 


  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("  Data = ");
  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();


  // convert the data to actual temperature


  unsigned int raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // count remain gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
 
   //Display current temperature*****************************************************************************
  
     
  lcd.setCursor ( 0, 0 );        // go to the next line 
  lcd.print("Current Temp:");
  lcd.print(fahrenheit);
  lcd.print(" F");
}
 
Its called "the Boolean wink". :D

There are 10 kinds of people in the world... those who understand binary, and those who don't.

Geek it till it Mhz!

Ok, I'm done... :D

Brandon
 
Running into my first problem which I could probably resolve with some Google-fu. Running 2 onewire devices on the same interface. I wired up the RTC last night, got it set and running, but could not get it to print the time to the LCD.
 
You'll have to create containers for the time, look for the 1602 LCD from sainsmarts demo code, it has a method for doing it.
 
If you're using the DS1307 chip try this:

Code:
void loop()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  char buffer[20];
  getDate(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  lcd.cursorTo(0,0);
  sprintf(buffer, "d:d:d", hour, minute, second);
  lcd.print(buffer);
  lcd.cursorTo(1,0);
  sprintf(buffer, "d:d:d:d", dayOfWeek, dayOfMonth, month, year);
  lcd.print(buffer);
}

// Convert binary coded decimal to decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val) );
}


// Gets the date and time
void getDate(byte *second,
             byte *minute,
             byte *hour,
             byte *dayOfWeek,
             byte *dayOfMonth,
             byte *month,
             byte *year)
{
  Wire.beginTransmission(0x68);
  Wire.send(0);
  Wire.endTransmission();
  Wire.requestFrom(0x68, 7);
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}
 
Planning to get back to building this week. Been busy and all over the place and havent had a chance to sit down and code.
 

IF YOU HAD TO TAKE A REEFING EXAM, WOULD YOU PASS?

  • Yes!

    Votes: 32 45.7%
  • Not yet, but I have one that I want to buy in mind!

    Votes: 9 12.9%
  • No.

    Votes: 26 37.1%
  • Other (please explain).

    Votes: 3 4.3%

New Posts

Back
Top