InduinoX User Guide - Working with RTC DS1307

The DS1307 on the InduinoX is meant to let you explore I2C communication on the Arduino. We shall see how to work with the DS1307 by using a Library[Part 1] and then by using our code based on the Arduino Wire Library [Part 2]

I2C Communication
I2C is short form for 'Inter Integrated Circuit' I2C Communication is Communication Bus standard developed by Phillips for standardising Communication between Integrated Circuits. For Eg. In a circuit, there could be a number of ICs each offering specific functionality[RTC, Temperature Sensor, EEPROM, etc] and they can all communicate on a single I2C Bus and provide combined functionalities. Each device on the I2C Bus would have a unique address by which it can be addressed.

Here's an Interesting Introduction from NXP



I2C on Arduino
The I2C Bus uses 2 lines for Communication - SDA(Serial Data) & SCL (Serial Clock). On the InduinoX / Arduino, these are available on  SDA (Analog Input 4) & SCL (Analog Input 5). The I2C bus can be accessed using the 'Wire' Library of Arduino. First, lets try out a Library


How to use Libraries in Arduino - An Overview

To use any library you download, unzip the downloaded file and copy its contents to the libraries folder inside your arduino directory. You can check the library by opening the arduino ide and going to Sketch -> Import Library Option, if your library is in the proper location, it will show up here. Next if there is an example provided with the library (it will be inside a folder called example inside the base folder of the library) it will show up under the libraries name in the File->Examples Menu.


Using the RTC Library
There are a number of libraries available to work with the DS1307, the one from Ladyada is our library of choice for this example. You can download it from here  => RTC Library

Unzip the downloaded file and copy its contents to the libraries folder inside your arduino directory. Open the Arduino IDE [close and reopen it if you had it open!], Open File->Examples->RTClib->ds1307

Compile & Upload the program to your InduinoX and open the Serial monitor. Set the baud rate of the Serial monitor to '57600' and voila you see the time!

Now Lets Modify the code and Build a simple project - Timer Controlled LED. The LED on pin 13 will  switch ON at a specific time and switch OFF at another specific Time.

Here's a Video the project in action


Here's the code for the project
 /*  
 Switches ON and OFF a LED at a Preset Time of Hour based on RTC  
  */  
 #include <Wire.h>  
 #include "RTClib.h"  
 RTC_DS1307 RTC;  
 #define ON_HOUR 13// Hour of the On Time  
 #define ON_MIN 0// Minute of the On Time  
 #define OFF_HOUR 13// Hour of the Off Time  
 #define OFF_MIN 1// Minute of the Off Time  
 void setup()  
 {  
  Serial.begin(9600);  
  pinMode(13,OUTPUT); // Pin of the LED to be Switched ON / OFF  
  Wire.begin();  
  RTC.begin();  
  RTC.adjust(DateTime("DEC 31 2011","12:59:45")); // Setting the time to a fixed value. If you want to use the system time comment this line and use the option below  
  // following line sets the RTC to the date & time this sketch was compiled  
  // RTC.adjust(DateTime(__DATE__, __TIME__)); //uncomment this line to set time to system time  
 }  
 void loop()  
 {  
  DateTime now = RTC.now();// Getting the current Time and storing it into a DateTime object  
  if(now.hour()==ON_HOUR && now.minute()==ON_MIN)  
   digitalWrite(13,HIGH);  
  if(now.hour()==OFF_HOUR && now.minute()==OFF_MIN)  
   digitalWrite(13,LOW);  
  Serial.print(now.year(), DEC);  
  Serial.print('/');  
  Serial.print(now.month(), DEC);  
  Serial.print('/');  
  Serial.print(now.day(), DEC);  
  Serial.print(' ');  
  Serial.print(now.hour(), DEC);  
  Serial.print(':');  
  Serial.print(now.minute(), DEC);  
  Serial.print(':');  
  Serial.print(now.second(), DEC);  
  Serial.println();  
  delay(1000);  
 }  




InduinoX User Guide - Programming the Arduino Booloader

The InduinoX was designed with FTDI bitbang mode in mind and there are Pinouts from the FTDI for the same. We will here focus only on how to wire the InduinoX to achieve the BitBang Method described at the following link

