diff --git a/841-tinycore-micronucleus-test/Blink.ino b/841-tinycore-micronucleus-test/Blink.ino new file mode 100644 index 0000000..6d8d33c --- /dev/null +++ b/841-tinycore-micronucleus-test/Blink.ino @@ -0,0 +1,49 @@ +/* -*-c++-*- + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + This example code is in the public domain. + */ + +#define LED LED_BUILTIN + +void blinken(int howlong) { + digitalWrite(LED, HIGH); + delay(howlong); + digitalWrite(LED, LOW); + delay(howlong); +} + +void lang() { + blinken(1000); +} + +void kurz() { + blinken(500); +} + +void sos() { + int i=0; + + for(i=0; i<3; i++) + lang(); + + for(i=0; i<3; i++) + kurz(); + + for(i=0; i<3; i++) + lang(); +} + +void setup() { + pinMode(LED, OUTPUT); + Serial.begin(9600); + Serial.print("Press any key: "); +} + +void loop() { + if (Serial.available()) { + Serial.println("blinked\n"); + } + sos(); + delay(3000); +} diff --git a/841-tinycore-micronucleus-test/Makefile b/841-tinycore-micronucleus-test/Makefile new file mode 100644 index 0000000..a190eb1 --- /dev/null +++ b/841-tinycore-micronucleus-test/Makefile @@ -0,0 +1,54 @@ +# 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_LIB_PATH = $(ARDUINO_DIR)/hardware/ATTinyCore/avr/libraries +ARDUINO_LIBS = #Wire SPI GFX SSD1306 # SPI +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) diff --git a/841-tinycore-micronucleus-test/README.md b/841-tinycore-micronucleus-test/README.md new file mode 100644 index 0000000..fe21e57 --- /dev/null +++ b/841-tinycore-micronucleus-test/README.md @@ -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) +``` diff --git a/841-tinycore-micronucleus-test/hardware b/841-tinycore-micronucleus-test/hardware new file mode 120000 index 0000000..d34e522 --- /dev/null +++ b/841-tinycore-micronucleus-test/hardware @@ -0,0 +1 @@ +/usr/local/arduino/hardware \ No newline at end of file diff --git a/841-tinycore-micronucleus-test/libraries/GFX b/841-tinycore-micronucleus-test/libraries/GFX new file mode 120000 index 0000000..4ade844 --- /dev/null +++ b/841-tinycore-micronucleus-test/libraries/GFX @@ -0,0 +1 @@ +/usr/local/esp32/arduino-core/libraries/GFX \ No newline at end of file diff --git a/841-tinycore-micronucleus-test/libraries/SPI b/841-tinycore-micronucleus-test/libraries/SPI new file mode 120000 index 0000000..56e807e --- /dev/null +++ b/841-tinycore-micronucleus-test/libraries/SPI @@ -0,0 +1 @@ +/usr/local/arduino/hardware/ATTinyCore/avr/libraries/SPI \ No newline at end of file diff --git a/841-tinycore-micronucleus-test/libraries/SSD1306 b/841-tinycore-micronucleus-test/libraries/SSD1306 new file mode 120000 index 0000000..c2d18df --- /dev/null +++ b/841-tinycore-micronucleus-test/libraries/SSD1306 @@ -0,0 +1 @@ +/usr/local/esp32/arduino-core/libraries/SSD1306 \ No newline at end of file diff --git a/841-tinycore-micronucleus-test/libraries/TinyWireM b/841-tinycore-micronucleus-test/libraries/TinyWireM new file mode 120000 index 0000000..a6a4ed0 --- /dev/null +++ b/841-tinycore-micronucleus-test/libraries/TinyWireM @@ -0,0 +1 @@ +/usr/local/esp32/arduino-core/libraries/TinyWireM \ No newline at end of file diff --git a/841-tinycore-micronucleus-test/libraries/Wire b/841-tinycore-micronucleus-test/libraries/Wire new file mode 120000 index 0000000..0211f71 --- /dev/null +++ b/841-tinycore-micronucleus-test/libraries/Wire @@ -0,0 +1 @@ +/usr/local/arduino/hardware/ATTinyCore/avr/libraries/Wire \ No newline at end of file diff --git a/861-tinycore-bcm280-test/Blink.ino b/861-tinycore-bcm280-test/Blink.ino new file mode 100644 index 0000000..d1e4619 --- /dev/null +++ b/861-tinycore-bcm280-test/Blink.ino @@ -0,0 +1,74 @@ +/* -*-c++-*- + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + This example code is in the public domain. + */ + +#include + +// via https://arduino-projekte.webnode.at/meine-libraries/luftdruck-luftfeuchtesensor-bme280/ +#define BME280_I2cAdd 0x76 +MyBME280 BME(BME280_I2cAdd); + +unsigned long wait_time; + +float temperature, pressure, reduced_pressure, humidity; +int altitude = 8; + +void take_measurement(); +void print_measurements(); + +void setup() { + Serial.begin(9600); + + if (BME.isReady()) { + Serial.println("BME280 ok"); + + BME.setWeatherMonitoring(); + BME.init(); + + take_measurement(); + print_measurements(); + } + else { + Serial.println("BME280 Error"); + while (1); + } + wait_time = millis(); +} + +void loop() { + if (millis() > wait_time + 60000) { + BME.startSingleMeas(); + take_measurement(); + print_measurements(); + wait_time = millis(); + } +} + + + +void take_measurement() { + temperature = BME.readTemp(); + pressure = BME.readPress(); + reduced_pressure = BME.readReducedPress(altitude); + humidity = BME.readHumidity(); +} + + + +void print_measurements() { + Serial.print(" Temperature: "); + Serial.print(temperature); + Serial.println(" Grad C"); + Serial.print(" Pressure: "); + Serial.print(pressure); + Serial.println(" hPa"); + Serial.print("Reduced Pressure: "); + Serial.print(reduced_pressure); + Serial.println(" hPa"); + Serial.print(" Humidity: "); + Serial.print(humidity); + Serial.println(" %"); + Serial.println(); +} diff --git a/861-tinycore-bcm280-test/Makefile b/861-tinycore-bcm280-test/Makefile new file mode 100644 index 0000000..2d8a470 --- /dev/null +++ b/861-tinycore-bcm280-test/Makefile @@ -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 = attinyx61 +BOARD_SUB = 861 +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 +# +# WORKS: +#ARDUINO_LIBS = Wire SPI +# +# DOESNT WORK: +ARDUINO_LIBS = Wire MyBME280 + +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 + +# 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 + + diff --git a/861-tinycore-bcm280-test/hardware b/861-tinycore-bcm280-test/hardware new file mode 120000 index 0000000..d34e522 --- /dev/null +++ b/861-tinycore-bcm280-test/hardware @@ -0,0 +1 @@ +/usr/local/arduino/hardware \ No newline at end of file diff --git a/861-tinycore-bcm280-test/libraries/GFX b/861-tinycore-bcm280-test/libraries/GFX new file mode 120000 index 0000000..4ade844 --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/GFX @@ -0,0 +1 @@ +/usr/local/esp32/arduino-core/libraries/GFX \ No newline at end of file diff --git a/861-tinycore-bcm280-test/libraries/MyBME280/MyBME280.cpp b/861-tinycore-bcm280-test/libraries/MyBME280/MyBME280.cpp new file mode 100644 index 0000000..68fa835 --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/MyBME280/MyBME280.cpp @@ -0,0 +1,626 @@ +//MyBME280.cpp +//Code fuer Arduino und Attiny85 +//Author Retian +//Version 2.1 + +/* +Abfrage eines Luftdruck-/Luftfeuchtesensors BME280 ueber I2C- oder SPI-Schnittstelle +(SPI-Schnittstelle nicht fuer Attiny) + +MyBME280 Name(i2cAdd); //fuer I2C-Schnittstelle +MyBME280 Name(cs, interface); //fuer SPI-Schnittstelle; interface: BME280_SPI + +Beispiel siehe unter: +http://arduino-projekte.webnode.at/meine-libraries/luftdruck-luftfeuchtesensor-bme280/ + +Funktionen siehe unter: +http://arduino-projekte.webnode.at/meine-libraries/luftdruck-luftfeuchtesensor-bme280/funktionen/ + +*/ + +//************************************************************************* + +#include "Arduino.h" +#include "MyBME280.h" + +MyBME280::MyBME280(byte i2cAdd) : _cs(-1) +{ + _i2cAdd = i2cAdd; + + Wire.begin(); + setDefaultParameters(); +} + +MyBME280::MyBME280(byte cs, byte interface) +{ +#if defined_ATtiny + //Keine Aktivitaet, wenn ein Attiny eingesetzt wird +#else + //"interface" wird nicht benoetigt, ist nur zur Unterscheidung + //beim Aufruf der Instanzen zwischen SPI- und I2C-Schnittstelle + _cs = cs; + + pinMode(_cs, OUTPUT); + SPI.begin(); + setDefaultParameters(); +#endif +} + +//************************************************************************* +//Setzen der Standard-Parameter +//(Interne Verwendung) + +void MyBME280::setDefaultParameters() +{ + controlVal = 0; + configVal = 0; + controlHumVal = 0; + + //Setzen der Voreinstellungen + mode = BME280_NORMAL_MODE; + setMode(mode); + + osrs_p = BME280_P_OVERSAMPLING_x8; //Pressure oversampling x8 + setPressOversampling(osrs_p); + + osrs_t = BME280_T_OVERSAMPLING_x2; //Temperature oversampling x2 + setTempOversampling(osrs_t); + + osrs_h = BME280_H_OVERSAMPLING_x8; //Humidity oversampling x8 + setHumidityOversampling(osrs_h); + + t_sb = BME280_STANDBY_TIME_1000; //Standby time (NORMAL_MODE) = 1000 ms + setStandbyTime(t_sb); + + filter = BME280_FILTER_COEFF_4; //Filter-Koeffizient = 4 (5 Stufen fuer 75%) + setFilterCoeff(filter); +} + + +//************************************************************************* +//BME280 vorhanden ? + +bool MyBME280::isReady() +{ + if (read8(BMP280_CHIP_ID_REG) == BMP280_CHIP_ID) return true; + else return false; +} + +//************************************************************************* +//BME280 initialisiern +void MyBME280::init() +{ + //BME280 zuruecksetzen + reset(); + delay(300); + + //Kalibrierungskoeffizienten einlesen + + //Wenn der BME280 gerade die Koeffizienten ins interne + //Image-Register liest, dann warte + while (read8(BME280_STATUS_REG) & 0x01) delay(1); + + dig_T1 = (unsigned int)read16(BME280_DIG_T1_REG); + dig_T2 = read16(BME280_DIG_T2_REG); + dig_T3 = read16(BME280_DIG_T3_REG); + dig_P1 = (unsigned int)read16(BME280_DIG_P1_REG); + dig_P2 = read16(BME280_DIG_P2_REG); + dig_P3 = read16(BME280_DIG_P3_REG); + dig_P4 = read16(BME280_DIG_P4_REG); + dig_P5 = read16(BME280_DIG_P5_REG); + dig_P6 = read16(BME280_DIG_P6_REG); + dig_P7 = read16(BME280_DIG_P7_REG); + dig_P8 = read16(BME280_DIG_P8_REG); + dig_P9 = read16(BME280_DIG_P9_REG); + dig_H1 = (uint8_t)read8(BME280_DIG_H1_REG); + dig_H2 = read16(BME280_DIG_H2_REG); + dig_H3 = (uint8_t)read8(BME280_DIG_H3_REG); + dig_H4 = (read8(BME280_DIG_H4_REG) << 4) | + (read8(BME280_DIG_H4_REG + 1) & 0xF); + dig_H5 = (read8(BME280_DIG_H5_REG + 1) << 4) | + (read8(BME280_DIG_H5_REG) >> 4); + dig_H6 = (uint8_t)read8(BME280_DIG_H6_REG); + + //Schreiben der gesetzten Parameter in die Register + //Aenderungen beim Humidity-Controll-Register werden erst nach einer + //Schreiboperation auf das Control-Register wirksam (lt. Datenblatt 5.4.3) + write8(BME280_CONFIG_REG, configVal); + write8(BME280_HUM_CONTROL_REG, controlHumVal); + write8(BME280_CONTROL_REG, controlVal); +} + +//************************************************************************* +//Starte Einzelmessung (FORCED_MODE) + +void MyBME280::startSingleMeas() +{ + controlVal &= B11111100; + controlVal |= BME280_FORCED_MODE; + write8(BME280_CONTROL_REG, controlVal); + while (statusMeas()); //Warte bis Messzyklus beendet +} + +//************************************************************************* +//Ermittlung der Lufttemperatur + +float MyBME280::readTemp() +{ + readRawData(); + if (adc_T == 0x80000) //Rueckgabe, wenn Temperaturmesseung ausgeschaltet ist + return NAN; + return calcTemp(); +} + +//************************************************************************* +//Ermittlung des Luftdrucks + +float MyBME280::readPress() +{ + readRawData(); + if (adc_P == 0x80000) //Rueckgabe, wenn Luftdruckmessung ausgeschaltet ist + return NAN; + calcTemp(); //calcPress() benoetigt t_fine aus calcTemp() + return calcPress(); +} + +//************************************************************************* +//Ermittlung der Luftfeuchtigkeit + +float MyBME280::readHumidity() +{ + readRawData(); + if (adc_H == 0x8000) //Rueckgabe, wenn Luftfeuchtemessung ausgeschaltet ist + return NAN; + calcTemp(); //calcHumidity() benoetigt t_fine aus calcTemp() + return calcHumidity(); +} + +//************************************************************************* +//Reduzierten Luftdruck bezogen auf Meereshoehe ermitteln + +float MyBME280::readReducedPress(int hoehe) +{ + //Berechne reduzierten Luftdruck + int _hoehe = hoehe; + readRawData(); + if (adc_P == 0x80000) //Rueckgabe, wenn Luftdruckmessung ausgeschaltet ist + return NAN; + calcTemp(); + return (calcPress() / (pow(1.0 - ((float)_hoehe / 44330.0), 5.255))); + } + +//************************************************************************* +//Einlesen von 8 Bytes (burst read) ueber die I2C-Schnittstelle +//(Interne Verwendung) + +void MyBME280::readRawData() +{ + while (statusMeas()); //Warte bis Messzyklus beendet + + if (_cs == -1) + { + Wire.beginTransmission(_i2cAdd); + Wire.write(BME280_DATA_REG); + Wire.endTransmission(); + Wire.requestFrom(_i2cAdd, (byte)8); + adc_P = Wire.read(); + adc_P <<= 8; + adc_P |= Wire.read(); + adc_P <<= 8; + adc_P |= Wire.read(); + adc_P >>= 4; + adc_T = Wire.read(); + adc_T <<= 8; + adc_T |= Wire.read(); + adc_T <<= 8; + adc_T |= Wire.read(); + adc_T >>= 4; + adc_H = Wire.read(); + adc_H <<= 8; + adc_H |= Wire.read(); + } + + else + { + #if defined_ATtiny + //Keine Aktivitaet, wenn ein Attiny eingesetzt wird + #else + SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); + digitalWrite(_cs, LOW); + SPI.transfer(BME280_DATA_REG | 0x80); + adc_P = SPI.transfer(0); + adc_P <<= 8; + adc_P |= SPI.transfer(0); + adc_P <<= 8; + adc_P |= SPI.transfer(0); + adc_P >>= 4; + adc_T = SPI.transfer(0); + adc_T <<= 8; + adc_T |= SPI.transfer(0); + adc_T <<= 8; + adc_T |= SPI.transfer(0); + adc_T >>= 4; + adc_H = SPI.transfer(0); + adc_H <<= 8; + adc_H |= SPI.transfer(0); + digitalWrite(_cs, HIGH); + SPI.endTransaction(); + #endif + } +} + +//************************************************************************* +//Temperatur ermitteln +//(Interne Verwendung) + +float MyBME280::calcTemp() +{ + int32_t var1, var2; + int32_t temp; + + //Berechne Temperatur + var1 = (((adc_T >> 3) - (dig_T1 << 1)) * dig_T2) >> 11; + var2 = (((((adc_T >> 4) - (dig_T1)) * ((adc_T >> 4) - dig_T1)) >> 12) * dig_T3) >> 14; + t_fine = var1 + var2; + temp = (t_fine * 5 + 128) >> 8; + return (float)temp / 100.0; +} + +//************************************************************************* +//Luftdruck ermitteln +//(Interne Verwendung) + +float MyBME280::calcPress() +{ + int64_t var1, var2; + int64_t press; + + //Berechne Luftdruck + var1 = ((int64_t)t_fine) - 128000; + var2 = var1 * var1 * (int64_t)dig_P6; + var2 = var2 + ((var1 * (int64_t)dig_P5) << 17); + var2 = var2 + (((int64_t)dig_P4) << 35); + var1 = ((var1 * var1 + (int64_t)dig_P3) >> 8) + ((var1 * (int64_t)dig_P2) << 12); + var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)dig_P1) >> 33; + if (var1 == 0) return 0; + press= 1048576 - adc_P; + press= (((press << 31) - var2) * 3125) / var1; + var1 = (((int64_t)dig_P9) * (press>> 13) * (press>> 13)) >> 25; + var2 = (((int64_t)dig_P8) * press) >> 19; + press = ((press + var1 + var2) >> 8) + (((int64_t)dig_P7) << 4); + press /= 256; + return (float) press / 100.0; +} + +//************************************************************************* +//Luftfeuchte ermitteln +//(Interne Verwendung) + +float MyBME280::calcHumidity() +{ + int32_t v_x1_u32r; + uint32_t humidity; + +//Berechne Luftfeuchtigkeit + v_x1_u32r = (t_fine - ((int32_t)76800)); + v_x1_u32r = (((((adc_H << 14) - (((int32_t)dig_H4) << 20) - (((int32_t)dig_H5) * v_x1_u32r)) + ((int32_t)16384)) >> 15) * (((((((v_x1_u32r * ((int32_t)dig_H6)) >> 10) * (((v_x1_u32r * ((int32_t)dig_H3)) >> 11) + ((int32_t)32768))) >> 10) + +((int32_t)2097152)) * ((int32_t)dig_H2) + 8192) >> 14)); + v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) * +((int32_t)dig_H1)) >> 4)); + v_x1_u32r = (v_x1_u32r < 0 ? 0 : v_x1_u32r); + v_x1_u32r = (v_x1_u32r > 419430400 ? 419430400 : v_x1_u32r); + humidity = (uint32_t)(v_x1_u32r >> 12); + return (float)humidity / 1024.0; +} + +//************************************************************************* +// Schreiben von 1 Byte ueber die I2C-Schnittstelle +//(Interne Verwendung) + +void MyBME280::write8(byte add, byte val) +{ + byte _add = add; + byte _val = val; + + if (_cs == -1) + { + Wire.beginTransmission(_i2cAdd); + Wire.write(_add); + Wire.write(_val); + Wire.endTransmission(); + } + + else + { + #if defined_ATtiny + //Keine Aktivitaet, wenn ein Attiny eingesetzt wird + #else + digitalWrite(_cs, LOW); + SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); + SPI.transfer(_add & 0x7F); + SPI.transfer(val); + SPI.endTransaction(); + digitalWrite(_cs, HIGH); + #endif + } + delay(5); +} + +//************************************************************************* +// Einlesen von 1 Byte ueber die I2C-Schnittstelle +//(Interne Verwendung) + +byte MyBME280::read8(byte adr) +{ + byte _adr = adr; + byte val; + + if (_cs == -1) + { + Wire.beginTransmission(_i2cAdd); + Wire.write(_adr); + Wire.endTransmission(); + Wire.requestFrom(_i2cAdd, (byte)1); + val = Wire.read(); + } + + else + { + #if defined_ATtiny + //Keine Aktivitaet, wenn ein Attiny eingesetzt wird + #else + SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); + digitalWrite(_cs, LOW); + SPI.transfer(_adr | 0x80); + val = SPI.transfer(0); + digitalWrite(_cs, HIGH); + SPI.endTransaction(); + #endif + } + return val; +} + +//************************************************************************* +// Einlesen von 2 Bytes ueber die I2C-Schnittstelle +//(Interne Verwendung) + +int MyBME280::read16(byte adr) +{ + byte _adr = adr; + int val; + + if (_cs == -1) + { + Wire.beginTransmission(_i2cAdd); + Wire.write(_adr); + Wire.endTransmission(); + Wire.requestFrom(_i2cAdd, (byte)2); + val = Wire.read() | (Wire.read() << 8); + } + + else + { + #if defined_ATtiny + //Keine Aktivitaet, wenn ein Attiny eingesetzt wird + #else + SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0)); + digitalWrite(_cs, LOW); + SPI.transfer(_adr | 0x80); + val = SPI.transfer(0) | (SPI.transfer(0) << 8); + digitalWrite(_cs, HIGH); + SPI.endTransaction(); + #endif + } + return val; +} + +//************************************************************************* +//Setzen des Modus + +void MyBME280::setMode(byte mode) +{ + byte _mode = mode; + + controlVal &= B11111100; //Loesche mode + controlVal |= _mode; +} + +//************************************************************************* +//Setzen Temperatur-Oversampling + +void MyBME280::setTempOversampling(byte osrs_t) +{ + byte _osrs_t = osrs_t; + + controlVal &= ~(B111 << 5); //Loesche Temp.oversampling + controlVal |= (_osrs_t << 5); +} + +//************************************************************************* +//Setzen Druck-Oversampling + +void MyBME280::setPressOversampling(byte osrs_p) +{ + byte _osrs_p = osrs_p; + + controlVal &= ~(B111 << 2); //Loesche Press.oversampling + controlVal |= (_osrs_p << 2); +} + +//************************************************************************* +//Setzen Feuchte-Oversampling + +void MyBME280::setHumidityOversampling(byte osrs_h) +{ + byte _osrs_h = osrs_h; + + controlHumVal &= ~(B111); //Loesche Humid.oversampling + controlHumVal |= _osrs_h; +} + +//************************************************************************* +//Setzen der Standby-Zeit (Normal-Modus) + +void MyBME280::setStandbyTime(byte t_sb) +{ + byte _t_sb = t_sb; + + configVal &= ~(B111 << 5); //Loesche Standby Time + configVal |= (_t_sb << 5); +} + +//************************************************************************* +//Setzen des Filterkoeffizienten + +void MyBME280::setFilterCoeff(byte filter) +{ + byte _filter = filter; + + configVal &= ~(B111 << 2); //Loesche Filter + configVal |= (_filter << 2); +} + +//************************************************************************* +//Abfrage des Controll-Register 0xF4 + +byte MyBME280::readControlReg(void) +{ + return read8(BME280_CONTROL_REG); +} + +//************************************************************************* +//Abfrage des Config-Register 0xF5 + +byte MyBME280::readConfigReg(void) +{ + return read8(BME280_CONFIG_REG); +} + +//************************************************************************* +//Abfrage des Humidity-Control-Register 0xF2 + +byte MyBME280::readHumidityControlReg(void) +{ + return read8(BME280_HUM_CONTROL_REG); +} + +//************************************************************************* +//Abfrage des Status des Measuring-Bit +//(Interne Verwendung) + +bool MyBME280::statusMeas() +{ + byte reg; + + reg = read8(BME280_STATUS_REG); + return (reg & B00001000) >> 3; +} + +//************************************************************************* +//Software-Reset +//(Interne Verwendung) + +void MyBME280::reset() +{ + write8(BME280_RESET_REG, BME280_RESET); +} + +//************************************************************************* +//Voreinstellung fuer Weather Monitoring + +void MyBME280::setWeatherMonitoring() +{ + mode = BME280_FORCED_MODE; + setMode(mode); + + osrs_p = BME280_P_OVERSAMPLING_x1; //Pressure oversampling x1 + setPressOversampling(osrs_p); + + osrs_t = BME280_T_OVERSAMPLING_x1; //Temperature oversampling x1 + setTempOversampling(osrs_t); + + osrs_h = BME280_H_OVERSAMPLING_x1; //Humidity oversampling x1 + setHumidityOversampling(osrs_h); + + /*Keine Bedeutung bei WeatherMonitoring (Forced Mode) + t_sb = BME280_STANDBY_TIME_62p5; + setStandbyTime(t_sb); + */ + + filter = BME280_FILTER_COEFF_0; //Filter aus + setFilterCoeff(filter); +} + +//************************************************************************* +//Voreinstellung fuer Humidity Sensing (Luftfeuchtemessung) + +void MyBME280::setHumiditySensing() +{ + mode = BME280_FORCED_MODE; + setMode(mode); + + osrs_p = BME280_P_OVERSAMPLING_x0; //Pressure oversampling x0 + setPressOversampling(osrs_p); + + osrs_t = BME280_T_OVERSAMPLING_x1; //Temperature oversampling x1 + setTempOversampling(osrs_t); + + osrs_h = BME280_H_OVERSAMPLING_x1; //Humidity oversampling x1 + setHumidityOversampling(osrs_h); + + /*Keine Bedeutung bei Humidity Sensing (Forced Mode) + t_sb = BME280_STANDBY_TIME_62p5; + setStandbyTime(t_sb); + */ + + filter = BME280_FILTER_COEFF_0; //Filter aus + setFilterCoeff(filter); +} + +//************************************************************************* +//Voreinstellung fuer Indoor Navigation + +void MyBME280::setIndoorNavigation() +{ + mode = BME280_NORMAL_MODE; + setMode(mode); + + osrs_p = BME280_P_OVERSAMPLING_x16; //Pressure oversampling x16 + setPressOversampling(osrs_p); + + osrs_t = BME280_T_OVERSAMPLING_x2; //Temperature oversampling x2 + setTempOversampling(osrs_t); + + osrs_h = BME280_H_OVERSAMPLING_x1; //Humidity oversampling x1 + setHumidityOversampling(osrs_h); + + t_sb = BME280_STANDBY_TIME_0p5; //Standby Time 0,5 ms + setStandbyTime(t_sb); + + filter = BME280_FILTER_COEFF_16; //Filter-Koeffizient = 16 (22 Stufen fuer 75%) + setFilterCoeff(filter); +} + +//************************************************************************* +//Voreinstellung fuer Gaming + +void MyBME280::setGaming() +{ + mode = BME280_NORMAL_MODE; + setMode(mode); + + osrs_p = BME280_P_OVERSAMPLING_x4; //Pressure oversampling x4 + setPressOversampling(osrs_p); + + osrs_t = BME280_T_OVERSAMPLING_x1; //Temperature oversampling x1 + setTempOversampling(osrs_t); + + osrs_h = BME280_H_OVERSAMPLING_x0; //Humidity oversampling x0 + setHumidityOversampling(osrs_h); + + t_sb = BME280_STANDBY_TIME_0p5; //Standby Time 0,5 ms + setStandbyTime(t_sb); + + filter = BME280_FILTER_COEFF_16; //Filter-Koeffizient = 16 (22 Stufen fuer 75%) + setFilterCoeff(filter); +} \ No newline at end of file diff --git a/861-tinycore-bcm280-test/libraries/MyBME280/MyBME280.h b/861-tinycore-bcm280-test/libraries/MyBME280/MyBME280.h new file mode 100644 index 0000000..287c3b6 --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/MyBME280/MyBME280.h @@ -0,0 +1,179 @@ +/* + MyBME280.h + + Modified to work with Attiny861+I2C+AttinyCore+Arduino-Makefile + +*/ + +#ifndef MyBME280_h +#define MyBME280_h + +#define defined_ATtiny (defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny861__)) + +#if defined_ATtiny + #include +#else + #include + #include +#endif + +#include "Arduino.h" + +#define BME280_SPI 1 //SPI-Schnittstelle + +#define BMP280_CHIP_ID_REG 0xD0 +#define BMP280_CHIP_ID 0x60 + +#define BME280_DIG_T1_REG 0x88 +#define BME280_DIG_T2_REG 0x8A +#define BME280_DIG_T3_REG 0x8C +#define BME280_DIG_P1_REG 0x8E +#define BME280_DIG_P2_REG 0x90 +#define BME280_DIG_P3_REG 0x92 +#define BME280_DIG_P4_REG 0x94 +#define BME280_DIG_P5_REG 0x96 +#define BME280_DIG_P6_REG 0x98 +#define BME280_DIG_P7_REG 0x9A +#define BME280_DIG_P8_REG 0x9C +#define BME280_DIG_P9_REG 0x9E +#define BME280_DIG_H1_REG 0xA1 +#define BME280_DIG_H2_REG 0xE1 +#define BME280_DIG_H3_REG 0xE3 +#define BME280_DIG_H4_REG 0xE4 +#define BME280_DIG_H5_REG 0xE5 +#define BME280_DIG_H6_REG 0xE7 + +#define BME280_HUM_MSB_REG 0xFD +#define BME280_TEMP_MSB_REG 0xFA +#define BME280_PRESS_MSB_REG 0xF7 +#define BME280_HUM_CONTROL_REG 0xF2 +#define BME280_STATUS_REG 0xF3 +#define BME280_CONTROL_REG 0xF4 +#define BME280_CONFIG_REG 0xF5 +#define BME280_DATA_REG 0xF7 +#define BME280_RESET_REG 0xE0 + +#define BME280_NORMAL_MODE B11 +#define BME280_FORCED_MODE B01 +#define BME280_SLEEP_MODE B00 + +#define BME280_RESET 0xB6 + +#define BME280_T_OVERSAMPLING_x0 B000 +#define BME280_T_OVERSAMPLING_x1 B001 +#define BME280_T_OVERSAMPLING_x2 B010 +#define BME280_T_OVERSAMPLING_x4 B011 +#define BME280_T_OVERSAMPLING_x8 B100 +#define BME280_T_OVERSAMPLING_x16 B101 + +#define BME280_P_OVERSAMPLING_x0 B000 +#define BME280_P_OVERSAMPLING_x1 B001 +#define BME280_P_OVERSAMPLING_x2 B010 +#define BME280_P_OVERSAMPLING_x4 B011 +#define BME280_P_OVERSAMPLING_x8 B100 +#define BME280_P_OVERSAMPLING_x16 B101 + +#define BME280_H_OVERSAMPLING_x0 B000 +#define BME280_H_OVERSAMPLING_x1 B001 +#define BME280_H_OVERSAMPLING_x2 B010 +#define BME280_H_OVERSAMPLING_x4 B011 +#define BME280_H_OVERSAMPLING_x8 B100 +#define BME280_H_OVERSAMPLING_x16 B101 + +#define BME280_STANDBY_TIME_0p5 B000 +#define BME280_STANDBY_TIME_62p5 B001 +#define BME280_STANDBY_TIME_125 B010 +#define BME280_STANDBY_TIME_250 B011 +#define BME280_STANDBY_TIME_500 B100 +#define BME280_STANDBY_TIME_1000 B101 +#define BME280_STANDBY_TIME_10 B110 +#define BME280_STANDBY_TIME_20 B111 + +#define BME280_FILTER_COEFF_0 B000 +#define BME280_FILTER_COEFF_2 B001 +#define BME280_FILTER_COEFF_4 B010 +#define BME280_FILTER_COEFF_8 B011 +#define BME280_FILTER_COEFF_16 B100 + + + +class MyBME280 +{ + public: + MyBME280(byte); + MyBME280(byte, byte); + bool isReady(void); + void init(); + void startSingleMeas(void); + float readTemp(void); + float readPress(void); + float readHumidity(void); + float readReducedPress(int); + void setMode(byte); + void setTempOversampling(byte); + void setPressOversampling(byte); + void setHumidityOversampling(byte); + void setStandbyTime(byte); + void setFilterCoeff(byte); + byte readControlReg(void); + byte readConfigReg(void); + byte readHumidityControlReg(void); + void setWeatherMonitoring(void); + void setHumiditySensing(void); + void setIndoorNavigation(void); + void setGaming(void); + + private: + void readRawData(void); + float calcTemp(void); + float calcPress(void); + float calcHumidity(void); + byte read8(byte); + int read16(byte); + void write8(byte, byte); + bool statusMeas(void); + void reset(void); + void setDefaultParameters(void); + + unsigned int dig_T1; + int dig_T2; + int dig_T3; + unsigned int dig_P1; + int dig_P2; + int dig_P3; + int dig_P4; + int dig_P5; + int dig_P6; + int dig_P7; + int dig_P8; + int dig_P9; + uint8_t dig_H1; + int dig_H2; + uint8_t dig_H3; + int dig_H4; + int dig_H5; + int8_t dig_H6; + + long t_fine; + long adc_T; + long adc_P; + long adc_H; + + byte _i2cAdd; + int8_t _cs; + + byte mode; + byte osrs_t; + byte osrs_p; + byte osrs_h; + byte t_sb; + byte filter; + + byte controlVal; + byte configVal; + byte controlHumVal; + +}; + +#endif + diff --git a/861-tinycore-bcm280-test/libraries/MyBME280/keywords.txt b/861-tinycore-bcm280-test/libraries/MyBME280/keywords.txt new file mode 100644 index 0000000..6d0e17c --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/MyBME280/keywords.txt @@ -0,0 +1,113 @@ +####################################### +# Syntax Coloring Map For MyBME280 +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +MyBME280 KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +isReady KEYWORD2 +init KEYWORD2 +startSingleMeas KEYWORD2 +readTemp KEYWORD2 +readPress KEYWORD2 +readHumidity KEYWORD2 +readReducedPress KEYWORD2 +setMode KEYWORD2 +setTempOversampling KEYWORD2 +setPressOversampling KEYWORD2 +setHumidityOversampling KEYWORD2 +setStandbyTime KEYWORD2 +setFilterCoeff KEYWORD2 +readControlReg KEYWORD2 +readConfigReg KEYWORD2 +readHumidityControlReg KEYWORD2 +setWeatherMonitoring KEYWORD2 +setHumiditySensing KEYWORD2 +setIndoorNavigation KEYWORD2 +setGaming KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + + +####################################### +# Constants (LITERAL1) +####################################### + +BME280_SPI LITERAL1 +BMP280_CHIP_ID_REG LITERAL1 +BMP280_CHIP_ID LITERAL1 +BME280_DIG_T1_REG LITERAL1 +BME280_DIG_T2_REG LITERAL1 +BME280_DIG_T3_REG LITERAL1 +BME280_DIG_P1_REG LITERAL1 +BME280_DIG_P2_REG LITERAL1 +BME280_DIG_P3_REG LITERAL1 +BME280_DIG_P4_REG LITERAL1 +BME280_DIG_P5_REG LITERAL1 +BME280_DIG_P6_REG LITERAL1 +BME280_DIG_P7_REG LITERAL1 +BME280_DIG_P8_REG LITERAL1 +BME280_DIG_P9_REG LITERAL1 +BME280_DIG_H1_REG LITERAL1 +BME280_DIG_H2_REG LITERAL1 +BME280_DIG_H3_REG LITERAL1 +BME280_DIG_H4_REG LITERAL1 +BME280_DIG_H5_REG LITERAL1 +BME280_DIG_H6_REG LITERAL1 +BME280_HUM_MSB_REG LITERAL1 +BME280_TEMP_MSB_REG LITERAL1 +BME280_PRESS_MSB_REG LITERAL1 +BME280_HUM_CONTROL_REG LITERAL1 +BME280_STATUS_REG LITERAL1 +BME280_CONTROL_REG LITERAL1 +BME280_CONFIG_REG LITERAL1 +BME280_DATA_REG LITERAL1 +BME280_RESET_REG LITERAL1 +BME280_NORMAL_MODE LITERAL1 +BME280_FORCED_MODE LITERAL1 +BME280_SLEEP_MODE LITERAL1 +BME280_T_OVERSAMPLING_x0 LITERAL1 +BME280_T_OVERSAMPLING_x1 LITERAL1 +BME280_T_OVERSAMPLING_x2 LITERAL1 +BME280_T_OVERSAMPLING_x4 LITERAL1 +BME280_T_OVERSAMPLING_x8 LITERAL1 +BME280_T_OVERSAMPLING_x16 LITERAL1 +BME280_P_OVERSAMPLING_x0 LITERAL1 +BME280_P_OVERSAMPLING_x1 LITERAL1 +BME280_P_OVERSAMPLING_x2 LITERAL1 +BME280_P_OVERSAMPLING_x4 LITERAL1 +BME280_P_OVERSAMPLING_x8 LITERAL1 +BME280_P_OVERSAMPLING_x16 LITERAL1 +BME280_H_OVERSAMPLING_x0 LITERAL1 +BME280_H_OVERSAMPLING_x1 LITERAL1 +BME280_H_OVERSAMPLING_x2 LITERAL1 +BME280_H_OVERSAMPLING_x4 LITERAL1 +BME280_H_OVERSAMPLING_x8 LITERAL1 +BME280_H_OVERSAMPLING_x16 LITERAL1 +BME280_STANDBY_TIME_0p5 LITERAL1 +BME280_STANDBY_TIME_62p5 LITERAL1 +BME280_STANDBY_TIME_125 LITERAL1 +BME280_STANDBY_TIME_250 LITERAL1 +BME280_STANDBY_TIME_500 LITERAL1 +BME280_STANDBY_TIME_1000 LITERAL1 +STANDBY_TIME_10 LITERAL1 +STANDBY_TIME_20 LITERAL1 +FILTER_COEFF_0 LITERAL1 +FILTER_COEFF_2 LITERAL1 +FILTER_COEFF_4 LITERAL1 +FILTER_COEFF_8 LITERAL1 +FILTER_COEFF_16 LITERAL1 + + + + + diff --git a/861-tinycore-bcm280-test/libraries/SPI b/861-tinycore-bcm280-test/libraries/SPI new file mode 120000 index 0000000..56e807e --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/SPI @@ -0,0 +1 @@ +/usr/local/arduino/hardware/ATTinyCore/avr/libraries/SPI \ No newline at end of file diff --git a/861-tinycore-bcm280-test/libraries/SSD1306 b/861-tinycore-bcm280-test/libraries/SSD1306 new file mode 120000 index 0000000..c2d18df --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/SSD1306 @@ -0,0 +1 @@ +/usr/local/esp32/arduino-core/libraries/SSD1306 \ No newline at end of file diff --git a/861-tinycore-bcm280-test/libraries/TinyWireM b/861-tinycore-bcm280-test/libraries/TinyWireM new file mode 120000 index 0000000..a6a4ed0 --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/TinyWireM @@ -0,0 +1 @@ +/usr/local/esp32/arduino-core/libraries/TinyWireM \ No newline at end of file diff --git a/861-tinycore-bcm280-test/libraries/Wire b/861-tinycore-bcm280-test/libraries/Wire new file mode 120000 index 0000000..0211f71 --- /dev/null +++ b/861-tinycore-bcm280-test/libraries/Wire @@ -0,0 +1 @@ +/usr/local/arduino/hardware/ATTinyCore/avr/libraries/Wire \ No newline at end of file