Sunday, December 27, 2015

Arduino Nintendo DS Touch Screen

Today I hope to add some clarification to a popular project, based on a Nintendo DS Touch Screen, with breakout board from Sparkfun ($10).

The concept is simple. Print out a picture of your buttons, sliders, etc., slide it under the glass, and with a series of if statements, create zones of co-ordinates that fit the printed controls.


SN754410 H-Bridge Motor Controller

One of our upcoming projects is a wireless controller for model railroading. A tiny Arduino installed in the engine with a wireless receiver and a H Bridge motor controller chip will allow us to go forward, reverse, coast, brake, and have speed control. Today we are testing the H Bridge chip, a SN754410 from Sparkfun ($2.35).


DIY I2C LCD and I/O

A few posts ago we discussed building your own I2C display to reduce the pin count from 6 to two. We have also added 5 inputs to this project, a video of the commercial version, and posted the instructable that you can vote on at http://www.instructables.com/id/DIY-I2C-LCD-Display-With-Inputs/


Wednesday, December 16, 2015

Building a IoT Server

The "Internet of Things" is one of the most exciting topics around these days. Millions of internet enabled gadgets sending data to a data storage & reporting server, and retrieving data back for local control or display.

Our last post described sending sensor data to a server. Today we will discuss more about setting up that server. We are using a hosting service (Hostgator) which gives easy control panel access to html directories, email accounts, and MySQL databases.


Sunday, December 13, 2015

Sending sensor data to a web server

Build your own IOT service! Collect sensor data and send it to a web/database server.

Today's project uses an Arduino equipped with a Ethernet shield, and a DHT-11 temperature / humidity sensor.

Arduino UNO
Arduino Ethernet Shield
DHT-11 Module

The Arduino reads the DHT-11, and submits the data to a php script on a hosted web server. That php page inserts the data into a mySQL database, and another php page creates a web page displaying the data as you can see below.


Saturday, November 21, 2015

Arduino Controlled Adjustable Constant Current Source

Did you know you could use the Arduino to control the amount of current from a constant current source? Another great project from Henry's Bench, this experimental project uses an MCP4725 Digital to Analog Converter, an LM358 Op Amp, an INA219 Current Sensor and a logic level N-Channel Mosfet to create a constant current source. You can program up to 3 amps of constant current.

Hot Tentacle Action

What happens when you combine an arduino, a servo, and a rubber tentacle. Well, it could be madness, or it could be a knife wielding tentacle bot. Either way it's a conversation starter, or ender.

More servo fun at:

http://arduinotronics.blogspot.com/2012/03/fun-with-servos.html





Thursday, November 19, 2015

Processing Now Optimized for the Pi

Thanks to the new Hardware I/O libraries, Processing is now optimized for the Raspberry Pi. This makes it much easier to use the Raspberry Pi I/O pins, and send data back and forth with a Arduino.


Sunday, November 15, 2015

WiFi Rechargeable Internet Clock

Many moons ago we built a Ethernet enabled clock that got it's time updates from a Internet NTP Server. We have updated that project for WiFi,and added a rechargeable battery that can be recharged with a USB cable.


Thursday, November 12, 2015

The Maker's Guide to the Zombie Apocalypse

Defend Your Base with Simple Circuits, Arduino, and Raspberry Pi

Where will you be when the zombie apocalypse hits? Trapping yourself in the basement? Roasting the family pet? Beheading reanimated neighbors?

No way. You'll be building fortresses, setting traps, and hoarding supplies, because you, savvy survivor, have snatched up your copy of The Maker's Guide to the Zombie Apocalypse before it's too late. This indispensable guide to survival after Z-day, written by hardware hacker and zombie anthropologist Simon Monk, will teach you how to generate your own electricity, salvage parts, craft essential electronics, and out-survive the undead.

Read and approved by the Guru's at Arduinotronics! For kids and adults alike.

http://amzn.to/1kQjpBX

Friday, November 6, 2015

Plotting Light Levels With Arduino 1.6.6

Long ago in a galaxy far away, we built a simple CdS Light Sensor (Sometimes called a LDR). Now with the real time plotting capability of Arduino 1.6.6, it's even more fun! The original project requires no changes, just pick Serial Plotter from the Tools menu.

