Show Posts
Pages: [1] 2 3 ... 11
1  Using Arduino / Programming Questions / Re: Changing modes question with SMlib on: Today at 02:40:08 am
So I am away from the boards, but I will back to you asap.
Serial speed: just for testing.
HW inputs: when I was trying to start and test my sim900 shield I found some information here in the forum maybe, it was one of the examples. This is working fine since months in another solution of mine with the same code.
The current hwSerialRead( ) code of yours compiled succesfully.
I will upload it and test as soon as I can!
2  Using Arduino / Programming Questions / Re: Changing modes question with SMlib on: July 23, 2014, 09:32:20 am
looks like a rebuilt of the code. thanks for helping me!
3  Using Arduino / Programming Questions / Re: Changing modes question with SMlib on: July 23, 2014, 01:41:04 am
Hi GoForSmoke,

here is the code:
Code:
//================================================LIBRARIES
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
//================================================DEFINE AND VARIABLES

// Data wire is plugged into port 3 on the Arduino
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress Thermometer1, Thermometer2, Thermometer3;
//                BS  E  D4 D5  D6 D7
LiquidCrystal lcd(7, 6, 28, 26, 24, 22);

int temp1;
int temp2;
int temp3;

InetGSM inet;
char msg[50];
char buff[100];
char senddata[64];
int numdata;
char inSerial[50];
int i=0;
boolean started=false;
const int GSMOnPIN = 9;
const int GSMresetPIN = 10;
const int ledPin =  8;

const unsigned long readsensorsinterval = 30000UL; //30 seconds
const unsigned long gsmsendinterval = 60000UL; //60 seconds

// Variable holding the timer value so far. One for each "Timer"
unsigned long readsensorstimer;
unsigned long gsmsendtimer;

//================================================SETUP

void setup()
{
  pinMode(GSMOnPIN, OUTPUT);
  pinMode(GSMresetPIN, OUTPUT);  
  pinMode(ledPin, OUTPUT);
  delay(100);

  Serial.begin(19200);
  // Start up the Sensors library
  sensors.begin();

  // locate devices on the bus
  Serial.print(F("Locating devices..."));
  Serial.print(F("Found "));
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(F(" devices."));

  // report parasite power requirements
  Serial.print(F("Parasite power is: "));
  if (sensors.isParasitePowerMode()) Serial.println(F("ON"));
  else Serial.println(F("OFF"));

  oneWire.reset_search();
  if (!oneWire.search(Thermometer1)) Serial.println(F("Unable to find address for Thermometer1"));
  if (!oneWire.search(Thermometer2)) Serial.println(F("Unable to find address for Thermometer2"));
  if (!oneWire.search(Thermometer3)) Serial.println(F("Unable to find address for Thermometer3"));
  
  // show the addresses we found on the bus
  Serial.print(F("Device 1 Address: "));
  printAddress(Thermometer1);
  Serial.println();
  Serial.print(F("Device 2 Address: "));
  printAddress(Thermometer2);
  Serial.println();
  Serial.print(F("Device 3 Address: "));
  printAddress(Thermometer3);
  Serial.println();
  

  // set the resolution to 9 bit
  sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION);
  sensors.setResolution(Thermometer2, TEMPERATURE_PRECISION);
  sensors.setResolution(Thermometer3, TEMPERATURE_PRECISION);
    
  Serial.print(F("Device 1 Resolution: "));
  Serial.print(sensors.getResolution(Thermometer1), DEC);
  Serial.println();
  Serial.print(F("Device 2 Resolution: "));
  Serial.print(sensors.getResolution(Thermometer2), DEC);
  Serial.println();
  Serial.print(F("Device 3 Resolution: "));
  Serial.print(sensors.getResolution(Thermometer3), DEC);
  Serial.println();
  
  readsensorstimer = millis ();
  gsmsendtimer = millis ();
 }
