Skip to content

Commit

Permalink
Beta 4b update + FlashAsEEPROM
Browse files Browse the repository at this point in the history
  • Loading branch information
Adminius committed Mar 11, 2020
1 parent 942a146 commit 00fb5fe
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
/* ---------------------------------------------------------------------------------------------
OneWire Temperature SingleSensor 1.0 (DS18B20, MAX31820) (Single sensor)
OneWire Temperature SingleSensor 1.1 (DS18B20, MAX31820) (Single sensor)
Hardware/Firmware/Sketch/kdevice.xml by E.Burkowski / [email protected], GPL Licensed
Compatible with: KONNEKTING Device Library 1.0.0 beta 4
Compatible with: KONNEKTING Device Library 1.0.0 beta 4b
------------------------------------------------------------------------------------------------*/

/* this libraries are required (click on link and download with library manager):
KONNEKTING Device Library: http://librarymanager/All#Konnekting
FlashStorage: http://librarymanager/All#FlashStorage
OneWire: http://librarymanager/All#OneWire
DallasTemperature: http://librarymanager/All#DallasTemperature
*/

#include <KonnektingDevice.h>

// include device related configuration code, created by "KONNEKTING CodeGenerator"
#include "kdevice_OneWire_Temeprature_SingleSensor_1_0.h"
#include "kdevice_OneWire_Temeprature_SingleSensor_1_1.h"
#include "mi.h"

#include <OneWire.h> //https://github.com/PaulStoffregen/OneWire
#include <DallasTemperature.h> //https://github.com/milesburton/Arduino-Temperature-Control-Library
#include <FlashAsEEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>


// ################################################
// ### DEBUG CONFIGURATION
// ################################################
#define KDEBUG // comment this line to disable DEBUG mode
//#define KDEBUG // comment this line to disable DEBUG mode
#ifdef KDEBUG
#include <DebugUtil.h>
#define DEBUGSERIAL SerialUSB
Expand All @@ -27,18 +35,13 @@ Compatible with: KONNEKTING Device Library 1.0.0 beta 4
// ################################################
// ### IO Configuration
// ################################################
//OneWire on pin D3
#define ONE_WIRE OWD3
#define ONE_WIRE_PULLUP OWD3PullUp

//OneWire on pin D4
//#define ONE_WIRE OWD4
//#define ONE_WIRE_PULLUP OWD4PullUp
//OneWire on pin SDA (pin with approx 4k7 should be used)
#define ONE_WIRE_PIN SDA

#define TEMPERATURE_PRECISION 10 //9: 0.5°, 10: 0.25°, 11: 0.125°, 12: 0.0625°


OneWire oneWire(ONE_WIRE);
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);/* Dallas Temperature Library */

unsigned long owDelay = 750;
Expand All @@ -61,6 +64,10 @@ int16_t limitTempMin = 0;
uint8_t valueTempMax = 255;
int16_t limitTempMax = 0;

#include "OneWire_functions.h"
#include "setup.h"
#include "loop.h"

// Callback function to handle com objects updates

