Notice to YSPilots/YSFLIGHT

Notice to YSPilots/YSFLIGHT
Legacy Pack available under the YSFLIGHT category.
Any individual requests for a model must be made to my email address, see bottom of the page..
Enjoy!
Skippy
Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Sunday, 5 January 2014

Project Freja: Final Code

So, a nice little code dump here. This is the final code dump of Project Freja. This logged the moisture, altitude, accuracy (in m), position and date to the SD card. Hope you can make something of it!

//Newest as of 02/11/2013
#include <SD.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 5, 4, 3, 2);
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <math.h>
SoftwareSerial mySerial(8, 7);
const int sensorPin = A0;
const float baselineMoisture = 0.0;
Adafruit_GPS GPS(&mySerial);
boolean usingInterrupt = false;
void useInterrupt(boolean);
#define chipSelect 10 //SD card define
File logfile;
int switchState = 0;

//Function
// convert NMEA coordinate to decimal degrees
float decimalDegrees(float nmeaCoord) {
  uint16_t wholeDegrees = 0.01*nmeaCoord;
  return wholeDegrees + (nmeaCoord - 100.0*wholeDegrees)/60.0;
}
//EndFunction

//Function
//To convert HDOP into metre range
float Accu(float x1) {
  float result;
  result = sqrt(sq(x1) * 44.89 + 1);
  return result;
}
//EndFunction

//Function Read Hex Value Return decimal

uint8_t parseHex(char c) {
  if (c < '0')
    return 0;
  if (c <= '9')
    return c - '0';
  if (c < 'A')
    return 0;
  if (c <= 'F')
    return (c - 'A')+10;
}
//Function end
void setup() 
{
   pinMode(9, INPUT); //The Switch input
   lcd.begin(16,2);
//Serial.begin(115200);
       // connect to the GPS at the desired rate
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 or 5 Hz update rate
  GPS.sendCommand(PGCMD_NOANTENNA);
    useInterrupt(true);

  delay(1000);
  mySerial.println(PMTK_Q_RELEASE);
}


SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
   pinMode(10, OUTPUT); //SD card select
   if (!SD.begin(10)) {
  //  Serial.println("initialization failed!");
    return;
  }
}

uint32_t timer = millis();
 
void loop()                     // run over and over again
{
  int sensorVal = analogRead(sensorPin);
  switchState = digitalRead(9);
#  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
 
  }
 
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
 
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();
 
if ((GPS.fix)&& (switchState == HIGH)) {
   logfile = SD.open("GPSlog.txt", FILE_WRITE);
//Serial.print("Fix & High");
   logfile.print(decimalDegrees(GPS.latitude), 5); logfile.print(",-");
   logfile.print(decimalDegrees(GPS.longitude), 5); logfile.print(",");
   logfile.print(sensorVal);
   logfile.print(",");
   logfile.print(Accu(GPS.HDOP));
   logfile.print(",");
   logfile.println(GPS.altitude);
   logfile.close();
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("Logged to Card");
   delay(1000);
}
 
  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
   
//  Serial.print(" quality: "); Serial.println((int)GPS.fixquality);

    if (GPS.fix) {
 
lcd.clear();
lcd.setCursor(0,0);
lcd.print(decimalDegrees(GPS.latitude), 5);
      lcd.print(",+-");
      lcd.print(Accu(GPS.HDOP), 1);
      lcd.print("m");
      lcd.setCursor(0,1);
      lcd.print(decimalDegrees(GPS.longitude), 5);
      lcd.print(",");

      lcd.print(sensorVal); lcd.print("%");
      lcd.print(GPS.speed, 1);
      
      }
      if (!GPS.fix) {
        lcd.clear();
       
        lcd.setCursor(0,0);
        lcd.print("No Fix");
      }
       }
}

Thursday, 25 April 2013

Project Freya: Moisture Sensor to the LCD screen

Okay, the first thing I thought would be useful would be to write data to an LCD screen, and my arduino starter kit came with an LCD screen.

So, my set up looks like this:

DSCF0462

The sensor leads are going off in the middle on the left hand side of the image.

Tada! Code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 5, 4, 3, 2);
const int sensorPin = A0;
const float baselineMoisture = 0.0;
void setup(){
  lcd.begin(16,2);
// Serial.begin(9600);
  lcd.print("loading");
}

void loop(){
  int sensorVal = analogRead(sensorPin);
//  Serial.println(sensorVal);
  lcd.print(sensorVal);
  delay(500);
  lcd.clear();
}

 

The result is this:

When the sensor (Two wires… 2 posts ago…) is not touching anything moist it reads 0:

DSCF0459

And when my dry fingers are across the two wires:

DSCF0461

// The potentiometer to the left is for LCD brightness

Project Freya: Overview

I wanted to give my little Arduino project a proper name. And with it coming along in leaps and bounds I figured it was about time to give it a good one.

So, Project Freya. Freya being the Norse goddess of love and fertility. Fertility being the key here as it’s to be used on a farm to assess fields… (So soil fertility)

Basically the outline of the project is for a device that does the following:

  • Records the coordinates for a given position
  • Records soil moisture taken from a probe/set of probes
  • Logs both of these values onto something that enables easy translation into a GIS program, in my case ESRI’s ArcMap.

My platform of choice is the Arduino (From www.arduino.cc)

I picked up the Arduino Uno Starter Kit.

image

I figured I’d do all the tutorials and so forth and get my hand in to the language. I did the first tutorial and decided to free lance from there.

The first part of the requirement was for GPS reception:
For this I got an Adafruit Ultimate GPS Logger Shield. http://www.adafruit.com/products/1272

The advantage of this is that it fills both the first and third requirement, GPS and SD card. Perfect!

I wrecked the board whilst soldering on the pins though, I stuck on standard male pins, then realised I actually needed some of the inputs to run the sensors and later the LCD screen, so I had to unsolder the pins and put header pins on, and broke some of the tracks in the process. Note: if you are using this board, choose header pins straight away and don’t even try and solder on normal pins…

 

My moisture sensors are very simple, and partially described in the previous post. The circuit diagram can be seen here:

[image%255B2%255D.png]

These are the actual probes of the sensor. Two nails soldered to wires. These will be mounted to something, maybe a broom handle, with some method of ensuring that each sample site the probes are inserted the same distance from each other and to the same depth.

DSCF0470

That’s the basics of the project. It has expanded from these few key parts a bit now, see later posts about that though!

-Skipper

Arduino Moisture Sensor

 

Hallo, so, I got an Arduino to take the place of my Raspberry Pi. It’s more hardware oriented and therefore more geared towards the RPi projects I mentioned earlier.

So, my first goal is to create a moisture sensor.

This is done using the analogue pins.

Analogue pin 0, A0, is held low by a 10kohm resistor, Above this is one wire of the sensor. From the +ve rail is the other wire of the sensor. Currently the sensor is simply 2 bits of wire and the moisture is read from my fingers. But in the final prototype it will be read off of 2 nails stuck in the soil.

image
Circuit diagram

This is the code I used, it echos the reading back over the serial port to the computer.

const int sensorPin = A0;
void setup(){
  Serial.begin(9200);
}
void loop(){
  int sensorVal = analogRead(sensorPin);
  Serial.println(sensorVal);
  delay(500);
}

 

Refresh rate is 1/2 a second.