Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: End a Statement if a Button is Pressed? on: March 13, 2014, 05:07:56 pm
How would that look in code terms?
I have not worked with any interrupt functions at all yet.
2  Using Arduino / Programming Questions / End a Statement if a Button is Pressed? on: March 13, 2014, 04:22:43 pm
Hi Everyone,

I have a question about an else statement that I have. So as you can see from looking at my code, I have a spot where if the button is not being pressed, it runs through some text on my LCD screen that I have as well as some Serial output for debugging. I am looking for a way to have the else statement cut off at any point if the button on pin 10 is pressed. Otherwise right now I have to keep the button pressed down until the else part of the loop ends.

Thanks in Advance
Max

Code:
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int buttonPin = 10;                     // The number of the pushbutton pin
const int relayPin1 = 11;                    // the number of the Relay pin 1
const int relayPin2 = 12;                    // The number of the Relay pin 2
const int relayPin3 = 13;                    // The number of the Relay pin 3

int buttonState = 0;                         // variable for reading the pushbutton status
int lcd_key     = 0;

void setup() {
  Serial.begin(9200);
  pinMode(relayPin1, OUTPUT);                // Initialize the Relay pin 1 as an output
  pinMode(relayPin2, OUTPUT);
  pinMode(relayPin3, OUTPUT); 
  pinMode(buttonPin, INPUT);                 // Initialize the pushbutton pin as an input
  Serial.println("Setup Complete");
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.println("System Ready");
  Serial.println("System Ready");
  delay(3000);
}

void loop(){
  lcd.setCursor(0, 1);
  buttonState = digitalRead(buttonPin);      // read the state of the pushbutton value
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    digitalWrite(relayPin1, HIGH);           // turn Relay 1 on
    Serial.println("Button Pressed!");
    lcd.clear();
    lcd.print("Cannon 1 Fired!");
    Serial.println("Relay 1 ON");
    delay(500);
    digitalWrite(relayPin2, HIGH);
    lcd.clear();
    lcd.print("Cannon 2 Fired!");
    Serial.println("Relay 2 ON");
    delay(500);
    digitalWrite(relayPin3, HIGH);
    lcd.clear();
    lcd.print("Cannon 3 Fired!");
    Serial.println("Relay 3 ON");
    delay(500);
    lcd.clear();
    lcd.print("Cannons Fired!");
    Serial.println("ALL relays ON!");
  }
  else {
    digitalWrite(relayPin1, LOW);            // turn Relay 1 off
    Serial.println("Relay 1 OFF");
    digitalWrite(relayPin2, LOW);            // turn Relay 2 off
    Serial.println("Relay 2 OFF");
    digitalWrite(relayPin3, LOW);            // turn Relay 3 off
    Serial.println("Relay 3 OFF");
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("Ready");
    delay(900);
    lcd.setCursor(1, 1);
    lcd.print("Waiting .");
    delay(900);
    lcd.setCursor(1, 1);
    lcd.print("Waiting ..");
    delay(900);
    lcd.setCursor(1, 1);
    lcd.print("Waiting ...");
    Serial.println("Waiting for Button-Press");
    delay(900);
  }
}
3  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 08:14:42 pm
Do these really go together?
Code:
    SendTextMessage(gps);
Code:
void SendTextMessage()

I didn't catch that. I just changed
Code:
SendTextMessage(gps)
to
Code:
SendTextMessage()
aaaand it works.
4  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 03:05:23 pm
So, you made some changes to your code. It doesn't compile. I, for one, refuse to play guessing games. Post your revised code.

Here you are:
Code:
/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and
 send a http request to the website, upload data to pachube.com by TCP connection,
 
 The microcontrollers Digital Pin 7 and hence allow unhindered
 communication with GPRS Shield using SoftSerial Library.
 IDE: Arduino 1.0 or later
 Replace the following items in the code:
 1.Phone number, don't forget add the country code
 2.Replace the Access Point Name
 3. Replace the Pachube API Key with your personal ones assigned
 to your account at cosm.com
 */


#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>

SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using
// Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate

  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    SendTextMessage(gps);
    //after start up the program, you can using terminal to connect the serial of gprs shield,
    //if you input 't' in the terminal, the program will execute SendTextMessage()

    if (Serial.available())
      switch(Serial.read())
      {
      case 't':
        SendTextMessage();
        delay(2000);
        lcd.clear();
        break;
      }
    if (mySerial.available())
      Serial.write(mySerial.read());
  }
}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Sending Text Msg");
  Serial.print("Sending Text Msg");
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  //the content of the message
  mySerial.println(flat, 4); //Latitude
  mySerial.println(", "); // Space between lat and lon
  mySerial.println(flon, 4); //Longitude
  //end of message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

