Showing posts with label Sparkfun. Show all posts
Showing posts with label Sparkfun. Show all posts

Friday, April 3, 2015

TMP36 Temperature Sensor


I wish it were this easy to use all sensors.  I got this TMP36 with a SparkFun SIK Inventor's Kit in 2014.  That kit is well worth it if you are just getting started out.  There is a lot more information and direction on getting this going for an Arduino in the kit.  But we are using the MSP-EXP430F5529 :-)

The TMP36 is a low voltage, precision centigrade temperature
sensor that provides an analog signal that is linearly
proportional to the Celsius (centigrade) temperature.
Accuracy is ±1°C at +25°C and ±2°C over the −40°C to +125°C
temperature range. It provides for single-supply operation
from 2.7 V to 5.5 V maximum. The supply current runs below
50 μA.


Looking at the flat side of the TMP36 the pins are as follows:
Left    Vs   (+2.7 to 5.5V)
Center  Vout (analog output)
Right   GND


The datasheet calls for a 0.1 μF bypass capacitor on the input
(i.e. between Vs on the TMP36 and GND). It specifies a ceramic
type with short leads and located as close as possible to the
temperature sensor supply pin.


Circuit
TMP 36    MSP430F5529
------    ---------------------------------------------------
Vs        3.3V
Vs        0.1uF capacitor to GND
Vout      Pin 6 (P6.6) This must be an analog read pin
GND       GND


Frank Milburn 3 April 2015
*/


const int TMP36Pin = 6;            // pin sensor is connected to
const int analogRes = 4095; // A/D resolution


void setup()
{
  Serial.begin(9600);
  Serial.println("Starting temperature readings...");
}


void loop()
{
  // Get the output from the sensor and multiply it by
  // 3.3 / resolution to get the voltage

  float voltage = (analogRead(TMP36Pin) * 3.3 / analogRes);
 
  // TMP36 datasheet provides the conversion formula
  float degC = (voltage - 0.5) * 100.0;
 
  // and if fahrenheit is desired
  float degF = (degC * 1.8) + 32.0;

 
  // Now the serial output...
  Serial.println("___________________________________________");
  Serial.print("Voltage:         "); Serial.println(voltage,3);
  Serial.print("Temperature (C): "); Serial.println(degC,1);
  Serial.print("Temperature (F): "); Serial.println(degF,1);

  delay(1000);
}

Thursday, April 2, 2015

Piezo Element Buzzer / Songs

OK, here is a sketch and circuit taken from the SparkFun Inventor's Kit (SIK) that plays a song using a piezo buzzer and the MSP-430F5529.

/*
BUZZER
  Use the buzzer to play a song!
  The buzzer in your Inventor's Kit is an electromechanical
  component you can use to make noise. Inside the buzzer is a
  coil of wire and a small magnet. When current flows through
  the coil, it becomes magnetized and pulls towards the magnet,
  creating a tiny "click". When you do this thousands of times
  per second, you create tones.
 
  The LaunchPad has a built-in command called tone() which clicks
  the buzzer at a certain frequency. This sketch knows the
  frequencies of the common notes, allowing you to create songs.
  We're never going to let you down!


Hardware connections:
  The buzzer has two pins. One is positive and one is negative.
  The postitive pin is marked by a "+" symbol on both the top
  and bottom of the buzzer.
 
  Connect the positive pin to Arduino digital pin 19.
  (Note that this must be a analogWrite() / PWM pin.)
  Connect the negative pin to GND.
 
  Tip: if the buzzer doesn't fit into the breadboard easily,
  try rotating it slightly to fit into diagonal holes.


This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
(This sketch was originally developed by D. Cuartielles for K3)
This code is completely free for any use.
Visit
http://learn.sparkfun.com/products/2 for SIK information.
Visit
http://www.arduino.cc to learn about the Arduino.
Visit
http://energia.nu/ to learn about Energia
Version 2.0 6/2012 MDG
modified by Frank Milburn for MSP-430F5529LP


This sketch uses the buzzer to play songs.
The Arduino's tone() command will play notes of a given frequency.
We'll provide a function that takes in note characters (a-g),
and returns the corresponding frequency from this table:

  note  frequency
  c     262 Hz
  d     294 Hz
  e     330 Hz
  f     349 Hz
  g     392 Hz
  a     440 Hz
  b     494 Hz
  C     523 Hz

For more information, see http://arduino.cc/en/Tutorial/Tone
*/
 
const int buzzerPin = 19;

// We'll set up an array with the notes we want to play
// change these values to make different songs!

// Length must equal the total number of notes and spaces
const int songLength = 18;
// Notes is an array of text characters corresponding to the notes
// in your song. A space represents a rest (no tone)

char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
// Beats is an array of values for each note and rest.
// A "1" represents a quarter-note, 2 a half-note, etc.
// Don't forget that the rests (spaces) need a length as well.

int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
// The tempo is how fast to play the song.
// To make the song play faster, decrease this value.

int tempo = 150;

void setup()
{
  pinMode(buzzerPin, OUTPUT);
}


void loop()
{
  int i, duration;
 
  for (i = 0; i < songLength; i++) // step through the song arrays
  {
    duration = beats[i] * tempo;  // length of note/rest in ms
   
    if (notes[i] == ' ')          // is this a rest?
    {
      delay(duration);            // then pause for a moment
    }
    else                          // otherwise, play the note
    {
      tone(buzzerPin, frequency(notes[i]), duration);
      delay(duration);            // wait for tone to finish
    }
    delay(tempo/10);              // brief pause between notes
  }
 
  // We only want to play the song once, so we'll pause forever:
  while(true){}
  // If you'd like your song to play over and over,
  // remove the above statement
}


int frequency(char note)
{
  // This function takes a note character (a-g), and returns the
  // corresponding frequency in Hz for the tone() function.
 
  int i;
  const int numNotes = 8;  // number of notes we're storing
 
  // The following arrays hold the note characters and their
  // corresponding frequencies. The last "C" note is uppercase
  // to separate it from the first lowercase "c". If you want to
  // add more notes, you'll need to use unique characters.

  // For the "char" (character) type, we put single characters
  // in single quotes.

  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
 
  // Now we'll search through the letters in the array, and if
  // we find it, we'll return the frequency for that note.
 
  for (i = 0; i < numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency
    }
  }
  return(0);  // We looked through everything and didn't find it,
              // but we still need to return a value, so return 0.
}


Wednesday, March 11, 2015

Sites I Frequent

These are sites I frequently visit and can recommend.  Here they are, in the order I more or less discovered them:

Arduino:  The educational / hobbyist / maker movement has benefited greatly from Arduino.  There is a lot of good stuff on their site and the internet is full of good (and not so good) support.  This is a very good place to start if you are new to microcontrollers (but this is a blog about the TI LaunchPad series so let's move on)

SparkFun:  I got started in microcontrollers with a "SparkFun  Inventor's Kit" and SparkFun RedBoard (an Arduino Uno compatible).  They have a large selection of hobbyist material and documentation for their products.

Adafruit:  Great products.  Great documentation.  Great service.  This is a really good place to go for Arduino, Raspberry Pi, and Beaglebone Black.  Many of their products can also be used with the Texas Instrument Launchpads.

Texas Instruments:  The Texas Instrument LaunchPad lineup offers incredible value and capability.  Read more about them here.

Energia:  Energia is a fork of Wiring and Arduino for various Texas Instruments LaunchPads - if you have some experience with the Arduino, this site is going to look familiar.  And the great thing is that moving to Code Composer Studio, TI's full featured development environment, is available if you need the additional capability.

Mouser:  I love these guys.  If you need one 10 cent resistor they will ship it to you.  And they carry an amazing array of products, all with datasheets - including the TI LaunchPad series.

Pololu:  I recently started using Pololu for robot components and have been pleased.  They have some interesting products with good range - especially in motors and motor controllers.

Addicore:  They don't have as large a selection as the companies above but what they do have is great value (free shipping on orders larger than $25 too!).  They are very quick and responsive - the best service I have received.  You will also find some of their items on Amazon (at a slightly higher price).