Saturday, March 30, 2013

Altera Cyclone IV EP4CE6 Testing

As I showed in my previous post,I’m going to test my CoreEP4CE6 board. It is based on Altera Cyclone IV FPGA (EP4CE6E22C8N) . I got my Altera USB Blaster (bought from here) today and tested the FPGA .

I connected the power cable to the FPGA board and connected the JTAG cable from USB Blaster. The both devices were powered by USB. I installed Altera Quartus II Web Edition which is the default IDE for Altera FPGAs. You can download the free web edition from here

I thought to check the board by powering up a LED. I just wanted to connect the LED on PIN11 to Vcc to do this. You can follow the detailed steps on this from here

The schematic diagram:

cct.

The pin assignment (according to the schematic of the board):

pin

The hardware test (you can see the LED in bottom left is ON):

DSCF5880

Saturday, March 23, 2013

Desoldering Surface Mount Devices (SMD)–The hard way

In my previous post, I used some scavenged parts from an old mother board. These old circuit boards are gold mines as they got many reusable components. They may also have very rare vintage chips too. But desoldering SMD is a quite complex task without proper instrument such as hot air gun,reflow oven or a soldering pot. But you can easily desolder SMD components with small pin count. I recommend upto  8 pin or so using this way, If the pins are so close you may try for higher pin count chips too.

You need a normal soldering iron,soldering wire,some tool to push chips and flux would also be helpful in some cases.

My Flux pen (Kester 951):

DSCF5865

My tool(small flat screw driver) to remove chips:

DSCF5867

First you have to apply some flux (if you have) and add some solder to the pins of the chip just as normal soldering.Make two solder blob in both sides like in this picture(only for one side is shown).

DSCF5851

Then simply heat both sides switching between two sides. Don’t take too much time and it will fry your chip. Simply push the chip from the back side using the tool when the solder is melted on pins and chip becomes loose. It will be better to use tweezers to pull up the chip if you have them. I used that flat screw driver as I don’t have a good tweezer. Finally you have to do is cleaning up the board and the desoldered chip. I haven’t used any special thing for it but I think desoldering wick will be helpful.

I have desoldered  this LM431 chip using this technique. You can see the PCB pads where it was soldered in the below picture too.

DSCF5856_792x600

DSCF5863_800x365

Thursday, March 21, 2013

Building Real Time Clock (RTC) module based on DS1307 for Arduino

In this post I’m going to build a Real Time Clock (RTC) module based on popular DS1307 RTC chip for using with Arduino or any other micro-controller platform. DS1307 uses I2C protocol to communicate with the microcontroller.

RTC Module:

This is the circuit we have to build and it has few readily available components. The 3V coil cell battery is used to give backup power to the RTC.  Make sure to solder a 4 pin connector for Vcc,GND,SCL,SDA connections. 1kOhm pull up resistors are used for the I2C bus in the circuit.

DSCF5835_640x480

I got the 32.768kHz Crystal and 3V CR2032 coil cell battery holder from an old computer mother board. I think they are available at any electronic component shop.

DSCF5814_640x480DSCF5823_640x480

After collecting parts I built the circuit on a piece of veroboard. Total cost was around Rs:70 ($0.55). I used 4pin connector for above mentioned connections. If you don’t have a coin cell battery, make sure to short the two battery pins as on the picture,but you won’t have the backup power in case of a power failure.

DSCF5829_640x480

Arduino Board:

I’m using my Techduino Pro board which I build on an earlier post along with the my modified CP2102 USB to UART board. Please note that my Arduino is working at 3.3V.

Connections:

I connected the two boards as follows, You can get Arduino –> ATMEGA328 pinout from here.Even though DS1307 datasheet tells that the operating voltage of the chip is 5V, It worked well even at the 3.3V as I used here. Please be aware of that to avoid unnecessary outcomes.

 

RTC Module Arduino
Vcc +3.3V or +5V (As you need)
GND GND
SDA SDA (Analog Pin 4)
SCL SCL (Analog Pin 5)

DSCF5834_640x480

Coding:

You can just write a code using Wire library. Make sure that DS1307 sends 7 BCD digits containing date & time. I was lazy to reinvent the wheel and opted to use the DS1307 RTC library for the Arduino. Get it from here and extract to the libraries folder in your Arduino IDE folder (Rename it to RTC after extracting).I modified the example file to show how to use it.

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(57600); // UART initialize
    Wire.begin();
    RTC.begin();
   // RTC.adjust(DateTime("MAY 21 2013","20:40:45")); //you can use this to set initial date/time as you wish
 
}