CdS Photoresistor - http://amzn.to/1XUu39r
10k Resistor - http://amzn.to/20zKoTc


Code - http://arduinotronics.blogspot.com/2012/03/light-sensing-with-cds-ldr.html

Plotting Temperature - http://arduinotronics.blogspot.com/2015/11/plotting-temperature-with-arduino-166.html

Thursday, November 5, 2015

Plotting Temperature with Arduino 1.6.6

One of the new features of Arduino1.6.6 is the ability to plot data. In this example, I have taken a DHT-11 temperature sensor, and I'm sending the data to the serial plotter (found on the Tools menu). You can only have one axis of data, so I have a single serial.println in the code.

I'm using a DHT-11 module that comes on a breakout board with the resistor all ready added. You will need the DHT library found at https://github.com/adafruit/DHT-sensor-library. I plugged the module directly into the Arduino, so the data pin is connected to Arduino pin 6, - is connected to Arduino Pin 7, and +5 is connected to pin 5. You will see in the code where I'm sending digitalWrite commands to pins 5 and 7 sending a high and a low respectively, powering the module. Because I'm taking a reading every 2 seconds (it's a slow sensor) the serial plotting crawls very slowly across the screen.





#include "DHT.h"

#define DHTPIN 6     // what digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  pinMode(7, OUTPUT);  
  pinMode(5, OUTPUT);  
  digitalWrite(7, LOW);
  digitalWrite(5, HIGH);
  //Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    //Serial.println("Failed to read from DHT sensor!");
    return;
  }


  Serial.println(f);
 
}

Monday, November 2, 2015

DIY I2C LCD

The typical LCD used with an Arduino has 16 pins. only 6 of them have to use a I/O port on the Arduino. But what if you could get that down to two I/O pins, and still have those pins available for other devices? The I2C interface is on pins A4 and A5 of the Arduino. These have addresses, and are therefore shareable with other I2C devices that have different addresses.

Now, you can buy I2C LCD's, and you can even find I2C LCD's with different addresses, but they are typically two line LCD's, and the addresses are fixed. I'm going to show you how to build your own I2C interface, select one of 8 addresses, and even be able to add up to 8 inputs, using a MCP23017 16 port expander chip.

This is the same chip Adafruit uses on their I2C LCD Keypad Shield, and uses their library to talk to it. First let's look at the wiring. The connections between the Hitachi type parallel LCD (2 or 4 line) and the MCP23017 are shown below. Pins 15, 16, and 17 on the MCP23017 determine the I2C address. We have all 3 grounded, as this is the default address the Adafruit library uses. To add multiple displays, or pick another address, the library will have to be modified, so we will go with the default in the this example.

Notice the 220 Ohm resistor on the LCD k (cathode, gnd) connection. This is a MUST! Without it, you can blow the backlight pin on the MCP23017.


SDA (pin 13 on the MCP2307) connects to Arduino A4 and SCL (pin 12 on the MCP2307) connects to Arduino A5.

Download and install the Adafruit library, run the example "Hello  World", and this lcd interface is operational. We will address adding inputs to this chip, and editing the library address so that up to 8 MCP23017 chips can be used in a future article. Email me with questions.

Address hint:
Adafruit_MCP23017.h contains 
#define MCP23017_ADDRESS 0x20
Pin 17 = A2, Pin 16 = A1, and Pin 15 = A0
0 = ground, 1 = +5v
The address format is 0100A2A1A0, so since we have grounded all 3 lines, we are using binary 0100000, or 20 in hex. 0100111 would be 27 in hex.

Now figure out how to pass the address when initializing MCP23017.h ......

So, what is next? 16 channel relay boards with jumpers for address selectors? Maybe seven segment LED controllers?

Thursday, October 29, 2015

Happy 46th Birthday, Internet!

46 years ago today was the first remote transmission between two computers using TCP/IP. You have come a long way baby!

In the glow of a green monochrome screen deep in the bowels of the computer science department at UCLA, a young graduate student (Charley Kline) picked up his phone and called the computer lab at Stanford. He is preparing to send the first message over an Internet connection. The men on either end of the phone are Charley Kline and Bill Duvall.


