Saturday, October 27, 2012

Using Interrupts With the Arduino

Good explanation of Interrupts with the Arduino from Dave Auld

The volatile keyword is added to the state variable, this causes the compiler to use RAM instead of a storage register. This is done because the storage register can be temporarily inaccurate if they are being modified by areas other than the main thread. In the Arduino, this relates to code being triggered by interrupts.

The attachInterrupt(param1, param2, param3) requires 3 parameters, these are;
param1 = Which interrupt to listen for. This is the Interrupt Number not the Digital In number
param2 = Which code function to call, this must be a method that takes no parameters and returns no value.
param3 = Which condition to watch for.

The Arduino can listen for 4 types of condition changes. These are;
LOW = The input is at a LOW state
RISING = The input state changes from LOW to HIGH
FALLING = the input state changes from HIGH to LOW
CHANGE = The input state changed from HIGH to LOW or LOW to HIGH, i.e. has changed its state

ReAssigning Interrupts
Interrupts can be changed at any point by using the attachInterrupt() method. As soon as this is done, any previously assigned interrupt on the associated pin is removed.

Starting / Stopping Interrupts
The Arduino also has the ability to temporarily ignore all the interrupts. You may want to do this if you have some sensitive code that must be executed without interruption. In this case you would issue a noInterrupts() call. Once your sensitive code block has completed, interrupts can be restarted by calling interrupts().

Removing Interrupts
Interrupts can also be removed by using the detachInterrupt(interrupt_number) method.

Tuesday, October 23, 2012

Interrupts on an Arduino

In a basic Arduino sketch, if you want to take action based on the status of a digital input pin, you’d check the state of the pin repeatedly until a particular condition is met. However, as your sketches become increasingly complex, you’ll find that it’s not always the best way to do this. EngBlaze posted a pair of guides to using interrupts so that you can execute code asynchronously in Arduino sketch. Here’s the analogy they use to illustrate the difference:


Save power on arduino

Narcoleptic library by Peter Knight
Caveats:
Library implementing sleep modes, allowing extremely low power consumption on Arduino based projects.
Narcoleptic uses the sleep functionality of the AVR microcontroller to almost completely shut down the entire CPU, just leaving a low power timer running to trigger the wake up.
Extract the download, and install in your Arduino Libraries directory. Restart Arduino and you will see the Narcoleptic library appear in the menus.
Syntax:
Narcoleptic.delay( time in milliseconds )
Note that Narcoleptic timings are only accurate to a few percent. Whilst sleeping, everything is stopped - including PWM outputs, the millis() timer, serial ports - everything. So code with this in mind.

Sunday, October 21, 2012

Conductivity and arduino

Building a small submersible conductivity probe using the details from EMEsystems.  I used to use a BASIC stamp for some of these measurements so time to pass this info to the Arduino.



Thursday, October 18, 2012

Engauge Digitizer - Import data from printed plots

Engauge Digitizer is Open source software, reads a printed graph, and saves the data to a file so it can be reused and re-plotted

Thursday, October 11, 2012

Thermistor array for under ice

Building a thermistor array to leave under the ice for the winter to look at cold stratification of the lake over the winter. Using an adafruit datalogger and 10K thermistors from adadfruit, I have a short string of three thermistors which will be placed in the lake next week hopefully.
String is complete for testing - here are the values being logged to the SD card for 3 thermistors at three depths (currently sitting in the workshop so values are in the 20s).