Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / Re: Problem using AikoEvents to control Relays within a sensor application on: April 13, 2011, 05:11:56 pm
Combined Code:

// SHT15 Temperature & Humidity Logger

// Libraries
#include <SdFat.h>                // SD card file system library GNU GPL V3 (Version 20100818)
#include <DS1302.h>               // Real Time clock (RTC) lib (C) Henning Karlsen
#include <SHT1x.h>                // SHT Temp and Humidity Library
#include <LiquidCrystal.h>
#include <AikoEvents.h>
using namespace Aiko;
// Connections

//IMPORTANT: for SD card code to work with datalogging shield a jumper is needed between digital 10 and 5

// Specify data and clock connections and instantiate SHT1x object - using pins 16 and 17 corresponds to the P2 4pin connector
#define dataPin  17
#define clockPin 16
SHT1x sht1x(dataPin, clockPin);

//create object to control an LCD.  
LiquidCrystal lcd(9, 8, 7, 10, 14, 2);  // this was 12,11,5,3,2

// Aiko Settings
int HumidityInterval = 5;         // Delay between Humid Air (in seconds)
int DryInterval = 10;              // Delay between Dry Air (in seconds) must be different from Humidity interval
int dryAirPin = 19;                 // Reed relay on digital pin 19  
int humidAirPin = 18;               // Reed relay on digital pin 18

int greenLEDpin=2;        //LED file system / SD card syncing activity - not needed?

// RTC uses digital pin 3 (SCLK), pin 4 (I/O), pin 5 (CE)
// Init the DS1302 passing connection pin numbers
DS1302 rtc(6, 4, 3);

//define variables for SD card logging check these, sensiron SHT15 needs min 6.5 s between readings to avoid self-heating
int LOG_INTERVAL=7500; // mills between entries
int ECHO_TO_SERIAL=1; // echo data to serial port
int SYNC_INTERVAL=7500; // Sensor reading saved to SD card every x seconds
long syncTime = 0;     // time of last sync()

// The objects to talk to the SD card
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

//Function Decleration

void sd_card(float,float);        //sd card logging code use void sd_card(float,float,float) if using temp_f


void setup()
  // start serial port
  Serial.println("Temperature & Humidity Sensor is Starting Up");
  //Welcome Message
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);          // set the cursor to column 0, line 0
  lcd.setCursor(0, 1);          // set the cursor to column 0, line 1
  delay(2000);   // remove this delay?
  // initialize the SD card
  if (!card.init()) error("card.init");
  // initialize a FAT volume
  if (!volume.init(card)) error("volume.init");
  // open root directory
  if (!root.openRoot(volume)) error("openRoot");
  // create a new file
  char name[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    name[6] = i/10 + '0';
    name[7] = i%10 + '0';
    if (, name, O_CREAT | O_EXCL | O_WRITE)) break;
  if (!file.isOpen()) error ("file.create");

  file.writeError = 0;

  // write header
  file.println("Milliseconds since start, Date, Time, Temperature (*C), Humidity");    
  if (ECHO_TO_SERIAL) Serial.println("Milliseconds since start, Date, Time, Temperature (*C), Humidity");
  pinMode(greenLEDpin, OUTPUT); //set SD card activity LED pin to output mode

  // attempt to write out the header to the file
  if (file.writeError || !file.sync()) {
    error("write header");

  // Set the clock to run-mode, and disable the write protection
  // Set RTC date and time (if needed!)
  //rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  pinMode(dryAirPin, OUTPUT);      // Set the dry air pin as an output
  digitalWrite(dryAirPin, LOW);
  pinMode(humidAirPin, OUTPUT);    // Set the humid air pin as an output
  digitalWrite(humidAirPin, LOW);
  //pinMode(ledPin, OUTPUT);        // Set the LED pin as an output
  //digitalWrite(ledPin, LOW);
  Events.addHandler(humidAir, HumidityInterval * 1000); // Every 'HumidityInterval' seconds
  Events.addHandler(dryAir, DryInterval * 1000); // Every 'HumidityInterval' seconds
} //end setup


void loop(void)
  // clear print error
  file.writeError = 0;
  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  //get individual sensor temperatures
  float temp_c;
  // float temp_f;
  float humidity;
  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  // temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  //log data to SD card
  if ((millis()-syncTime) > SYNC_INTERVAL){
// (note: line 1 is the second row, since counting begins with 0):
 // Print a message to the LCD.
  lcd.setCursor(0, 0);          // set the cursor to column 0, line 0
  lcd.setCursor(0, 1);          // set the cursor to column 0, line 1
  lcd.print(temp_c);      //send the data to the computer
  lcd.print((char)223);         // degree symbol
  delay (3750);
  lcd.setCursor(0, 0);          // set the cursor to column 0, line 0
  lcd.setCursor(0, 1);          // set the cursor to column 0, line 1
}  //end loop

void humidAir()
  digitalWrite(dryAirPin, LOW);   // Turn off dry air relay
  digitalWrite(humidAirPin, HIGH); // Turn on humid air relay

void dryAir()
  digitalWrite(dryAirPin, HIGH);   // Turn on dry air relay
  digitalWrite(humidAirPin, LOW); // Turn off humid air relay

//SD card error function
void error(char *str)
  boolean flag=false;
  Serial.print("error: "); Serial.println(str);
    digitalWrite(greenLEDpin, HIGH);
    digitalWrite(greenLEDpin, LOW);

void sd_card(float temp_c,float humidity)      //void sd_card(float temp_c,float temp_f,float humidity)
  //log milliseconds since starting
  long m = millis();
  file.print(m); file.print(",");              // milliseconds since start, I disabled this because it messes up the Columns when logged
  //save current date and time
  file.print(rtc.getDateStr()); file.print(",");
  file.print(rtc.getTimeStr()); ;file.print(",");
  file.print(temp_c);file.print(", ");
  //file.print(temp_f);file.print(", ");
  file.println(humidity);file.print(", ");

    Serial.print(m); Serial.print(", ");         // milliseconds since start

    Serial.print(rtc.getDateStr()); Serial.print(", ");
    Serial.print(rtc.getTimeStr()); Serial.print(", ");
    Serial.print(temp_c);Serial.print(", ");
    //Serial.print(temp_f);Serial.print(", ");

  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(greenLEDpin, HIGH);
  if (!file.sync()) error("sync");
  digitalWrite(greenLEDpin, LOW);
  if (file.writeError) error("write data");

17  Using Arduino / Programming Questions / Problem using AikoEvents to control Relays within a sensor application on: April 13, 2011, 05:11:10 pm
Hi everyone,

I have an issue I hope someone on this forum can help out with.
I also have no programming experience whatsoever, so go easy please. The code below I have cobbled together and adapted from various libraries and other projects I found on the internet, and it compiles.

What is it for:

This is an Arduino UNO, a datalogger shield (nuelectronics), a LCD and a SHT15 temperature and humidity sensor which I am using to log conditions within a reaction chamber. The code for this on its own works fine.
I would now like to control the humidity in said chamber using two solenoid valves connected via relays to the arduino.
The code (Aiko) for this I took from Jonathan Oxer's book "Practical Arduino: Cool Projects for Open Source Hardware" from the time-lapse camera example. Again, on its own, the code from the book obviously works fine and cycles the relays the way I want to.

However when I merge the code together, the relay on D19 (A5) switches and stays switched, whereas nothing happens with the relay on D18.

My Questions:

1. Can someone help me find out why the relays do not cycle correctly in the merged code?
2. How can I limit the cycles so that the chamber is filled with humid air (relay on e.g. D18) for one hour, then dry air (relay on e.g. D19) for an hour, the process is then repeated x times and finishes with one hour of dry air before closing the valve (rather than continuing ad infinitum)?

18  Forum 2005-2010 (read only) / Exhibition / Re: New oscilloscope for arduino (Mac only) on: May 04, 2010, 11:31:39 am
I'm using an intel mac and installed librxtx from another source. It now works. Thank you for your help!
19  Forum 2005-2010 (read only) / Exhibition / Re: New oscilloscope for arduino (Mac only) on: April 26, 2010, 05:51:58 pm
Hi Alvaro,

Thank you for your reply. The UI never shows up the app just crashes. I tried opening it through Terminal but it crashes there as well, however I don't know how to see the error outputs other than to check the log in control panel. From there it seems there is a problem with the RXTXcomm.jar / librxtxSerial.jnilib installation:

"26/04/2010 17:50:10      [0x0-0x1544543][17901]      Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib:  no suitable image found.  Did find:  /Library/Java/Extensions/librxtxSerial.jnilib: no matching architecture in universal wrapper
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.lang.ClassLoader$NativeLibrary.load(Native Method)
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.lang.ClassLoader.loadLibrary0(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.lang.ClassLoader.loadLibrary(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.lang.Runtime.loadLibrary0(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.lang.System.loadLibrary(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at<clinit>(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at com.alvie.arduino.oscope.Protocol.getPortList(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at com.alvie.arduino.oscope.ArduinoOscopeImpl.populateSerialMenu(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at com.alvie.arduino.oscope.ArduinoOscopeImpl.createAndShowGUI(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at com.alvie.arduino.oscope.ArduinoOscope$
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.event.InvocationEvent.dispatch(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.EventQueue.dispatchEvent(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.EventDispatchThread.pumpOneEventForFilters(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.EventDispatchThread.pumpEventsForFilter(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.EventDispatchThread.pumpEventsForHierarchy(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.EventDispatchThread.pumpEvents(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at java.awt.EventDispatchThread.pumpEvents(
26/04/2010 17:50:10      [0x0-0x1544543][17901]            at"

I'll try to install from another source in the thread and see what happens, unless you have some other suggestion?
20  Forum 2005-2010 (read only) / Exhibition / Re: New oscilloscope for arduino (Mac only) on: April 22, 2010, 08:54:02 am
Hi everyone, this is my first post and I only just got my Arduino yesterday, so please bear with me:

I'm trying to get Alvaros oscilloscope running on my Intel Mac (10.6).
I've installed XCode and downloaded RXTXcomm.jar / librxtxSerial.jnilib and placed these in the Java library folder, as well as downloading arduino-oscope-snapshot-20091112.

I then compiled oscope.pde and protocol.h on the Arduino desktop and uploaded it to the Arduino.

However cannot start arduino-oscope.jar, it just seems to crash the moment you open it.

Where am I going wrong? All help appreciated!

Pages: 1 [2]