Thank you Leonard Kleinrock, Charley Kline and Bill Duvall, it was the start of a beautiful friendship.

http://www.theinternetday.com/

https://en.wikipedia.org/wiki/Internet 

Wednesday, October 28, 2015

Add up to 128 Inputs, Outputs, or a mix to your Arduino or Raspberry Pi

The MCP23017 is a very useful chip. This I2C device can be wired for 8 unique addresses, and offers 16 inputs, 16 outputs, or 8 of each. A one stop chip for all needs.

You can talk directly to the chip, or use widely available libraries to insulate your experience from the nitty gritty.

Tronixstuff has a fantastic Arduino tutorial which covers a non library implementation. Very easy to understand, you may wish to avoid a library altogether.

Adafruit has a great Raspberry Pi tutorial to get you up to speed with a great increase in I/O capability, as well as allowing 5v I/O where the Raspberry Pi would only accept 3v inputs.

These can be used to convert a parallel lcd to I2C, and give button inputs as well. Adafruit makes a lcd button shield using this functionality. Build your own at http://arduinotronics.blogspot.com/2015/11/diy-i2c-lcd.html



Drive this 16 channel relay board - http://amzn.to/1OmvGLp


Sunday, October 25, 2015

Arduino Ethernet Cable Tester

As a network engineer, I never go anywhere without my Ethernet cable tester. That and a audible cable finder (fox & hound) are invaluable for finding and testing cable pairs. Today I'm showcasing a Arduino Ethernet cable tester. This tester is switchable for a straight through or crossover test. Test results are seen in a ordered line of LED's, as well as serial output that could be displayed on a LCD and written to a sd card.

A Arduino fox and hound will come  later, and then maybe a TDR distance to fault tester. We will see.

https://variecose.wordpress.com/2012/04/15/ethernet-lan-rj45-cable-tester-with-arduino/

Sunday, October 18, 2015

Temp / Voltage Without Sensors

The Arduino UNO (and 328 clones) has the ability to report the rail voltage and temperature of the chip. You don't need any additional wiring or sensors, just the Arduino itself. The temperature is not very accurate, and reports in Celcius, so we added a "adjustment" factor until it read room temperature, and converted to Fahrenheit. This is a fun "ok, I made it blink, now what" project.

Code


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

}   
void loop() 
{ 
  
 float volts = readVcc();
 Serial.print(volts/1000);
 Serial.println(" VDC");

 float temp = readTemp();
 temp = temp/1000;
 temp = temp + 25.7; //adjustment 
 temp = (temp * (9/5)) + 32; //conversion to fahrenheit
 Serial.print(temp);
 Serial.println(" F");
 delay(1000);
}   

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

long readTemp() {
  long result;
  // Read temperature sensor against 1.1V reference
  ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = (result - 125) * 1075;
  return result;
}

Friday, October 9, 2015

Arduino Flood Level Monitor

Since half of South Carolina is under water, and the levels keep increasing each day, I decided to modify our fuel and cistern fluid level project to a flood level monitor. We start with a eTape level sensor from Milone Technologies. You could connect this to a ethernet or wifi shield, or even a gsm shield to notify you of water levels.

Their website lists up to 32", but longer units are available.


Connect to an available analog input. Different length sensors have different resistance values which we will enable in the code.

So, with pin 1 to +5, pin 2 to Gnd, and pins 3 & 4 to Arduino analog in:

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

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

void loop() {
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue); //actual adc value
Serial.println(" ADC");

// Uncomment one of the lines below to match your sensor
//h = mapfloat(sensorValue, 215, 512, 8, 0) //8"
h = mapfloat(sensorValue, 170, 512, 12, 0); //12"
//h = mapfloat(sensorValue, 93, 512, 24, 0); //24"
//h = mapfloat(sensorValue, 75, 512, 32, 0); //32"

Serial.print(h, 2); // fluid height (inches)
Serial.println(" inches");
delay(5000); //how long between measurements
 }

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;
}

Monday, October 5, 2015