http://www.geocities.jp/arduino_diecimila/bootloader/index_old_en.html#mega8_328

You can download Serjtag from the above link and use the commands from the same.

Check this video for the wiring

Things to know

Where to find Fuse Settings for arduino?
The fuse settings for different microcontrollers used in different configurations are available in the boards.txt file in your arduino install. You can find this file here
Your Arduino Directory > Hardware > arduino > boards.txt

Where to find the Bootloader for arduino?
Your Arduino Directory > Hardware > arduino >bootloaders
All the bootloaders have their own directories, so choose the One you want.

Keep us posted on how it goes, mail us on info|at|simplelabs|dot|co|dot|in





InduinoX User Guide - Programming the LDR

The LDR on the InduinoX is connected to Analog Pin 3 through a Voltage Divider configuration. The Voltage divider is in such a configuration that the voltage sensed by the Analog Pin3 would be inversely proportional to the light incident on the LDR. The voltage would vary in the range of 0-5 Volts

The Analog Input on Arduino is of 10-bit resolution. 10-bit resolution means that the Voltage range of 0-5 Volts is represented in 1024 steps from 0-1023. So you would be reading an input value in the range of 0-1023 where 1023 would correspond to 5 Volts(or very very less light!)

Arduino[the IDE!] comes with a serial library that can be used to transmit data serially to a computer. We shall make use of this library to transmit our LDR value to a Computer every 1 second.

Here's a Video of the Sample Program




Here's the Source Code.

 int val = 0; // A Variable to Store the Light Value from the LDR  
 void setup()  
 {  
  Serial.begin(9600);// Start a Serial Connection  
 }  
 void loop()  
 {  
  val = analogRead(3);// Reads a 10-bit value corresponding to the voltage applied on analog input pin 3.  
  Serial.print("Light Intensity is : ");// Prints the given string / value to the serial monitor  
  Serial.println(val);// prints the value of the variable val to the serial monitor and moves the cursor to the next line (the ln part of println does this  
  delay(1000);  
 }  


Now Lets build a Simple Lighting Level Controller using the LDR and the 3 on-board LEDS[11,12 & 13]. We will try and increase / decrease the number of lights that are ON based on changing Light Intensity Levels Measured by the LDR.

Make note of the values shown in the serial monitor for various levels of light intensity. Use these values as threshold and every time the LDR value increases above one of the thresholds, switch On a LED and everytime it decreases below the threshold, switch Off the LED.

Here's a Video of the project in Action



Here's the source code

 /*  
 ### LDR Based Lighting Level Controller ###  
  This is a simple program where 3 LEDS are switched ON / OFF one by one as the Light Intensity Sensed by the LDR Decreases / Increases  
  */  
 #define threshold1 650 // First Threshold Value of Darkness above which the first LED is switched ON  
 #define threshold2 750 // Second Threshold Value of Darkness above which the second LED is switched ON  
 #define threshold3 950 // Third Threshold Value of Darkness above which the third LED is switched ON  
 int val = 0; // A Variable to Store the Light Value from the LDR  
 void setup()  
 {  
  pinMode(11,OUTPUT); // LED 1   
  pinMode(12,OUTPUT); // LED 2  
  pinMode(13,OUTPUT); // LED 3  
  Serial.begin(9600);// Start a Serial Connection  
 }  
 void loop()  
 {  
  val = analogRead(3);// Reads a 10-bit value corresponding to the voltage applied on analog input pin 3.  
  Serial.print("Light Intensity is : ");// Prints the given string / value to the serial monitor  
  Serial.println(val);// prints the value of the variable val to the serial monitor and moves the cursor to the next line (the ln part of println does this  
  if(val > threshold1) // Checks & Turns the First LED ON / OFF based on Light Intensity  
   digitalWrite(11,HIGH);  
  else  
   digitalWrite(11,LOW);  
  if(val > threshold2) // Checks & Turns the Second LED ON / OFF based on Light Intensity  
   digitalWrite(12,HIGH);  
  else  
   digitalWrite(12,LOW);  
  if(val > threshold3) // Checks & Turns the Thirdf LED ON / OFF based on Light Intensity  
   digitalWrite(13,HIGH);  
  else  
   digitalWrite(13,LOW);  
 }  




InduinoX - An Overview

InduinoX

Induino is an electronics prototyping board, developed by Simple Labs, based on the open-source Arduino platform. Induino-X, the latest version of the Induino boards, contains a few sensors, components and devices on-board for easy prototyping. The hardware is programmed using a Wiring-based language (syntax + libraries), similar to C++ with some simplifications and modifications, and a Processing-based IDE. The term Induino is a simple combination of words, India + Arduino = Induino.. ;)








Click Here to buy Induino-X @ Simple Labs




Pin Mappings


Contents

Platform

Hardware

The Induino board consists of an 8-bit Atmel AVR micro-controller with complementary components to facilitate programming and incorporation into other circuits. An important aspect is the standard way that connectors are exposed, allowing the CPU board to be connected to any external devices and a variety of interchangeable add-on modules (known as shields). Also, the on-board components on Induino-X can be connected/disconnected to/from the i/o pins by using jumpers.

The Induino can be connected to a computer and programmed using a standard USB. A FTDI FT232 is used for USB to serial conversion. In-spite of an internal oscillator in the micro-controller, the boot-loader is configured such that it works with a 16MHz external clock oscillator.

Shields

Shields are the add-on circuits which are mounted on the Induino board, which gives extended functionality from the available functionality of the board.

               Induino Motor Shield

Software

 

Arduino IDE
The Arduino IDE is a cross-platform application written in Java, and is derived from the IDE for the Processing programming language and the Wiring project. It is designed to introduce programming to artists and other newcomers unfamiliar with software development. It includes a code editor with features such as syntax highlighting, brace matching, and automatic indentation, and is also capable of compiling and uploading programs to the board with a single click. There is typically no need to edit makefiles or run programs on the command line. The ArduinoIDE comes with a C/C++ library called "Wiring" (from the project of the same name), which makes many common input/output operations much easier. Arduino programs are written in C/C++, although users only need define two functions to make a runnable program:
  • setup() – a function run once at the start of a program that can initialize settings
  • loop() – a function called repeatedly until the board powers off
The IDE is available forWindows,MAC & Linux.

The Induino-X board description

Microcontrollers



ATmega 168
The Induino-X is compatible with the following micro-controllers...
Micro-controllers with their memories:

FLASH SRAM EEPROM
ATmega 328 32 KB 2 KB 1 KB
ATmega 168 16 KB 1 KB 512 B
ATmega 88 8 KB 512 B 256 B
2 KB of the flash memory is consumed by the bootloader. All the above controllers have 8-bit CPUs and 14 digital input/output pins, out of which 6 can be used as analog inputs and 6 as PWM outputs.


Power Supply

The Induino-X operates at 5V. It can be powered via the USB or with an external power supply. A 5V linear voltage regulator is employed on-board to support non-USB power supplies. The power source is selected automatically between the USB(IRF 9530) or the external supply(voltage regulator). External supply can be given via the screw terminals (7-12V DC recommended) In the screw terminals the one towards the edge of the board is negative and the other one is positive.

Hardware on-board

The following is a list of hardware on-board with their respective pin numbers on the Induino-X. Each lead of the Interface-able Hardware, which is connected to the micro-controller, is provided with a jumper to facilitate the isolation of micro-controller and the hardware when not in use.
1. RGB Tri-colour LED
Red    : Pin 5 (PWM)
Green : Pin 6 (PWM)
Blue   : Pin 3 (PWM)
2. Tactile switches
Switch 1 : Pin 7
Switch 2 : Pin 8
Switch 3 : Pin 9
3. LEDs (Colours of the LEDs may vary depending upon the version you have)
LED 1 (red)    : Pin 11 (PWM)
LED 2 (blue)   : Pin 12
LED 3 (white) : Pin 13
4. IR LED : Pin 14 (Analog 0)
5. TSOP   : Pin 15 (Analog 1)
6. LDR     : Pin 17 (Analog 3)
7. DS1307 (RTC)
SDA : Pin 18 (Analog 4)
SCL : Pin 19 (Analog 5)

