Zápisník experimentátora
Hierarchy: ATtiny85
In this article we will discuss A/D converter in microcontroller ATtiny85. We will build on previous articles in which we described the A/D converter in Arduino Uno. In this article, we will show the basic use of the converter and we will identify differences. We will discuss the differences in detail in one of the future articles.
ATtiny85 has a similar converter as Arduino Uno (with ATmega328P microcontroller). It has several interesting differences.
In normal use, however, it does not differ from Arduino.
If we use the core ATTinyCore, then we can use the reference voltage as follows:
To display the measured results, we will use a simple TM1637 display that suits it. We need two pins to control it, and we need another pin for an analogue measurement. This is the pin 7 on which this analog input is located. You see, according to the schematic, that one potentiometer will be sufficient for the basic measurement. The TM1637 display was described in the article ATtiny85 and the TM1637 display. I wrote two examples.
Example does not need a comment. The measured analog value is displayed with the function showNumberDec
. The measured value is in the range 0-1023.
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 4
#define DIO 3
int adc1 = 0;
TM1637Display display(CLK, DIO);
void setup() {
display.setBrightness(0x02);
}
void loop() {
adc1 = analogRead(1);
display.showNumberDec(adc1, false);
delay(200);
}
When converting the measured value to volts, we must work in an integer arithmetic because the display actually shows a number in the range 0-9999. And the decimal point is just specified with the function showNumberDecEx
in the second parameter. To achieve integer arithmetic, multiply the result by 100.
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 4
#define DIO 3
long adc1 = 0;
TM1637Display display(CLK, DIO);
void setup() {
display.setBrightness(0x02);
}
void loop() {
// ADC = ADC1 * 5 V / 1023 (0-5 V)
// ADC = ADC * 100 {2 decimal places)
adc1 = analogRead(1) * 500L / 1023;
// value, decimal dot, no leading zeros
display.showNumberDecEx(adc1, 0b01000000, false);
delay(200);
}
The source code is located on the GitHub server.
The video is located on YouTube.
26.12.2018