Simple Seven Segment LED Displays

Seven Segment LED's are a common method of displaying data. With 8 datapins, they are also complicated to wire up, as each LED needs a Arduino pin and a resistor. With a library, we can simplify the wiring, and the data display. Typical displays look like the following:

To reduce the number of Arduino connections if we want to use multiple digits, we will connect all the a segments together, all the b segments together, all the c segments, and so on. We will have a data line for each common so we can light up each segment with different data.

So here goes, connect a 330 ohm resistor to Arduino pin 2. then connect the other end of that resistor to segment a on each module. Follow the chart for the other pins.

Arduino pin 2 -> 330 ohm resistor -> all segment a's
Arduino pin 3 -> 330 ohm resistor -> all segment b's
Arduino pin 4 -> 330 ohm resistor -> all segment c's
Arduino pin 5 -> 330 ohm resistor -> all segment d's
Arduino pin 6 -> 330 ohm resistor -> all segment e's
Arduino pin 7 -> 330 ohm resistor -> all segment f's
Arduino pin 8 -> 330 ohm resistor -> all segment g's
Arduino pin 9 -> 330 ohm resistor -> all segment p's (decimal Point)

1st module com to Arduino pin 10
2nd module com to Arduino pin 11
etc.


You will need to download and install the library from https://github.com/DeanIsMe/SevSeg

Now the code:



#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object


void setup() {
  Serial.begin(9600);
  
  byte numDigits = 2;   // number of modules
  byte digitPins[] = {10,11}; // where your common pins are connected
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; //where your segments pins are connected

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); //Use COMMON_CATHODE if your modules use gnd on the common, or COMMON_ANODE if they take positive on the common.
  sevseg.setBrightness(90);
}

void loop() {
  
  int d1 = 12; // number you want displayed, usually from a sensor
  sevseg.setNumber(d1, 1); //display number, with optional decimal point (1 place)

  sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///

More info at http://playground.arduino.cc/Main/SevenSegmentLibrary

Thursday, October 1, 2015

Arduino WiFi Shield 101 - SSL for $50

Arduino WiFi Shield 101 is a powerful IoT shield with crypto-authentication that connects your Arduino or Genuino board to the internet wirelessly. Connecting it to a WiFi network is simple, no further configuration in addition to the SSID and the password are required. The WiFI library allows you to write sketches which connect to the internet using the shield.

The shield is based on the Atmel SmartConnect-WINC1500 module, compliant with the IEEE 802.11 b/g/n standard. The WINC1500 module provided is a network controller capable of both TCP and UDP protocols.  The main feature is an hardware encryption/decryption security protocol provided by the ATECC508A CryptoAuthentication chip that is an ultra secure method to provide key agreement for encryption/decryption, specifically designed for the IoT market.

The WiFi Shield 101 is the first Arduino product fully supporting SSL and all the communication between your board and a secured server. With the power of the Arduino Zero and the WiFi Shield 101 it is possible to make secure IoT applications simply and just using the Arduino Language.

Wednesday, September 30, 2015

Arduino Pocket Simon

Remember the old Pocket Simon game? A fun game of memorization, you press the button that corresponds with the light and sound,and each time you get it right, it adds another to the sequence. Here is our Arduino version. It consists of 4 LED's, 4 buttons, 4 resistors, a Piezo element (speaker), all on a protoshield. We also included a Adafruit LiPo shield for wireless / rechargeable operation.

Tutorial - https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-16-simon-says




Igaging Micrometers and Calipers

I've added the Igaging SpeedMic and OriginCal to our list of Arduino connected Mitutoyo measurement equipment (Micrometer, Caliper, Dial Indicator, and DRO Scale). I made some improvements to our Mitutoyo Instructable to facilitate connection to the Igaging equipment. The Igaging SPC enabled gear is Mitutoyo compatible, using the same 52 bit data stream. It even uses a Mitutoyo SPC cable for connection (not the same cable as our Mitiyoyo Coolant protected Micrometer).

Igaging SpeedMic and OriginCal

Cable for Arduino

Discuss (Yahoo)
Discuss (Facebook)

Schematic






Now comes with a new professionally made board!







Order interface Boards (one for each axis):


Options:

Code:



int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)

