mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-16 19:00:57 +01:00
got it to work with sleep, vcc, bme measurement and radio out
This commit is contained in:
79
841-tinycore-micronucleus-blink/Blink.ino
Normal file
79
841-tinycore-micronucleus-blink/Blink.ino
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/* -*-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
|
||||||
|
https://raw.githubusercontent.com/SpenceKonde/ATTinyCore/master/avr/extras/ATtiny_x41.png
|
||||||
|
Caution: reverse Pinout: PA3 => Pin 3
|
||||||
|
|
||||||
|
Nanite841 Pinout from above (ARDUINO pins in the middle):
|
||||||
|
|
||||||
|
button
|
||||||
|
SDO/MISO PA5 5/5 4/6 PA6 SDI/MOSI
|
||||||
|
SCK PA4 4/6 3/7 PA7
|
||||||
|
CS PA3 3/7 2/8 PB2
|
||||||
|
RX0 PA2 8/2 11/11 PB3
|
||||||
|
TX0 PA1 1/9 9/1 PB1
|
||||||
|
PA0 0/10 10/0 PB0
|
||||||
|
GND VCC
|
||||||
|
usb
|
||||||
|
|
||||||
|
attiny841 pins => Arduino layout
|
||||||
|
|
||||||
|
TOCC0 OC0B pin 9 / PA1 - 841 pin 12 disabled
|
||||||
|
TOCC1 OC0A pin 8 / PA2 - 841 pin 11 disabled
|
||||||
|
TOCC2 OC1B pin 7 / PA3 - 841 pin 10
|
||||||
|
TOCC3 OC0A pin 6 / PA4 - 841 pin 9
|
||||||
|
TOCC4 OC0B pin 5 / PA5 - 841 pin 8
|
||||||
|
TOCC5 OC1A pin 4 / PA6 - 841 pin 7
|
||||||
|
TOCC6 OC2B pin 3 / PA7 - 841 pin 6
|
||||||
|
TOCC7 OC2A pin 2 / PB2 - 841 pin 5
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#define LED 10 // PB2
|
||||||
|
|
||||||
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
||||||
|
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
||||||
|
#define SET_LOW(pin) PORTB &= ~(1 << pin)
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
uint8_t i = 0;
|
||||||
|
SET_OUTPUT(LED);
|
||||||
|
for (i=0; i<11; i++) {
|
||||||
|
pinMode(i, OUTPUT);
|
||||||
|
}
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("init");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop_ard() {
|
||||||
|
uint8_t i = 0;
|
||||||
|
for (i=0; i<11; i++) {
|
||||||
|
Serial.print("Turning on pin: ");
|
||||||
|
Serial.println(i);
|
||||||
|
digitalWrite(i, HIGH);
|
||||||
|
delay(1000);
|
||||||
|
digitalWrite(i, LOW);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop_man() {
|
||||||
|
SET_HIGH(LED);
|
||||||
|
delay(1000);
|
||||||
|
SET_LOW(LED);
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
loop_man();
|
||||||
|
}
|
||||||
56
841-tinycore-micronucleus-blink/Makefile
Normal file
56
841-tinycore-micronucleus-blink/Makefile
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# 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/bin/avrdude
|
||||||
|
ARDUINO_LIBS =
|
||||||
|
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)
|
||||||
|
|
||||||
|
console:
|
||||||
|
screen /dev/ttyUSB0 115200
|
||||||
1
841-tinycore-micronucleus-blink/hardware
Symbolic link
1
841-tinycore-micronucleus-blink/hardware
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware
|
||||||
@@ -41,7 +41,7 @@ MNINST = sudo micronucleus
|
|||||||
# compiler stuff
|
# compiler stuff
|
||||||
CFLAGS_STD = -std=gnu11
|
CFLAGS_STD = -std=gnu11
|
||||||
CXXFLAGS_STD = -std=gnu++11
|
CXXFLAGS_STD = -std=gnu++11
|
||||||
CXXFLAGS + = -pedantic -Wall -Wextra
|
CXXFLAGS += -pedantic -Wall -Wextra
|
||||||
CURRENT_DIR = $(shell pwd)
|
CURRENT_DIR = $(shell pwd)
|
||||||
|
|
||||||
# keep this!
|
# keep this!
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ ARDUINO_DIR = /usr/local/arduino
|
|||||||
ARDMK_DIR = /usr/local/arduino/Arduino-Makefile
|
ARDMK_DIR = /usr/local/arduino/Arduino-Makefile
|
||||||
MONITOR_PORT = /dev/ttyACM0
|
MONITOR_PORT = /dev/ttyACM0
|
||||||
ISP_PORT = /dev/ttyACM0
|
ISP_PORT = /dev/ttyACM0
|
||||||
AVRDUDE = /usr/local/bin/avrdude
|
AVRDUDE = /usr/bin/avrdude
|
||||||
ARDUINO_LIBS = SPI TinyBME280 RFTransmitter
|
ARDUINO_LIBS = SPI TinyBME280 RFTransmitter
|
||||||
ARDUINO_SKETCHBOOK = .
|
ARDUINO_SKETCHBOOK = .
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ MNINST = sudo micronucleus
|
|||||||
# compiler stuff
|
# compiler stuff
|
||||||
CFLAGS_STD = -std=gnu11
|
CFLAGS_STD = -std=gnu11
|
||||||
CXXFLAGS_STD = -std=gnu++11
|
CXXFLAGS_STD = -std=gnu++11
|
||||||
CXXFLAGS + = -pedantic -Wall -Wextra
|
CXXFLAGS += -pedantic -Wall -Wextra
|
||||||
CURRENT_DIR = $(shell pwd)
|
CURRENT_DIR = $(shell pwd)
|
||||||
|
|
||||||
# keep this!
|
# keep this!
|
||||||
@@ -51,3 +51,6 @@ include $(ARDMK_DIR)/Arduino.mk
|
|||||||
install: $(TARGET_HEX) verify_size
|
install: $(TARGET_HEX) verify_size
|
||||||
@echo "########### Press RESET on the Nanite! ##############"
|
@echo "########### Press RESET on the Nanite! ##############"
|
||||||
$(MNINST) $(TARGET_HEX)
|
$(MNINST) $(TARGET_HEX)
|
||||||
|
|
||||||
|
console:
|
||||||
|
screen /dev/ttyUSB0 115200
|
||||||
|
|||||||
@@ -6,19 +6,31 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
./hardware/ATTinyCore/avr/cores/tinymodern/core_pins.h
|
./hardware/ATTinyCore/avr/cores/tinymodern/core_pins.h
|
||||||
|
https://raw.githubusercontent.com/SpenceKonde/ATTinyCore/master/avr/extras/ATtiny_x41.png
|
||||||
Caution: reverse Pinout: PA3 => Pin 3
|
Caution: reverse Pinout: PA3 => Pin 3
|
||||||
|
|
||||||
Nanite841 Pinout from above:
|
Nanite841 Pinout from above (ARDUINO pins in the middle):
|
||||||
|
|
||||||
button
|
button
|
||||||
SDO/MISO PA5 PA6 SDI/MOSI
|
SDO/MISO PA5 5/5 4/6 PA6 SDI/MOSI
|
||||||
SCK PA4 PA7
|
SCK PA4 4/6 3/7 PA7
|
||||||
CS PA3 PB2
|
CS PA3 3/7 2/8 PB2
|
||||||
RX0 PA2 PB2
|
RX0 PA2 8/2 11/11 PB3
|
||||||
TX0 PA1 PB1
|
TX0 PA1 1/9 9/1 PB1
|
||||||
PA0 PB0
|
PA0 0/10 10/0 PB0
|
||||||
GND VCC
|
GND VCC
|
||||||
usb
|
usb
|
||||||
|
|
||||||
|
attiny841 pins => Arduino layout
|
||||||
|
|
||||||
|
TOCC0 OC0B pin 9 / PA1 - 841 pin 12 disabled
|
||||||
|
TOCC1 OC0A pin 8 / PA2 - 841 pin 11 disabled
|
||||||
|
TOCC2 OC1B pin 7 / PA3 - 841 pin 10
|
||||||
|
TOCC3 OC0A pin 6 / PA4 - 841 pin 9
|
||||||
|
TOCC4 OC0B pin 5 / PA5 - 841 pin 8
|
||||||
|
TOCC5 OC1A pin 4 / PA6 - 841 pin 7
|
||||||
|
TOCC6 OC2B pin 3 / PA7 - 841 pin 6
|
||||||
|
TOCC7 OC2A pin 2 / PB2 - 841 pin 5
|
||||||
|
|
||||||
Bosch BME280 Breakout from above pin header left:
|
Bosch BME280 Breakout from above pin header left:
|
||||||
|
|
||||||
@@ -44,19 +56,19 @@ SDO/MISO PA5 PA6 SDI/MOSI
|
|||||||
#include <RFTransmitter.h>
|
#include <RFTransmitter.h>
|
||||||
|
|
||||||
#define NODE_ID 1
|
#define NODE_ID 1
|
||||||
#define OUTPUT_PIN 7
|
#define SENDER_PIN 10 // == PB0 // ARDUINO PIN#
|
||||||
#define LED 2 //LED_BUILTIN // PORTB2
|
#define LED 2 // LED_BUILTIN // PORTB2
|
||||||
#define CS 3
|
#define CS 3
|
||||||
#define DELAY 5000
|
#define DELAY 5000
|
||||||
#define WDTREPEATS 3
|
#define WDTREPEATS 3
|
||||||
|
|
||||||
static tiny::BME280 sensor;
|
static tiny::BME280 sensor;
|
||||||
RFTransmitter transmitter(OUTPUT_PIN, NODE_ID);
|
RFTransmitter transmitter(SENDER_PIN, NODE_ID);
|
||||||
const long InternalReferenceVoltage = 1083L;
|
const long InternalReferenceVoltage = 1083L;
|
||||||
|
|
||||||
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
||||||
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
#define SET_LOW(pin) PORTB |= (1 << pin)
|
||||||
#define SET_LOW(pin) PORTB &= ~(1 << pin)
|
#define SET_HIGH(pin) PORTB &= ~(1 << pin)
|
||||||
|
|
||||||
typedef struct _measurements_t {
|
typedef struct _measurements_t {
|
||||||
uint32_t pres;
|
uint32_t pres;
|
||||||
@@ -80,13 +92,16 @@ void print_asifloat(int32_t val, uint16_t factor) {
|
|||||||
void print_measurements() {
|
void print_measurements() {
|
||||||
measurements_t ms;
|
measurements_t ms;
|
||||||
byte sendms[sizeof(measurements_t)];
|
byte sendms[sizeof(measurements_t)];
|
||||||
|
|
||||||
|
Serial.println("-- Enter Measure");
|
||||||
SET_LOW(LED);
|
SET_LOW(LED);
|
||||||
|
|
||||||
|
Serial.println("-- Read measurementes");
|
||||||
ms.temp = sensor.readFixedTempC();
|
ms.temp = sensor.readFixedTempC();
|
||||||
ms.humidity = sensor.readFixedHumidity();
|
ms.humidity = sensor.readFixedHumidity();
|
||||||
ms.pres = sensor.readFixedPressure();
|
ms.pres = sensor.readFixedPressure();
|
||||||
|
|
||||||
|
Serial.println("-- Read VCC");
|
||||||
adc_enable();
|
adc_enable();
|
||||||
adc_start();
|
adc_start();
|
||||||
ms.vcc = adc_get_adcw();
|
ms.vcc = adc_get_adcw();
|
||||||
@@ -140,17 +155,33 @@ void setup() {
|
|||||||
sleep_setup();
|
sleep_setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop_nosleep() {
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
print_measurements();
|
print_measurements();
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop_sleep() {
|
||||||
|
uint8_t i;
|
||||||
|
Serial.println("-- ENTER LOOP");
|
||||||
|
|
||||||
|
print_measurements();
|
||||||
|
//delay(DELAY);
|
||||||
|
|
||||||
for(i=0; i<WDTREPEATS; i++) {
|
for(i=0; i<WDTREPEATS; i++) {
|
||||||
delay(DELAY);
|
delay(DELAY);
|
||||||
Serial.print("----- ENTER SLEEP: ");
|
Serial.print("----- ENTER SLEEP: ");
|
||||||
Serial.println(i);
|
Serial.println(i);
|
||||||
sleep_enter();
|
sleep_enter_keep_spi();
|
||||||
Serial.println("----- LEAVE SLEEP");
|
Serial.println("----- LEAVE SLEEP");
|
||||||
}
|
}
|
||||||
Serial.println("-- DONE");
|
Serial.println("-- AWAKE");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
loop_sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep_vect();
|
sleep_vect();
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ MNINST = sudo micronucleus
|
|||||||
# compiler stuff
|
# compiler stuff
|
||||||
CFLAGS_STD = -std=gnu11
|
CFLAGS_STD = -std=gnu11
|
||||||
CXXFLAGS_STD = -std=gnu++11
|
CXXFLAGS_STD = -std=gnu++11
|
||||||
CXXFLAGS + = -pedantic -Wall -Wextra
|
CXXFLAGS += -pedantic -Wall -Wextra
|
||||||
CURRENT_DIR = $(shell pwd)
|
CURRENT_DIR = $(shell pwd)
|
||||||
|
|
||||||
# keep this!
|
# keep this!
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ SDO/MISO PA5 PA6 SDI/MOSI
|
|||||||
#define LED 2 //LED_BUILTIN // PORTB2
|
#define LED 2 //LED_BUILTIN // PORTB2
|
||||||
#define CS 3
|
#define CS 3
|
||||||
#define DELAY 5000
|
#define DELAY 5000
|
||||||
#define WDTREPEATS 10
|
#define WDTREPEATS 10 // results in 8s x 10 times == 80 seconds sleep
|
||||||
|
|
||||||
#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)
|
||||||
|
|||||||
@@ -55,6 +55,21 @@
|
|||||||
delay(10); \
|
delay(10); \
|
||||||
SPCR = (1<<SPE)
|
SPCR = (1<<SPE)
|
||||||
|
|
||||||
|
// go into sleep mode, keep SPI running
|
||||||
|
// disable ADC
|
||||||
|
// wait a little for the last serial out (if any) to flush
|
||||||
|
// set all bits in power reduction register to one (shutdown everything)
|
||||||
|
// actually sleep
|
||||||
|
// wake up after WDT timeout
|
||||||
|
// wait a little
|
||||||
|
#define sleep_enter_keep_spi() \
|
||||||
|
adc_disable(); \
|
||||||
|
delay(10); \
|
||||||
|
PRR = 0xFF; \
|
||||||
|
sleep_mode(); \
|
||||||
|
PRR = 0x00; \
|
||||||
|
delay(10);
|
||||||
|
|
||||||
// nothing extra to do on wake up, just wake up
|
// nothing extra to do on wake up, just wake up
|
||||||
#define sleep_vect() ISR(WDT_vect){}
|
#define sleep_vect() ISR(WDT_vect){}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user