mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-16 19:00:57 +01:00
testing Vbg reading
This commit is contained in:
@@ -31,6 +31,8 @@ SDO/MISO PA5 PA6 SDI/MOSI
|
||||
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#define TINY_BME280_SPI
|
||||
#include <TinyBME280.h>
|
||||
|
||||
@@ -45,6 +47,7 @@ SDO/MISO PA5 PA6 SDI/MOSI
|
||||
|
||||
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)
|
||||
@@ -84,8 +87,6 @@ void print_measurements() {
|
||||
print_asufloat(humidity, 1000);
|
||||
Serial.println(" %");
|
||||
|
||||
Serial.println();
|
||||
|
||||
transmitter.send((byte *)temp, sizeof(temp));
|
||||
SET_HIGH(LED);
|
||||
}
|
||||
@@ -94,10 +95,26 @@ void halt() {
|
||||
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() {
|
||||
SET_OUTPUT(LED);
|
||||
Serial.begin(115200);
|
||||
Serial.println("init");
|
||||
// Enable ADC
|
||||
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 );
|
||||
|
||||
if(sensor.beginSPI(CS) == false) {
|
||||
Serial.println("Sensor BME280 connect failed, check wiring!");
|
||||
@@ -105,9 +122,9 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
print_measurements();
|
||||
print_voltage();
|
||||
delay(DELAY);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user