Tuesday, March 26, 2013

Repairing an Arduino Mega or Uno USB port

Both the Arduino Mega 2560 and the Arduino Uno R3 use a micro-controller (the ATmega16U2 in the case of the Mega and the ATmega8U2with the Uno) instead of the FTDI chip used in previous boards. This makes the USB port more versatile. The downside is that it can stop working. You may have damaged your board beyond repair. However, in many cases the device simply needs re-programming.

This link  Programming the DFU describes how to program or re-program the micro-controller. There is a bit of problem though.  If you're in the situation that your Mega is not being recognized by either the Arduino IDE or the system then you will not be able to program it this way. The good news is that you can still program it in-system with an in-system programmer. You won't be able to do it with an FTDI serial interface either because that will end up talking to the main microprocessor on the board not the auxiliary processor.

The cheapest and simplest solution is likely to be a USBASP programmer available here. You will connect the programmer via a six pin adapter available here to the ICSP connector closest to the USB micro-controller (that is, the one furthest from the main micro-controller on the board). You may need to bend out the shield pins a little to get the adapter onto the pins because the key needs to be towards the outside of the board.  This diagram shows the ICSP for USB interface on an Uno. It is in a similar location on the Mega.


You'll need a driver for the USBASP if you're on Windows available here. If you're on Mac or Linux your USBASP programmer will simply show up when it's plugged into the USB port.