void loop () {
    DateTime now = RTC.now();
    
// Sending date & time to UART every second    
    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);
}

scrn

Tuesday, March 19, 2013

Connecting Arduino Pro (3.3V/8Mhz) to TV

In this post I’m going to connect my home made  Arduino Pro clone to the television using composite input on the TV. I found a good library called arduino-tvout, but had to modify the hardware a bit to run with 3.3V board as the hardware connections shown in the library site is for 5V systems. Let’ s check the process part by part.

TV connector module:


As the arduino-tvout library wiki has connections for a 5V system,I had to modify it as follows. If you have an idea about composite signals you can understand the modification.

The original connection is like this (Source),

The internal termination impedance of a composite input of a TV is 75Ω. So at 5V,considering only sync resistor, Vid = (75)/(1000+75) * 5V = 0.35V . Actually a standard composite sync level is 0.3V and I used a 680Ω resistor instead of 1kΩ resistor. So, Vid=(75)/(680+75) * 3.3V = 0.33V. Same for the video resistor. As Vid= (75)/(470+75) * 5V = 0.69V, I used a 270Ω resistor to get Vid= (75)/(270+75) * 3.3V = 0.72V. So my TV module’s circuit is as follows and I built this on a veroboard (Cost Rs:25/ $0.2)

image

Arduino Board:


I’m using my Techduino Pro board which I build on an earlier post along with the my modified CP2102 USB to UART board. Please note that my Arduino is working at 3.3V.

Connections:


I connected the two boards as follows, You can get Arduino –> ATMEGA328 pinout from here.

TV Module Arduino
Sync Pin 9 (Pin15/PB1 on chip)
Video Pin 7 (Pin13/PD7 on chip)
GND GND

DSCF5803_640x480

DSCF5800_640x480

Code:

First of all you have to download the arduino-tvout library from here and extract it into your Arduino IDE’s library folder. I used TVOutBeta1 version for testing. Then I tested this simple code (later I tried a simple counter too). You can get full documentation from the library’s documentation. I tested various resolutions but most of them had synchronization problems(may be due to 8Mhz clock,this library is designed for 16MHz clock systems). I found out that 48*36 resolution in PAL system worked well for me.

#include <TVout.h>
#include <fontALL.h>

TVout TV;

void setup() {
  TV.begin(PAL,48,36);
  TV.clear_screen();
  TV.select_font(font4x6);
  TV.println(0,0,"Hello");
  TV.println(4,12,"incrediblediy.com");
  TV.delay(5000);
}

void loop() {

  }

Testing:

I have tested the circuit on 2 TVs and it worked on the both for 48*36 resolution in PAL system. As I mentioned for other resolutions I got vertical synchronization problems.(May be able to fixing by playing with library headers, I didn’t check yet)

Testing on a CRT TV,

DSCF5791_640x480

Testing on a LED 3DTV,

DSCF5810_640x480

Thursday, March 14, 2013

Video Blog Episode #1 : Unboxing Altera Cyclone IV Development board & module based implementation


In this Incredible DIY video blog episode, I'm unboxing my new FPGA development board which I got from Waveshare Electronics called CoreEP4CE6. It is based on Altera Cyclone IV FPGA (EP4CE6E22C8N) . It is a minimalistic barebone system which only got FPGA, serial configuration device to store code and some LEDs. The all pins are taken out for standard 2.54mm connector header for development. I'm also talking about what are needed for the module based implementation of designs and I'm showing some modules I have.


Tuesday, March 12, 2013

Testing a Digital Compass module based on MMC2120MG magnetic sensor

Here I’m going to show you how to use a digital compass for you robot project. This can be easily used to obtain the heading of the robot and adjust the path of it. I got this module and tested it before two years ago. Here,I’m using Sure Electronics DC-SS504 module which includes a MMC2120MG magnetic sensor. Actually this module has the magnetic sensor and a PIC16F690 on-board. This PIC is used here to drive the magnetic sensor and convert it’s I2C interface to UART interface. You can get a digital compass with I2C and drive it using your own uC too. Actually I got this for UART interface and this was used to build a robot.

Unboxing:

The compass arrived with a nice little plastic casing. I had the digital compass module and some 2.54mm connectors.

282657_168290536573363_62333_n

Calibration:

As any other digital compass (including digital compasses on mobile phones), it had to be calibrated for the place where it’s going to use. The typical 8 direction motion was required for the calibration after issuing the calibration command. You can also set the magnetic declination using the appropriate command. You can find those on the datasheet. These calibrations are easy as we use the UART interface provided by on-board uC. I also found out that if we issue the calibration command and don’t move the compass, you can measure the angle reference to that starting point. Cool!!! isn’t it ?

