mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-16 19:00:57 +01:00
fixes
This commit is contained in:
@@ -43,7 +43,7 @@ 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 5000
|
#define DELAY 1000
|
||||||
|
|
||||||
static tiny::BME280 sensor;
|
static tiny::BME280 sensor;
|
||||||
RFTransmitter transmitter(OUTPUT_PIN, NODE_ID);
|
RFTransmitter transmitter(OUTPUT_PIN, NODE_ID);
|
||||||
@@ -68,6 +68,7 @@ void print_asifloat(int32_t val, uint16_t factor) {
|
|||||||
void print_measurements() {
|
void print_measurements() {
|
||||||
uint32_t pres, humidity;
|
uint32_t pres, humidity;
|
||||||
int32_t temp;
|
int32_t temp;
|
||||||
|
int vcc;
|
||||||
|
|
||||||
temp = sensor.readFixedTempC();
|
temp = sensor.readFixedTempC();
|
||||||
humidity = sensor.readFixedHumidity();
|
humidity = sensor.readFixedHumidity();
|
||||||
@@ -87,7 +88,19 @@ void print_measurements() {
|
|||||||
print_asufloat(humidity, 1000);
|
print_asufloat(humidity, 1000);
|
||||||
Serial.println(" %");
|
Serial.println(" %");
|
||||||
|
|
||||||
|
|
||||||
|
ADCSRA |= _BV( ADSC );
|
||||||
|
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
|
||||||
|
//vcc = 1.1 * 1024 / ADCW;
|
||||||
|
vcc = 1024 / ADCW;
|
||||||
|
|
||||||
|
// vcc = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L;
|
||||||
|
Serial.print(" Voltage: ");
|
||||||
|
Serial.println(vcc);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
transmitter.send((byte *)temp, sizeof(temp));
|
transmitter.send((byte *)temp, sizeof(temp));
|
||||||
|
|
||||||
SET_HIGH(LED);
|
SET_HIGH(LED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,25 +108,16 @@ void halt() {
|
|||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_voltage() {
|
|
||||||
int value;
|
|
||||||
ADCSRA |= _BV( ADSC );
|
|
||||||
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
|
|
||||||
value = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L;
|
|
||||||
Serial.print(" Voltage: ");
|
|
||||||
Serial.println(value);
|
|
||||||
Serial.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
SET_OUTPUT(LED);
|
SET_OUTPUT(LED);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("init");
|
Serial.println("init");
|
||||||
// Enable ADC
|
// Enable ADC
|
||||||
|
ADMUXB |= (0<<REFS0);
|
||||||
|
ADMUXA |= (13<<MUX0);
|
||||||
|
ADCSRB |= (0<<ADLAR);
|
||||||
ADCSRA |= (1 << ADEN);
|
ADCSRA |= (1 << ADEN);
|
||||||
ADMUXB = (0<<REFS2) | (1<<REFS1) | (0<<REFS0);
|
|
||||||
ADMUXA = (0<<MUX5) | (0<<MUX4) | (0<<MUX3) | (0<<MUX2) | (0<<MUX1) | (1<<MUX0);
|
|
||||||
ADCSRB = (0<<ADLAR);
|
|
||||||
//analogReference( INTERNAL );
|
//analogReference( INTERNAL );
|
||||||
|
|
||||||
if(sensor.beginSPI(CS) == false) {
|
if(sensor.beginSPI(CS) == false) {
|
||||||
@@ -124,7 +128,6 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
print_measurements();
|
print_measurements();
|
||||||
print_voltage();
|
|
||||||
delay(DELAY);
|
delay(DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
53
841-tinycore-micronucleus-vcc-test/Makefile
Normal file
53
841-tinycore-micronucleus-vcc-test/Makefile
Normal file
@@ -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 =
|
||||||
|
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)
|
||||||
17
841-tinycore-micronucleus-vcc-test/README.md
Normal file
17
841-tinycore-micronucleus-vcc-test/README.md
Normal file
@@ -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)
|
||||||
|
```
|
||||||
107
841-tinycore-micronucleus-vcc-test/SensorSerial.ino
Normal file
107
841-tinycore-micronucleus-vcc-test/SensorSerial.ino
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/* -*-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>
|
||||||
|
|
||||||
|
#define NODE_ID 1
|
||||||
|
#define OUTPUT_PIN 7
|
||||||
|
#define LED 2 //LED_BUILTIN // PORTB2
|
||||||
|
#define CS 3
|
||||||
|
#define DELAY 2000
|
||||||
|
|
||||||
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
||||||
|
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
||||||
|
#define SET_LOW(pin) PORTB &= ~(1 << pin)
|
||||||
|
|
||||||
|
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() {
|
||||||
|
float vcc;
|
||||||
|
|
||||||
|
SET_LOW(LED);
|
||||||
|
|
||||||
|
ADCSRA = (1 << ADEN); // enable ADC
|
||||||
|
_delay_ms(10); // give it some time to settle
|
||||||
|
ADCSRA |= _BV( ADSC ); // start measuring
|
||||||
|
while( ( (ADCSRA & (1<<ADSC)) != 0 ) ); // till it's completed
|
||||||
|
// >> 1.1 * 1024 / 225 #=> 5.006222222222223
|
||||||
|
// >> 1.1 * 1024 / 341 #=> 3.3032258064516133
|
||||||
|
vcc = 1.1 * 1024 / ADCW; // read actual measurement
|
||||||
|
// ADCSRA &= ~(1<<ADEN); // we're done, disable ADC
|
||||||
|
|
||||||
|
Serial.print("Voltage: ");
|
||||||
|
Serial.println(vcc);
|
||||||
|
|
||||||
|
SET_HIGH(LED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void halt() {
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
SET_OUTPUT(LED);
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("init");
|
||||||
|
|
||||||
|
// Setup the ADC
|
||||||
|
// https://www.avrfreaks.net/forum/measuring-vcc-attiny841-using-adc-and-internal-bandgap#comment-2862601
|
||||||
|
ADMUXB = (0<<REFS0); // enable REFS0 bit == internal 1.1 bandgap
|
||||||
|
ADMUXA = (13<<MUX0); // use channel #13 to read the bandgap (binary 1101, see table 16-3)
|
||||||
|
ADCSRB = (0<<ADLAR); // do not left shift result
|
||||||
|
|
||||||
|
// disable ADC for powersaving
|
||||||
|
// ADCSRA &= ~(1<<ADEN);
|
||||||
|
|
||||||
|
// disable analog comperators for powersaving
|
||||||
|
ACSR0A |= _BV(ACD0);
|
||||||
|
ACSR1A |= _BV(ACD1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
print_measurements();
|
||||||
|
delay(DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
1
841-tinycore-micronucleus-vcc-test/hardware
Symbolic link
1
841-tinycore-micronucleus-vcc-test/hardware
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware
|
||||||
1
841-tinycore-micronucleus-vcc-test/libraries/RFTransmitter
Symbolic link
1
841-tinycore-micronucleus-vcc-test/libraries/RFTransmitter
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware/ATTinyCore/avr/libraries/RFTransmitter
|
||||||
1
841-tinycore-micronucleus-vcc-test/libraries/SPI
Symbolic link
1
841-tinycore-micronucleus-vcc-test/libraries/SPI
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware/ATTinyCore/avr/libraries/SPI
|
||||||
1
841-tinycore-micronucleus-vcc-test/libraries/TinyBME280
Symbolic link
1
841-tinycore-micronucleus-vcc-test/libraries/TinyBME280
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
/usr/local/arduino/hardware/ATTinyCore/avr/libraries/TinyBME280
|
||||||
Reference in New Issue
Block a user