风筝
发表于: 2019-12-24 21:08:31 | 显示全部楼层

在前面的文章中,我们已经介绍了Arduino与ATtiny系列AVR微控制器之间在规格参数方面的差异。但是,它们两者之间的另一个主要区别在于微控制器的编程方式。


只需通过USB电缆将Arduino开发板插入计算机即可对Arduino板进行编程。除自举程序外,这些开发板还集成了许多外围组件,使它们无需任何特殊连接或软件即可进行编程。


但是,ATtiny系列微控制器不是这种情况。根据项目的规模,可以使用几种不同的方式对ATtiny系列微控制器进行编程。


编程ATtiny微控制器的方法

156.jpg


本文上已经介绍了一种编程ATtiny的方法是使用Arduino Uno作为ISP编程器。使用Arduino作为AVR编程器是对单个单元进行原型制作的不错选择,但是对于生产产品的企业来说是不切实际的。对于使用SMD微控制器的设计而言尤其如此,因为它们无法插入Arduino或面包板。


在本文中,我们将研究对ATtiny微控制器进行编程的三种不同方法,这些方法允许对SMD封装进行编程,并且可以用于从不超过100个单元的小型原型运行扩大到数百个批量生产:

●    使用IC测试夹和ISP编程器进行编程

●    PCB插头连接器或测试点,使用插头连接器或pogo引脚将ISP编程器与PCB进行连接;

●    在将微控制器焊接到板上之前,可以使用SMT测试夹直接进行编程,也可以对芯片进行工厂编程。


定制设计测试PCB

为了测试对ATtiny系列微控制器进行编程的各种方法,我设计了一个简单的测试PCB。


PCB是一个温度计,背面带有DHT22温湿度传感器。在本例中,此传感器仅读取温度。

he back view of the custom PCB.jpg

使用DHT22传感器的定制PCB的后视图。


测试板的正面还带有一排LED,类似于模拟温度计上的汞/酒精管。在较高的温度下更多的LED点亮,此外,LED在低温和高温之间将颜色从蓝色变为红色。

At cold temperatures.jpg

在低温下(例如冬天的外面),LED会发出蓝色光,并且较少的LED灯点亮。

At high temperatures.jpg

在高温下(例如在热风枪前面),LED会亮红色,并且更多LED灯会亮起。


测试板的主要部分包含多种封装,用于安装以下ATtiny系列微控制器之一:ATtiny84、ATtiny85、ATtiny2313和ATmega328。每个微控制器还具有一些无源组件,以使一切正常工作。

The PCB also contains footprints.jpg

PCB还包含用于安装ATtiny 84,ATtiny 85,ATtiny2313或ATmega328的封装。


最后,系统由电路板底部的Micro USB端口供电。


如果要制作自己的温度计测试板,则可以在此处下载Autodesk Eagle设计文件:Eagle设计文件


生产的PCB为红色,匹配酒精温度计的颜色。除了DHT22之外,所有其他组件都是SMD部件,因此可以通过回流焊接组装电路板。


运行测试PCB的代码

运行测试PCB的代码不太复杂。


在每次循环开始时,微控制器都会从DHT22获取温度读数。然后,使用两个不同的map()语句将温度读数转换为LED的颜色和要点亮的LED个数。

  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 <Adafruit_NeoPixel.h>

  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. }
复制代码

使用测试PCB尝试ATtiny编程方法

如前所述,有三种主要的ATtiny系列微控制器编程方法。PCB电路板是一种温度计,带有DHT22温度传感器以及一排LED,用于根据颜色和发光LED的数量指示当前温度。 本系列的后续部分将全部使用同一测试板来说明如何使用上述编程方法。

跳转到指定楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 32 | 回复: 41



手机版|

GMT+8, 2024-3-28 19:16 , Processed in 0.231822 second(s), 6 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表