Skip to content

Commit

Permalink
Merge pull request #122 from OPEnSLab-OSU/develop
Browse files Browse the repository at this point in the history
SmartRock Workshop example
  • Loading branch information
Kenneth Kang authored Sep 2, 2020
2 parents dac42bc + 9dd98f9 commit 0c060ca
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
133 changes: 133 additions & 0 deletions examples/Lab Examples/SmartRock_Workshop/SmartRock_Workshop.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
///////////////////////////////////////////////////////////////////////////////

// This is a basic example that demonstrates usage of the Hypnos board
// Deep sleep functionality.

// The Hypnos board includes
// - SD
// - DS3231 RTC
// - Ability to power of peripherals

// Further details about the Hypnos board can be found here:
// https://github.com/OPEnSLab-OSU/OPEnS-Lab-Home/wiki/Hypnos

///////////////////////////////////////////////////////////////////////////////

#include <Loom.h>

// Include configuration
const char* json_config =
#include "config.h"
;

// Set enabled modules
LoomFactory<
Enable::Internet::Disabled,
Enable::Sensors::Enabled,
Enable::Radios::Enabled,
Enable::Actuators::Enabled,
Enable::Max::Enabled
> ModuleFactory{};

LoomManager Loom{ &ModuleFactory };


const int switchPin = 9;
int switchPos = 0;

volatile bool rtc_flag = false;

void wakeISR_RTC() {
// disable the interrupt
detachInterrupt(12);
rtc_flag = true;
}

void setup()
{

pinMode(switchPin, INPUT);
// Needs to be done for Hypno Board
pinMode(5, OUTPUT); // Enable control of 3.3V rail
pinMode(6, OUTPUT); // Enable control of 5V rail
pinMode(12, INPUT_PULLUP); // Enable waiting for RTC interrupt, MUST use a pullup since signal is active low
pinMode(13, OUTPUT);

//digitalWrite(switchPin, HIGH);
//See Above
digitalWrite(5, LOW); // Enable 3.3V rail
digitalWrite(6, HIGH); // Enable 5V rail
digitalWrite(13, LOW);

Loom.begin_serial(true);
Loom.parse_config(json_config);
Loom.print_config();

// Register an interrupt on the RTC alarm pin
Loom.InterruptManager().register_ISR(12, wakeISR_RTC, LOW, ISR_Type::IMMEDIATE);

LPrintln("\n ** Setup Complete ** ");
Serial.flush();
}


void loop()
{
//re-enable pin upon wake up
pinMode(switchPin, INPUT);

/////////////////////////////////////////////
//change interval depending the on position of pin
//interval is the variable that gets passed to TimeSpan function below
switchPos = digitalRead(switchPin);
int secs = 0;
int mins = 0;
if (switchPos == HIGH) {
mins = 1200;
}else{
secs = 1;
}
/////////////////////////////////////////////

digitalWrite(5, LOW); // Disable 3.3V rail
digitalWrite(6, HIGH); // Disable 5V rail
digitalWrite(13, HIGH);

// As it turns out, if the SD card is initialized and you change
// the states of the pins to ANY VALUE, the SD card will fail to
// write. As a result, we ensure that the board has been turned
// off at least once before we make any changes to the pin states
if (rtc_flag) {
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(10, OUTPUT);

delay(1000);

Loom.power_up();
}


Loom.measure();
Loom.package();
Loom.display_data();
Loom.SDCARD().log();

// set the RTC alarm to a duration of 10 seconds with TimeSpan
Loom.InterruptManager().RTC_alarm_duration(TimeSpan(0,0,mins,secs));
Loom.InterruptManager().reconnect_interrupt(12);

digitalWrite(13, LOW);
digitalWrite(5, HIGH); // Enable 3.3V rail
digitalWrite(6, LOW); // Enable 5V rail
pinMode(23, INPUT);
pinMode(24, INPUT);
pinMode(10, INPUT);

// Sleep Manager autmatically calls power_down on every sensor before sleeping
// And power_up after waking.

rtc_flag = false;
Loom.SleepManager().sleep();
while (!rtc_flag);
}
33 changes: 33 additions & 0 deletions examples/Lab Examples/SmartRock_Workshop/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"{\
'general':\
{\
'name':'Device',\
'instance':1\
},\
'components':[\
{\
'name':'Analog',\
'params':[8,12,true,false,true,false,false,false,5,0,4,0,0,0]\
},\
{\
'name':'SD',\
'params': [true,1000,10,'data',true]\
},\
{\
'name':'DS3231',\
'params':[11, true]\
},\
{\
'name':'Interrupt_Manager',\
'params':'default'\
},\
{\
'name':'Sleep_Manager',\
'params':[true,false,1]\
},\
{\
'name':'MS5803',\
'params':[119]\
}\
]\
}"
2 changes: 1 addition & 1 deletion src/Sensors/Analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ float Loom_Analog::convert_turbidity(const uint16_t analog) const
// return -1120.4 * (voltage * voltage) + (5742.3 * voltage) - 4352.9;


return analog // turbidity values are fairly qualitative, just returning the analog value for now
return analog; // turbidity values are fairly qualitative, just returning the analog value for now
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 0c060ca

Please sign in to comment.