// Feed data as it becomes available
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

  }
  return false;
}
5  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 02:37:12 pm
Quote
So it should look like this? ... rather then this:
Yes.

Alright, I have done so, but It's still the exact same error, howerver this time It looks like this:
Code:
GPRS_Project.ino: In function 'void loop()':
GPRS_Project:23: error: too few arguments to function 'void SendTextMessage()'
GPRS_Project:66: error: at this point in file

Is there anything else I should know, or is there more Variables that I need to remove?
6  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 02:21:33 pm
Quote
Ok, so I have that but now it gives me this:
The IDE does not generate function prototypes correctly for functions that take reference arguments. I keep telling you that you do not need to pass gps (a global variable) to the function. You keep ignoring me. This will be my last response until you stop ignoring me.

Ok, bare with me here.

So does this mean that Because I have
Code:
TinyGPS gps;
defined I don't need to place it in the function like I currently have it.
So it should look like this?
Code:
void SendTextMessage()
rather then this:
Code:
void SendTextMessage(TinyGPS &gps)
7  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 02:02:17 pm
I suggest you get a basic textbook on C/C++ programming,  because you clearly have no idea what you are doing.

I'm pretty sure I have an idea as to what I am doing. This is the first time I have ever tried something like this and I am just looking for some help on understanding why I have these errors and how to fix them. However your constructive criticism is much obliged.
8  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 12:59:11 pm
Your code needs to look more like:

Ok, so I have that but now it gives me this:
Code:
GPRS_Project.ino: In function 'void loop()':
GPRS_Project:23: error: too few arguments to function 'void SendTextMessage(TinyGPS&)'
GPRS_Project:66: error: at this point in file
9  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 12:44:19 pm
Quote
So this is the part that does not need to be defined in void loop()?:
No. That does need to be there.

Quote
I ran the auto-format but a message on the bar below said "No changes necessary for Auto Format."
In which version of the IDE? I just pasted your code in 1.0.5 (again), and Tools + Auto Format makes significant changes. It now looks like:
Code:
/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and
 send a http request to the website, upload data to pachube.com by TCP connection,
 
 The microcontrollers Digital Pin 7 and hence allow unhindered
 communication with GPRS Shield using SoftSerial Library.
 IDE: Arduino 1.0 or later
 Replace the following items in the code:
 1.Phone number, don't forget add the country code
 2.Replace the Access Point Name
 3. Replace the Pachube API Key with your personal ones assigned
 to your account at cosm.com
 */


#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>

SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using
// Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate

  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    SendTextMessage(gps);
    //after start up the program, you can using terminal to connect the serial of gprs shield,
    //if you input 't' in the terminal, the program will execute SendTextMessage()

    if (Serial.available())
      switch(Serial.read())
      {
      case 't':
        SendTextMessage();
        delay(2000);
        lcd.clear();
        break;
      }
    if (mySerial.available())
      Serial.write(mySerial.read());
  }

  ///SendTextMessage()
  ///this function is to send a sms message
  void SendTextMessage(TinyGPS &gps)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Sending Text Msg");
    Serial.print("Sending Text Msg");
    mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
    delay(100);
    mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
    delay(100);
    //the content of the message
    mySerial.println(flat, 4); //Latitude
    mySerial.println(", "); // Space between lat and lon
    mySerial.println(flon, 4); //Longitude
    //end of message
    delay(100);
    mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
    delay(100);
    mySerial.println();
  }
}
// Feed data as it becomes available
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

  }
  return false;
}
SendTextMessage() is defined in loop(). Count the closing braces for SendTextMessage() if you don't believe me.

I just updated the IDE. I was running 1.0.
It's not that I don't believe you. I just don't understand where I need to define it then. Or how to do so.
10  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 12:32:17 pm
Quote
Also, how do you suggest I go about this then if I don't need to define SendTextMessage() Function.
You do need to define the function. AFTER loop(), not IN loop().

You don't need to pass it a value, since the value is in a global variable.

So this is the part that does not need to be defined in void loop()?:

Code:
 bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
      SendTextMessage(gps);
