Archive

Archive for the ‘Uncategorized’ Category

Caesar Cipher written in C++

December 1, 2013 Leave a comment

Just submitted my last assignment for my Data Structures and Algorithms C class.  I plan on taking some time off from school so I can write some code and apply all of this great information that I have learned in the last year of attending UCSD extension program. I finished the C/C++ certification program and decided to take one more class, which was the Data Structures and Algorithms class.

Over the Thanksgiving holiday I decided to take a Caesar Cipher program I found out on the web, that I have played around with an convert it to C++.  I figure the more I write the more I will learn.

So I finished the application and posted it out on GitHub.

https://github.com/jpitz31/CaesarCipher

Instructions and an explanation of how the application functions is posted as a readme file on the GiHub site.

There is also a link to the Caesar Cipher wikipedia site.

For my C/C++ classes I used Visual Studio 2013 Express version and Professional version at work.

But at home I enjoy working on the Mac with OS X.  I have started working with Qt and Qt Creator.

I really like Qt and the cross platform environment.  So I plan on working on some C++ GUI applications  using Qt.

 

Categories: Uncategorized

Busy, but I will start posting soon

April 26, 2013 Leave a comment

Sorry, I have been tied up since last September taking classes at UCSD Extension so I can earn a Certificate in C/C++.  Too busy to work on any projects.

I did change jobs recently.  I am currently doing some consulting at Qualcomm here in San Diego working on developing some GUI automation on an application that tests ARM chip debug sub-systems.  I am making an all out effort to get up to speed on embedded systems.  With all of the connected devices, mobile devices,  and ARM processors invading our universe it is just a matter of time before all of the devices in our homes and cars will be communicating with one another.  To me this is an incredible opportunity  for software development.  I think these devices and software that talks to these devices is going to be a major portion of the software industry.  What better way to make a living than writing software that communicates with hardware.

But in between classes I did pick up a Shapeoko and have started to put it together.  I will be using GRBL loaded on an Arduino UNO and will be testing out some software and getting up to speed on learning about CNC machines and software.  As I start to make some progress I will post some articles.

I also have some robotic ideas that I am kicking around that I will post here when I get some more  time.

Until then I got to keep my nose in the C++ books.

Thanks

Joe

Categories: Uncategorized

Chicken Light Relay Timer

November 13, 2011 13 comments

Chicken Light Timer

The wife is into raising chickens and now that the daylight savings is getting near she wanted a way to keep the egg laying production in high gear.  According to the material that she reads, chickens will maintain their egg laying production if they get 12 – 15 hours of daylight.

I thought to myself, what a great opportunity for me to put together a DIY electronics project that would also be green.  I wanted a quick and inexpensive solution so I decided to go with the Arduino as the MCU and build everything from scratch.

This document will document my project from beginning to end.

I had picked up a battery powered LED light that would be great for this project.

I have a bunch of ATMega chips lying around as well as a few Arduino clone boards, so I was well on to my way of building this project with material and parts that are in my parts bins in my shop.

I started to think about what kind of design I wanted and decided to go simple, lean and mean.

I have done some work with latching relays in the past and really like the idea of using the MCU to latch the relay on and off without having to keep constant power on the ATMega ports all of the time.  The chicken coop is located in an area where there is no easy access to AC power and I wanted a battery solution that I could, at a later date, add solar panel access for charging.

First off I had to determine the volts and amp requirements of the LED light.

I took the LED light apart and soldered some wires to the existing switch circuit so I could trigger the light with the relay.

The LED light consumed 6 volts at around 500 milliamps.

D-cell batteries originally powered the LED light.  I did not want two different battery sources and I did not want to change batteries all of the time.  So I decided on a single battery source to power the MCU and LED light.

Below is image of LED light mounted in Chicken coop, two wires for switch and two wires for power:

Once I decided on a circuit I laid out the circuit on a breadboard using an Arduino clone as the microcontroller.  This way I could test the circuit using components that I knew worked and gave me a stable platform to write the code.

I also do not like to power external devices directly from the microcontroller ports so I decided to use some NPN transistors as part of the relay circuit.

To provide an accurate time source for the relay timer I decided to use a DS1307 RTC, Real Time Clock chip.  LadyAda has a really good write up on using this chip and has created her own code branch of JeeLab’s RTCLib library.

Here are the links to the web sites:

http://www.ladyada.net/learn/breakoutplus/ds1307rtc.html

https://github.com/adafruit/RTClib

Here is an image of the breadboard setup:

The breadboard shows a SparkFun DS1307 RTC, I have several of these that I use for testing purposes. But the production version of the Light Relay board uses the same RTC board that LadyAda documents in her writeup.