int dat = 2; //mic Data line goes to pin 2

int clk = 3; //mic Clock line goes to pin 3

int i = 0; int j = 0; int k = 0;

byte mydata[14];

float num;

void setup() {

Serial.begin(9600);

pinMode(req, OUTPUT);

pinMode(clk, INPUT_PULLUP);

pinMode(dat, INPUT_PULLUP);

digitalWrite(req,LOW); // set request at LOW

}

void loop() { // get data from mic

digitalWrite(req, HIGH); // generate set request

for(i = 0; i < 13; i++ ) {

k = 0;

for (j = 0; j < 4; j++) {

while( digitalRead(clk) == LOW) {// hold until clock is high

}

while( digitalRead(clk) == HIGH) {// hold until clock is low

}

bitWrite(k, j, (digitalRead(dat) & 0x1)); // read data bits, and reverse order )

}

// extract data

mydata[i] = k;

}

// sign = mydata[4];

// decimal = mydata[11];

// units = mydata[12];

// assemble measurement from bytes

char buf[7];

for(int lp=0;lp<6;lp++)

buf[lp]=mydata[lp+5]+'0';

buf[6]=0;

num=atol(buf); //assembled measurement, no decimal place added

Serial.println(num/1000, 3); //add decimal

}


Wednesday, September 16, 2015

Student Arrested for Building a Homemade Clock

Update - Ahmed Clock Hoax!

"When 14-year-old Ahmed Mohamed arrived at school on Monday morning with a digital clock he’d built from scratch, he was keen to show his teachers the fruit of his labors. Instead, he was pulled out of class and arrested for attempting to build a bomb."

Or so we were told. The truth is something else entirely.


Ahmed's father is a Muslim activist and put his son up to this. Ahmed took a off the shelf AC clock, removed the case, and stuck it in this pencil case. This was done deliberately to get the school authorities to jump, so he could get fame and fortune, and desensitize America of "see something suspicious, report it" ...


For real clock projects, See:

http://arduinotronics.blogspot.com/2014/03/the-arduino-lcd-clock.html (DS1307)
http://www.instructables.com/id/Arduino-Internet-Time-Client/ (NTP)
http://arduinotronics.blogspot.com/2014/03/gps-on-lcd.html (GPS)

Saturday, September 12, 2015

Infra Red Contactless Temperature Sensor

We have a Contactless Thermometer at work. Just aim the little red dot at what ever you want to read, and the temperature displays on the LCD screen. I must be related to Rube Goldberg somewhere in my family tree, because my philosophy is why buy when you can build, even though I have to buy some parts. It's more satisfying when you construct something yourself, and know how it works.

This could be used in a security system, to detect a IR heat source, like fire, or people / animal presence.

I ordered a $10 TMP006 IR Sensor from Adafruit. Found out later they have a TMP007 which is supposed to be a little better. Anyway, the TMP006 uses 4 wires to connect, +5v, Gnd, SCL (pin A5), and SDA (pin A4).

The tutorial on the Adafruit site misses a step, and adds a GITHUB error. To begin, you will need to download two libraries from GITHUB.

https://github.com/adafruit/Adafruit_Sensor and https://github.com/adafruit/Adafruit_TMP006

As usual, GITHUB adds a -master to the download, so you can't use the Arduino IDE import library menu option. You need to download both zip files, extract them,and then rename the folders by removing the -master. Then you need to copy both folders into your libraries folder. Now you can run the example sketch found on your Examples - Adafruit_TMP006 menu.

As the default is Celsius, and I prefer Fahrenheit, I have added a Celsius to Fahrenheit conversion line in two places.

Now I just have to add red LED "laser" pointer for aiming.







