Posts Tagged ‘Atmega328’
First custom PCB
This is my first working printed circuit board. I used the toner transfer method to draw the traces on the copper board. The purpose of this circuit board is to drive a stepper motor. This is a proof of concept for the final board version that will complete my equatorial mount project. The equatorial mount will be my first project in my new “Projects” section. I will begin with the conception and the making of this board.
I have designed the PCB using Fritzing, an open source circuit designer. You can find the project and the PDF of the circuit on my github. More details to come in the Projects section … hopefully in a few days.
I had a bit of troubles soldering the power connector because I drilled the holes too large. I’ll have to renew my stocks of small drill bits … I broke two 1/32″ bits while doing this board!
Build a Custom Arduino (Part 3) – Add a Compass
This post is the last part of this series of articles showing how to build a project using a custom Arduino board. To the accelerometer I added a compass. It begins to look more like a forest than an electronic circuit.
The compass uses the IC2 protocol to communicate with the Arduino micro-controller. That make it more complicated to interface with than the accelerometer. This protocol is handled by the library Wire.h that comes standard with the Arduino API.
In this example, you connect the SCL pin of the compass to the analog input #5 (pin #28) and the SDA pin to the analog input #4 (pin #27) of the micro-controller. As with the accelerometer, the compass is powered with the 3.3v output of the micro-controller on pin #20.
#include <Wire.h>
int x, y, z;
int pin13 = LOW;
int slaveAddress;
byte headingData[2];
int i, headingValue;
int HMC6352Address = 0x42;
void setup()
{
Wire.begin();
slaveAddress = HMC6352Address >> 1;
pinMode(13, OUTPUT);
Serial.begin(19200);
}
void loop()
{
// Send a "A" command to the HMC6352
Wire.beginTransmission(slaveAddress);
Wire.send("A"); // The "Get Data" command
Wire.endTransmission();
delay(100);
i = 0;
Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first)
while(Wire.available() && i < 2)
{
headingData[i] = Wire.receive();
i++;
}
headingValue = headingData[0]*256 + headingData[1]; // Put the MSB and LSB together
Serial.print("Current heading: ");
Serial.print(int (headingValue / 10)); // The whole number part of the heading
Serial.print(".");
Serial.print(int (headingValue % 10)); // The fractional part of the heading
Serial.println(" degrees");
x = analogRead(0);
y = analogRead(1);
z = analogRead(2);
Serial.print("acceleretations are x, y, z: ");
Serial.print(x, DEC);
Serial.print(" ");
Serial.print(y, DEC);
Serial.print(" ");
Serial.println(z, DEC);
//pin13 = !pin13;
//digitalWrite(13,pin13);
delay(400);
}
The output will refresh twice a seccond and display the compass heading and the accelerometer three axis values.
I had a problem of interference between the compass and the small green LED. When the LED is turned on, the compass reading is off by up to 10 degrees. I can’t explain that one but, when the LED is disables in the code, the compass readings is back to normal and stable. If you have an explanation for that please let me know in the comment section below.
Build an Arduino Clone (Part 2) – 3 Axis Accelerometer
I just received a adxl335 triple axis accelerometer breakout board from sparkfun.com. I decided to test it on my custom Arduino board.
Make sure, while wiring the accelerometer, to respect the maximum voltage of the device. This specific accelerometer accept a maximum voltage of 3.3v. You can get 3.3v from the Atmega328 Avcc pin #20. You should also make sure the reference voltage for the analog inputs is the same as the output voltage of the accelerometer. Do this by connecting the Aref pin #21 to the Avcc pin #20.
I added a blinking LED to the code from Wiring.org.co to test the device.
int x, y, z;
int pin13 = LOW;
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
x = analogRead(0);
y = analogRead(1);
z = analogRead(2);
Serial.print("acceleretations are x, y, z: ");
Serial.print(x, DEC);
Serial.print(" ");
Serial.print(y, DEC);
Serial.print(" ");
Serial.println(z, DEC);
pin13 = !pin13;
digitalWrite(13,pin13);
delay(100);
}
You can read the output using the Arduino IDE Serial Monitor. Values for the three axis will be displayed 10 times per second on the output of the Serial Monitor.
Values for all three axis analog inputs are ranging from a little less than 400 to a little more than 600 with a neutral value around 500.
When mounted the same way as in the picture above, the X and Y axis can be compared to the pitch and roll of an airplane. The Z axis on the other hand ranges from 600 when pointing to the ceiling to 400 when flipped over, pointing to the floor.
I also received an electronic compass with this accelerometer … I’ll add that to our custom Arduino board and write a short note about it.
Build an Arduino Clone
There are many different kinds of Arduino boards out there. Most of the time you will find one that fulfill all your needs but, sometime, you may want to build your own Arduino based board. Why would someone build its own Arduino board? Well, I can see two reasons to do that.
Reason #1: Size and space
The size of an Arduino board will fit most applications but, sometime, size and space really matter. The minimum hardware requirement to deploy an Arduino based application is an Atmega328 microcontroller with the Arduino boot loader and a 16Mhz crystal.
Reason #2: Price
The price of an Arduino board ranges from 20$ to 60$ depending on the features you want. This is OK for prototyping but way too expensive for large scale production. You can get an Atmega328 micro-controller and a 16Mhx clock for about 5$ or less if ordered in large quantity.
The micro-controller can be programmed using an USB-TTL adapter. Here I am using the Mini USB Adapter. Some of these adapters are designed to fit on a breadboard and match the Rx/Tx pins without the need of jumper wires. An other solution is to use an Arduino board (like the Arduino Uno) to program the micro-controller and then move it to your final product.
Build it
To build your Arduino clone you only need two components:
- An Atmega328 or Atmega168 micro-controller with the Arduino bool loader.
- A 16Mhz crystal oscillator
Connect the crystal between pin #9 and pin #10. Connect pin #8 to ground and pin #7 to 5V regulated power. The power can be provided by the USB-TTL adapter if you use one.
That’s it. If you want to program your micro-controller you must connect the Rx/Tx pins of the USB-TTL adapter to the Rx/Tx pins #2 and #3 of the Atmega328 micro-controller.
Program it
Once your program is ready to upload, connect the USB cable to your Arduino clone board and click the Upload button of the Arduino IDE. Some USB-TTL adapters are connected to the reset pin of the micro-controller and will reset it before to upload the new code. The Mini USB Adapter doesn’t have the reset pin so you have to manually reset the micro-controller immediately after you clicked the Upload button in the IDE.
You can reset the micro-controller by connecting the pin #1 to the ground. The upload will start when you disconnect the reset pin #1 from the ground. You don’t have to connect it to the 5V since there is an internal pull-up resistor on the reset pin.
In this example the program simply toggles the output pin #13 to which a green LED is attached. The value of a byte counter is incremented every time the LED is toggled and its value sent to the serial port.
byte pin13Value = LOW;
byte count = 0;
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(19200);
}
void loop()
{
pin13Value = !pin13Value;
digitalWrite(13, pin13Value)
Serial.println(count++, DEC);
delay(100);
}
You have made an Arduino custom board? Share your project in the Comment section below.







