Geralmente, para passar de uma ideia para uma implementação, é necessário um protótipo do dispositivo, conveniente para verificar e depurar no local, o que é especialmente importante para um dispositivo móvel. A seguir, tentarei analisar em detalhes o processo de criação de um protótipo de um sensor sem fio baseado no ATtiny85.

— , , : , , . CR2032, , 2.7V ( TMP36), 200mAh.
ATtiny85 5 / RESET . :
- 3 — NRF24L01+, , 3- ;
- 1 — BPW17N;
- 2 — TMP36, , .
, .
RESET /
RESET /. RESET , (Fuses). , RESET . , «» (12V) , Fuse-.
Arduino ATTiny Fuse Reset with 12 Volt Charge Pump. , 12V (Charge Pump).
, .
(4) 5V, (2) (), C1 5V. (2) 5V 1 10V, D2, (3), C2. (3) (2) 15V C3, 20V ( ~17V) C4. R2/R3 A0, , 12V, ( (2) (3)) . Q1 . ATtiny85 .
:


( )
, USB , , . , , :

, .
KiCad EDA, .
KiCad GitHub, attwlight_sensor.pcb.
, YouTube KiCAD Quick-Start Tutorial.
, KiCad
, :
,
,
.
, . .
. Ctrl+E ( ) :
,
,
.
, Preferences → Component Libraries, Add . ,
.
:

, . , . , . , , , .
TMP36
PB5 . VCC D10 P2. RESET RESET. ADC2.
C1, RESET . , RESET , , , . , , , — . , D1 SCK, , SCK , . C1 , , 5V. 1.8-5.5V 3V . TMP36 10nF , . .
NRF24L01+
KiCad , NRF24L01+. 3 MISO MOSI, , : R3, D1 C2. nRF24L01+ with ATtiny85 3 Pins.
, CE (chip enable) , CSN (chip select) , . , CSN , SCK (clock). SCK C2 CSN , SCK , CSN. MISO MOSI , .
1-10μF , C4.
, ATtiny85 . , avrdude , … . , - - . . , .
ATtiny85
8MHz, . , 30cm, , , , - . , , , . , . ATtiny85 1MHz , . .
BPW17N
, , . PCINT3 (Pin Change Interrupt).
R1 C3 , , . 3 Q1 , . , 0.1μF, 10MΩ , — . , / R2, , .
, , , . , , 7μA 260μA . , , (PCINT3 WDT), ADC3, , PCINT3. , .
. KiCad. :
, .
. :

.
, 1/10" (2.54mm). , , , , (Ctrl+E) .
.
- netlist
, .
.
, netlist (Read Current Netlist), , . , netlist .
netlist . 1/10" (2.54mm), ( m), Visibles → Render → Values , , .
:

, . KiCad , . , : Visibles → Render → Footprints Front, .

:

: R1,C3 .

, . , , .
IDE
Arduino IDE AVR .
, Arduino IDE ATtiny85, . , Programming an ATtiny w/ Arduino 1.6. ATtiny85 Arduino . , , — , .
Arduino ATtiny85, arduino-tiny, Arduino 1.5 . , , , , . , , Arduino IDE v1.6.6 - , c 1.6.5.
Arduino IDE v1.6.5- Arduino hardware;
- arduino-tiny-0150-0020.zip ;
- «Prospective Boards.txt» boards.txt , , ATtiny85, ;
- Arudino IDE Tools → Board .
. , Arduino File → Examples → ArduinoISP, , , 10μF, RST GND Arduino.

. Tools → Board , : ATtiny85 @ 1 MHz (internal oscillator; BOD disabled), Tools → Port USB Tools → Programmer , : Arduino as ISP, Upload.
, , :
- NRF24L01+;
- ;
- ;
- WDT (WatchDog Timer);
- Pin Change PCINT;
- .
:
NRF24L01+, ATtiny85. libraries Arduino.
. GitHub attwlight_sensor, attwlight_rx .
void sleep() void loop() PCINIT3 WDT. .
, . ATtiny85 datasheet «23. Register Summary», .
#include <avr/wdt.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define WDTO_INFINITE 255
#define SLEEP_PERIOD WDTO_8S
#define SKIP_WDT_WAKEUPS 14
ISR(PCINT0_vect)
{
light_pcint = true;
}
ISR(WDT_vect)
{
wakeup_counter++;
}
void sleep()
{
GIMSK = _BV(PCIE);
if (SLEEP_PERIOD == WDTO_INFINITE || payload.light != LIGHT_FUZZY)
PCMSK |= _BV(LIGHT_PIN);
ADCSRA &= ~_BV(ADEN);
if (SLEEP_PERIOD != WDTO_INFINITE) {
wdt_enable(SLEEP_PERIOD);
WDTCR |= _BV(WDIE);
}
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sei();
sleep_cpu();
cli();
PCMSK &= ~_BV(LIGHT_PIN);
sleep_disable();
ADCSRA |= _BV(ADEN);
sei();
}
« ». , , 20μA.
#define FUZZY_VOLTAGE 0.4
const unsigned int fuzzy_start = int(1024.0 * (1.0 - FUZZY_VOLTAGE) / 2.0);
const unsigned int fuzzy_stop = 1023 - fuzzy_start;
light_t readLightStatus(unsigned int ms)
{
delay(ms);
int input = analogRead(LIGHT_PIN);
if (input >= fuzzy_start && input <= fuzzy_stop)
return LIGHT_FUZZY;
if (input < fuzzy_start)
return LIGHT_OFF;
if (input > fuzzy_stop)
return LIGHT_ON;
return LIGHT_UNKNOWN;
}
AREF , , . , , . .
, Vbg (Bandgap reference voltage) 1.1V. Vbg 1.0-1.2V, 1125300.
long readVcc()
{
ADMUX = _BV(MUX3) | _BV(MUX2);
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA, ADSC));
uint8_t low = ADCL;
uint8_t high = ADCH;
long result = (high << 8) | low;
result = 1125300L / result;
return result;
}
, .
float readTmp36(long vcc)
{
int input = analogRead(TMP36_PIN);
float refVolts = float(vcc) / 1000.0;
float voltage = float(input) * refVolts / 1024.0;
float temperatureC = (voltage - 0.5) * 100.0;
return temperatureC;
}
, , . , , , , .
, , 8KiB :
Sketch uses 7,120 bytes (86%) of program storage space. Maximum is 8,192 bytes.
Global variables use 227 bytes (44%) of dynamic memory, leaving 285 bytes for local variables. Maximum is 512 bytes.
, , Fuses RESET /. Arduino IDE , :
avrdude -c stk500v1 -p attiny85 -P /dev/ttyUSB0 -v -C /etc/avrdude.conf -b 19200 -U lfuse:w:0x62:m -U hfuse:w:0x5f:m -U efuse:w:0xff:m
- avrdude — Arduino IDE hardware/tools/avr/bin/;
- /dev/ttyUSB0 — ;
- /etc/avrdude.conf — Arduino IDE hardware/tools/avr/etc/avrdude.conf.
Fuses, Engbedded Atmel AVR® Fuse Calculator.
, : 8 ( 1MHz); , ; BOD (Brown-out Detector) — ; ; RESET.

. : 120sec, , ; ; 200mAh.
| 1MHz | 8MHz |
---|
() | 15.7mA | 18.3mA |
() | 1.1mA | 4.3mA |
() | 7μA | 7μA |
( ) | 51ms | 16ms |
( ) | 15ms | 4ms |
() | 513 | 739 |
, . , 8MHz . , .
GitHub