The Arduino clone pictured is the Diavolino from Evil Mad Science Labs.  Nice board and very inexpensive.  I use this board as one of my prototype boards.

Since I needed two different voltages for this configuration, 5 volts for the microcontroller and 6 volts for the LED light, I decided to use two linear power regulators.  For low cost I decided to use 7805 and 7806 regulators to drive the microcontroller and the LED light.

Since I wanted to keep the price low, I decided to build the production version of the circuit board on solder based breadboards.

After building this board, I learned a lot of lessons, In the future, I more than likely take the time to build my own custom PCB boards.  Building the solder breadboard was very time consuming and tedious.

Here is a shot of the finished production breadboard:

Notice the terminal blocks on the breadboard.  The left terminal block is connected to the two switch wires of the LED Light.  The output from the relay is connected to this terminal block.

The terminal block on the right is the voltage input for the microcontroller and relay circuit.

The 90 degree header pins are used to upload the Arduino program to the ATMega 328P.  Notice the red wire just below the right terminal block.

This wire was originally set up to connect to the USB power lead of the FTDI USB-TTL cable.

This way I could power the circuit from the USB port when I was debugging the circuit.  Just before installation I removed the lower red wire so I could power the circuit from the right terminal block from the single source battery.

My biggest expense was to purchase a deep cycle 12-volt wet cell battery.  The amp hour rating on this battery was around 110 amp hours.

This way I could power the board and light for several weeks on a single charge.  I decided to re-charge the battery once a week, until I can add the solar panel charging circuit.

After building the above circuit board and voltage regulator boards I mounted the boards into a project case.

Below is an image of the finished case with the circuit boards mounted:

Notice the top terminal block. This terminal block provides 12 volts from the deep cycle battery and powers the voltage regulators.

The lower left terminal block on the voltage regulator board provides 6 volts to power the LED light.

The right terminal block on the voltage regulator board powers the microcontroller circuit.

I also purchased a plastic battery box and mounted the micro-controller, relay circuit and the battery in this battery box just behind the chicken coop.

Here are some images of the mounting:

Here is an image of the circuit:

Here is the code for the Relay Controller:

I have included two programs that can be used as is or modified for your custom use.  One program, RTC_Relay, this program is based on turning the relay on and off within a 24 hour period when the end time is greater than the start time.

The second program, RTC_Relay_DHMS, Allows a Start Hour and a Start Minute to be set, and a day, hour, minute and second duration to be set.  When the Start Hour and Start Minute time is reached the relay is turned on and stays on for the given day, hour, minute and second duration.

The code is well documented and I have given Creative Commons license to the code, so please feel free to use the code as long as you give me credit in your code.

// Program .....: RTC_Relay
// Author ......: Joe Pitz, Objetek Systems, objetek@gmail.com
// Copyright ...: Creative Commons, CC BY-SA
// Description .: Turn on and off a latching relay using a ATMega 328P
// Date Created.: 10/30/2011
// Usage and dependencies:
//
// Variables are used to set start time and end time.
// Times are based on 24 hour clock, i.e.:
// 1:00 pm = 13:00 and Midnight is 00:00
//
// Start time must be less than end time and both times must fall within the
// same 24 hour period.
//
// Code uses RTCLIB, a branch provided from:
// https://github.com/adafruit/RTClib
//
// Thanks to LadyAda for the great tutorial on DS1307
// http://www.ladyada.net/learn/breakoutplus/ds1307rtc.html
//

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

// Setup Start and End TImes
// This is where you define your start hour and start minute times
unsigned int StartHr = 19;
unsigned int StartMin = 58;

unsigned int StartDayofWeek;
unsigned int CurrentDay;
unsigned int EndDay;

// Sleep is a measure of minutes and must be greater than 0
// is used to pause the loop() function.  If you are checking for a start
// time of hours and minutes you do not want to use up processor
// cycles by checking the time every second. Every minute or so it good unless
// you are performing a more frequent activity.
// In this program we are turning on a relay for a period of time every day,
// so minutes are fine for a sleep delay.

long Sleep = 1L;

// The delay() function takes a argument of milliseconds so
// we need a multipler of 60,000 in order to convert our delay variable (sleep)
// to millisconnds.  So a delay of 1 minute  (1 * 60,000) = 60,000 milliseconds.  

long MultiMinute = 60000L;

boolean LightOn = false;

unsigned int EndHr = 19;
unsigned int EndMin = 59;

// ledPin used for debug using Arduino on board LED.
int ledPin = 13;