/*************************************************** 
  This is an example for the TMP006 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit TMP006 Breakout 
  ----> https://www.adafruit.com/products/1296

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TMP006.h"

// Connect VCC to +3V (its a quieter supply than the 5V supply on an Arduino
// Gnd -> Gnd
// SCL connects to the I2C clock pin. On newer boards this is labeled with SCL
// otherwise, on the Uno, this is A5 on the Mega it is 21 and on the Leonardo/Micro digital 3
// SDA connects to the I2C data pin. On newer boards this is labeled with SDA
// otherwise, on the Uno, this is A4 on the Mega it is 20 and on the Leonardo/Micro digital 2

Adafruit_TMP006 tmp006;
//Adafruit_TMP006 tmp006(0x41);  // start with a diferent i2c address!

void setup() { 
  Serial.begin(9600);
  Serial.println("Adafruit TMP006 example");

  // you can also use tmp006.begin(TMP006_CFG_1SAMPLE) or 2SAMPLE/4SAMPLE/8SAMPLE to have
  // lower precision, higher rate sampling. default is TMP006_CFG_16SAMPLE which takes
  // 4 seconds per reading (16 samples)
  if (! tmp006.begin()) {
    Serial.println("No sensor found");
    while (1);
  }

  Serial.println("Send s to enter sleep mode, or w to wake up.  Measurements are not updated while asleep!");
}

void loop() {
  // Check for sleep/wake command.
  while (Serial.available() > 0) {
    char c = Serial.read();
    if (c == 'w') {
      Serial.println("Waking up!");
      tmp006.wake();
    }
    else if (c == 's') {
      Serial.println("Going to sleep!");
      tmp006.sleep();
    }
  }

  // Grab temperature measurements and print them.
  float objt = tmp006.readObjTempC();
  objt = (objt * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  Serial.print("Object Temperature: "); Serial.print(objt); Serial.println("*F");
  float diet = tmp006.readDieTempC();
  diet = (diet * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*F");
   
  delay(4000); // 4 seconds per reading for 16 samples per reading
}

Saturday, September 5, 2015

Shift Registers - Unlimited Inputs With Only 3 Data Lines?

Last week we demonstrated how to use an output shift register (74HC595) to control 8 LED's with only 3 data lines. Since shift registers can be daisy chained, the number of LED's can be virtually unlimited. This week we wanted to show how to use an input shift register, the CD4021. 8 push button switches can be polled and used to input data or control devices, with only 3 data lines, And as with the output shift register, multiple chips can be daisy chained with no additional i/o lines needed. See the video below!

Wiring:

Pin 3 of the CD4021 goes to Arduino Pin 9
Pin 9 of the CD4021 goes to Arduino Pin 8
Pin 10 of the CD4021 goes to Arduino Pin 7

Pins 1, 4-6, & 13-5 of the CD4021 go to push button switches and Gnd. The other side of each switch goes to +5v.

Data sheet:
http://www.redrok.com/CMOS_CD4021BC_8-StageStaticShiftRegister_Fairchild.pdf

Code:
//**************************************************************//
//  Name    : shiftIn Example 1.1                              //
//  Author  : Carlyn Maw                                        //
//  Date    : 25 Jan, 2007                                      //
//  Version : 1.0                                               //
//  Notes   : Code for using a CD4021B Shift Register     //
//          :                                                   //
//****************************************************************

//define where your pins are
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

//Define variables to hold the data 
//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 72;  //01001000

void setup() {
  //start serial
  Serial.begin(9600);

  //define pin modes
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);

}

void loop() {

  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin,1);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(20);
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin,0);

  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first 
  switchVar1 = shiftIn(dataPin, clockPin);

  //Print out the results.
  //leading 0's at the top of the byte 
  //(7, 6, 5, etc) will be dropped before 
  //the first pin that has a high input
  //reading  
  Serial.println(switchVar1, BIN);

//white space
Serial.println("-------------------");
//delay so all these print satements can keep up. 
delay(500);

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
  for (i=7; i>=0; i--)
  {
    digitalWrite(myClockPin, 0);
    delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      //set the bit to 0 no matter what
      myDataIn = myDataIn | (1 << i);
    }
    else {
      //turn it off -- only necessary for debuging
     //print statement since myDataIn starts as 0
      pinState = 0;
    }

    //Debuging print statements
    //Serial.print(pinState);
    //Serial.print("     ");
    //Serial.println (dataIn, BIN);

    digitalWrite(myClockPin, 1);

  }
  //debuging print statements whitespace
  //Serial.println();
  //Serial.println(myDataIn, BIN);
  return myDataIn;
}