Once you have the USBASP connected all you have to do is use AVRDUDE (the program that you use to program the Arduino's main micro-controller) to flash the contents of the hex file: MEGA-dfu_and_usbserial_combined.hex to the USB micro-controller. This hex file is a combination of boot-loader and the USB serial code.

This example is for the Mega on a Mac, the process is very similar for a Uno on Linux & Windows. The hex file for the Uno is Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex. You will also have to set the device to be -p ATmega8U2 for the Uno rather than -p ATMega16U2 for the Mega.

Open a Terminal window and go to the location of the hex file for the USB controller:

cd /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/firmwares 

Then issue the following command:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -c usbasp -p ATmega16U2 -F -U flash:w:MEGA-dfu_and_usbserial_combined.hex 

AVRDUDE should do it's job and you should see something like this:

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9489
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: current erase-rewrite cycle count is -231 (if being tracked)
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "MEGA-dfu_and_usbserial_combined.hex"
avrdude: input file MEGA-dfu_and_usbserial_combined.hex auto detected as Intel Hex
avrdude: writing flash (7452 bytes):

Writing | ################################################## | 100% 3.79s



avrdude: 7452 bytes of flash written
avrdude: verifying flash memory against MEGA-dfu_and_usbserial_combined.hex:
avrdude: load data flash data from input file MEGA-dfu_and_usbserial_combined.hex:
avrdude: input file MEGA-dfu_and_usbserial_combined.hex auto detected as Intel Hex
avrdude: input file MEGA-dfu_and_usbserial_combined.hex contains 7452 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.53s



avrdude: verifying ...
avrdude: 7452 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


And you're done. 

P.S. If you see a signature zeros rather than the one expected, you may have the adapter the wrong way around...


 





Monday, July 2, 2012

Using the Arduino PT2322 library for audio control

There are a limited set of audio volume & tone processors available on the market especially in an easy to use DIP format. The PT2322 is in common use in audio equipment around the world. However it hasn't been picked up by the Arduino community; most likely because of the lack of an available library. In the process of developing an internet radio around this chip and an MP3 decoder I created a library for the PT2322. The PT2322 is available from oddWires here.

The PT2322 is an interesting chip and is very flexible for audio control. It's designed as a 5.1 audio processor enabling you to control your audio setup from your Arduino. oddWires has the only library written for the Arduino for this device. Download it here: Library and Example. In addition to its designed use you could use the 6 channels to control an active loudspeaker system using 3 channels for hi/mid/lo over two channels. It's very cost-effective if you use any of the chip amps oddWires has on the site. There is also a PCB board for LM1875/TDA2030 chip amps available here.

PT2322 is a 6-Channel Audio Processor IC utilizing CMOS Technology specially designed for audio applications. 6-channel individual input, 6-channel master volume control, 6-channel individual volume trim control, 3-band tone control (treble, middle, and bass), mute function, 3D effect function, tone defeat function are all built into a single chip having the highest performance and reliability with few external components. The features are shown below.

Features
  • Very Low Power Consumption (DC=9V)
  • I2C Bus Control
  • 6-Channel Individual Input
  • 6-Channel Master Volume Control: 0 to -79 dB (1 dB/step)
  • 6-Channel Individual Output TRIM Volume Control: 0 to -15 dB (1dB/step)
  • 3-Band Tone Control (Treble, Middle, Bass): + 14dB , 2dB/step
  • Mute Function
  • 3D Effect Function
  • Tone Defeat Function
  • Low Noise
  • High Channel Separation
  • Low Harmonic Distortion
  • Few External Components
  • Easy to Use
  • 28-pin DIP Package 
Functional Diagramhttp://www.oddwires.com/product_images/t/087/Screen_Shot_2012_06_23_at_4.18.16_PM__78824_zoom.png

Constructing the PT2322 circuit

At first, the wiring diagram may seem to require a lot. In fact, much of the circuitry is repeated. It consists of impedence setting resistors & DC blockers on all the inputs and outputs. Then there are a set of RC circuits for shaping the treble, mid and bass response. Hooking up the Arduino is simple as the PT2322 is an I2C device using SDA & SCL. You'll hook these up to pin 4 and 5 respectively on your controller board unless you have an Arduino Mega where the pins are 20 and 21.  The chip works from 5 to 15V DC. I used the 9V supply used to power my Arduino. A regulated supply would be preferable.

http://www.oddwires.com/product_images/l/535/Screen_Shot_2012_06_24_at_3.19.25_PM__08157_zoom.pngUsing the oddWires PT2322 Library

Once you have it wired up, you're ready to start. You could program it directly using the standard Arduino Wire library but an easier solution is to use the library referred to above because it handles all the control necessary to drive the device per the datasheet to perform all of its capabilities:

      int init(void);
    void muteOn(void);
    void muteOff(void);
    void _3DOn(void);
    void _3DOff(void);
    void toneOn(void);
    void toneOff(void);
    void leftVolume(unsigned char flv);
    void rightVolume(unsigned char frv);
    void centerVolume(unsigned char cv);
    void rearLeftVolume(unsigned char rlv);
    void rearRightVolume(unsigned char rrv);
    void subwooferVolume(unsigned char sv);
    void masterVolume(unsigned char mv);
    void bass(unsigned char tb);
    void middle(unsigned char tm);
    void treble(unsigned char tt);


Just call init() first and then use the functions above as you wish. An example is supplied with the library. The example has additional functionality and shows how to use four buttons and a 16 x 2 LCD to display the current settings, change settings, mute etc.

The PT2322 is available from oddWires here.


Saturday, June 23, 2012

Burning a bootloader into a bare ATmega328

Introduction 

Burning the standard Arduino boot-loader onto a bare ATMEGA328 is fairly straightforward but the steps that make it a more streamlined process are not found altogether on the web. This post gives you all you need to do it yourself. If in the end you decide not to do it yourself you can get an ATmega328P with a boot-loader already installed here for $4.95.

You will be using an existing Arduino Uno or Mega as an ISP (In-System Programmer) to program a bare ATmega328 micro-controller. You do not require any ancillary components at all despite what you may have read elsewhere. Neither do you need any other software than the Arduino IDE. You will need to create a simple circuit on a breadboard that you will use to interconnect with the Uno/Mega.

Here are the steps:
  1. Prepare the Arduino environment
  2. Wire up the simple breadboard circuit
  3. Burn the boot-loader

Prepare the Arduino environment

The Arduino IDE is already set up for use with multiple boards. However you need to be able to specify the minimal bread-boarded ATMEGA328 as a target. You can enable the IDE for this by using a predefined boards.txt file. You can download the required boards.txt file in a zipped breadboard folder containing it here .

Once you have downloaded the zip file, unzip it and place the breadboard folder in a folder called hardware in your Arduino sketches folder.  You need to restart the Arduino IDE  to see an option in the Tools/Boards menu for ATmega328 on a breadboard (8 MHz internal clock). The reason it shows 8Mhz rather than 16Mhz is that you will be using the built-in internal clock on the ATmega328 of 8Mhz rather than an external 16Mhz clock to simplify the bread-boarding (no external crystal required).

Next you need to load the ArduinoISP sketch provided with the IDE. Just make one change to the sketch for Arduino 1.0. Locate the delay(40) in the heartbeat() function and change it to delay(20).

Make sure you specify Uno/Mega or whatever Arduino you are using as the programmer in Tools/Boards. Once you have done this you are ready to bread-board your ATmega328.

 

Wire up the simple breadboard circuit


This is taken from the Arduino tutorial that can be found here. Pin connections are per this table (all boards except the Mega use the Uno connections):


Arduino Programmer                      ATMega328 Target
Uno Pin   Mega pin  Function Function Pin
9 9  GND

10 10  RESET TARGET (LOW) RESET 1



+5V 7



GND 8
11 51  MOSI MOSI 17
12 50  MISO MISO 18
13 52  SCK SCK 19



+5V 20



GND 22

Once you have finished bread-boarding you're ready to burn the boot-loader.

 

Burn the boot-loader

Select  Tools/Boards/ATmega328 on a breadboard (8 MHz internal clock).  Then  Tools/Burn Bootloader. You should see avrdude do its thing. The result should be similar to this:



################################################# | 100% 0.06s






avrdude: 1 bytes of lock written


avrdude: verifying lock memory against 0x0F:

avrdude: load data lock data from input file 0x0F:

avrdude: input file 0x0F contains 1 bytes

avrdude: reading on-chip lock data:








Reading | avrdude: Send: V [56] X [58] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 



avrdude: Recv: . [cf] 



avrdude: Recv: . [10] 



################################################## | 100% 0.02s






avrdude: verifying ...



avrdude: 1 bytes of lock verified


avrdude: Send: Q [51]   [20] 


avrdude: Recv: . [14] 



avrdude: Recv: . [10] 









avrdude done.  Thank you.



And that's it! Use your bootloaded ATMega328 as you like. Of course, if this sounds like too much effort you can get an ATmega328P with a bootloader already installed here for $4.95.

oddWire