Showing posts with label Engineering. Show all posts
Showing posts with label Engineering. Show all posts

Tuesday, January 15, 2019

Arduinos and SD cards

If you require an SD card interface for your Arduino project I highly recommend purchasing an Arduino with one built-in.  It took three attempts to get an SD card interface added to my basic Arduino Mega:

  1. A very cheap generic (“LC Studio”) break out module that seemed to work intermittently at best;
  2. A cheap shield (linksprite SD Card Shield v1.0b) - not compatible with the Mega (it does not state this on the packaging but if you search the documentation on their website it clearly states this, I should have done my research first);
  3. And finally, a not so cheap Ethernet plus SD card shield (Freetronics) that worked without a hitch.
I would have been better off spending the extra coin on a Mega with the SD card interface built-in and reclaiming most of my weekend...

Sunday, August 26, 2018

[Part 7] Arduino Data Logger

// ------------------------------------------------------------------------------------------------------------------------------------------------
// Project:   DataLogger
// Version:   0.4
// Date:      26 August 2018
// Author:    Greg Howell <gjhmac@gmail.com>
// ------------------------------------------------------------------------------------------------------------------------------------------------
// Version    Date              Comments
// 0.4        26 August 2018    Modified code to only log to the SD card if the new value is different to the old value
// 0.3        30 June 2018      Added debugging and diagnostics on serial port, sped up ADC for analogue read (128kHz -> 1MHz), fixed "A REF"
// 0.2        26 April 2018     Addition of switch to enable/disable logging to SD card and LED to indicate logging status
// 0.1        17 February 2018  Initial Development
//
// ------------------------------------------------------------------------------------------------------------------------------------------------
// Description:
//  - Logs analog0 value to a text file on the SD card along with date/time stamp in CSV format
//  - Maintains date/time via DS1302 Real Time Clock
//  - Builds with Arduino 1.8.5
// ------------------------------------------------------------------------------------------------------------------------------------------------

// #includes
#include <SPI.h>    // Serial Peripheral Interface
#include <SD.h>     // SD Cards
#include <DS1302.h> // DS1302 RTC

const int chipSelect = 4;
const int buttonPin = 5;  // Pin 5 is the button to enable/disable logging (digital input)
const int ledPin =  6;    // Pin 6 is the LED indicate logging status (digital output)

const byte PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
const byte PS_16 = (1 << ADPS2);

int buttonState = 0;      // initialise button state to off
int oldsensor;            // variable to store the previous sensor value (used in loop())

