mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-16 19:00:57 +01:00
add
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
../mylibs/841sleep.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../mylibs/841vcc.h
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
||||||
|
|
||||||
|
# attiny841:
|
||||||
|
# BOARD_TAG = attinyx41
|
||||||
|
# BOARD_SUB = 841
|
||||||
|
# attiny861:
|
||||||
|
# BOARD_TAG = attinyx61
|
||||||
|
# BOARD_SUB = 861
|
||||||
|
# attiny85:
|
||||||
|
# BOARD_TAG = attinyx5
|
||||||
|
# BOARD_SUB = 85
|
||||||
|
# attiny84:
|
||||||
|
# BOARD_TAG = attinyx4
|
||||||
|
# BOARD_SUB = 84
|
||||||
|
|
||||||
|
ARDUINO_VERSION = 10810
|
||||||
|
|
||||||
|
PROJECT_DIR = $(shell pwd)
|
||||||
|
BOARD_TAG = attinyx41
|
||||||
|
BOARD_SUB = 841
|
||||||
|
ARDUINO_DIR = /usr/local/arduino
|
||||||
|
ARDMK_DIR = /usr/local/arduino/Arduino-Makefile
|
||||||
|
MONITOR_PORT = /dev/ttyACM0
|
||||||
|
ISP_PORT = /dev/ttyACM0
|
||||||
|
AVRDUDE = /usr/local/bin/avrdude
|
||||||
|
ARDUINO_LIBS = SPI TinyBME280 RFTransmitter
|
||||||
|
ARDUINO_SKETCHBOOK = .
|
||||||
|
|
||||||
|
# mk stuff
|
||||||
|
ALTERNATE_CORE = ATTinyCore
|
||||||
|
F_CPU = 8000000L
|
||||||
|
MONITOR_BAUDRATE = 115200
|
||||||
|
AVRDUDE_ARD_PROGRAMMER = stk500v2
|
||||||
|
AVRDUDE_ARD_BAUDRATE = 9600
|
||||||
|
AVR_TOOLS_DIR = /usr/local/avr
|
||||||
|
AVRDUDE_CONF = /usr/local/etc/avrdude.conf
|
||||||
|
|
||||||
|
# Micronucleus
|
||||||
|
MNINST = sudo micronucleus
|
||||||
|
|
||||||
|
# compiler stuff
|
||||||
|
CFLAGS_STD = -std=gnu11
|
||||||
|
CXXFLAGS_STD = -std=gnu++11
|
||||||
|
CXXFLAGS + = -pedantic -Wall -Wextra
|
||||||
|
CURRENT_DIR = $(shell pwd)
|
||||||
|
|
||||||
|
# keep this!
|
||||||
|
include $(ARDMK_DIR)/Arduino.mk
|
||||||
|
|
||||||
|
# install using micronucleus
|
||||||
|
install: $(TARGET_HEX) verify_size
|
||||||
|
@echo "########### Press RESET on the Nanite! ##############"
|
||||||
|
$(MNINST) $(TARGET_HEX)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Usable Pins
|
||||||
|
|
||||||
|
```
|
||||||
|
PIN_A0 (10)
|
||||||
|
PIN_A1 ( 9)
|
||||||
|
PIN_A2 ( 8)
|
||||||
|
PIN_A3 ( 7)
|
||||||
|
PIN_A4 ( 6)
|
||||||
|
PIN_A5 ( 5)
|
||||||
|
PIN_A6 ( 4)
|
||||||
|
PIN_A7 ( 3)
|
||||||
|
PIN_B0 ( 0)
|
||||||
|
PIN_B1 ( 1)
|
||||||
|
PIN_B2 ( 2)
|
||||||
|
PIN_B3 (11) /* RESET */
|
||||||
|
LED_BUILTIN (2)
|
||||||
|
```
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
/* -*-c++-*-
|
||||||
|
Blink
|
||||||
|
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||||
|
This example code is in the public domain.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
./hardware/ATTinyCore/avr/cores/tinymodern/core_pins.h
|
||||||
|
Caution: reverse Pinout: PA3 => Pin 3
|
||||||
|
|
||||||
|
Nanite841 Pinout from above:
|
||||||
|
|
||||||
|
button
|
||||||
|
SDO/MISO PA5 PA6 SDI/MOSI
|
||||||
|
SCK PA4 PA7
|
||||||
|
CS PA3 PB2
|
||||||
|
RX0 PA2 PB2
|
||||||
|
TX0 PA1 PB1
|
||||||
|
PA0 PB0
|
||||||
|
GND VCC
|
||||||
|
usb
|
||||||
|
|
||||||
|
Bosch BME280 Breakout from above pin header left:
|
||||||
|
|
||||||
|
VCC
|
||||||
|
GND
|
||||||
|
SCL => SCK
|
||||||
|
SDI => MOSI
|
||||||
|
CSB => PA3/3
|
||||||
|
SDO => MISO
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include "841vcc.h"
|
||||||
|
#include "841sleep.h"
|
||||||
|
#include "data2wire.h"
|
||||||
|
|
||||||
|
#define TINY_BME280_SPI
|
||||||
|
#include <TinyBME280.h>
|
||||||
|
|
||||||
|
// https://andreasrohner.at/posts/Electronics/New-Arduino-library-for-433-Mhz-AM-Radio-Modules/
|
||||||
|
#include <RFTransmitter.h>
|
||||||
|
|
||||||
|
#define NODE_ID 1
|
||||||
|
#define OUTPUT_PIN 7
|
||||||
|
#define LED 2 //LED_BUILTIN // PORTB2
|
||||||
|
#define CS 3
|
||||||
|
#define DELAY 5000
|
||||||
|
#define WDTREPEATS 3
|
||||||
|
|
||||||
|
static tiny::BME280 sensor;
|
||||||
|
RFTransmitter transmitter(OUTPUT_PIN, NODE_ID);
|
||||||
|
const long InternalReferenceVoltage = 1083L;
|
||||||
|
|
||||||
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
||||||
|
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
||||||
|
#define SET_LOW(pin) PORTB &= ~(1 << pin)
|
||||||
|
|
||||||
|
typedef struct _measurements_t {
|
||||||
|
uint32_t pres;
|
||||||
|
uint32_t humidity;
|
||||||
|
int32_t temp;
|
||||||
|
uint16_t vcc;
|
||||||
|
} measurements_t;
|
||||||
|
|
||||||
|
void print_asufloat(uint32_t val, uint16_t factor) {
|
||||||
|
Serial.print(val / factor);
|
||||||
|
Serial.print(".");
|
||||||
|
Serial.print(val % factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_asifloat(int32_t val, uint16_t factor) {
|
||||||
|
Serial.print(val / factor);
|
||||||
|
Serial.print(".");
|
||||||
|
Serial.print(val % factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_measurements() {
|
||||||
|
measurements_t ms;
|
||||||
|
byte sendms[sizeof(measurements_t)];
|
||||||
|
|
||||||
|
SET_LOW(LED);
|
||||||
|
|
||||||
|
ms.temp = sensor.readFixedTempC();
|
||||||
|
ms.humidity = sensor.readFixedHumidity();
|
||||||
|
ms.pres = sensor.readFixedPressure();
|
||||||
|
|
||||||
|
adc_enable();
|
||||||
|
adc_start();
|
||||||
|
ms.vcc = adc_get_adcw();
|
||||||
|
adc_disable();
|
||||||
|
|
||||||
|
Serial.print("Voltage: ");
|
||||||
|
Serial.println(ms.vcc);
|
||||||
|
|
||||||
|
Serial.print(" Temperature: ");
|
||||||
|
print_asifloat(ms.temp, 100);
|
||||||
|
Serial.println(" Grad C");
|
||||||
|
|
||||||
|
Serial.print(" Pressure: ");
|
||||||
|
print_asufloat(ms.pres, 100);
|
||||||
|
Serial.println(" hPa");
|
||||||
|
|
||||||
|
Serial.print(" Humidity: ");
|
||||||
|
print_asufloat(ms.humidity, 1000);
|
||||||
|
Serial.println(" %");
|
||||||
|
|
||||||
|
data32_to_wire(ms.pres, &sendms[0]);
|
||||||
|
data32_to_wire(ms.humidity, &sendms[sizeof(ms.humidity) + 1]);
|
||||||
|
data32_to_wire(ms.temp, &sendms[sizeof(ms.temp) + 1]);
|
||||||
|
data16_to_wire(ms.vcc, &sendms[sizeof(ms.vcc) + 1]);
|
||||||
|
|
||||||
|
transmitter.send((byte *)sendms, sizeof(sendms));
|
||||||
|
|
||||||
|
SET_HIGH(LED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void halt() {
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
SET_OUTPUT(LED);
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("init");
|
||||||
|
|
||||||
|
delay(4000);
|
||||||
|
|
||||||
|
adc_setup_vcc_measurement();
|
||||||
|
|
||||||
|
if(sensor.beginSPI(CS) == false) {
|
||||||
|
Serial.println("Sensor BME280 connect failed, check wiring!");
|
||||||
|
halt();
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep_setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
uint8_t i;
|
||||||
|
print_measurements();
|
||||||
|
for(i=0; i<WDTREPEATS; i++) {
|
||||||
|
delay(DELAY);
|
||||||
|
Serial.print("----- ENTER SLEEP: ");
|
||||||
|
Serial.println(i);
|
||||||
|
sleep_enter();
|
||||||
|
Serial.println("----- LEAVE SLEEP");
|
||||||
|
}
|
||||||
|
Serial.println("-- DONE");
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep_vect();
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../mylibs/data2wire.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware/ATTinyCore/avr/libraries/RFTransmitter
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware/ATTinyCore/avr/libraries/SPI
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware/ATTinyCore/avr/libraries/TinyBME280
|
||||||
@@ -40,8 +40,8 @@ SDO/MISO PA5 PA6 SDI/MOSI
|
|||||||
#define OUTPUT_PIN 7
|
#define OUTPUT_PIN 7
|
||||||
#define LED 2 //LED_BUILTIN // PORTB2
|
#define LED 2 //LED_BUILTIN // PORTB2
|
||||||
#define CS 3
|
#define CS 3
|
||||||
#define DELAY 1000
|
#define DELAY 5000
|
||||||
#define WDTREPEATS 3
|
#define WDTREPEATS 10
|
||||||
|
|
||||||
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
||||||
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
||||||
@@ -84,7 +84,7 @@ void setup() {
|
|||||||
SET_OUTPUT(LED);
|
SET_OUTPUT(LED);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("init");
|
Serial.println("init");
|
||||||
|
delay(4000);
|
||||||
adc_setup_vcc_measurement();
|
adc_setup_vcc_measurement();
|
||||||
sleep_setup();
|
sleep_setup();
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,8 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
print_measurements();
|
print_measurements();
|
||||||
delay(DELAY);
|
Serial.println("delay...");
|
||||||
|
delay(10000);
|
||||||
for(i=0; i<WDTREPEATS; i++) {
|
for(i=0; i<WDTREPEATS; i++) {
|
||||||
Serial.print("----- ENTER SLEEP: ");
|
Serial.print("----- ENTER SLEEP: ");
|
||||||
Serial.println(i);
|
Serial.println(i);
|
||||||
|
|||||||
@@ -33,21 +33,26 @@
|
|||||||
ACSR1A |= _BV(ACD1); \
|
ACSR1A |= _BV(ACD1); \
|
||||||
CCP = 0xD8; \
|
CCP = 0xD8; \
|
||||||
WDTCSR = _BV(WDIE) | SLEEP_DURATION_BITS; \
|
WDTCSR = _BV(WDIE) | SLEEP_DURATION_BITS; \
|
||||||
CCP = 0xD8; \
|
|
||||||
CLKPR = (_BV(CLKPS0) | _BV(CLKPS1));
|
CLKPR = (_BV(CLKPS0) | _BV(CLKPS1));
|
||||||
|
|
||||||
// FIXME: check!
|
|
||||||
// PRR = 0xFF;
|
|
||||||
|
|
||||||
|
// go into sleep mode
|
||||||
// go into sleep mode and wake up after wtd timeout
|
// disable ADC
|
||||||
// also disable SPI
|
// wait a little for the last serial out (if any) to flush
|
||||||
|
// disable SPI
|
||||||
|
// set all bits in power reduction register to one (shutdown everything)
|
||||||
|
// actually sleep
|
||||||
|
// wake up after WDT timeout
|
||||||
|
// wait a little
|
||||||
|
// re-enable SPI
|
||||||
#define sleep_enter() \
|
#define sleep_enter() \
|
||||||
adc_disable(); \
|
adc_disable(); \
|
||||||
|
delay(10); \
|
||||||
SPCR &= ~_BV(SPE); \
|
SPCR &= ~_BV(SPE); \
|
||||||
sleep_enable(); \
|
PRR = 0xFF; \
|
||||||
sleep_mode(); \
|
sleep_mode(); \
|
||||||
sleep_disable(); \
|
PRR = 0x00; \
|
||||||
|
delay(10); \
|
||||||
SPCR = (1<<SPE)
|
SPCR = (1<<SPE)
|
||||||
|
|
||||||
// nothing extra to do on wake up, just wake up
|
// nothing extra to do on wake up, just wake up
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#define VCC_8441_H
|
#define VCC_8441_H
|
||||||
|
|
||||||
// disable ADC globally
|
// disable ADC globally
|
||||||
#define adc_disable() ADCSRA &= ~(1<<ADEN)
|
#define adc_disable() ADCSRA &= ~(1<<ADEN);
|
||||||
|
|
||||||
// enable
|
// enable
|
||||||
#define adc_enable() ADCSRA = (1<<ADEN); _delay_ms(10);
|
#define adc_enable() ADCSRA = (1<<ADEN); _delay_ms(10);
|
||||||
@@ -39,9 +39,14 @@
|
|||||||
ADCSRA |= _BV( ADSC ); \
|
ADCSRA |= _BV( ADSC ); \
|
||||||
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
|
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
|
||||||
|
|
||||||
// return measured voltage
|
/* return measured voltage, adc value between 1-1023
|
||||||
// >> 1.1 * 1024 / 225 #=> 5.006222222222223
|
Calculate like:
|
||||||
// >> 1.1 * 1024 / 341 #=> 3.3032258064516133
|
|
||||||
|
>> 1.1 * 1024 / 225 #=> 5.006222222222223
|
||||||
|
>> 1.1 * 1024 / 341 #=> 3.3032258064516133
|
||||||
|
*/
|
||||||
|
#define adc_get_adcw() ADCW;
|
||||||
|
|
||||||
#define adc_get_vcc() 1.1 * 1024 / ADCW;
|
#define adc_get_vcc() 1.1 * 1024 / ADCW;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
70
mylibs/data2wire.h
Normal file
70
mylibs/data2wire.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
from PCP pcp/libpcp/util.c.
|
||||||
|
|
||||||
|
Convert byte arrays from big endian to numbers and vice versa. Do
|
||||||
|
not take care about host endianess. In Rob Pikes' words:
|
||||||
|
https://commandcenter.blogspot.de/2012/04/byte-order-fallacy.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DATA2WIRE_H
|
||||||
|
#define DATA2WIRE_H
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
|
inline uint64_t wire_to_data64(uint8_t *data) {
|
||||||
|
uint64_t i =
|
||||||
|
((uint64_t)data[7]<<0) |
|
||||||
|
((uint64_t)data[6]<<8) |
|
||||||
|
((uint64_t)data[5]<<16) |
|
||||||
|
((uint64_t)data[4]<<24) |
|
||||||
|
((uint64_t)data[3]<<32) |
|
||||||
|
((uint64_t)data[2]<<40) |
|
||||||
|
((uint64_t)data[1]<<48) |
|
||||||
|
((uint64_t)data[0]<<56);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline uint32_t wire_to_data32(uint8_t *data) {
|
||||||
|
uint32_t i =
|
||||||
|
((uint32_t)data[3]<<0) |
|
||||||
|
((uint32_t)data[2]<<8) |
|
||||||
|
((uint32_t)data[1]<<16) |
|
||||||
|
((uint32_t)data[0]<<24);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint16_t wire_to_data16(uint8_t *data) {
|
||||||
|
uint16_t i =
|
||||||
|
((uint16_t)data[1]<<0) |
|
||||||
|
((uint16_t)data[0]<<8);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void data64_to_wire(uint64_t i, uint8_t *data) {
|
||||||
|
data[0] = (i >> 56) & 0xFF;
|
||||||
|
data[1] = (i >> 48) & 0xFF;
|
||||||
|
data[2] = (i >> 40) & 0xFF;
|
||||||
|
data[3] = (i >> 32) & 0xFF;
|
||||||
|
data[4] = (i >> 24) & 0xFF;
|
||||||
|
data[5] = (i >> 16) & 0xFF;
|
||||||
|
data[6] = (i >> 8) & 0xFF;
|
||||||
|
data[7] = i & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void data32_to_wire(uint32_t i, uint8_t *data) {
|
||||||
|
data[0] = (i >> 24) & 0xFF;
|
||||||
|
data[1] = (i >> 16) & 0xFF;
|
||||||
|
data[2] = (i >> 8) & 0xFF;
|
||||||
|
data[3] = i & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void data16_to_wire(uint16_t i, uint8_t *data) {
|
||||||
|
data[0] = (i >> 8) & 0xFF;
|
||||||
|
data[1] = i & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user