// Pins used to control latching relay
int RelayOn = 6;
int RelayOff = 7;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();

    pinMode(RelayOn, OUTPUT);
    pinMode(RelayOff,OUTPUT);

    RTC.adjust(DateTime(__DATE__, __TIME__));

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop () {
    DateTime now = RTC.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    // Check status of light
    if (LightOn == false)
    {
      if (((int)now.hour() >= StartHr && (int)now.minute() >= StartMin) &&
         ((int)now.hour() <= EndHr && (int)now.minute() < EndMin))
      {
        // turn on light
        LightOn = true;
        digitalWrite(RelayOn, HIGH);

        Serial.print("Light On"); 

         // only need a short time to trigger the latching relay
        //then we can turn the port back off
        delay(1000);
        digitalWrite(RelayOn, LOW); 

      }
    }
    else
    {
      // Check curren time, turn off light when conditions are met
      if ((int)now.hour() >= EndHr && (int)now.minute() >= EndMin)
      {
        LightOn = false;
        // turn light off
        digitalWrite(RelayOff, HIGH);

        Serial.print("Light Off"); 

         // only need a short time to trigger the latching relay
        //then we can turn the port back off
        delay(1000);
        digitalWrite(RelayOff, LOW);
      }
    }

    // for debugging purposes go ahead and set your delay(3000) so you
    // can debug quickly then for production you can change your delay
    // time to the calculation.
    // delay(3000);
    delay((Sleep*MultiMinute));
}
// Program .....: RTC_Relay_DHMS
// Author ......: Joe Pitz, Objetek Systems, objetek@gmail.com
// Copyright ...: Creative Commons, CC BY-SA
// Description .: Turn on and off a latching relay using a ATMega 328P
// Date Created.: 10/30/2011
// Usage and dependencies:
//
// Variables are used to set relay start time, Duration of relay on time
// is performed by setting day, hour, minute and second variables.
//
// Times are based on 24 hour clock, i.e.:
// 1:00 pm = 13:00 and Midnight is 00:00
//
// Duration can exceed 24 hour period.

//
// Code uses RTCLIB, a branch provided from:
// https://github.com/adafruit/RTClib
//
// Thanks to LadyAda for the great tutorial on DS1307
// http://www.ladyada.net/learn/breakoutplus/ds1307rtc.html
//
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

// Setup Start and End Times
// This is where you set your relay start time

int StartHr = 16;
int StartMin = 13;

// Sleep is a measure of minutes and must be greater than 0
// is used to pause the loop() function.  If you are checking
// for a start time of hours and minutes you do not want to use
// up processor cycles by checking the time every second.
// every minute or so it good unless you are performing a more
// frequent activity.  In this program we are turning on a
// relay for a period of time every day, so minutes are fine for
// a sleep delay.

long Sleep = 1L;

// The delay() function takes a argument of milliseconds so
// we need a multipler of 60,000 in order to convert our delay
// variable (sleep) to millisconnds.  So a delay of 1 minute
// (1 * 60,000) = 60,000 milliseconds.  

long MultiMinute = 60000L;

boolean LightOn = false;

// Relay will stay latched on until current time
// matches duration variables
// If duration is 1 day and 3 hours then
// relay will stay latched on 1 day and 3 hours from the start time

DateTime future;
DateTime DelayFuture;
DateTime Start;

int DurDay = 0;
int DurHour = 0;
int DurMinute = 1;
int DurSecond = 0;

// ledPin used for debug using Arduino on board LED.
int ledPin = 13;

// Pins used to control latching relay
int RelayOn = 6;
int RelayOff = 7;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();

    RTC.adjust(DateTime(__DATE__, __TIME__));

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this
    // sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__)); 

  }

   // Start the StartHr and StartMin for Relay times
   DateTime now = RTC.now();
   DateTime SetStart(now.year(),now.month(),now.day(),StartHr,StartMin,
      now.second());

   Start = SetStart;
}

