Programming IC

Basic Arduino experience for this is recommended. If you have never programmed ICs, this might be overwhelming, but you can do it.

Please read through instructions carefully.
These instructions with assist in copying the provide Code below and upload it to an ATTiny with Arduino IDE, using an Arduino setup as an ISP. Sounds fun.


You will need:
ATTiny IC <- Check parts list
Arduino UNO with USB (or any other Arduino device capable of ArduinoISP) ELEGOO UNO R3 Board ATmega328P with USB Cable(Arduino-Compatible) for Arduino : Amazon.ca: Electronics
PC with the Arduino IDE Installed <-You must source yourself
before soldering chip, but this is optional.

Make sure you have the ATTiny Board installed on the Arduino IDE.
To do this. Open File->Preferences. Click on Settings tab. Last setting is "Additonal Board Manager URLs".
In the text field copy this link:
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
Select OK, and then close the Arduino IDE.
Re-open Arduino IDE. Search the Board Manager for "ATTiny"
"attiny by David A. Mellis" should show up. Install the most recent version.
Do another restart of the Arduino IDE, just for good measure.
Under Tool -> Boards -> there should be another option for ATTiny right under Arduino AVR Boards.
Do not select it now, but this will be needed for when we program the ATTiny.

Next connect USB from computer to an Arduino, and without anything else connected to Arduino
Now to set-up an Arduino as an ISP.
Open the Arduino IDE on a PC.
Load example sketch 11.ArduinoISP-ArduinoISP in the IDE.
Check IDE settings :tools:board and make sure your correct Arduino board is selected, (I use an UNO)
as well select your Port: COM that Arduino is connected to.
Then click "Upload" to upload this sketch to Arduino. Complete.
Now you have set-up your Arduino as an ISP for SPI communication to other MCUs/ICs.
Setting Up Arduino as an ISP


Now to Program that little ATtiny.

**Note for Programming ICs without Serial Communication
ATtinys do not have serial communication, so must be programmed with SCK, MISO, MOSI, RESET pins.
This is known as SPI communication.
SPI has four logic signals (which go by alternative namings):
  • SCLK : Serial Clock (clock signal from main)
  • MOSI : Main Out Sub In (data output from main)
  • MISO : Main In Sub Out (data output from sub)
  • CS : Chip Select (active low signal from main to address subs and initiate transmission)


*TIP: Highly recommend an IC holder, to use to program SOIC8 style IC packages without having to solder any connections. I use a SOIC8 SOP8 to DIP8 EZ Programmer Adapter Socket Converter Module which I plug straight into a breadboard for ease of programming. Link to this adapter ----> HiLetgo 2pcs SOIC8 SOP8 to DIP8 EZ Programmer Adapter Socket Converter Module with 150mil : Amazon.ca: Industrial & Scientific
 

Now connect Arduino to ATtiny for Programming with jumpers.
Arduino       ATtiny85

5V     --->   Vcc              
GND    --->   GND               
Pin 13 --->   Pin 2
Pin 12 --->   Pin 1
Pin 11 --->   Pin 0
Pin 10 --->   Reset




An electrolytic capacitor connected to GND & RESET on the Arduino is recommend to prevent the Arduino from restarting it's self. It is recommended to use a 10uF, but I've used 22uF before and it worked fine.

Open a new sketch on the Arduino IDE and copy the Code below.
Now you must check the Arduino IDE Settings, before uploading program to ATtiny.

Arduino IDE - Settings
Board:ATtiny25/45/85
Port:*Select COM port* USB must be already connected to Arduino
Processor:*Select Version of ATtiny you are using*
Clock:Internal 1MHZ <---Will also work on "Internal 8MHZ" but will use more Power
                   the trade off is slower processing at 1MHz but less power consumption
                                    **********Highly Recommended Setting*******

Now you should have done everything correctly and are ready to Burn a Bootloader Click on "Burn Bootloader". Once it is complete, we can then upload our program.
Click on "Upload using Programmer". Once program is complete we are done, and now should test IC before continuing, but testing is optional.

