From a6569c884ac1a93604013f8222dc676240441f4a Mon Sep 17 00:00:00 2001 From: Marco Noord Date: Wed, 13 Jan 2016 17:19:59 +0100 Subject: [PATCH 1/5] Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output If no pullup is used, the reported usage will be too high because of the floating pin --- .../EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino index 30d18cf..144bc72 100644 --- a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino +++ b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino @@ -70,6 +70,10 @@ void setup() { // Fetch last known pulse count value from gw request(CHILD_ID, V_VAR1); + + // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output + // If no pullup is used, the reported usage will be too high because of the floating pin + digitalWrite(DIGITAL_INPUT_SENSOR,HIGH); attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); From 9858cb19f0f3e5a08df9e9079b254837132439ad Mon Sep 17 00:00:00 2001 From: Marco Noord Date: Wed, 13 Jan 2016 17:57:48 +0100 Subject: [PATCH 2/5] Changed digitalwrite to pinmode, to make it more obvious what is happening here, and to offer more support within the Arduino API --- .../examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino index 144bc72..9b957de 100644 --- a/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino +++ b/libraries/MySensors/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino @@ -73,7 +73,7 @@ void setup() // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output // If no pullup is used, the reported usage will be too high because of the floating pin - digitalWrite(DIGITAL_INPUT_SENSOR,HIGH); + pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP); attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); From c1ceeccc6bd608e269d67dfb23b1491df60f6556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Fri, 8 Jan 2016 22:47:09 +0100 Subject: [PATCH 3/5] Changed name for SPI the last couple of places --- .../samd/libraries/Ethernet/src/Ethernet.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hardware/MySensors/samd/libraries/Ethernet/src/Ethernet.cpp b/hardware/MySensors/samd/libraries/Ethernet/src/Ethernet.cpp index 54cf8d6..cf4f612 100644 --- a/hardware/MySensors/samd/libraries/Ethernet/src/Ethernet.cpp +++ b/hardware/MySensors/samd/libraries/Ethernet/src/Ethernet.cpp @@ -16,10 +16,10 @@ int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned l // Initialise the basic info W5100.init(); - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setMACAddress(mac_address); W5100.setIPAddress(IPAddress(0,0,0,0).raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); // Now try to get our config info from a DHCP server int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout); @@ -27,11 +27,11 @@ int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned l { // We've successfully found a DHCP server and got our configuration info, so set things // accordingly - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setIPAddress(_dhcp->getLocalIp().raw_address()); W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address()); W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); _dnsServerAddress = _dhcp->getDnsServerIp(); } @@ -65,12 +65,12 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) { W5100.init(); - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setMACAddress(mac); W5100.setIPAddress(local_ip.raw_address()); W5100.setGatewayIp(gateway.raw_address()); W5100.setSubnetMask(subnet.raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); _dnsServerAddress = dns_server; } @@ -86,11 +86,11 @@ int EthernetClass::maintain(){ case DHCP_CHECK_RENEW_OK: case DHCP_CHECK_REBIND_OK: //we might have got a new IP. - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setIPAddress(_dhcp->getLocalIp().raw_address()); W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address()); W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); _dnsServerAddress = _dhcp->getDnsServerIp(); break; default: @@ -104,27 +104,27 @@ int EthernetClass::maintain(){ IPAddress EthernetClass::localIP() { IPAddress ret; - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getIPAddress(ret.raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); return ret; } IPAddress EthernetClass::subnetMask() { IPAddress ret; - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getSubnetMask(ret.raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); return ret; } IPAddress EthernetClass::gatewayIP() { IPAddress ret; - SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + SPI_ETH.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getGatewayIp(ret.raw_address()); - SPI.endTransaction(); + SPI_ETH.endTransaction(); return ret; } From c4adcccbdccff69288b47fa31ebb62cedbec0712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Tue, 12 Jan 2016 21:42:13 +0100 Subject: [PATCH 4/5] Moved default LED initialization from MyConfig.h to MySensors.h --- libraries/MySensors/MyConfig.h | 35 ++++++---------------------------- libraries/MySensors/MySensor.h | 34 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index bbbabdb..c28e15f 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -152,35 +152,12 @@ //#define MY_WITH_LEDS_BLINKING_INVERSE - -// default LEDs blinking period in milliseconds -#ifndef MY_DEFAULT_LED_BLINK_PERIOD -#define MY_DEFAULT_LED_BLINK_PERIOD 300 -#endif -// The RX LED default pin -#ifndef MY_DEFAULT_RX_LED_PIN - #if defined(ARDUINO_ARCH_ESP8266) - #define MY_DEFAULT_RX_LED_PIN 8 - #else - #define MY_DEFAULT_RX_LED_PIN 6 - #endif -#endif -// The TX LED default pin -#ifndef MY_DEFAULT_TX_LED_PIN - #if defined(ARDUINO_ARCH_ESP8266) - #define MY_DEFAULT_TX_LED_PIN 9 - #else - #define MY_DEFAULT_TX_LED_PIN 5 - #endif -#endif -// The Error LED default pin -#ifndef MY_DEFAULT_ERR_LED_PIN - #if defined(ARDUINO_ARCH_ESP8266) - #define MY_DEFAULT_ERR_LED_PIN 7 - #else - #define MY_DEFAULT_ERR_LED_PIN 4 - #endif -#endif +// The following defines can be used to set the port pin, that the LED is connected to +// If one of the following is defined here, or in the sketch, MY_LEDS_BLINKING_FEATURE will be +// enabled by default. (Replace x with the pin number you have the LED on) +//#define MY_DEFAULT_ERR_LED x +//#define MY_DEFAULT_TX_LED x +//#define MY_DEFAULT_RX_LED x /********************************************** * Gateway inclusion button/mode configuration diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index 2833f5a..ebb881b 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -58,6 +58,7 @@ #include "core/MyHwSAMD.cpp" #endif +// LEDS #if !defined(MY_DEFAULT_ERR_LED_PIN) & defined(MY_HW_ERR_LED_PIN) #define MY_DEFAULT_ERR_LED_PIN MY_HW_ERR_LED_PIN #endif @@ -67,7 +68,7 @@ #endif #if !defined(MY_DEFAULT_RX_LED_PIN) && defined(MY_HW_TX_LED_PIN) - #define MY_DEFAULT_TX_LED_PIN MY_HW_TX_LED_PIN + #define MY_DEFAULT_RX_LED_PIN MY_HW_TX_LED_PIN #endif // Not necessary to include blinking feature if no LED's are defined! @@ -80,13 +81,42 @@ #define MY_LEDS_BLINKING_FEATURE #endif -// LEDS #if defined(MY_LEDS_BLINKING_FEATURE) #include "core/MyLeds.cpp" #else #include "core/MyLeds.h" #endif +// default LEDs blinking period in milliseconds +#ifndef MY_DEFAULT_LED_BLINK_PERIOD +#define MY_DEFAULT_LED_BLINK_PERIOD 300 +#endif +// The RX LED default pin +#ifndef MY_DEFAULT_RX_LED_PIN + #if defined(ARDUINO_ARCH_ESP8266) + #define MY_DEFAULT_RX_LED_PIN 8 + #else + #define MY_DEFAULT_RX_LED_PIN 6 + #endif +#endif +// The TX LED default pin +#ifndef MY_DEFAULT_TX_LED_PIN + #if defined(ARDUINO_ARCH_ESP8266) + #define MY_DEFAULT_TX_LED_PIN 9 + #else + #define MY_DEFAULT_TX_LED_PIN 5 + #endif +#endif +// The Error LED default pin +#ifndef MY_DEFAULT_ERR_LED_PIN + #if defined(ARDUINO_ARCH_ESP8266) + #define MY_DEFAULT_ERR_LED_PIN 7 + #else + #define MY_DEFAULT_ERR_LED_PIN 4 + #endif +#endif + + // INCLUSION MODE #if defined(MY_INCLUSION_MODE_FEATURE) #include "core/MyInclusionMode.cpp" From eacac55be0a4ba40fb3383a0b0598a4c1d436370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Wed, 13 Jan 2016 19:28:03 +0100 Subject: [PATCH 5/5] Moved includes for MyLeds.* to be after the default assignments for LED's --- libraries/MySensors/MySensor.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index ebb881b..75ef82d 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -81,11 +81,6 @@ #define MY_LEDS_BLINKING_FEATURE #endif -#if defined(MY_LEDS_BLINKING_FEATURE) - #include "core/MyLeds.cpp" -#else - #include "core/MyLeds.h" -#endif // default LEDs blinking period in milliseconds #ifndef MY_DEFAULT_LED_BLINK_PERIOD @@ -116,6 +111,12 @@ #endif #endif +#if defined(MY_LEDS_BLINKING_FEATURE) + #include "core/MyLeds.cpp" +#else + #include "core/MyLeds.h" +#endif + // INCLUSION MODE #if defined(MY_INCLUSION_MODE_FEATURE)