LEDs



LED
There are three LEDs on the InduinoX (red, blue and white) connected to pins 11, 12 and 13 respectively. Every LED is connected to the micro-controller with a 470 ohm resistor in series, to limit the amount of current flowing through it.  All the LEDs have their jumpers right above them.

Tactile Switches


Tactile Switch
There are three switches on the InduinoX, connected to pins 7, 8 and 9. The tactile switches are connected in active-low mode[They give a HIGH logic when not being pressed and a LOW logic when pressed]. The Internal Pull-up resistors of the micro-controller should be enabled to use the switches. In the  To enable the internal pull-up resistors, first set a pin input mode and write a digital HIGH to that particular pin. 

RGB LED


RGB LED
The RGB LED on the Induino-X is of common-cathode type. It has one common cathode and 3 anodes - one each for blue , red and green connected to pins 3, 5 and 6 respectively on the Induino-X. the Pins 3,5 & 6 are PWM pins and can be controlled from the program by giving 8-bit values. The RGB led is equivalent to one pixel of an LED TV.. ;)

LDR

LDR
The LDR is a light dependent resistor. The resistance of the LDR is inversely proportional to the intensity of light incident on it. The LDR on the InduinoX board is to help you learn to work with Analog Inputs from Sensors. the LDR is connected to the lower half of a potential divider configuration with a 10K ohm resistor, the output of the potential divider is connected on analog pin 3. The jumper for the LDR is on the right side of the LDR.

TSOP


TSOP
The TSOP SM0038 is an IR receiver on the InduinoX. The TSOP will help you to interface your TV remote with the InduinoX and in the Process learn the basics of Wireless Communication. The TSOP is connected to pin digital 15(Analog 1). The Jumper for the TSOP is right above it.

IR LED

 


IR LED
The InduinoX has an IR LED connected to pin 14 (Analog 0). Using this, you can simulate remote control signals for various devices. [You can build universal remotes using the InduinoX!] You can also use this along with the TSOP and build a simple low-cost wireless communication system. An NPN transistor(IN2222A) switches the IR LED through a 10 ohm resistor. The jumper of the IR LED is right below it.

DS1307 (RTC)



DS1307
The DS1307 is a Real Time Clock IC [An IC dedicated to the task of keeping track of Time]. This IC helps learn and work with I2C Communication using the Arduino. The IC is connected to the I2C pins of the Arduino (SDA - Analog 4 & SCL - Analog 5). You can program this IC using eith Wire.H or using the DS1307 Library.

Getting started

We have a separate post on this. Check it here => InduinoX - Getting Started Guide

Overview of the Blink Program...

We hope you are reading this after having gone through the InduinoX - Getting Started Guide In the program we use pin 13 to blink LED. As blinking an LED is an output operation pin 13 is set as an output pin. The LED is then turned ON and OFF at an interval of 1000 milliseconds (or 1 second)
//A program to Blink the LED connected to the pin number 13
void setup()
{
pinMode(13,OUTPUT);
//Now we are initializing the pin13 as output pin.
}
// a function which executes again and again
void loop()
{
digitalWrite(13,HIGH);
// now we are turning the LED ON
delay(1000);
//delay in Milli seconds 1000 will produce a delay of one second
digitalWrite(13,LOW);
//Turning the LED OFF
delay(1000);
//Delay again
}
Note: Arduino is case sensitive so the upper case is not equal to the lower case. And the "//" provided here are called the comments that means the compiler ignores the text after it encounters "//".
Click Here to Download InduinoX Sample Codes & Required Libraries[Right Click & use Save As]

Simple Labs' InduinoX and Arduino Uno Comparison


What is InduinoX?


InduinoX is an indian made Arduino clone board. InduinoX is a clone of the popluar Arduino Duemilanove, the predecessor of the current Arduino UNO. It is functionally and mechanically very similar to the Arduino Duemilanove and will work with all types of Shields made for the Arduino Uno / Duemilanove.

About 3 years back, we designed our first Arduino Clone the Induino. We named it Induino to add to our pride of having made it in India. The Induino was an affordable arduino clone that was priced at 800/- [The cheapest to be sold on some scale at that time!] however the Induino evolved over a period of time to include many on-board peripherals increasing the experimentation capabilities and became the InduinoX.