// Init the DS1302
// Pin 2 = RST
// Pin 3 = DAT
// Pin 4 = CLK
DS1302 rtc(2, 3, 4);
// ------------------------------------------------------------------------------------------------------------------------------------------------
// setup()
// ------------------------------------------------------------------------------------------------------------------------------------------------
void setup() {

  ADCSRA &= ~PS_128;  // remove prescale of 128
  ADCSRA |= PS_16;    // add prescale of 16 (1MHz)

  analogReference(EXTERNAL);  // Analogue reference set to "A REF" pin

  pinMode(buttonPin, INPUT);  // Initialize the pushbutton pin as an input
  pinMode(ledPin, OUTPUT);    // Initialize the LED pin as an output

  rtc.halt(false);            // Set the clock to run-mode
  rtc.writeProtect(false);    // and disable the write protection

  Serial.begin(9600);

  // Use following lines once to set clock if battery fails (modify to suit)
  //rtc.setDOW(SUNDAY); // Set Day-of-Week to FRIDAY
  //rtc.setTime(21, 50, 0); // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(26, 8, 2018); // Set the date to August 6th, 2010

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Print current system date from RTC at start up
  Serial.print("System date: ");
  Serial.println(String(rtc.getDateStr()) + "," + String(rtc.getTimeStr()));

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}
// ------------------------------------------------------------------------------------------------------------------------------------------------
// loop()
// ------------------------------------------------------------------------------------------------------------------------------------------------
void loop() {
  String dataString = "";                 // make a string for assembling the data to log
  int sensor = analogRead(A0);            // read analogue
  dataString += String(sensor);           // construct string with analogue signal
  buttonState = digitalRead(buttonPin);   // read button state

  // Logging enabled
  if (buttonState == HIGH) {
    File dataFile = SD.open("datalog.txt", FILE_WRITE);

    // if the file is available, write to it
    if (dataFile) {

      // if the new data is different to the old data write it to file
      if (sensor != oldsensor) {
        // Write data to serial output
        Serial.println(String(rtc.getDateStr()) + "," + String(rtc.getTimeStr()) + "," + dataString);
        Serial.println(String(sensor) + "," + String(oldsensor));
        // Write data to SD card
        dataFile.println(String(rtc.getDateStr()) + "," + String(rtc.getTimeStr()) + "," + dataString);
        dataFile.close();
      }
      else {
        dataFile.close();
      }
    // set logging LED to high
    digitalWrite(ledPin, HIGH);
  }
  // if the file isn't open, print an error
  else {
    digitalWrite(ledPin, LOW);
    Serial.println("error opening datalog.txt");
  }
}
  // Logging disabled
  else {
    // set logging LED to low
    digitalWrite(ledPin, LOW);
  }
  // set the old sensor value to the current sensor value (read at top of loop())
  oldsensor = sensor;
  // Wait before repeating :)
  delay (500);
}

Saturday, July 07, 2018

[Part 6] Arduino Data Logger

// ------------------------------------------------------------------------------------------------------------------------------------------------
// Project:   DataLogger
// Version:   0.3
// Date:      30 June 2018
// Author:    Greg Howell
// ------------------------------------------------------------------------------------------------------------------------------------------------
// Version    Date              Comments
// 0.3        30 June 2018      Added debugging and diagnostics on serial port, sped up ADC for analogue read (128kHz -> 1MHz), fixed "A REF"
// 0.2        26 April 2018     Addition of switch to enable/disable logging to SD card and LED to indicate logging status
// 0.1        17 February 2018  Initial Development
//
// ------------------------------------------------------------------------------------------------------------------------------------------------
// Description:
//  - Logs analog0 value to a text file on the SD card along with date/time stamp in CSV format
//  - Maintains date/time via DS1302 Real Time Clock
//  - Builds with Arduino 1.8.5
// ------------------------------------------------------------------------------------------------------------------------------------------------

// #includes
#include    // Serial Peripheral Interface
#include     // SD Cards
#include // DS1302 RTC

const int chipSelect = 4;
const int buttonPin = 5;  // Pin 5 is the button to enable/disable logging (digital input)
const int ledPin =  6;    // Pin 6 is the LED indicate logging status (digital output)

const byte PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
const byte PS_16 = (1 << ADPS2);

int buttonState = 0;      // initialise button state to off