Testing:

I tested the compass by connecting it to the Pickit2 UART tool. Pickit2 got a cool logic analyser feature and UART tool built it. These feature are really helpful when doing projects. You can build your own Pickit2 lite from my previous post.

266821_168305566571860_7908553_o

278297_168305513238532_4680939_o

Monday, March 11, 2013

Building a SD Card Temperature logger (ATMEGA328 + SDCARD + LM35)

As we built an Arduino powered web server in previous post, let’s build a temperature logger using a SD card this time. I build this because I wanted to see how we can use a SD Card for our projects. The beauty of Arduino libraries are they have a FAT16/FAT32 library. So, we can use a large SD Card without any problem provided that the AVR you use has enough RAM & programming memory. Here I’m using ATMEGA328 which has 2kB RAM and 32kB program memory.

SD Card module:

Here I’m using a SD Card holding module I got a year back from ebay for $1.6. You can even use a microsd card with a microSD to SD card adaptor. Just you have to solder some wires to the adaptor.SD Card pin out is available at pinout.ru site. SD Cards are also using SPI protocol for the communication.

Arduino Board:

I’m using my Techduino Pro board which I build on an earlier post along with the my modified CP2102 USB to UART board. Please note that my Arduino is working at 3.3V.

LM35 Temperature Sensor:

This is a typical analog temperature and you can find the datasheet from here. It has 10mV/Celsius linear scale factor and works at minimum of 4V for full range. According to the datasheet it can be used at less voltages but the measuring temperature range will be very low (check the Minimum Supply Voltage vs. Temperature curve).

Connections:

I connected the two boards as follows to establish a SPI link between two,

SD Card Module Arduino Pro
3.3V 3.3V
GND GND
MOSI Pin 11
MISO Pin 12
SCK Pin 13
CS Pin 10



DSCF5755
DSCF5751

I connected LM35 to the Arduino to get temperature. I connected LM35’s Vout pin to Arduino’s analog input 1 (A0). I also gave power supply by connecting +5V and GND to LM35. I powered up this using the USB power itself and so common ground maintained between Arduino and LM35.

DSCF5752

Code:

I’m here going to use ATMEGA328’s built in 10bit ADC with the Vref=3.3V(Vcc of the uC). You can learn accessing ADC on Arduino by reading this article. The SD card is accessed using the built in SD card library on Arduino. You can learn more about that using this link. As I previously mentioned, LM35 has has 10mV/Celsius linear scale factor. So we have to do a little calculation to obtain the temperature. Here I’m using the full scale ADC method to get the ADC voltage.



So we get total factor as 0.32258 and we have to multiply is by ADC reading to get the temperature value.Here is the final code for the whole thing,

#include <SPI.h>
#include <SD.h>
File myFile;
int x=0;
int tempValue;
void setup()
{
pinMode(10, OUTPUT);
SD.begin(10);
}
void loop()
{
  tempValue=analogRead(A0);
myFile = SD.open("temp.txt", FILE_WRITE);
if (myFile) {
      myFile.print("Temperature ");
      myFile.print(x);
      myFile.print(":");
      myFile.println((long)tempValue*0.32258);
}
    myFile.close();
    x++;
    delay(1000);
  } 

Testing:

I hooked up everything and uploaded the compiled code. The SD card was inserted too. Then I checked the results by reading the SD Card using computer after some time. The results were impressive.

TempLog

Saturday, March 9, 2013

Arduino based Webserver (ATMEGA328 + ENC28j60)

Updated on 09-01-2017 to correct issue with MAC address: (Identifed by Julien as per in the comment section)

Replaced : static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01}; with new value.