Comparison Table
Parameter                                     InduinoX Arduino UNO

Microcontroller

Atmega328

Atmega328
USB Serial ConverterFT232RLAtmega8u2
ICSP Programming HeadersYesYes

Arduino As a Programmer
YesYes

On-Board Rx Tx LEDs  
YesYes

On-Board IO LEDs  
3 LEDS
[PIN 11,12 & 13]
1 LED
[PIN 13]

On-Board Push Buttons
3
[PIN 7,8 & 9]
None

On-Board Resettable Fuse
YesYes

On-Board RTC
YesNo

On-Board TSOP 
(Remote Cotnrol Receiver)
Yes
[PIN 15 a.k.a. A1]
No

On-Board RGB LED
Yes
[PWM 3,5&6]
No

On-Board Sensor – LDR
Yes
[Analog IN 3]
No

On-Board IR LED
(Generates Remote Control Signals)
Yes
[PIN 14 a.k.a A0]
No

Shield Compatible
YesYes

USB Connector Type
USB BUSB B

Programming IDE
ArduinoArduino

Works on USB Power
YesYes

External Power Supply Connector
2 Pin Screw Terminal
[Easy for Battery]
DC Adaptor Jack

Bit Bang Programming Headers
YesNo


Here are both the boards side by side. InduinoX on the Left Side and UNO on the right side.


InduinoX User Guide - Programming the RGB LED

In this edition we will see how to use the RGB LED on the InduinoX Board.  The RGB LED was included as part of the InduinoX board for the user to be able to experiment with analog outputs / PWM.

The InduinoX board has 6 PWM Pins [Pins 3,5,6,9,10,11] that can generate a PWM signal of 8-bit resolution.[8-bits can represent a maximum value of 255, and a 8-bit resolution here means that 5 volts is represented by 255 divisions. So if you want to generate 1 volt, you would use the value 51]

The RGB LED is connected to PWM Pins 3,5 & 6. [Blue to 3, Red to 5 & Green to 6] The RGB LED is a common Cathode Type LED
.
The Intensity of each of the Color Spectrum [Red, Green & Blue] can be varied by controlling the voltage applied on the individual pins. The PWM pins in addition to generating digital HIGH / LOW signals can generate analog voltages between 0 & 5. The analogWrite function will help us use these pins.

The analogWrite function will take a 8-bit numerical value as a parameter [called duty cycle] and produce an output voltage corresponding to this value. It will set the pin to generate a steady square wave of the specified duty cycle at roughly 490Hz frequency.

So Lets try to experiment with the RGB LED. Try the following code
 void setup()  
 {  
 }  
 void loop()  
 {  
  analogWrite(3,153);// Setting the voltage for Blue to around 3 Volts  
  analogWrite(5,51);// Setting the voltage for Red to around 1 Volt  
  analogWrite(6,51);// Setting the voltage for Green to around 1 Volt  
 }  

Now you will see that the RGB LED glows with more of Blue color. Try to change the Values for the other Colors & experiment.

Here's a small project implementing the LEDs, Buttons & the RGB LED.

2 Buttons - 7 & 9 are used to increment and decrement the brightness of a chosen color in the RGB LED. A color can be chosen by using the Button on the 8th pin. The 3 regular LEDs are used to display the chosen color. When you choose Blue, the Blue LED will glow. In addition to this, pressing the Buttons 7 & 9 at the same time will cause the RGB LED to be reset to its initial state - all colors become zero. Note that the increment and decrement happen in a cyclic fashion ( 255 ++ will become 0 and 0 -- will become 255) Enjoy!

#### Video Errata - The RGB LED is a Common Cathode Type & Not Common Anode as mentioned in the Video####