11  Using Arduino / Programming Questions / Re: Sending Text Message w/GPS Data on: December 29, 2013, 12:19:50 pm
Your code needs to be formatted correctly. Use Tools + Auto Format, and you'll see immediately what the problem is.

You are trying to define SendTextMessage() inside the loop() function.

Passing a global variable to the function is unnecessary.

I ran the auto-format but a message on the bar below said "No changes necessary for Auto Format."

Also, how do you suggest I go about this then if I don't need to define SendTextMessage() Function. I have tried changing it or removing it but I just gives me different errors.
12  Using Arduino / Programming Questions / Sending Text Message w/GPS Data on: December 28, 2013, 10:34:11 pm
Hi Everyone!

This should be a simple fix, but I can't seem to figure out what the error in my code is.

This is what I am using:

So the problem is simply my code. It should be working but the console is giving me this error:
Code:
GPRS_Project.ino: In function 'void loop()':
GPRS_Project:58: error: 'gpsdump' was not declared in this scope
GPRS_Project:79: error: a function-definition is not allowed here before '{' token

I have done a ton of troubleshooting and at this point, I don't know what's wrong.
The idea is that when I send "t" to the arduino over serial, it will send the current lat and lon to my cell phone. That's basically the idea anyway. The LCD display is for troubleshooting and a user interface. I will eventually set it up so that when one of the buttons on the LCD are pressed, the device will send the lat and lon to my cell phone too. That's why I have it.

Anyway... Here is the code:
Code:
/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and
  send a http request to the website, upload data to pachube.com by TCP connection,
 
  The microcontrollers Digital Pin 7 and hence allow unhindered
  communication with GPRS Shield using SoftSerial Library.
  IDE: Arduino 1.0 or later
  Replace the following items in the code:
  1.Phone number, don't forget add the country code
  2.Replace the Access Point Name
  3. Replace the Pachube API Key with your personal ones assigned
  to your account at cosm.com
  */
 
 
#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>
 
SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using
                                       // Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate  
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate
  
  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
      SendTextMessage(gps);
  //after start up the program, you can using terminal to connect the serial of gprs shield,
  //if you input 't' in the terminal, the program will execute SendTextMessage()
 
  if (Serial.available())
    switch(Serial.read())
   {
     case 't':
       SendTextMessage();
       delay(2000);
       lcd.clear();
       break;
   }
  if (mySerial.available())
    Serial.write(mySerial.read());
}
 
///SendTextMessage()
///this function is to send a sms message
void SendTextMessage(TinyGPS &gps)
{
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Sending Text Msg");
  Serial.print("Sending Text Msg");
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  //the content of the message
  mySerial.println(flat, 4); //Latitude
  mySerial.println(", "); // Space between lat and lon
  mySerial.println(flon, 4); //Longitude
  //end of message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
  }
}
// Feed data as it becomes available
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
      
  }
  return false;
}

Thanks in advance!
Max Kulik
13  Using Arduino / Interfacing w/ Software on the Computer / Re: Send Joystick data over serial to Arduino Uno on: October 03, 2013, 09:17:53 am
Hi,

Thanks for the response. It seems that option #2 is going to be my best bet. I was looking for something on the software side so that is one reason why I think my searches were coming up dry. I do allot of hardware based things so this is going to be an easy solution to my problem. Do you know of any Arduino librarys that I could would work with this or am I going to have to come up with something myself?

Thanks again
Max
14  Using Arduino / Interfacing w/ Software on the Computer / Send Joystick data over serial to Arduino Uno on: October 02, 2013, 05:47:37 pm
Hi Everyone,

Just a small question here. I have a Logitech Extreme 3D Pro joystick and I am looking for some sort of software that will allow me to send all the movement data over to my Arduino. I have been looking around already for some answers but have been coming up dry.

Thanks for all the help!
Max Kulik
15  Using Arduino / Displays / Re: Is Arduino Micro enough to use with OLED Display? on: September 18, 2013, 07:38:23 am
From your link:
Quote
You can download our SSD1306 OLED display Arduino library from github which comes with example code. The library can print text, bitmaps, pixels, rectangles, circles and lines. It uses 512 bytes of RAM since it needs to buffer the entire display but its very fast! The code is simple to adapt to any other microcontroller.

From http://arduino.cc/en/Main/ArduinoBoardMicro:
Quote
SRAM   2.5 KB (ATmega32u4)

Thanks for the help!
Pages: [1] 2 3 ... 5