Minimal Programming Demo Video (Not recommended, but works 99%)




Optional, but Recommmended Option for Testing Programmed ATTiny
before construction/soldering of circuit)
(Also Please Check out Videos below if having any issues with programming)

Using same breadboard for programming, we will now construct a test setup. First connect the VCC of ATTiny to 3.3V instead of 5V. Remove jumpers from SCK, MISO, MOSI and RESET.
Connect a jumper from VCC (Terminal 8) to RESET (Terminal 1). Connect both LED Negative cathode to GND (Terminal 4).
Connect Yellow LED Positive Anode to PWM 1 (Terminal 6).
Connect Red LED Positive Anode to PWM 0 (Terminal 5) Attach a simple NO button to breadboard.
Connect one side of NO button to VCC (Terminal 8)
Connect the other side of NO button to A3 (Terminal 2)
Connect Analog 3 (Terminal 2) to one side a 100kOhm Resistor
Connect other side of the same 100kOhm Resistor to GND (Terminal 4)
Connect Digital 2 (Terminal 7) to 1nF capacitor,
Connect other side of 1nF capacitor to GND.
Refer to video for example.
Make sure you supply with a 2V-3V, and not 5V as the circuit may be damaged otherwise, depending on
the differences in the parts you may have sourced parts.

Explanation of Testing Board and the Setups


Setting Up For Programming. Set Clock Speed and Burning Bootloader to ATTiny. Upload ATTiny a Clock Checking Program.


Setup Breadboard for Running IC Clock Frequency Test Program on ATTiny.


Testing IC Clock Frequency


Uploading LED Sketch


Now all we have to do is test function. Hold down button, and LED should come on.
Continue to Hold down button, and the brightness levels should cycle through.
Lift the 1nF from ground to test for an audio Signal, lights should flicker, re-attach to ground, no flicker.
Triple Tap the button and check to see if the Sound Settings Change.
Cycle power to check that the defaults setting.
Lastly if possible check the current to make sure the ATTiny does not have some manufacture defect.
Do this by connecting a mA meter in series, and verifying that the current of IC is around 1mA at 3V.


If the test was successful, congratulations.
We can now move onto assembling the components of this modification.

If you need more detailed instructions for programming the ATTiny IC, refer to this website:

If you require an assistance please feel free to contact me, always happy to help.

ATTiny Clock Frequency Detection Arduino Code:

//ATTiny Clock Frequency Test
//Ver 1.0
//July 10, 2020
//Joe V.

    // Install LED Pos Long Lead with 100 Resistor in Series to Pin 7
    // Install LED Neg Short Lead to Pin 4
    // Slow blink for 1-MHz   One second on, one second off
    // Fast blink for 8-MHz   2 Blinks per Second
    // Verify the clock speed.
    // If correct then upload programming sketch.
    // Else try re-Burning Bootloader with Clock Speed Set,
    // and then Upload this Sketch again and Test Clock Speed again.

unsigned long Start_Time = 0;
unsigned long End_Time = 0;

void setup()
{
  pinMode(0, OUTPUT);
}
void loop()
{
  Start_Time = micros();
  delayMicroseconds(5);
  End_Time = micros();


  if ((End_Time - Start_Time) >= 50) {
    // Slow blink for 1-MHz
    digitalWrite(0, HIGH);
    delay(1000);
    digitalWrite(0, LOW);
    delay(1000);
  }
  else {
    // Fast blink for 8-MHz
    digitalWrite(0, HIGH);
    delay(250);
    digitalWrite(0, LOW);
    delay(250);
    digitalWrite(0, HIGH);
    delay(250);
    digitalWrite(0, LOW);
    delay(250);
  }
}
*************************************************************************************
****************************** THAT WAS THE END OF THAT CODE ************************
*************************************************************************************

No comments:

Post a Comment

Please Leave Your Reviews: