{C++ etc.}

Latest Posts
 
Home | C++ Posts | Linux Posts | Programming Posts | Issue Tracking Posts

Tuesday, September 06, 2011

Burning Bootloader of an Arduino Uno with Another Arduino Uno

If you but a new ATMEGA 328P chip and plan to use it as a stand alone Arduino (with the proper wiring), you'll have to burn a boot loader on to it. This is easy if you have two Arduino boards. I'll outline how to achieve this using two Arduino Uno boards, since that's what I had at hand. I tried to get the boot loader on to the chip using an AVR JTAGICE MK2 but it didn't go well. This process is a bit of a hassle to set up but the actual burning process is very easy.

The main instructions for this are given here. Just follow them to the point and you could get a new bootloader on to your Uno in several minutes.

The only thing that I did differently to the above article, was to use the arduino IDE instead of using AVRDude. I'l give the steps for the complete process below:

1. Connect your two Arduinos according to the above schematic




2. Open the Arduino IDE. Select the correct COM port and set the board to Arduino Uno

3. Load the Arduino ISP sketch on to the programmer board. This sketch is located at [Arduino istallation folder]->Examples->ArduinoISP

4. In the IDE, select Tools->Burn Bootloader->w/ Arduino as ISP

This will begin the burning process. It'll take about a minute for writing to finish. After that, you could disconnect the two boards and use the newly programmed board as a stanalone Arduino Uno

Thursday, June 09, 2011

HC-SR04 Rangefinder (with Arduino)

Setup:
Connect digital pin 13 to Trigger.
Connect digital pin 12 to Echo.
5V of Arduino to Vcc.
Ground of Arduino to Gnd of SR04

Note: The 5V out from Arduino might not be enough for the range finder to work. If it's not giving proper values, try giving power from an external source (like 4 AA batteries).

Code: (This consists of a sample that I got off the net. I don't remember the exact page but I want to give credit to the original creator)


int pingPin = 13;
int inPin = 12;

long duration, inches, cm;
 
void setup() {
  //pinMode(13, OUTPUT);
  pinMode(pingPin, OUTPUT);
  pinMode(inPin, INPUT);
  Serial.begin(9600);
}
 
void loop()
{
  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  //pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);
  //delayMicroseconds(2);
 
  // a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
 
  duration = pulseIn(inPin, HIGH);
 
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
 
  Serial.print("Distance: [");
  Serial.print(inches);
  Serial.print("]inches. [");
  Serial.print(cm);
  Serial.print("]cm\n");
  delay(1000);
}
 
long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  return microseconds / 74 / 2;
}
 
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}


Monday, January 31, 2011

How to extract the contents of HXF files

The .HXF extension is used in a variety of applications. The one that's being referred to in this case are the HXF files which come bundled with firmware upgrades for some Chinese PMPs.

I bought an Onda VX575 FHD (Full HD) recently and wanted to customize some of the images and text which come with the original firmware. This is reletively easy to do. You only have to extract the contents of the HXF file, make the changes to the files that you want, repack it and burn it to the device. There's a great tool which has been written to unpack and repack HXF files. It's called HXF extract (what else :)) and could be downloaded here.

Once it's downloaded, all you have to do is run it, click the "Unpack HXF" button and point it to the HXF file. It's extract it's contents to a folder named "out_hxf". Make changes to the files in the out_hxf folder, run the tool, select "Repack HXF" and select a file name for the new file and you're done.
Sometimes you might encounter an error (can't remember the exact message) which would most likely be due to a missing COMDLG32.OCX file. Download it from a valid site (you could find it via google search) and type:

regsvr32  \comdlg32.ocx

at a command prompt to register it. The tool should work fine after that.


Resources:
http://www.mp4nation.net/forum/viewtopic.php?f=63&t=13184
http://dingoo-digital.com