-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michal Nicpon
committed
Jun 6, 2014
0 parents
commit 0ab0a94
Showing
45 changed files
with
3,432 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build-uno | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BOARD_TAG = uno | ||
MONITOR_PORT = /dev/ttyACM0 | ||
USER_LIB_PATH := $(realpath /home/michal/Projects/Arduino/libraries) | ||
ARDUINO_LIBS = Time Menu Wire DS1307RTC LiquidCrystal Button | ||
|
||
include $(ARDMK_DIR)/Arduino.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
#include "Arduino.h" | ||
#include "LiquidCrystal.h" | ||
|
||
// Set up LCD | ||
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); | ||
|
||
#include "Menu.h" | ||
#include "DS1307RTC.h" | ||
#include "Time.h" | ||
#include "Wire.h" | ||
#include "math.h" | ||
#include "Button.h" | ||
|
||
// Addresses for sensors | ||
byte HIH6130_address = 0x27; // temperature humidity sensor address | ||
byte DS1307RTC_address = 0x68; // real time clock address | ||
|
||
// Initiate variables for sensor data | ||
byte status; | ||
float RH, T_C; | ||
float RH_sp = 0; // set point for humidity | ||
float RH_sp_new = 0; | ||
|
||
// Valve position | ||
int valve1_pin = 10; // Dry stream; | ||
int valve1_level = 0; // this should be a percentage | ||
int valve1_sp = 0; // | ||
int valve2_pin = 11; // Wet stream; | ||
int valve2_level = 0; | ||
int valve2_sp = 0; | ||
|
||
// initiate menu | ||
Menu * main_menu = new Menu(); | ||
|
||
// get the temperature and humidity | ||
byte get_humidity_temperature() | ||
{ | ||
byte Hum_H, Hum_L, Temp_H, Temp_L, status; | ||
unsigned int H_dat, T_dat; | ||
|
||
Wire.beginTransmission(HIH6130_address); | ||
Wire.write(0); | ||
Wire.endTransmission(); | ||
delay(100); | ||
|
||
Wire.requestFrom(HIH6130_address, 4); | ||
Hum_H = Wire.read(); | ||
Hum_L = Wire.read(); | ||
Temp_H = Wire.read(); | ||
Temp_L = Wire.read(); | ||
|
||
status = (Hum_H >> 6) & 0x03; | ||
Hum_H = Hum_H & 0x3f; | ||
H_dat = (((unsigned int)Hum_H) << 8) | Hum_L; | ||
T_dat = (((unsigned int)Temp_H) << 8) | Temp_L; | ||
T_dat = T_dat >> 2; | ||
RH = H_dat * 0.00610388817; | ||
T_C = T_dat * 0.01007141549 - 40; | ||
return(status); | ||
} | ||
|
||
void print2digits(int number) | ||
{ | ||
if (number >= 0 && number < 10) | ||
{ | ||
lcd.print("0"); | ||
lcd.print(number); | ||
} | ||
else | ||
{ | ||
lcd.print(number); | ||
} | ||
} | ||
|
||
void Display(int input=-1) | ||
{ | ||
// digital clock display of the time | ||
time_t t = now(); | ||
tmElements_t tm; | ||
breakTime(t, tm); | ||
|
||
lcd.clear(); | ||
print2digits(tm.Hour); | ||
lcd.print(":"); | ||
print2digits(tm.Minute); | ||
lcd.print(":"); | ||
print2digits(tm.Second); | ||
|
||
status = get_humidity_temperature(); | ||
|
||
if (status == 0) | ||
{ | ||
lcd.setCursor(0, 1); | ||
lcd.print("RH:"); | ||
lcd.print(RH, 1); | ||
lcd.print("T:"); | ||
lcd.print(T_C, 1); | ||
} | ||
else | ||
{ | ||
lcd.setCursor(0, 1); | ||
lcd.print("failed: "); | ||
lcd.print(status); | ||
} | ||
|
||
if (input == 3) | ||
{ | ||
main_menu->change_current_action(main_menu::navigate); | ||
} | ||
} | ||
|
||
void check_valves() | ||
{ | ||
int level; | ||
|
||
if (valve1_level != valve1_sp) | ||
{ | ||
level = map(valve1_sp, 0, 100, 0, 255); | ||
analogWrite(valve1_pin, level); | ||
valve1_level = valve1_sp; | ||
} | ||
if (valve2_level != valve2_sp) | ||
{ | ||
level = map(valve2_sp, 0, 100, 0, 255); | ||
analogWrite(valve2_pin, level); | ||
valve2_level = valve2_sp; | ||
} | ||
} | ||
|
||
void change_humidity(int input=-1) | ||
{ | ||
switch (input) | ||
{ | ||
case -1: | ||
RH_sp_new = RH_sp; | ||
|
||
lcd.clear(); | ||
lcd.print("Change Humidity "); | ||
lcd.setCursor(0, 1); | ||
lcd.print("RH:"); | ||
lcd.print(RH_sp_new, 0); | ||
break; | ||
case 1: // Up Key | ||
RH_sp_new++; | ||
if (RH_sp_new > 100) RH_sp_new = 100; | ||
lcd.setCursor(3, 1); | ||
lcd.print(RH_sp_new, 0); | ||
break; | ||
case 2: // Down Key | ||
RH_sp_new--; | ||
if (RH_sp_new < 0) RH_sp_new = 0; | ||
lcd.setCursor(3, 1); | ||
lcd.print(RH_sp_new, 0); | ||
break; | ||
case 4: // Select Key | ||
main_menu->change_current_action(&(main_menu->save_changes_dialog)); | ||
main_menu->change_last_action(change_humidity); | ||
break; | ||
case 9: // Recieved selection from menu save dialog | ||
if (main_menu->get_selection() == 1) // If "yes" | ||
{ | ||
RH_sp = RH_sp_new; // commit change | ||
} | ||
main_menu->change_current_action(main_menu->navigate); | ||
|
||
break; | ||
default: | ||
break; | ||
} | ||
|
||
|
||
} | ||
|
||
void setup() | ||
{ | ||
setSyncProvider(RTC.get); | ||
lcd.begin(16, 2); | ||
lcd.print("Hello World"); | ||
delay(5000); | ||
Wire.begin(); | ||
|
||
Item * display_item = new Item("Display "); | ||
display_item->add_action(&Display); | ||
Item * change_humidity_item = new Item("Change Humidity "); | ||
change_humidity_item->add_action(&change_humidity); | ||
//Item * events_item = new Item("Events "); | ||
|
||
main_menu->add_item_down(display_item); | ||
main_menu->add_item_down(change_humidity_item); | ||
//main_menu->add_item_down(events_item); | ||
|
||
main_menu->navigate_to_top(); | ||
|
||
pinMode(valve1_pin, OUTPUT); | ||
pinMode(valve2_pin, OUTPUT); | ||
} | ||
|
||
|
||
|
||
void loop() | ||
{ | ||
static const int where_am_I = 1; // 1 is main menu; | ||
// 2 is event_handler | ||
check_valves(); | ||
|
||
key = check_button(); | ||
if (key >= 0) | ||
{ | ||
main_menu->current_action(key); | ||
} | ||
|
||
delay(100); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// -------------------------------------- | ||
// i2c_scanner | ||
// | ||
// Version 1 | ||
// This program (or code that looks like it) | ||
// can be found in many places. | ||
// For example on the Arduino.cc forum. | ||
// The original author is not know. | ||
// Version 2, Juni 2012, Using Arduino 1.0.1 | ||
// Adapted to be as simple as possible by Arduino.cc user Krodal | ||
// Version 3, Feb 26 2013 | ||
// V3 by louarnold | ||
// Version 4, March 3, 2013, Using Arduino 1.0.3 | ||
// by Arduino.cc user Krodal. | ||
// Changes by louarnold removed. | ||
// Scanning addresses changed from 0...127 to 1...119, | ||
// according to the i2c scanner by Nick Gammon | ||
// http://www.gammon.com.au/forum/?id=10896 | ||
// Version 5, March 28, 2013 | ||
// As version 4, but address scans now to 127. | ||
// A sensor seems to use address 120. | ||
// | ||
// | ||
// This sketch tests the standard 7-bit addresses | ||
// Devices with higher bit address might not be seen properly. | ||
// | ||
|
||
#include <Wire.h> | ||
|
||
|
||
void setup() | ||
{ | ||
Wire.begin(); | ||
|
||
Serial.begin(9600); | ||
Serial.println("\nI2C Scanner"); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
byte error, address; | ||
int nDevices; | ||
|
||
Serial.println("Scanning..."); | ||
|
||
nDevices = 0; | ||
for(address = 1; address < 127; address++ ) | ||
{ | ||
// The i2c_scanner uses the return value of | ||
// the Write.endTransmisstion to see if | ||
// a device did acknowledge to the address. | ||
Wire.beginTransmission(address); | ||
error = Wire.endTransmission(); | ||
|
||
if (error == 0) | ||
{ | ||
Serial.print("I2C device found at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.print(address,HEX); | ||
Serial.println(" !"); | ||
|
||
nDevices++; | ||
} | ||
else if (error==4) | ||
{ | ||
Serial.print("Unknow error at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.println(address,HEX); | ||
} | ||
} | ||
if (nDevices == 0) | ||
Serial.println("No I2C devices found\n"); | ||
else | ||
Serial.println("done\n"); | ||
|
||
delay(5000); // wait 5 seconds for next scan | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BOARD_TAG = uno | ||
MONITOR_PORT = /dev/ttyACM0 | ||
USER_LIB_PATH := $(realpath /home/michal/Projects/Arduino/libraries) | ||
ARDUINO_LIBS = Wire Time DS1307RTC Menu | ||
|
||
include $(ARDMK_DIR)/Arduino.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BOARD_TAG = uno | ||
MONITOR_PORT = /dev/ttyACM0 | ||
USER_LIB_PATH := $(realpath /home/michal/Projects/Arduino/libraries) | ||
ARDUINO_LIBS = Wire Time DS1307RTC Menu | ||
|
||
include $(ARDMK_DIR)/Arduino.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BOARD_TAG = uno | ||
MONITOR_PORT = /dev/ttyACM0 | ||
USER_LIB_PATH := $(realpath /home/michal/Projects/Arduino/libraries) | ||
ARDUINO_LIBS = Wire Time DS1307RTC Menu | ||
|
||
include $(ARDMK_DIR)/Arduino.mk |
Oops, something went wrong.