More Info:
https://www.arduino.cc/en/Tutorial/ShiftIn


Video (still processing, try back in an hour):


Thursday, August 27, 2015

Arduino Controlled Spectrum Analyzer for Ham Radio

As a Ham, of course I want to be able to examine frequencies, and the strength of the signal on that frequency. So imagine my excitement when I found the following Arduino solution!

The Specan is actually a very simple but robustly built receiver. it is, in essence, a double conversion superhet receiver with 112 Mhz and 12 Mhz Intermediate frequencies. The first mixer uses an Si570 as the local oscillator. The second oscillator is a crystal controlled at 100 MHz; built with a common microprocessor crystal of 20 MHz. Unlike most radio receivers, the second IF has two filters : a narrow band crystal filter with 1 Khz bandwidth and a wide band LC filter with 300 Khz bandwidth. The detector converts the tuned signals into a log scale. The detector output is a decibel measure of the incoming signal.
The Specan is controlled with an Arduino board. The Arduino controls the Si570, handles the front panel, talks to the computer over the USB port, reads the detector and switches the filters. In a very simple usage, the Specan can be tuned around like a regular radio. Instead of listening to the signals, you read their strength on the LCD display.
You can switch between wide and narrow filters : using the wide filters to hunt for signals and then use the narrow filter to locate and measure them with greater precision. This in itself is quite a useful function. It is possible to measure intercepts, gains and harmonics without using a computer.
Under a PC's control, the Specan can be made to step through any sequence of frequencies and plot them on the computer screen. The Specan understands a handful of text commands sent over the USB port of the Arduino.
The Specan also accomplishes a long standing personal goal - to make the homelab at VU2ESE entirely homebrew. The Specan can easily replace our aging TEK 465 scope and do even more.
This Specan can be built for far less than hundred dollars. Though it needs quite a few evenings of work. Construction is straightforward.You won't need any special tools. Modules of the Specan are used to align the rest of it! The Specan serves as its own set of test and alignment gear!

Monday, August 24, 2015

What good are Shift Registers?

Everyone eventually runs into the problem of running out of I/O pins on the Arduino, and the Raspberry Pi. A shift register is a chip that can give you 8 or more additional I/O ports, while only using 3 ports on the microcontroller. There are input and output shift registers, and today I'm showing an example of an output shift register,the 74HC595.

I've taken an Adafruit protoboard, and soldered in a 74HC595, 8 LED's, and 8 220 ohm resistors.

The tutorial I followed is found at https://www.arduino.cc/en/Tutorial/ShiftOut and documents the construction,and gives three example sketches.

Have fun!

Sunday, August 23, 2015

Using a 3x4 Keypad

Ever want to use a 3x4 Keypad? These keypads from Adafruit can be used for numeric data entry or for access control for a security system. Our example allows you to input a multiple digit entry with a "enter key" (#) and a "cancel key" (*). In our example, we will assemble a file name for submission to a sd card, but you can drop that off if you don't need that.

I plugged the keypad cable into a male extended length header, and plugged in directly into pins 2-8 on the arduino.



Download the library file at http://playground.arduino.cc/Code/Keypad and install into your library folder.

The following sketch will allow a key sequence of  at least 6 digits. You can enlarge the string if you need more digits. It displays each digit as entered in the serial monitor,and allows you to press * to cancel and start over if you make a mistake.

Thanks to Mike McRoberts and Mark Stanley for their help!

Also see our RFId and Fingerprint scanner tutorials!

#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the kpd

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

char entryStr[8]; 
int i=0;

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char key = keypad.getKey();
 
 if (key){ 
   if (key == '*'){
   memset(entryStr, 0, sizeof(entryStr));  
   i=0;
   key=0;
   Serial.println(""); 
   Serial.println("Canceled"); 
   
   } else if (key != '#'){
     entryStr[i]= key;
     i++;
     Serial.print(key);
     }
   else {
   Serial.println(""); 
   i=0;
   key=0;
   
   String fileName = entryStr;
   memset(entryStr, 0, sizeof(entryStr));
   fileName = fileName + ".mp3";
   Serial.println(fileName);
   }  


 }
}