Here's the Source Code

 /*  
 ***********************************************************************************************************************  
 *******************************### RGB LED COLOR CONTROL USING BUTTONS ###*********************************************  
 */  
 int RGB[3]; // Variable to store individual Color Value of Different Colors of the RGB LED  
 int arr_ind=0; // Variable for Navigating through the Above Array - An Aray Index Variable  
 void setup()  
 {  
  pinMode(7,INPUT); // The Increment Button  
  pinMode(8,INPUT); // The Color Select Button  
  pinMode(9,INPUT); // The Decrement Button  
  digitalWrite(7,HIGH); // Enabling the Internal Pull-Up Resistor for the Button  
  digitalWrite(8,HIGH);// Enabling the Internal Pull-Up Resistor for the Button  
  digitalWrite(9,HIGH);// Enabling the Internal Pull-Up Resistor for the Button  
  pinMode(11,OUTPUT);//LED for Current Selected Color Indication for RED Color - Lights up When the User Selects RED Color  
  pinMode(12,OUTPUT);//LED for Current Selected Color Indication for BLUE Color - Lights up When the User Selects BLUE Color  
  pinMode(13,OUTPUT);//LED for Current Selected Color Indication for GREEN Color - Lights up When the User Selects GREEN Color  
  RGB[0] = 0; // RGB[0] will store the value for the BLUE Color  
  RGB[1] = 0; // RGB[1] will store the value for the RED Color  
  RGB[2] = 0; // RGB[2] will store the value for the GREEN Color  
  applyColor(); // Calling a Function that will handle the AnalogWrite functions for the RGB LED  
 }  
 void loop()  
 {  
  if(digitalRead(7)==0) // Checking if the Increment button is Being Pressed, If True, the value of the currently selected color's value is incremented  
  {  
   if(RGB[arr_ind]<255) // Checks if the currently selected color value is lesser than 255 before incrementing. So when it reaches 255, the value is reset to 0.  
    RGB[arr_ind]++;  
   else  
    RGB[arr_ind]=0;  
   delay(100);  
  }  
  if(digitalRead(9)==0)// Checking if the Decrement button is Being Pressed, If True, the value of the currently selected color's value is decremented  
  {  
   if(RGB[arr_ind]>0)// Checks if the currently selected color value is greater than 0 before decrementing. So when it reaches 0, the value is reset to 255.  
    RGB[arr_ind]--;  
   else  
    RGB[arr_ind]=255;  
   delay(100);  
  }  
  if(digitalRead(8)==0)// Checking if the color button is Being Pressed, If True, the value of the array index is incremented to the next value  
  {  
   if(arr_ind<2)  
    arr_ind++;  
   else  
    arr_ind=0;  
   while(digitalRead(8)==0); // This while is used to debounce the button press or in other words, wait for the user to release the button  
   delay(50);  
  }  
  if((digitalRead(7)==0)&&(digitalRead(9)==0))// Checking if both the increment & decrement buttons are being pressed at the same time. If so, all color values are reset to zero  
  {  
   RGB[0] = 0; // RGB[0] will store the value for the BLUE Color  
   RGB[1] = 0; // RGB[1] will store the value for the RED Color  
   RGB[2] = 0; // RGB[2] will store the value for the GREEN Color  
   digitalWrite(11,HIGH);digitalWrite(12,HIGH);digitalWrite(13,HIGH);// This to indicate a reset in progress. All three LEDS GLOW for 200 milliseconds and go Off  
   delay(200);  
   digitalWrite(11,LOW);digitalWrite(12,LOW);digitalWrite(13,LOW);  
  }  
  switch(arr_ind) // The switch is used to indicate the current color selection through the corresponding LED based on the current value of the Array Index  
  {  
   case 0: digitalWrite(11,LOW);digitalWrite(12,HIGH);digitalWrite(13,LOW);break;  
   case 1: digitalWrite(11,HIGH);digitalWrite(12,LOW);digitalWrite(13,LOW);break;  
   case 2: digitalWrite(11,LOW);digitalWrite(12,LOW);digitalWrite(13,HIGH);break;  
  }  
  applyColor();// Calling a Function that will handle the AnalogWrite functions for the RGB LED  
 }  
 // The function applyColor() will apply the RGB array variable's current value to the Analog Pins 3,5 & 6 which control the RGB LED  
 void applyColor()  
 {  
  analogWrite(3,RGB[0]);  
  analogWrite(5,RGB[1]);  
  analogWrite(6,RGB[2]);  
 }