Enter Your Project for a chance to win a grand prize for the most innovative use of Arduino or a $200 shopping cart! The Birthday Special: Arduino Projects for Arduino Day! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
Happy Birthday to Project14 [April 14th, it's been a month already ]
and to ARDUINO
This blog post is to celebrate the ARDUINO day and Project14 Birthday.
However, I am not the guy who likes to use Arduino in almost every project, I am more comfortable with the raw use of Microcontroller. But I do appreciate the way Arduino changed the concept of open source hardware and firmware. The most glorious part of Arduino is that it own the heart of everyone from enthusiasts, hobbyists to professionals.
To pay my tribute to Arduino I decided to share an old project based on AVR microcontroller, Atmega32.
This project does not directly related to Arduino, but stays with the themes suggested for Birthday Special.
Theme: DIY Your Own Arduino - build your own AVR dev board that can be programmed using a C or C++ compiler.
Yep, this blog is about an AVR Development Board that I designed and named it MEGATRON32
this is the first time I am posting a blog on this development board.
Project timeline: around the end of 2010 and the beginning of 2011.
Megatron32:
It's a Development Board based on Atmega32 AVR microcontroller.
However Atmega16 and similar 40 pin AVR MCUs can be used too.
This board can be programmed using a C compiler.
I have used various IDEs like AVR studio, Bascom and MikroC Pro for AVR.
Recently I came to know and checked that Arduino IDE can also be used in case of Atmega32 and Atmega16 with additional header files.
It uses on board USBasp programmer to down load the hex file.
This board has some builtin sensors, displays, motor drivers but all the pins are accessible to the user through IDC10 terminals.
It can be directly powered by USB, whereas external supply can be used too.
Top and Bottom views -
Side views-
Why do I need to design something which is readily available?
Ok, actually I was not intended to design a development board. After completing my Bachelor on December 2009 I started working on embedded system based design. I found that developing a proto board for R&D in every project is time consuming and boring. Therefore, I started to design modular boards which can be connected together for experimenting with the MCU. Now a days this sort of modular boards for sensors, displays etc are available in local market, but at that time it was not that much familiar in my region.
Later on, in my leisure time, I started joining all the modules in a single board. My intention was to use it in training purpose, if I need it in future by any means.
Meanwhile, I got an opportunity to conduct a workshop on 'embedded system design' arranged by IEEE student branch in my University. To facilitate the workshop we needed development boards so that students can easily execute and modify the sample codes which makes the demonstration easier.
Somehow, a large number of students registered for the workshop because of the intense publicity of the organizers and I decided to go for a set of my own development board customized for that workshop.
So, let's check out what are the features MEGATRON32 has...
Features:
- Supported Microcontrollers
- AtMega32, AtMega16 and similar 40 pin MCUs
- AtMega8, AtMega48 and similar 28 pin MCUs with adapter board
- All the AVR MCUs supported by USBasp can be programmed through CON_PROG header [beneath LCD display].
- Peripheral Interfacing
- RS232 communication
- IR communication
- PS2 AT keyboard / mouse interfacing
- L293D motor driver, can drive up to 4 DC motors
- 6v Relay
- Buzzer
- Display
- 8 7Segment display
- 8x8 Dot Matrix display
- 16x2 Alphanumeric LCD
- Analog Devices [on ADC port]
- LIN POT 1KOhms
- LDR
- LM35 temperature sensor
- Photodiode [IR]
- Selectable AREF connection
- Microphone
- Other On Board Features
- 8x4 LED logic display for 4 Ports
- 10x4 IDC 10 Port pin connectors for interfacing with external device with Vcc and GND pins
- Selectable 8x4 DIP Switches for Pull up and Pull down Port pins
- 8x2 Button Keys for Port A and D with selectable Pull up or Pull down
- BCD to 7seg driver, 4 to 16 multiplexer, 8 channel high current 0v provider by ULN 2803A IC with open connectors for interfacing with external devices
- 5v regulator [ac/dc 7v – 30v input]
- Burner
- USBASP [by Thomas Fischl]
- External programmer can also be connected
- Power Supply [DC 5v operation]
- External AC/DC input from 7v to 30v
- USB Port
1. Atmega 32 mounted on zif socket
2. 16x2 alphanumeric display
3. 8x8 Dot matrix display
4. 8 seven segment LED display
5. Buzzer
6. Relay
7. 8x4 LED for indication of PORT pins status
8. IDC10 header to connect external devices
9. DIL 8 switch to pull up or down PORT pins
10. Jumper to select PORT pin pull up or down
11. DIL 8 switch to enable onboard modules
12. Analog sensors and transducers
13. 8x2 button switches for digital input
14. Jumper to select button pull up or down
15. PS2 port
16. 8 jumpers to isolate analog circuitry from digital i/o of PORTA
17. Reset switch
18. Terminal blocks to connect external power and Dc motor [4]
19. RS232 port
20. USB port for USBasp programmer
21. External 5v 2A supply
Circuit Diagram:
The detail circuit diagram is separated in several parts -
MCU main unit LEDs and Buttons Analog
Display Peripherals Programmer
Compilers / IDEs:
It's a development board with an USBasp programmer on board, which needs *.hex file. Any compiler which can produce a hex file can be used with it.
However, I have used Atmelstudio, Bascom and mostly MikroC Pro for AVR so far.
When I thought about posting this blog on Arduino day, I was thinking to figure out a way to setup the MEGATRON32 board to be used with Arduino IDE.
I searched the internet and found it's quite easy to do and no modification is needed.
- that there are header files for ATmega32 and ATmega16 to be used in Arduino IDE.
- USBasp is already supported by Arduino IDE
- libraries work fine [like LCD], but pin configurations need to be changed according to the circuit diagram
To use the USBasp programmer with ATmega32 in Arduino IDE, I followed this tutorial - Using Atmega32 With Arduino IDE
Arduino IDE [sample codes]:
I tried some basic codes using Arduino IDE. It works fine. But the USBasp programmer was not detected by the IDE, therefore I used the hex output option [export compiled binary] and AVRdude to burn the hex into the board.
I think the reason why the programmer is not detected by the Arduino IDE can be the firmware version. I have to check it out, and will post an update on the result.
As usual the very first code is to blink LEDs. Target is to toggle all the PORT pins on every 0.5 seconds.
/*Blink Turns on an LED on for 0.5 second, then off for 0.5 second, repeatedly. */ byte SET = B11111111; byte CLEAR = B00000000; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. DDRA = 255; DDRB = B11111111; DDRC = 0XFF; DDRD = B11111111; } // the loop routine runs over and over again forever: void loop() { PORTA = SET; // turn the LED on PORTB = SET; PORTC = SET; PORTD = SET; delay(500); // wait for a second PORTA = CLEAR; // turn the LED off PORTB = CLEAR; PORTC = CLEAR; PORTD = CLEAR; delay(500); // wait for a second }
The 2nd code is the LCD library project. It displays the "hello, world!" on the 16*2 LCD display and scrolls through out the screen.
/* LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "Hello World!" to the LCD and uses the scrollDisplayLeft() and scrollDisplayRight() methods to scroll the text. The circuit: * LCD RS pin to digital pin 2 * LCD Enable pin to digital pin 3 * LCD D4 pin to digital pin 4 * LCD D5 pin to digital pin 5 * LCD D6 pin to digital pin 6 * LCD D7 pin to digital pin 7 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe modified 7 Nov 2016 by Arturo Guadalupi This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll */ // include the library code: #include // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); delay(1000); } void loop() { // scroll 13 positions (string length) to the left // to move it offscreen left: for (int positionCounter = 0; positionCounter < 13; positionCounter++) { // scroll one position left: lcd.scrollDisplayLeft(); // wait a bit: delay(250); } // scroll 29 positions (string length + display length) to the right // to move it offscreen right: for (int positionCounter = 0; positionCounter < 29; positionCounter++) { // scroll one position right: lcd.scrollDisplayRight(); // wait a bit: delay(250); } // scroll 16 positions (display length + string length) to the left // to move it back to center: for (int positionCounter = 0; positionCounter < 16; positionCounter++) { // scroll one position left: lcd.scrollDisplayLeft(); // wait a bit: delay(250); } // delay at the end of the full loop: delay(1000); }
The third code that I tried is the analog input project. It reads the voltage from a Potentiometer connected to ADC[2] and then toggle PortB.0 [digital pin 0 in Arduino].
The delay between the output switching/toggling depends on the analog voltage [ADC value], which is displayed on the LCD.
In this board, PORTB.0 [digital pin 0 in Arduino] is connected to a buzzer, so this code will generate a pulsatile sound which can be varied by the potentiometer.
/* Analog Input Demonstrates analog input by reading an analog sensor on analog pin 2 and turning on and off a light emitting diode(LED) connected to digital pin 0. The amount of time the LED will be on and off depends on the value obtained by analogRead(). The same digital pin 0 is connected to a buzzer. It will produce a pulsatile sound where on/off time depends on the analog input value. The 16*2 LCD will show the ADC value. The circuit: - potentiometer center pin of the potentiometer to the analog input 2 one side pin (either one) to ground the other side pin to +5V - LED and Buzzer anode (long leg) attached to digital output 0 cathode (short leg) attached to ground created by David Cuartielles This example code is in the public domain. http://www.arduino.cc/en/Tutorial/AnalogInput */ int sensorPin = 2; // select the input pin for the potentiometer int BUZPin = 0; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor // include the library code: #include // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup() { // declare the ledPin as an OUTPUT: pinMode(BUZPin, OUTPUT); // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("ADC EXAMPLE"); } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); // turn the ledPin on digitalWrite(BUZPin, HIGH); // stop the program for milliseconds: delay(sensorValue); // turn the ledPin off: digitalWrite(BUZPin, LOW); // stop the program for for milliseconds: delay(sensorValue); lcd.setCursor(0, 1); // bottom left String stringOne = String(sensorValue); lcd.print(stringOne); lcd.print(" "); }
Attached video contains the demonstration of some sample codes for MEGATRON32.
Codes are written Using Arduino IDE and MikroC Pro for AVR.
Well, that's all about it so far.
Don't know whether this is worth posting this blog or not,
just hoping some of you may find it interesting.
Top Comments