Tuesday, August 18, 2015

Arduino / MySQL Connector Improvements

There have been some exciting improvements in the Arduino direct to MySQL communications. As a recap, this library allows a Arduino Ethernet or WiFi shield enabled Arduino to directly make SQL INSERT, DELETE, UPDATE, and SELECT queries, no intermediary code or web server. The big news is the documentation has been greatly improved. Get the Updated Library and Documentation at https://launchpad.net/mysql-arduino

Original Experiment

Example

Beginning Sensor Networks with Arduino and Raspberry Pi

Wednesday, August 12, 2015

My Favorite eReader - Kindle Paperwhite

Why am I talking about eReaders on a microcontroller site? Well, 5 years ago I had a house fire, and lost my 3000+ title library. I lived in an RV for a couple of years after, and did not have room for a lot of books. That's when I got my first Kindle. I've been through several generations of Kindles now, and my newest is the 300 PPI Paperwhite ($119)

This one is very different. The first thing you notice is the backlit screen, no more need for cases with built in lights, or external lighting. The next thing I noticed was the improved readability. A new font (bookery) that is much easier on the eyes. The 6" screen means it's easy to hold in one hand, and change pages by swiping my finger forward or back.

So, how does this tie in with Microcontrollers?

The complete collection is searchable, so all my Arduino, Raspberry Pi, Python, PHP, MySQL, etc. content is available at a few finger presses. Makes it easy to find what I need to make any new project.

There are other improvements, but these are the ones that stand out for me.

I did get a nice case for it. The Coredy Kickstand Case Cover ($14) protects my Kindle well, has a built in stand and stylus, and automatically turns on my Kindle when I open it. Highly recommended.

Solar charge your kindle / tablet / cell phone - http://amzn.to/1EmP95b




Monday, August 10, 2015

Measuring Wind Speed with an Arduino / Anemometer

A while back, we got a set of weather sensors from Sparkfun. It includes a Anemometer (speed), Wind Vane (direction), and a Rain Gauge.

I used a hand held wind speed device to calibrate my Arduino code.

I'm using pinMode(2, INPUT_PULLUP); so no pull up or pull down resistor is needed.

I used a prototype dual 6 pin phone jack from IC Breakout to connect the weather sensors to the Arduino.

For this sketch, I connected the two wires from the anemometer to pins 2 (interrupt 0) and ground.





Code:

 // diameter of anemometer
 float diameter = 2.75; //inches from center pin to middle of cup
 float mph;
 
 // read RPM
 int half_revolutions = 0;
 int rpm = 0;
 unsigned long lastmillis = 0;
 
 void setup(){
 Serial.begin(9600); 
 pinMode(2, INPUT_PULLUP); 
 attachInterrupt(0, rpm_fan, FALLING);
 }
 
 void loop(){
 if (millis() - lastmillis == 1000){ //Update every one second, this will be equal to reading frequency (Hz).
 detachInterrupt(0);//Disable interrupt when calculating
 rpm = half_revolutions * 30; // Convert frequency to RPM, note: 60 works for one interruption per full rotation. For two interrupts per full rotation use half_revolutions * 30.
 Serial.print("RPM =\t"); //print the word "RPM" and tab.
 Serial.print(rpm); // print the rpm value.
 Serial.print("\t Hz=\t"); //print the word "Hz".
 Serial.print(half_revolutions/2); //print revolutions per second or Hz. And print new line or enter. divide by 2 if 2 interrupts per revolution
 half_revolutions = 0; // Restart the RPM counter
 lastmillis = millis(); // Update lastmillis
 attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
 mph = diameter / 12 * 3.14 * rpm * 60 / 5280;
 mph = mph * 3.5; // calibration factor for anemometer accuracy, adjust as necessary
 Serial.print("\t MPH=\t"); //print the word "MPH".
 Serial.println(mph);
  }
 }
 // this code will be executed every time the interrupt 0 (pin2) gets low.
 void rpm_fan(){
  half_revolutions++;
 }

Related Posts Plugin for WordPress, Blogger...