Saturday, March 14, 2015

IC Station MicroSD Card Module

This tutorial will help you get the IC Station Micro SD Card Module up and running. This is ideal for recording data from sensors for future analysis. This is a 5v piece, where commonly sd card modules are 3.3v.

The right angle header that comes pre soldered isn't long enough to sit in our standard breadboard, so we used a mini breadboard where the card can hang off the side. You can also use male to female jumpers.


Use checkout code "steveics", and get a 15% discount on the sensors!

Code: steveics Discount Amount: 15% Max Use: 1 No Min Order Started Date: 16th Mar, 2015 Ended Date: 16th May, 2015

The connections are as follows:


 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - pin 10 on Arduino Uno/Duemilanove/Diecimila. You can change this one.

Connect GND to Arduino GND and VCC to Arduino +5v.

Insert a fat32 formatted micro sd card.

No libraries have to be downloaded or installed, as the Arduino IDE comes pre configured with the SD Card libraries.

Just load the example from File, Examples, SD, Card Info.

This example already comes with the Leonardo / Micro serial delay.

After uploading you should see something similar to the following:



The Arduino only reports volumes less than 2GB, even if using a larger sd card. Stay tuned for a data logging project using this and the 3 previous modules we have blogged about.

IC Station DS1307 Real Time Clock

In this tutorial, we will be using the IC Station DS1307 Real Time Clock Module. This will allow you to not only build a clock display, but add date and time stamping functions to your projects, so you know when a particular value was recorded by a sensor.


Use checkout code "steveics", and get a 15% discount on the sensors!

Code: steveics Discount Amount: 15% Max Use: 1 No Min Order Started Date: 16th Mar, 2015 Ended Date: 16th May, 2015

This module does not include a battery, or the pin headers. You will need to order those:

LI2032 (rechargeable, non-rechargeable CR2032 will also work)
Right Angle Breakaway Headers (you can never have too many)

Solder the header to the module. I used the 5 hole side of the module. Only 4 pins are used. VCC to Arduino +5, GND to Arduino GND, SCL to Arduino SCL (A5), and SDA to Arduino SDA (A4).

You will need to download a library to use this module. I prefer the Adafruit library:

RTClib

Download and install into your IDE using the Sketch, Import Library, Add Library function.

Now load the File, Examples, RTClib-master, DS1307 example sketch.

Because we are using the Arduino Micro, we need to add the Serial delay in setup:

Serial.begin(9600);
   while (!Serial) ; //needed for Leonardo and Micro

Now you can upload to the Arduino. The time and date will be set from your computer during the compile and upload process.

When you run the Serial Monitor, you should see something similar to this:



We will show you how to use this for data logging and LCD display in a upcoming blog post.

IC Station DHT22 Temperature Humidity

This tutorial will teach you how to read temperature and humidity readings using the IC Station DHT22 Temperature & Humidity Module. Once you have those readings, you can calculate neat things like Heat Index and Dew Point, and by adding a wind speed sensor, Wind Chill.


Use checkout code "steveics", and get a 15% discount on the sensors!

Code: steveics Discount Amount: 15% Max Use: 1 No Min Order Started Date: 16th Mar, 2015 Ended Date: 16th May, 2015

Unlike the bare sensors, this one is assembled with the appropriate resistor, so there's only 3 connections. + connects to Arduino 5v or 3.3v, - to Ground, and out connects to the digital pin of your choice. We are using pin 2 per the included example.

Once again we are using an awesome library written by Adafruit:

DHT Sensor Library

Download and import into your Arduino sketchbook libraries folder using the import library feature in the IDE per our previous tutorial.

Load the example sketch DHTtester found under File, Examples, DHT Sensor Library.

Since we are using the Arduino Micro, we added the following line just after Serial.begin(9600);

  while (!Serial) ; //needed for leonardo and micro

Now upload to your Arduino and run the Serial Monitor. You should see something similar to the following:


This example already includes Metric and Standard unit display. We will be adding Dew Point calculations at a later date.