void loop () {
    DateTime now = RTC.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

     // Check status of light
    if (LightOn == false)
    {
      // Calculate current time + delay minutes, (Sleep variable time)
      // to give a wide window, making sure we can hit the start time
      // if you start the program after this window the relay will
      // not start until the StartHr and StartMin comes around
      // the next day.

      DelayFuture = CalcFuture(Start,0L,0L,Sleep,0L);

      if ((int)now.hour() >= StartHr && (int)now.hour() <=
         DelayFuture.hour() && (int)now.minute() >= StartMin &&
         (int)now.minute() <= DelayFuture.minute())
      {
        // set future DateTime, used to determine duration for
        // light on time
        future = CalcFuture(now,DurDay,DurHour,DurMinute,DurSecond);

        // turn on light
        LightOn = true;
        digitalWrite(RelayOn, HIGH);

        Serial.print("\r\nLight On\r\n"); 

        // only need a short time to trigger the latching relay
        //then we can turn the port back off
        delay(1000);
        digitalWrite(RelayOn, LOW); 

      }
    }
    else
    {
      // Check curren time, turn off light when conditions are met
      if ((int)now.day() >= (int)future.day() && (int)now.hour() >=
         (int)future.hour() && (int)now.minute() >= (int)future.minute())
      {
        LightOn = false;
        // turn light off
        digitalWrite(RelayOff, HIGH);

        Serial.print("\r\nLight Off\r\n"); 

        // only need a short time to trigger the latching relay
        //then we can turn the port back off

        delay(1000);
        digitalWrite(RelayOff, LOW);
      }
    }    

    // for debugging purposes go ahead and set your delay(3000) so
    // you can debug quickly then for production you can change
    // your delay time to the calculation.
    // delay(3000);
    delay((Sleep*MultiMinute));
} 

// CalcFuture() uses unixtime() to calculate proper DateTime for
// passed days, hours, minutes and seconds
DateTime CalcFuture(DateTime now, int Days, int Hours, int Minutes,
   int Seconds)
{
  DateTime future;
  long DaySeconds = 86400L;
  long HourSeconds = 3600L;
  long MinuteSeconds = 60L;

  future = (now.unixtime() + (Days * DaySeconds) +
     (Hours * HourSeconds) + (Minutes * MinuteSeconds) +
     Seconds);
  return future;
}
Categories: Uncategorized

Latest Cool Stuff

September 30, 2011 Leave a comment

Most of my day I spend my time writing C# and SQL code.  Since I do a lot of database data manipulation I am always running into issues with column length of data, when importing data from .csv files into database tables.  I started playing around with Python for some projects I have been working on at home.

I have found Python, extremely useful and easy to use.  I have not had a chance to use an interpretive language in many years.

So I decided to write a simple Python script to check the max length of data, in a particular column,  in a .csv file.

The script takes three arguments,  The .csv file name, the  delimiter that the .csv file is using and the number of the column (zero based)

that you want to parse.

When the script runs it parsed that column for every row in the .csv file and returns the longest length of text in the file.

The script runs very fast and parses what it is suppose to do nicely.

Python is very cool and something that I will keep on learning.

Here is the code that I wrote to parse .csv files:

#===============================================================================
# Program....: ParseCSV.py
# Author.....: Joe Pitz
# Date.......: 09/13/2011
# Description: Pass .csv file, which column to parse and delimiter
# program will return longest length of column, zero based
#===============================================================================
#
import sys
args = sys.argv[1:]

if len(args) != 3:
    print("ParseCSV takes three arguments\n\r" )
    print("<.csv file> <delimiter> <column to parse, zero based>\n\r")
    print ("Ex: ParseCSV file.csv ; 4")
    sys.exit(None)

try:
    file = args[0]
    delimiter = args[1]
    column = int(args[2])

    chrCnt = 0

    f = open(file)
    for line in f:
        llist = line.split(delimiter)

        # Check for number of columns
        numCols = len(llist)

        if column > numCols:
            print ("ERROR -> column argument is greater than number
            of columns in file <- ERROR" )
            sys.exit(None)

        colLen = len(llist[column])

        if colLen > chrCnt:
            chrCnt = colLen

    print("Longest column is " + str(chrCnt))
except TypeError:
    print "ERROR -> Check your parameters <- ERROR"
    f.close()
except StandardError:
    print "ERROR -> Error Parsing .csv File <- ERROR"
except IOError:
    print "ERROR -> Error finding or opening .csv file <- Error"
else:
    f.close()    

sys.exit(None)
Categories: Uncategorized

Consulting at Sony Electronics

November 8, 2010 Leave a comment

A few months ago I started a new consulting project.  I am working at Sony Electronics in the VAIO mobile of America group.  I was brought in to setup unit testing and white box test strategies.  But I am currently doing some ASP.NET development.

We plan on re-designing a customer survey web site using ASP.NET MVC.  So I am getting up to speed on ASP.NET MVC and starting to work on design.

Categories: Uncategorized

Publishing Articles

April 30, 2010 Leave a comment

I have been busy learning Linq to SQL and Writing articles about my data layer ventures.

Here are some links to my articles:

Article about creating data layers for ado.net
Optimize your Data Layer for quicker Code Development

Article about Linq to SQL Performance Considerations Part 1
Linq to SQL Performance Considerations Part 1

Article about Linq to SQL Performance Consideratiions Part 2
Linq to SQL Performance Considerations Part 2

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.