void knxEvents(byte index) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
void configureOW(){
pinMode(ONE_WIRE_PULLUP, OUTPUT);
digitalWrite(ONE_WIRE_PULLUP, HIGH); //enable OneWire PullUp
#ifdef KDEBUG
Debug.println(F("Searching for sensors..."));
#endif
Expand All @@ -23,7 +21,7 @@ float getCurrentTemp(uint8_t index){
currTemp = sensors.getTempCByIndex(index);
long end = millis();
#ifdef KDEBUG
Debug.println(F("currentTemp: %3.2f %cC time: %d ms"), currTemp, 0x00B0, (end-start));
Debug.println(F("currentTemp: %3.2f °C time: %d ms"), currTemp, 0x00B0, (end-start));
#endif
return currTemp;
}
Expand All @@ -40,4 +38,3 @@ void limitReached(float comVal, float comValMin, float comValMax, int minObj, in
}
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ byte KonnektingDevice::_paramSizeList[] = {
/* Index 6 - tempMaxValue */ PARAM_UINT8,
/* Index 7 - tempMaxLimit */ PARAM_INT16
};
const byte KonnektingDevice::_numberOfParams = sizeof (_paramSizeList); // do not change this code
const int KonnektingDevice::_numberOfParams = sizeof (_paramSizeList); // do not change this code
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: E.Burkowski / [email protected], GPL Licensed
Multi Interface has 6 SERCOMs, but each Sercom can be used only once!
this 3 Sercoms are reserved for system and can't be changed!
Sercom3: I�C EEPROM / external I�C header
Sercom3: I2C EEPROM / external I2C header
Sercom4: SPI-Flash
Sercom5: Serial for KNX-Tranceiver
Expand All @@ -20,10 +20,12 @@ Sercom1,2 are free for use.
#define useSerial3 //uses sercom1
*/

#define useExternalEEPROM // comment if internal Flash EEPROM is used
//#define useExternalEEPROM // comment if internal Flash EEPROM is used

//don't change this lines!
#ifdef useExternalEEPROM
#include <Wire.h>
#endif
#include <Arduino.h>
#include "wiring_private.h" // for pinPeripheral() function

Expand Down Expand Up @@ -95,14 +97,10 @@ void Serial3_init(){
#define KNX_SERIAL Serial
#define FLASH_CS 9

#define OWD3 3
#define OWD3PullUp A3
#define OWD4 4
#define OWD4PullUp A4

#ifdef useExternalEEPROM
// MI uses 24AA256 I2C EEPROM
int readMemory(int index) {
byte readMemory(int index) {
byte data = 0xFF;
if(index >= 0 && index < 32768){
Wire.beginTransmission(0x50);
Expand All @@ -117,7 +115,7 @@ int readMemory(int index) {
return data;
}

void writeMemory(int index, int val) {
void writeMemory(int index, byte val) {
if(index >= 0 && index < 32768 && val >= 0 && val < 256){
Wire.beginTransmission(0x50);
Wire.write((int) (index >> 8));
Expand All @@ -128,7 +126,7 @@ void writeMemory(int index, int val) {
}
}

void updateMemory(int index, int val) {
void updateMemory(int index, byte val) {
if (readMemory(index) != val) {
writeMemory(index, val);
}
Expand All @@ -139,25 +137,24 @@ void commitMemory() {
}

#else
#include "ZeroEEPROM.h" // download from connecting GIT and don't forget Emulated EEPROM lib referenced there
#include "FlashAsEEPROM.h" //

// ZeroEEPROM.init(); ...call this function in setup() after Konnekting.setMemory...() functions

int readMemory(int index) {
return ZeroEEPROM.read(index);
byte readMemory(int index) {
return EEPROM.read(index);
}

void writeMemory(int index, int val) {
ZeroEEPROM.write(index, val);
void writeMemory(int index, byte val) {
EEPROM.write(index, val);
}

void updateMemory(int index, int val) {
void updateMemory(int index, byte val) {
if (readMemory(index) != val) {
writeMemory(index, val);
}
}

void commitMemory() {
ZeroEEPROM.commit();
EEPROM.commit();
}
#endif
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
void setup() {
// debug related stuff
#ifdef KDEBUG
// Start debug serial with 9600 bauds
DEBUGSERIAL.begin(9600);
// Start debug serial with 115200 bauds
DEBUGSERIAL.begin(115200);
while (!DEBUGSERIAL)
// make debug serial port known to debug class
// Means: KONNEKTING will sue the same serial port for console debugging
Debug.setPrintStream(&DEBUGSERIAL);
#endif

#ifdef useExternalEEPROM
Wire.begin();
#endif
Konnekting.setMemoryReadFunc(&readMemory);
Konnekting.setMemoryWriteFunc(&writeMemory);
Konnekting.setMemoryUpdateFunc(&updateMemory);
Konnekting.setMemoryCommitFunc(&commitMemory);
// ZeroEEPROM.init(); // uncomment if internal EEPROM Emulation is used

// Initialize KNX enabled Arduino Board
Konnekting.init(KNX_SERIAL, PROG_BUTTON_PIN, PROG_LED_PIN, MANUFACTURER_ID, DEVICE_ID, REVISION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
/* ---------------------------------------------------------------------------------------------
Temperature and relative humidty Sensor (HTU21D, SHT21...)
Temperature and relative humidty Sensor 1.1 (HTU21D, SHT21...)
Hardware/Firmware/Sketch/kdevice.xml by E.Burkowski / [email protected], GPL Licensed
Compatible with: KONNEKTING Device Library 1.0.0 beta 4
Compatible with: KONNEKTING Device Library 1.0.0 beta 4b
------------------------------------------------------------------------------------------------*/

/* this libraries are required (click on link and download with library manager):
KONNEKTING Device Library: http://librarymanager/All#Konnekting
FlashStorage: http://librarymanager/All#FlashStorage
SparkFun HTU21D: http://librarymanager/All#SparkFun_HTU21D
*/

#include <KonnektingDevice.h>
#include "mi.h"

// include device related configuration code, created by "KONNEKTING CodeGenerator"
#include "kdevice_Temp_RH.h"

#include <FlashAsEEPROM.h>

// ################################################
// ### DEBUG CONFIGURATION
// ################################################
//#define KDEBUG // comment this line to disable DEBUG mode
#define KDEBUG // comment this line to disable DEBUG mode
#ifdef KDEBUG
#include <DebugUtil.h>
#define DEBUGSERIAL SerialUSB
#endif

#include "SparkFunHTU21D.h" //https://github.com/sparkfun/SparkFun_HTU21D_Breakout_Arduino_Library
#include "SparkFunHTU21D.h"

// Create an instance for HTU21D sensor
HTU21D htu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ byte KonnektingDevice::_paramSizeList[] = {
/* Index 13 - rhMaxValue */ PARAM_UINT8,
/* Index 14 - rhMaxLimit */ PARAM_INT16
};
const byte KonnektingDevice::_numberOfParams = sizeof (_paramSizeList); // do not change this code
const int KonnektingDevice::_numberOfParams = sizeof (_paramSizeList); // do not change this code
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Author: E.Burkowski / [email protected], GPL Licensed
Multi Interface has 6 SERCOMs, but each Sercom can be used only once!
this 3 Sercoms are reserved for system and can't be changed!
Sercom3: I�C EEPROM / external I�C header
Sercom3: I2C EEPROM / external I2C header
Sercom4: SPI-Flash
Sercom5: Serial for KXN-Tranceiver
Sercom5: Serial for KNX-Tranceiver
Sercom0 is reserved for "Serial1" (D0,D1) if you use Serial1.begin(..), but this pins are only internaly available
Expand All @@ -20,8 +20,12 @@ Sercom1,2 are free for use.
#define useSerial3 //uses sercom1
*/

//#define useExternalEEPROM // comment if internal Flash EEPROM is used

//don't change this lines!
#ifdef useExternalEEPROM
#include <Wire.h>
#endif
#include <Arduino.h>
#include "wiring_private.h" // for pinPeripheral() function

Expand Down Expand Up @@ -93,13 +97,10 @@ void Serial3_init(){
#define KNX_SERIAL Serial
#define FLASH_CS 9

#define OWD3 3
#define OWD3PullUp A3
#define OWD4 4
#define OWD4PullUp A4

#ifdef useExternalEEPROM
// MI uses 24AA256 I2C EEPROM
int readMemory(int index) {
byte readMemory(int index) {
byte data = 0xFF;
if(index >= 0 && index < 32768){
Wire.beginTransmission(0x50);
Expand All @@ -114,7 +115,7 @@ int readMemory(int index) {
return data;
}

void writeMemory(int index, int val) {
void writeMemory(int index, byte val) {
if(index >= 0 && index < 32768 && val >= 0 && val < 256){
Wire.beginTransmission(0x50);
Wire.write((int) (index >> 8));
Expand All @@ -125,7 +126,7 @@ void writeMemory(int index, int val) {
}
}

void updateMemory(int index, int val) {
void updateMemory(int index, byte val) {
if (readMemory(index) != val) {
writeMemory(index, val);
}
Expand All @@ -134,3 +135,26 @@ void updateMemory(int index, int val) {
void commitMemory() {
// EEPROM needs no commit, so this function is intentionally left blank
}

#else
#include "FlashAsEEPROM.h" //


byte readMemory(int index) {
return EEPROM.read(index);
}

void writeMemory(int index, byte val) {
EEPROM.write(index, val);
}

void updateMemory(int index, byte val) {
if (readMemory(index) != val) {
writeMemory(index, val);
}
}

void commitMemory() {
EEPROM.commit();
}
#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
void setup() {
// debug related stuff
#ifdef KDEBUG
// Start debug serial with 9600 bauds
DEBUGSERIAL.begin(9600);
// Start debug serial with 115200 bauds
DEBUGSERIAL.begin(115200);
while (!DEBUGSERIAL)
// make debug serial port known to debug class
// Means: KONNEKTING will sue the same serial port for console debugging
Expand Down

0 comments on commit 00fb5fe

Please sign in to comment.