How to Test and Program an ATtiny Controller Using a Custom PCB

Publisher:科技梦行者Latest update time:2022-07-25 Source: csdn Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the previous article, we have already covered the differences in specifications between the Arduino and ATtiny series AVR microcontrollers. However, another major difference between the two is the way the microcontrollers are programmed.


The Arduino board can be programmed simply by plugging it into a computer via a USB cable. In addition to the bootloader, these boards also integrate a number of peripheral components that allow them to be programmed without any special connections or software.


However, this is not the case with the ATtiny series of microcontrollers. The ATtiny series of microcontrollers can be programmed in a few different ways, depending on the size of your project.


Methods for Programming ATtiny Microcontrollers



One method of programming the ATtiny that has been covered in this article is to use an Arduino Uno as an ISP programmer. Using an Arduino as an AVR programmer is a good option for prototyping a single unit, but is impractical for a business producing a product. This is especially true for designs using SMD microcontrollers, as they cannot be plugged into an Arduino or a breadboard.


In this article we will look at three different methods of programming ATtiny microcontrollers that allow programming of SMD packages and can be used to scale up from small prototype runs of no more than 100 units to mass production runs of several hundred:

● Programming using IC test clip and ISP programmer

● PCB plug connector or test point, use the plug connector or pogo pins to connect the ISP programmer to the PCB;

● The microcontroller can be programmed directly using SMT test clips before being soldered to the board, or the chip can be factory programmed.


Custom Design Test PCB

In order to test various methods of programming the ATtiny range of microcontrollers I designed a simple test PCB.


The PCB is a thermometer with a DHT22 temperature and humidity sensor on the back. In this case, this sensor only reads the temperature.


Back view of the custom PCB using the DHT22 sensor.


The test board also features a row of LEDs on the front, similar to the mercury/alcohol tubes on an analog thermometer. At higher temperatures more LEDs light up, and in addition the LEDs change color from blue to red between low and high temperatures.


In cold temperatures (like outside in the winter), the LEDs glow blue and fewer LEDs light up.


Under high temperatures (such as in front of a heat gun), the LED will light up red and more LEDs will light up.


The main part of the test board contains a variety of packages for mounting one of the following ATtiny series microcontrollers: ATtiny84, ATtiny85, ATtiny2313, and ATmega328. Each microcontroller also has some passive components to make everything work properly.


The PCB also contains footprints for mounting an ATtiny 84, ATtiny 85, ATtiny2313, or ATmega328.


Finally, the system is powered by the Micro USB port on the bottom of the board.


The produced PCB is red, matching the color of the alcohol thermometer. Except for the DHT22, all other components are SMD parts, so the board can be assembled by reflow soldering.


Run the code to test the PCB

The code to run the test PCB is not too complex.


At the beginning of each loop, the microcontroller takes the temperature reading from the DHT22. The temperature reading is then converted into the color of the LEDs and the number of LEDs to light using two different map() statements.

  1. /*

  2.    Project:  ATtiny Microcontroller Test Platform

  3.    Published on Maker Pro

  4.    Author:  Scott Hatfield (Toglefritz)  

  5. */


  6. // CONFIGURATION  //


  7. // If you are using an ATint84, the LEDs are connected to pin 2. For any of the other

  8. // microcontrollers, the LEDs are connected to pin 4.


  9. // ATtiny84

  10. // #define PIN 2


  11. // ATtiny85 or ATTiny2313 or ATmega328

  12. #define PIN 4


  13. // NEOPIXEL SETUP //


  14. // Include the Adafruit NeoPixel library

  15. #include


  16. #define NUMPIXELS 7   // There are seven LEDs on the board


  17. // Set up the NeoPixel library

  18. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);


  19. // DHT22 SETUP  //

  20. #include "TinyDHT.h"


  21. // The temperature sensor is connected to pin 3 for all microcontrollers

  22. #define DHTPIN 3


  23. #define DHTTYPE DHT22   // DHT 22  (AM2302)

  24. DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor


  25. // SKETCH VARIABLES  //

  26. float temp;  // Stores temperature value

  27. int color;   // The color of the LEDs, for use with the Wheel() function

  28. int number;  // The number of LEDs to illuminate



  29. void setup() {

  30.   // Set up the LEDs

  31.   pixels.begin();   // Initialize NeoPixel object

  32.   pixels.clear();   // Set all pixel colors to 'off' to start

  33.   pixels.setBrightness(50);   // The LEDs do not need to be super bright


  34.   dht.begin();    // Initialize the DHT22 object

  35. }


  36. void loop() {

  37.   // Read the temperature

  38.   int16_t temp = 30;//dht.readTemperature();

  39.   // Reading temperature or humidity takes about 250 milliseconds!

  40.   delay(250);

  41.   /*

  42.      The DHT22 is capable of measuring temperatures between -40C and 125C. But, because this is supposed to

  43.      be hand-held device, we will map the temperatures only to between -25C and  40C.

  44.   */


  45.   // Map the temperature reading to a color number used for the LEDs. At the coldest temperatures, the light will be blue,

  46.   // at the hottest, the light will be red.

  47.   color = map(temp, -18, 30, 75, 1);


  48.   // Then, map the temperature reading to a number of LEDs to illuminate. At the lowest temperatures, only the bottom LED will

  49.   // illuminate, at the hightest temperatures, all LEDs will illuminate.

  50.   number = map(temp, -18, 30, 0, 6);


  51.   // Set the LEDs to the color corresponding to the current temperature reading

  52.   for(int i = 0; i <= number; i++) {

  53.     pixels.setPixelColor(i, Wheel(color));

  54.   }

  55.   pixels.show();

  56. }


  57. // Wheel() is a helper function to get colors from single values between 0 and 255  

  58. // Input a value 0 to 255 to get a color value.

  59. // The colours are a transition r - g - b - back to r.

  60. // For a visual representation of the values, see https://docs.google.com/spreadsheets/d/1vYsRDL4QzcZtP30jqQByM2pK3_Xq2RPOyVwkcxQOnPI/edit?usp=sharing

  61. uint32_t Wheel(byte WheelPos) {

  62.     if(WheelPos < 85) {

  63.         return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);

  64.     }

  65.     else if(WheelPos < 170) {

  66.         WheelPos -= 85;

  67.         return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);

  68.     }

  69.     else {

  70.         WheelPos -= 170;

  71.         return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);

  72.     }

  73. }


Trying out ATtiny programming methods using a test PCB

As mentioned earlier, there are three main methods of programming the ATtiny series of microcontrollers. The PCB board is a thermometer with a DHT22 temperature sensor and a row of LEDs to indicate the current temperature based on the color and number of illuminated LEDs. Subsequent parts of this series will all use the same test board to illustrate how to use the above programming methods.


Reference address:How to Test and Program an ATtiny Controller Using a Custom PCB

Previous article:How to Program ATtiny Microcontrollers Using IC Test Clips
Next article:High-speed camera trigger using ATtiny85 controller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号