//================================================FUNCTIONS
void serialhwread(){
  i=0;
  if (Serial.available() > 0){            
    while (Serial.available() > 0) {
      inSerial[i]=(Serial.read());
      delay(10);
      i++;      
    }

    inSerial[i]='\0';
    if(!strcmp(inSerial,"/END")){
      Serial.println("_");
      inSerial[0]=0x1a;
      inSerial[1]='\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if(!strcmp(inSerial,"TEST")){
      Serial.println(F("SIGNAL QUALITY"));
      gsm.SimpleWriteln("AT+CSQ");
    }
    //Read last message saved.
    if(!strcmp(inSerial,"MSG")){
      Serial.println(msg);
    }
    else{
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }    
    inSerial[0]='\0';
  }
}

void serialswread(){
  gsm.SimpleRead();
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print(F("0"));
    Serial.print(deviceAddress[i], HEX);
  }
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(F("Temp C: "));
  Serial.print(tempC);
}

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
  Serial.print(F("Resolution: "));
  Serial.print(sensors.getResolution(deviceAddress));
  Serial.println();    
}

// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print(F("Device Address: "));
  printAddress(deviceAddress);
  Serial.print(F(" "));
  printTemperature(deviceAddress);
  Serial.println();
}  

// read sensors
void readsensorstolcd(){
  //READ TEMPERATURE
  Serial.print(F("Requesting temperatures..."));
  sensors.requestTemperatures();
  Serial.println(F("DONE"));

  Serial.print(F("Temperatures are "));
  Serial.print(sensors.getTempC(Thermometer1));
  Serial.print(F(" Celsius, "));
  Serial.print(sensors.getTempC(Thermometer2));
  Serial.print(F(" Celsius, "));
  Serial.print(sensors.getTempC(Thermometer3));
  Serial.print(F(" Celsius, "));
  Serial.print(F("\n\r"));
  delay(100);
  temp1=(sensors.getTempC(Thermometer1));
  temp2=(sensors.getTempC(Thermometer2));
  temp3=(sensors.getTempC(Thermometer3));
  delay(100);
    
  readsensorstimer = millis ();
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("T1:   C");
  lcd.setCursor(0, 1);
  lcd.print("T2:   C");
  lcd.setCursor(0, 2);
  lcd.print("T3:   C");
    lcd.setCursor(3, 0);
  lcd.print(temp1);
  lcd.setCursor(3, 1);
  lcd.print(temp2);
  lcd.setCursor(3, 2);
  lcd.print(temp3);
  lcd.setCursor(3, 3);
  delay(200);
}

//GSM start,send ,stop
void gsmandsend(){

  digitalWrite(GSMOnPIN, LOW);    
  delay(3000);      
  Serial.println(F("GSM Shield starting..."));
  digitalWrite(GSMOnPIN, HIGH);   // sets the GSM on
  delay(800);                
  Serial.println(F("Its now Started"));
  digitalWrite(GSMOnPIN, LOW);
  delay(5000);

  if (gsm.begin(4800)){
    Serial.println(F("\nstatus=READY"));
    started=true;  
  }
  else Serial.println(F("\nstatus=IDLE"));
  if(started){
    if (inet.attachGPRS("***********************", "", ""))
      Serial.println(F("status=ATTACHED"));
    else Serial.println(F("status=ERROR attaching APN"));
    delay(1000);
    if (inet.connectedClient())
      digitalWrite(ledPin, HIGH);
    else
      digitalWrite(ledPin, LOW);


    //Read IP address.
    gsm.SimpleWriteln("AT+CIFSR");
    delay(5000);
    //Read until serial buffer is empty.
    gsm.WhileSimpleRead();

    // Sending data

    sprintf(senddata,"/update?key=***************************",temp1,temp2,temp3);
    delay(500);
    numdata=inet.httpPOST("*************************", 80, senddata, buff, msg, 50);

    //Print the results.
    Serial.println(F("\nNumber data received:"));
    Serial.println(numdata);  
    Serial.println(F("\nData received:"));
    Serial.println(msg);  
  }
  serialhwread();

  //Read for new byte on NewSoftSerial.
  serialswread();
  delay(800);    
  digitalWrite(GSMOnPIN, LOW);    
  delay(3000);      
  Serial.println(F("GSM Shield stopping..."));
  digitalWrite(GSMOnPIN, HIGH);   // sets the GSM off
  delay(800);                
  Serial.println(F("Its now Stopped"));
  digitalWrite(GSMOnPIN, LOW);
  gsmsendtimer = millis ();
  delay(5000);
}

//================================================LOOP

void loop()
{
  if ( ( millis() - readsensorstimer ) >= readsensorsinterval )
  {
    readsensorstolcd();
    readsensorstimer += readsensorsinterval; }

  if (( millis() - gsmsendtimer ) >= gsmsendinterval )
  {
    gsmandsend();
    gsmsendtimer += gsmsendinterval;
  }
}

This is for testing purposes, it will be extended with more sensors.  So it is now reading sensors in every 30 seconds, and sending data in every 60 seconds (what can be found in temp variables at that time will be send, thinking if it is the right way, or should I read sensors again before sending the data in gsmandsend() ).
So main goal is to read sensor values and send to lcd, and in other hand send the sensor values with gsm.
1. If I would like to have 'independent' routines for showing data on LCD and for sending data, I should put sensor readings too to gsmandsend() routing. Is it correct?

2. I would like to have a pushbutton to set modes for sensor readings and drive relays for example (push1 - mode1: switch relay with X temp1 sensor value ; push2-mode2: switch relay with Y temp1 value ; push3-mode1;push4-mode2 and so on) . Beside the values have to send with gsmandsend()

3. After further tests (and learning smiley ) I would like to have lcd and button to set the temp1 values for example  (but this is not important at this point.

Thanks for any help!

4  Using Arduino / Programming Questions / Changing modes question with SMlib on: July 22, 2014, 01:43:46 am
Hi,
I am currently using my loop as below (reading sensors and sending data with gsm):
Code:
void loop()
{
  if ( ( millis() - readsensorstimer ) >= readsensorsinterval )
  {
    readsensorstolcd();
    readsensorstimer += readsensorsinterval;
  }                                                                           

  if (( millis() - gsmsendtimer ) >= gsmsendinterval )
  {
    gsmandsend();
    gsmsendtimer += gsmsendinterval;
  }
}

I would like to have states with a pushbutton / or can be a switch button too, like:

- when button pushed/switched - use readsensorstolcd(); than gsmandsend(); (this should be mode1)
- when button pushed/switched again - use readsensorstolcd2(); than gsmandsend(); (this should be mode2) //here readsensorstolcd2(); would be new with different values

Maybe SMlib example 2 can be a starting point?
Your help would be appreciated, thanks!
5  Using Arduino / Sensors / Re: Temp, Humidity CO2 sensor and library. on: July 09, 2014, 01:03:41 am
aaah thanks! I am testing on pins 11-12. works also perfect smiley
6  Using Arduino / Sensors / Re: Temp, Humidity CO2 sensor and library. on: July 08, 2014, 08:26:30 am
Happy to hear that!!! Great!
Note: if you are using MEGA 2560 board, and you are using ICSP pins ( for example wiznet shield ), than do not use 50 - 51 pins, because ICSP using in this case 50-51-52 pins. So in case try using other pins from the availables( for example 11-12).
Usually pin10 is wiznet, pin4 is sd, pin13 is onboard led on mega...
Anyway I do not know what and where is 62, 63, 64, 65, 66, 67, 68, 69  ...  smiley-confuse
7  Using Arduino / Sensors / Re: Temp, Humidity CO2 sensor and library. on: July 07, 2014, 04:29:26 pm
Dear All,

I have found the solution to use this sensor with mega 2560!
As Softwareserial notes:
"Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69"

So let's connect the RX pin of the sensor to mega pin 51, and TX pin of the sensor to mega pin 50 and use DirtGambit's sketch with modification:

Code:
SoftwareSerial nss(50,51); // TX and RX pins

And smile when you realise this is working fine after calibration!
8  Using Arduino / Sensors / Re: Temp, Humidity CO2 sensor and library. on: July 07, 2014, 04:03:56 pm
Hi,
I have tried DirtGambit's library, tried all the possibilities ( 5v, pins, and so on ) what can be found here, but the same problem:
Code:
Celcius : 0.00
Fahrenheit : 32.00
Humidity : 0.00
CO2 : 0
Digital Filter : 0
I am trying this with Mega board...

Maybe there is a problem with the sofwareserial...? When using sim900 shield, there was a hwserial lib instead of the swserial...
Do you have any idea?
It would be great to make it work on mega...
9  Using Arduino / Programming Questions / Re: storing latch solenoid state problem on: July 03, 2014, 03:57:12 pm
working fine! smiley sorry for the rookie question! smileysmileysmiley And thanks!!
10  Using Arduino / Programming Questions / Re: storing latch solenoid state problem on: July 03, 2014, 03:46:10 pm
ooohhhh....serious mistake...testing that...
11  Using Arduino / Programming Questions / Re: storing latch solenoid state problem on: July 03, 2014, 03:38:44 pm
AWOL, I have modified from solenoidclosed =true  to solenoidclosed = true...
but...
I mean  I need to work like  if it is closed and <=60  let's open else if it was opened, stay opened (use solenoid_off) and
if it is opened and >=61 let's close else if it was closed, stay closed.
12  Using Arduino / Programming Questions / storing latch solenoid state problem on: July 03, 2014, 03:29:09 pm
Hi,
I have tried to use this in my code to store if the solenoid was closed or opened but not working...
I would like to use like:
if value is less than or equal to 60 and solenoid is closed, than open that
if value is less than or equal to 60 and solneoid is open, stay open ( solenoid_off)

if value is more than or equal to 61 and solenoid is opened, than close that
if value is lmore than or equal to 61 and solneoid is closed, stay closed ( solenoid_off)

Thanks for any help!

Code:
if ((moistvalue1mapped <= 60) && (solenoidclosed =true ))
  {
    solenoid_open();
    solenoidclosed = false;
    delay(200);
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is opened"));
    lcd.setCursor(0, 0);
    lcd.print("ON");
    delay(100);
  }
  else if (solenoidclosed = false)
  {
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is opened"));
    lcd.setCursor(0, 0);
    lcd.print("ON");
    delay(100);
  }
  if ((moistvalue1mapped >= 61) && (solenoidclosed = false))
  {
    solenoid_close();
    solenoidclosed = true;
    delay(200);
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is closed"));
    lcd.setCursor(0, 0);
    lcd.print("OFF");
    delay(200);
  }
  else if (solenoidclosed = true)
  {
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is closed"));
    lcd.setCursor(0, 0);
    lcd.print("OFF");
    delay(200);
  }
13  Using Arduino / Project Guidance / Re: Pulse latching solenoid help needed on: July 03, 2014, 03:21:23 pm
Hi,

L293D works fine!

Thanks.
14  Using Arduino / Project Guidance / Re: Pulse latching solenoid help needed on: June 30, 2014, 03:09:52 am
What do you think about this example?:
http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/
15  Using Arduino / Project Guidance / Pulse latching solenoid help needed on: June 30, 2014, 02:23:17 am
Hi,
I need help please how to control a 9v pulse latching solenoid valve.
It needs only a pulse and a reversed pulse to open/close.
I have tried with an 500mA adaptor directly, and works fine.
I have external power supply to feed the valve instead of the arduino board.
Can somebody show some example circuit please how to do this?
I have checked this, but it is enough??
http://www.instructables.com/id/Controlling-solenoids-with-arduino/

Thank you!

Pages: [1] 2 3 ... 11