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.
/*
Project: ATtiny Microcontroller Test Platform
Published on Maker Pro
Author: Scott Hatfield (Toglefritz)
*/
// CONFIGURATION //
// If you are using an ATint84, the LEDs are connected to pin 2. For any of the other
// microcontrollers, the LEDs are connected to pin 4.
// ATtiny84
// #define PIN 2
// ATtiny85 or ATTiny2313 or ATmega328
#define PIN 4
// NEOPIXEL SETUP //
// Include the Adafruit NeoPixel library
#include
#define NUMPIXELS 7 // There are seven LEDs on the board
// Set up the NeoPixel library
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// DHT22 SETUP //
#include "TinyDHT.h"
// The temperature sensor is connected to pin 3 for all microcontrollers
#define DHTPIN 3
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor
// SKETCH VARIABLES //
float temp; // Stores temperature value
int color; // The color of the LEDs, for use with the Wheel() function
int number; // The number of LEDs to illuminate
void setup() {
// Set up the LEDs
pixels.begin(); // Initialize NeoPixel object
pixels.clear(); // Set all pixel colors to 'off' to start
pixels.setBrightness(50); // The LEDs do not need to be super bright
dht.begin(); // Initialize the DHT22 object
}
void loop() {
// Read the temperature
int16_t temp = 30;//dht.readTemperature();
// Reading temperature or humidity takes about 250 milliseconds!
delay(250);
/*
The DHT22 is capable of measuring temperatures between -40C and 125C. But, because this is supposed to
be hand-held device, we will map the temperatures only to between -25C and 40C.
*/
// Map the temperature reading to a color number used for the LEDs. At the coldest temperatures, the light will be blue,
// at the hottest, the light will be red.
color = map(temp, -18, 30, 75, 1);
// Then, map the temperature reading to a number of LEDs to illuminate. At the lowest temperatures, only the bottom LED will
// illuminate, at the hightest temperatures, all LEDs will illuminate.
number = map(temp, -18, 30, 0, 6);
// Set the LEDs to the color corresponding to the current temperature reading
for(int i = 0; i <= number; i++) {
pixels.setPixelColor(i, Wheel(color));
}
pixels.show();
}
// Wheel() is a helper function to get colors from single values between 0 and 255
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
// For a visual representation of the values, see https://docs.google.com/spreadsheets/d/1vYsRDL4QzcZtP30jqQByM2pK3_Xq2RPOyVwkcxQOnPI/edit?usp=sharing
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
else {
WheelPos -= 170;
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
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.
Previous article:How to Program ATtiny Microcontrollers Using IC Test Clips
Next article:High-speed camera trigger using ATtiny85 controller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- HC05 Bluetooth module debugging documentation with buttons
- Infineon Position2Go Development Kit Review - skypinglee
- Schematic diagram of a quadrature oscillator
- Please tell me about the PB pin of GD32E230C
- Qorvo UWB Solution Receives Apple U1 Interoperability Certification
- Can't even see the taillights? LED makes car tail lighting safer
- EEWORLD University - How and why to replace discrete MOSFETs with load switches
- 【ESP32-C3-DevKitM-1】+ESP32 series universal Windows environment construction
- Digi-Key KOL video is here~ Senior algorithm engineer talks about the secrets of image processing
- 【RPi PICO】Run Fuzix system