IC Station BMP180 Barometric Pressure

A while back we did a tutorial using the IC Station BMP085 Barometric Pressure Sensor. We wanted to do another tutorial using the newer BMP180, and the latest Unified Sensor Drivers from Adafruit. Another twist? We are using the Arduino Micro, which uses the Atmel ATmega32u4 like the Leonardo, instead of the ATmega328p like the UNO.

First, let's talk about the BMP180 from ICStation. You will need to solder the included header to the board. There are 5 pins, of which only 4 are needed. there is a VCC pin for 5v operation, or a 3.3 pin for 3.3v operation. GND connects to Arduino GND, SCL connects to Arduino SCL (A5), and SDA which connects to Arduino SDA (A4).


Use checkout code "steveics", and get a 15% discount on the sensors!

Code: steveics Discount Amount: 15% Max Use: 1 No Min Order Started Date: 16th Mar, 2015 Ended Date: 16th May, 2015

You will need to download and import two libraries (using the Arduino Sketch, Import Library, Add Library menu sequence). Those libraries are:

Adafruit Sensor
Adafruit BMP085 Unified

The code for a BMP085 and a BMP180 is identical. The BMP180 is a smaller, cheaper version of the older BMP085.

There is a example sketch on the File, Examples, Adafruit BMP085 menu called sensorapi. Load that into your IDE.

Because we are using the Arduino Micro, there is a small change that we have to make. This concerns the Leonardo as well. These units use the ATmega32u4 which not only is the processor, but is also the USB interface. As such, a reset not only resets the processor, but also resets the USB connection. We have to add a small delay after Serial.begin, or nothing in the Setup() will get printed to the serial monitor.

  Serial.begin(9600);

   while (!Serial) ; //needed for leonardo and micro

So, now that we have connected, and opened the example sketch, make sure you have chosen the correct board and port on the tools menu, go ahead and upload the sketch. When it says done uploading, open your Serial Monitor, and you should see something like the following:


Notice all the values are in metric (SI). I prefer US Customary (Standard) units myself, so I will probably add some conversion code to the units.

Monday, March 9, 2015

Arduino Map: Floats or Ints?

The Arduino Map function is a very useful function. It allows you to map a input range from a analog sensor to another set of values. For instance, lets say we have a fuel gauge, with a varying resistance. We do a analogRead on the variable resistor, but then we want to map that to inches of fuel (we will convert inches to volume, and volume to gallons). The problem with the map command is it only works for integers, so:

h = map(sensorValue, 0, 1023, 0, 12);

results in a number like 5 inches, which would throw off our calculations. We need to be able to handle float values, and get a fractional result. If we had a function called mapfloat, we could do the following:

h = mapfloat(sensorValue, 0, 1023, 0, 12);

and get a result of 5.87 inches, which will make our fuel gauge more accurate. But the Arduino doesn't do floats with the map command, does it? No, it does not, so we will make our own function by adding the following chunk of code after the last } in your sketch:

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

now our mapfloat call will return a float that more accurately describes the amount of fuel in our tank. Remember to specify the number of decimal places in your Serial.print command:

Serial.print(h, 2);

so now the complete sketch would look something like this:

int sensorPin = 0; // select the analog input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor

float h; // variable for height of liquid
float v; // variable for volume in cu. in.
float g; // variable for gallons
float r = 3; //radius

void setup() {
Serial.begin(9600);

}

void loop() {

sensorValue = analogRead(sensorPin);
Serial.print(sensorValue); //actual adc value
Serial.println(" ADC");
h = mapfloat(sensorValue, 171, 512, 12, 0);
Serial.print(h, 2); // fluid height (inches)
Serial.println(" inches");
v = h*PI*sq(r); // volume (cu. in.)
g= v * 0.004329; // gallons conversion
Serial.print(g, 2); // gallons
Serial.println(" gallons");
delay(5000);
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Related Posts Plugin for WordPress, Blogger...