// Init the DS1302
// Pin 2 = RST
// Pin 3 = DAT
// Pin 4 = CLK
DS1302 rtc(2, 3, 4);
// ------------------------------------------------------------------------------------------------------------------------------------------------
// setup()
// ------------------------------------------------------------------------------------------------------------------------------------------------
void setup() {
  
  ADCSRA &= ~PS_128;  // remove prescale of 128
  ADCSRA |= PS_16;    // add prescale of 16 (1MHz)

  analogReference(EXTERNAL);  // Analogue reference set to "A REF" pin
  
  pinMode(buttonPin, INPUT);  // Initialize the pushbutton pin as an input
  pinMode(ledPin, OUTPUT);    // Initialize the LED pin as an output

  rtc.halt(false);            // Set the clock to run-mode
  rtc.writeProtect(false);    // and disable the write protection

  Serial.begin(9600);

  // Use following lines once to set clock if battery fails (modify to suit)
  //rtc.setDOW(THURSDAY); // Set Day-of-Week to FRIDAY
  //rtc.setTime(15, 50, 0); // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(26, 4, 2018); // Set the date to August 6th, 2010

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Print current system date from RTC at start up
  Serial.print("System date: ");
  Serial.println(String(rtc.getDateStr()) + "," + String(rtc.getTimeStr()));

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}
// ------------------------------------------------------------------------------------------------------------------------------------------------
// loop()
// ------------------------------------------------------------------------------------------------------------------------------------------------
void loop() {
  String dataString = "";                 // make a string for assembling the data to log
  int sensor = analogRead(A0);            // read analogue
  dataString += String(sensor);           // construct string with analogue signal
  buttonState = digitalRead(buttonPin);   // read button state

  // Logging enabled
  if (buttonState == HIGH) {
    File dataFile = SD.open("datalog.txt", FILE_WRITE);

    // if the file is available, write to it:
    if (dataFile) {
      // Write data to serial output
      Serial.println(String(rtc.getDateStr()) + "," + String(rtc.getTimeStr()) + "," + dataString);
      // Write data to SD card
      dataFile.println(String(rtc.getDateStr()) + "," + String(rtc.getTimeStr()) + "," + dataString);
      dataFile.close();
      digitalWrite(ledPin, HIGH);
    }
    // if the file isn't open, pop up an error:
    else {
      digitalWrite(ledPin, LOW);
      Serial.println("error opening datalog.txt");
    }
  }
  // Logging disabled
  else {
    digitalWrite(ledPin, LOW);
  }

  // Wait before repeating :)
  delay (200);
}

[Part 5] Arduino Data Logger

Connected "A REF" pin to 5VDC power supply.



[Part 4] Arduino Data Logger

Now with added 500mA fuse.


Saturday, April 28, 2018

[Part 2] Arduino Data Logger


  • For the external plug pack I selected the POWERTRAN MB8968B from Altronics.  Input is 100-240VAC @ 50-60Hz/0.8A, output is 24VDC @ 1A.
  • To produce the 5VDC (from the 24VDC) for the Arduino I selected the Z6334 DC-DC Buck Module from Altronics.  Input is 3-40VDC, output 1.5-35VDC @ 3A maximum (adjusted to provide a 5VDC output).
  • To maintain the date and time while the logger is powered off I selected the DS1302 based Real Time Clock Module from Altronics.  Reports online indicate that the DS1302 chip can be unreliable (as opposed to the DS1307) but I have had no issues with the one I purchased.
  • The Arduino I selected was one I had already, the Freetronics EtherTen.  The on-board MicroSD slot was the main reason I decided to use this, I didn't require the Ethernet port.

Thursday, April 26, 2018

[Part 1] Arduino Data Logger

This is the first post in a series in which I'll document the development of an Arduino-based data logger. The requirements for this data logger are:
  • Data to be logged is a 4-20mA current loop signal (2-wire) from a sensor (using 4-20mA for analogue measurement is an industrial automation standard);
  • Sensor requires a 24VDC supply (I'll be using a 240VAC-to-24VDC transformer plug pack to provide the 24VDC so there will be no mains supply work required);
  • Whole system to be contained in a box that can be sealed up and made "weather-proof".

Sunday, June 25, 2017

Planes I have flown in (updated to include Saab 340)

Tuesday, May 02, 2017

May 2017 Update

So it's been a while since I've posted.  Notice a theme?
Anyway, here goes:

  • I've quit my job as a Control Systems Engineer in the mining industry and have started a new job as a Control Systems Engineer in the grain handling industry.  The change has been good and I feel reinvigorated.  I'm enjoying engineering more as I no longer have people reporting to me.  I'm also going away with work a lot less (and when I do go away it's generally a day trip).
  • I'm catching the bus to and from work so the 1975 Mini Clubman is no longer a daily drive.  I'm getting some of the more involved work done on it now (disc brakes and suspension).  I'm planning on it being a fairly original car with some upgrades for safety (disc brakes and suspension) and for the look (period roof rack, possibly a rear window shade).  Recently fitted new plugs and leads as it lost a cylinder...

Monday, December 12, 2016

End of 2016 Update

So it's been a while since I've posted an update.  Apologies to my regular readers...

Here is a point form update:
  • Work and life are very busy (so no change there);
  • I'm not sure what I think about Fitbit buying Pebble (I don't remember an acquisition like this ever going well);
  • The finches are doing well, the Painteds seem happy and are breeding, the Zebras perhaps a little too happy...;
  • Bird watching has taken a bit of a hit (closely related to amount of free time available unfortunately);
  • Using a 1975 Mini Clubman as a daily driver seems to be going well (after the clutch was replaced).

Wednesday, June 15, 2016

Planes I have flown in (updated to include Airbus A320)

Wednesday, March 09, 2016

Planes I have flown in (updated to include Fokker 70)

Friday, September 18, 2015

Birds seen from my office window

List of birds seen from my first floor office window in Applecross, Perth, WA (in order seen/recorded).
  1. Silver Gull - regular fly-bys throughout the day
  2. Singing Honeyeater
  3. Rainbow Lorikeet - frequent
  4. Galah
  5. Australian Magpie - nesting nearby
  6. Australian Pelican - seen circling high
  7. Australian Raven - nesting nearby
  8. Red-tailed Black-cockatoo
  9. Red Wattlebird
  10. Laughing Dove
  11. Australian White Ibis
  12. Rock Dove
  13. Spotted Dove
  14. Willie Wagtail - road verge
  15. Brown Honeyeater
  16. Magpie-lark
  17. Black-faced Cuckoo-shrike
  18. Eastern Osprey
  19. New Holland Honeyeater
  20. Carnaby's Black-Cockatoo
  21. Laughing Kookaburra

Thursday, December 27, 2012

Planes I have flown in

The latest addition to the list is the Brasilia, a plane I travelled on from the Carina mine site (East Jaurdi) to Perth.  A very noisy and bumpy ride.

Edited to add 737-800 (thanks John).

Sunday, June 24, 2012

Mulga Parrot

Part of the safety plan when driving from site to Perth is to call your supervisor when you reach Great Eastern Highway.  The Boorabbin Memorial looked like a good spot to pull over as it's within a kilometre or so of the where we emerge from the bush.  As I pulled over I noticed a parrot perched in a low tree, seemingly attempting to defrost on what was a very chilly morning.  A Mulga Parrot!  What a spectacular bird.  It gave me enough time to get my binoculars out and then after a few seconds was off into the scrub.  Mulga Parrot (Psephotus varius) is number 269 on my life list.

Saturday, October 08, 2011

My Apple History

With the passing of Steve Jobs, I thought it would be a good time to reflect on the impact Apple Computers has had on me.  Here is a rundown of my "main computer" Macs.  I haven't included those acquired for my (rather out-of-control) collection.

  • It all started in the mid-1990s and involves playing the original version of Cyan's Myst with Simon Wright on his Apple clone (the brand was Umax if my memory serves me correctly).  Simon and I used to prepare all our group assignments on this setup (he had a scanner and a printer as well I think).  This got me hooked on all things Apple.
  • In the mid-1990s my folks bought us a second hand Apple Macintosh IIci (8MB/80MB) from Simon's Dad's work.  It was fantastic.  Mum and Dad then splashed out and bought a brand new StyleWriter 1200!  I still have the IIci and StyleWriter.  Years later I discovered the IIci had come with a Nubus ethernet card, making it even cooler.  The IIci remains my favourite Apple product.
  • After a few years of University studies I purchased (for a ridiculously high price) a Performa 5400 (160MHz/32MB/1.6GB).  Not one of my better decisions.  I foolishly chose the higher clocked 603-based Mac over the slower clocked 604-based one.  I bought my first (of many) boxed Mac OS version for the 5400 - Mac OS 8.5 (I updated to 8.6 by downloading all of the disk images over a 33.6 modem).  I did get it to boot MkLinux from a 250MB Zip Disk (once).
  • Early in the piece I purchased (for about $500 I think) my first PowerBook, a PowerBook 150 (4MB/500MB).  I sold it a few years later.  I spent a while trying to find more RAM for it but had no luck at all.  I now have a handful in my collection...
  • My next PowerBook was a PowerBook 1400 (133MHz/Passive Matrix Screen/40MB/1.3GB) and a PowerCD (as the 1400 had no internal CD drive).  I sold the PowerBook a while later but have kept the PowerCD.  I think I paid about $1400 for this.  The 1400 also ran MkLinux briefly...  Needless to say I have kept the reasonably rare and unusual AppleCD in my collection.
  • For the last few years of Uni I had a Lombard G3 PowerBook (400MHz/192MB/6GB) until upgrading to a brand new PowerBook G4 12" 1GHz (256GB/40GB).  Later I upgraded the RAM to 768MB and the hard disk to 320GB.  This is the only new Macintosh I have ever bought.
  • The latest upgrade (nearly three years ago now) was a second hand MacBook 2.16GHz (2GB/120GB).  I later upgraded the hard disk to 320GB.  I'm currently typing this post on it!  It has been a good work horse.
  • I guess I should also include the iOS devices.  I started with a 2nd Generation iPod Touch (8GB), followed with an iPhone 4 (16GB Black, I was a late adopter) and the latest acquisition has been an iPad 2 (Black/Wifi-only/16GB).  They are incredible pieces of kit.
For the record I think it is perfectly normal to remember the specifications of all computers you have owned.

Thursday, November 25, 2010

Return from intermission

I have come to the realisation that it has been almost two months since I have posted anything on this blog.  Apologies to my dedicated readers for the unscheduled hiatus.

The last two months have unfortunately been dominated by work.  I had hoped to reduce the amount of site time I was doing but have found it steadily increasing.  In an effort to stay in Perth more often I am taking on more managerial roles, something that I am not too comfortable with to be honest.  I am, however, grateful to have a job.

Computer-wise, not a lot has changed.  Kylie has a "new" iMac G5 (replacing her eMac G4 which was becoming decidedly long in the tooth).  I haven't added much to the computer collection (I think a complete Apple IIC was the last acquisition).  Recent Apple announcements have been a roller-coaster of emotions for me: the new MacBook Air looks awesome (the 11 inch model in particular) but why oh why have they canned the Xserve?

The model train layout I have been building for the last year or so is progressing nicely.  The under-board wiring has been neatened up and more work on the scenery completed.  I have also started to fix the location of buildings.  Still a very long way to go but I'm not sure I ever want this project to end...

The last few months have been fantastic for me with regards to birding.  The highlight was a trip to Neale Junction with Martin Cake and John Graff.  You can read the trip report here.  It was a fantastic adventure into an area that I have never travelled before.  Already there are plans to go back.  In all I got 17 lifers.

Sunday, June 27, 2010

Another rambling update...

Here's an insight into what I have been up to recently:
  • Started basketball training again (with the intention to play a season on a team). I really need the exercise...
  • Still tinkering with model trains. I'm in the process of re-doing a whole heap of track work I did earlier in the year (or late last year) that I'm not entirely happy with. Contemplated (briefly) a new, much larger N gauge layout but decided to continue with the one I have been working on. Still acquiring random trains/rolling stock/buildings and other miscellanea. Lots of fun.
  • Not bird-watching/photographing anywhere near as much as I would like. Don't like my chances of reaching 250 species by the end of the year (currently sitting on 215).
  • I have finally delved back into Mac programming. Just working on a simple project to start with but hopefully things will ramp up once I get familiar with it again. Seriously liking the new version of Xcode.
  • Still working (probably too much). Got to pay the bills somehow. While the downturn means less project work it does mean we are putting together a lot more quotations and proposals.