As I built a Arduino Pro clone based development board running with 3.3V, I thought to give it a try with my Ethernet module for testing. This is an example for 3.3V LVTTL system. If you use this ENC28J60 on a 5V system,you may have to use logic level convertors.
Ethernet module:
Based on Microchip’s ENC28J60 chip. I’m using a board made by Sure electronics (really good manufacture) called MB-CM14111. I got this 2 years back from ebay for $10. You can now find cheap boards on ebay and do an ebay search as “enc28j60”. ENC28J60 is a SPI device and needed to be connected to ATMEGA328’s SPI module.
Arduino Board:
I’m using my Techduino Pro board which I build on an earlier post along with the my modified CP2102 USB to UART board.
Connections:
I connected the two boards as follows to establish a SPI link between two;
Ethernet Module Techduino
3.3V 3.3V
GND GND
DI Pin 11
DO Pin 12
CLK Pin 13
CS Pin 10
DSCF5688_640x480
DSCF5693_480x640
DSCF5697_640x480
Software Library:
I used EtherCard Arduino library from JCW’s GIT repository. See here for downloads and installation instructions. You just have to download the zip file and extract it to your Arduino’s library folder(in my case arduino-1.0.3\libraries) and rename it to EtherCard.
Code:
I used a very basic code just to serve a static page from the webserver. You can find many more detailed information on using this library from LUCA’s ENC28J60 tutorials.This is the code I used. You just have to copy this code to Arduino IDE and compile it and upload.Modify myip[] ass you wish.This is the device’s IP address.The library also supports DHCP but here I’m using a static IP for the simplicity.I also omitted the standard HTTP requests/replies on this code for the simplicity.
#include <EtherCard.h>
static byte mymac[] = {0xDE,0xDD,0xDD,0x00,0x00,0x01};
static byte myip[] = {192,168,1,10};
byte Ethernet::buffer[700];
 
void setup () {
  ether.begin(sizeof Ethernet::buffer, mymac,10);
  ether.staticSetup(myip);
}
 
void loop() {
 
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
 
  if(pos) {   
    
    BufferFiller bfill = ether.tcpOffset();
    bfill.emit_p(PSTR("<h1>hello</h1>"));
    ether.httpServerReply(bfill.position());
  }
}
Testing:
I connected the Ethernet module to my gigabit Ethernet card using a straight cable (my card auto detects straight or crossover connection).I set my PC’s address to be 192.168.1.1 manually. Then I tried a ping test to the Ethernet module by  “ping 192.168.1.10” on command prompt. It was a success in first round.
Ping
Then I opened my browser and visited http://192.168.1.10 , TaDa!!!! The web page is working Open-mouthed smile
Web
I did a simple packet tracking using WireShark too. Just to see what’s happening there. You can see how  the ping requests and replies going through the network.













Wireshark 



Building an Arduino Pro / Arduino UNO (with TechDuino)

I wanted to build a 3.3V microcontroller development system for a long time. This is because most newer sensors and other  devices are working on LVTTL voltage levels. Now,5V systems are becoming obsolete and even 1.8V systems can be seen. Arduino is an open source microcontroller development system which uses Atmel ATMEGA series microcontrollers. As I found out they can operate at 3.3V at 8Mhz. As AVRs(let’s call them as AVR) are running 1MIPS per 1Mhz,you can get 8MIPS even at 3.3V. Quite impressive isn’t it ?
There is a board called Arduino Pro which is designed to run at 3.3V specially. But the majority uses Arduino UNO which seems to be the most popular Arduino board in present day. When I look for DIY Arduino boards,I found out about the TechDuino which is a custom built Arduino UNO clone with through hole components.
You can buy a prebuilt Techduino or as parts( PCB,uC…etc) separately from the TechShop. They are delivering the items by post and they are nicely packed. The service is awesome in all ways.
As I needed to build an Arduino Pro (as on a Arduino UNO layout,a hybrid of course), I ordered some PCBs for TechDuino and a Arduino Pro(3.3V/8Mhz) bootloader preloaded ATMEGA328 from Techshop. For a PCB & an uC IC is costs Rs700 (US$5.5) and it’s really cheap. Then I had to find a 3.3V voltage regulator and I picked AMS1117-3.3 voltage regulator (You can use any other 3.3 regulator like 7833 or even a LM317 with a proper circuit).I had a bunch of them got from ebay sometime ago.I also got some resisters,capacitors,LEDs,connectors from my stores.
This is the TechDuino PCB I got.
DSCF5714_640x480
Then I soldered the components. You can refer the parts list & buidling notes from here.  I had to do following changes to make it a 3.3V system and suite my other needs.Please compare the changes with the coloured arrows in the picture.
  • Replaced the 7805 with my AMS1117-3.3 (Please note it has different pin out and a surface mount IC,So you have to compare with 7805 pinout and solder using wires or so) [RED]
  • Opted out the DC power jack and soldered a connector to it. [PURPLE]
  • Used a 8Mhz Crystal not a 16Mhz as for the 5V system. [BLUE]
  • Used 100 Ohm resistors in series with LEDs [GREEN]
  • Didn’t have a 4pin push button switch,just used a jumper to make a ground connection as needed [ORANGE]
  • Shorted 3.3V & 5V pins in the board,so that both 3.3V & 5V lines will also have 3.3V
Arduino
After this you can use a CP2102 USB to UART board to connect this to the computer (You may purchase it too at TechShop when you get the PCB…etc).If you have any other please refer my previous post.. Please only connect RX,TX,GND,Reset pins to the programming header. Then connect 5V pin to the external power connector Red wire(shown in purple arrow) if you power the Arduino with USB or else you can power it with external source using the external power connector.
Then download the Arduino IDE from arduino.cc site. Here I’m using Arduino IDE 1.0.3 version. You have to select Tools->Board as Arduino Pro 3.3V/8Mhz.You also have to select the serial port which the Arduino is connected to. The prebootloaded ATMEGA has a pre programed program to blink the LED at Pin13.So,the LED will start to blink when you supply the power.Use an example like led blink on Arduino IDE to test that the everything is working correctly.
ArduinoScrn
Happy Arduinoing!!!! Open-mouthed smile I will show how to build a Arduino powered webserver in my next post Winking smile

Modifying a cheap CP2102 USB to UART board to get a DTR pin (for Arduino programming)

I got this CP2102 USB to UART board from ebay recently as showed in my previous post. I got this mostly for Arduino progeamming using the Arduino bootloader in my ATMEGA328. Even though, this board has a pin called RST (Reset), it is not connected to DTR pin of the CP2102 IC. I have seen that many have stated that they had to face a problem in programming an Arduino using CP2102. I also faced this problem first. The problem was we all had tried to use this RST pin as the Arduino reset pin. If you try this you will get following error because this RST pin is actually connected to the Reset pin of the CP2102 itself. So, If you have did this and got this error this guide will help you to correct it and program your Arduino with this board.
Error: “avrdude: stk500_getsync(): not in sync: resp=0x00
When I check the CP2102 datasheet,I found out that the actual DTR pin is at pin #28 of the QFN-28 package.So,the only thing I had to do is soldering a wire to this pin.This is the pinout of the IC according to the datasheet figure:2.
Pinout
Please note that the QFN28 is a really small IC package,You need to have good soldering skills to solder it using a normal soldering iron (like my $1 soldering iron).This is the actual photo of the board,the pin shown by the red arrow is the pin #28 in my case.Compare the pin size with a surface mount resistor.
cp2102
I soldered a jump wire to this pin and used glue to secure the wire as below. The red arrow shows the wire I soldered to the DTR pin.
DSCF5706_640x480
You can test the DTR pin using a terminal program. Here I’m going to use RealTerm for this. Just set the port number on Port tab and toggle the DTR as shown on the picture using DTR Set & Clear buttons. Just measure voltage between DTR & Ground pins when you toggle this.It should be Set=0V and Clear=3.3V if you have done everything correctly.
RealTerm
Now you can use this CP2102 board to program your  Arduino happily. I should thank Kalinga aiya for telling me about this DTR problem on these boards.
This is a really hard work for a beginner. I strongly recommend you to buy a pre-modified CP2102 board for your Arduino if you are going use such a thing for first time. Techkatha shop has this modified board for a very good price and they will ship too. Check there if you need a pre-modified board.

Tuesday, March 5, 2013

USB to UART Convertors (PL2303 & CP2102)

If you are working with any UART stuff with micro controllers,you may have to debug them or send/receive data with a PC. In good old days,all of the computers got RS232 serial ports and we could use a MAX232 IC to convert RS232 to UART. But in recent years,RS232 ports got vanished in consumer computers specially in laptops (In good old days we got laptops with serial and parallel ports).
There are many solutions for USB to UART interface but some of them are not really cheap(like FT232). The cheapest way to use a simple USB to UART convertor.I recently got two of them and one is using PL2303HX and other one is using CP2102. Both are compatible with 3.3V LVTTL logic levels as it seems.  If you have an Arduino board you can use them them program the board using the boot loader. The one I got with PL2303HX doesn’t have a pin soldered for automatic reset (it uses the DTR pin on a serial port for resetting) in Arduino programming, but according to datasheet you can solder it to pin 2 on PL2303HX. This a guide with pictures telling you how to do it. CP2102 board got a presoldered pin called RST,but it is for CP2102 reset,So you need to solder DTR pin for pin 28 of CP2102 according to the datasheet.

You can get DTR pre soldered CP2102 from Techkatha. They also get Arduino UNO clone kits for very good price.The service they provide is really good :)

 I got PL2303HX based one for $1.68  and CP2102 based one for $2.13 . I got the both boards with required female to female jumper wires too.
Here I’m testing too boards and you can get drivers from;
PL2303HX Drivers
CP2102 Drivers
DSCF5633
image
I did a simple echo test using my favourite serial debugging tool SSCOM32 (like good old HyperTerminal) . You can download it from here. The echo test on both modules was a success.
sscom