From 61d6a2a3d41203dabdd73bb2bceeab16c1d3ea2d Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 28 Mar 2021 12:05:29 +0200 Subject: [PATCH 01/44] Rename file to folder name and change main file extension to .ino --- diff | 377 --------------------- pilight_usb_nano.c => pilight-usb-nano.ino | 0 2 files changed, 377 deletions(-) delete mode 100644 diff rename pilight_usb_nano.c => pilight-usb-nano.ino (100%) diff --git a/diff b/diff deleted file mode 100644 index 48ba9d9..0000000 --- a/diff +++ /dev/null @@ -1,377 +0,0 @@ -diff --git a/README.md b/README.md -index 5c180cc..e669d2e 100644 ---- a/README.md -+++ b/README.md -@@ -1,2 +1,31 @@ --# pilight-usb-nano --pilight Arduino Nano USB interface -+# pilight USB Nano -+ -+The pilight Arduino Nano software allows any computer with an USB port to work with pilight. -+ -+1. Compile the firmware: -+`avr-gcc -Os -Wall -DF_CPU=16000000UL -mmcu=atmega328p -c -o usbto433.o usbto433.c -lm -I.` -+`avr-gcc -mmcu=atmega328p usbto433.o -o usbto433` -+`avr-objcopy -O ihex -R .eeprom usbto433 usbto433.hex` -+2. Flash the firmware on the Arduino Nano: -+`avrdude -b 57600 -p atmega328p -c arduino -P COM5 -U flash:w:usbto433.hex` -+3. Connect the receiver data pin to D2 and the sender to D5. -+4. Connect the Arduino Nano to your computer. -+5. Check what COM port the Arduino Nano is using. -+6. Configure pilight to interface with the Arduino Nano: -+Linux example: -+``` -+ "hardware": { -+ "433nano": { -+ "comport": "/dev/ttyUSB0" -+ } -+ } -+``` -+Windows Example: -+``` -+ "hardware": { -+ "433nano": { -+ "comport": "COM5" -+ } -+ } -+``` -+7. Start pilight normally and it should work OOTB. -\ No newline at end of file -diff --git a/usbto433.c b/usbto433.c -new file mode 100644 -index 0000000..ce83dcf ---- /dev/null -+++ b/usbto433.c -@@ -0,0 +1,332 @@ -+/* -+ Copyright (C) 2015 CurlyMo -+ -+ This file is part of pilight. -+ -+ pilight is free software: you can redistribute it and/or modify it under the -+ terms of the GNU General Public License as published by the Free Software -+ Foundation, either version 3 of the License, or (at your option) any later -+ version. -+ -+ pilight is distributed in the hope that it will be useful, but WITHOUT ANY -+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -+ A PARTICULAR PURPOSE. See the GNU General Public License for more details. -+ -+ You should have received a copy of the GNU General Public License -+ along with pilight. If not, see -+*/ -+ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#define BUFFER_SIZE 256 -+#define MAX_PULSE_TYPES 10 -+#define BAUD 57600 -+#define MIN_PULSELENGTH 8 //tested to work down to 30us pulsewidth (=2) -+#define MAX_PULSELENGTH 1600 -+#define MIN_FOOTER_LENGTH 510 // 5100 deviced by 10 -+#define MIN_STREAM_LENGTH 25 -+ -+#include -+ -+// Code formatting meant for sending -+// on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486;r:5@ -+// off c:102020202020202020220202020020202200202200202020202020202020202203;p:279,2511,1395,9486;r:5@ -+ -+ -+// Code formatting outputted by receiver -+// on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486@ -+// off c:102020202020202020220202020020202200202200202020202020202020202203;p:279,2511,1395,9486@ -+ -+char data[BUFFER_SIZE]; -+volatile unsigned long ten_us_counter1 = 0; -+volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYPES]; -+volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; -+volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, plslen = 0, nrpulses = 0; -+ -+void initUART(void) { -+ DDRD |= _BV(PD1); -+ DDRD &= ~_BV(PD0); -+ -+ UBRR0H = UBRRH_VALUE; -+ UBRR0L = UBRRL_VALUE; -+ -+#if USE_2X -+ UCSR0A |= _BV(U2X0); -+#else -+ UCSR0A &= ~_BV(U2X0); -+#endif -+ -+ UCSR0B |= _BV(RXEN0); -+ UCSR0B |= _BV(RXCIE0); -+ // UCSR0B = UCSR0B | (1 << TXEN0); -+ -+ UCSR0C |= _BV(USBS0); -+ UCSR0C |= _BV(UCSZ01) | _BV(UCSZ00); -+} -+ -+void setup() { -+ uint8_t oldSREG = SREG; -+ -+ cli(); -+ -+ /* We initialize our array to zero -+ * here to spare resources while -+ * running. -+ */ -+ for(r=0;r 0 && spulse > 0 && srepeat > 0) { -+ z = strlen(&data[spulse]); -+ s = spulse; -+ nrpulses = 0; -+ for(i = spulse; i < spulse + z; i++) { -+ if(data[i] == ',') { -+ data[i] = '\0'; -+ plstypes[nrpulses++] = atoi(&data[s]); -+ s = i+1; -+ } -+ } -+ plstypes[nrpulses++] = atoi(&data[s]); -+ -+ codelen = strlen(&data[scode]); -+ repeats = atoi(&data[srepeat]); -+ cli(); -+ for(i=0;i 100000) { -+ putByte('\n'); -+ ten_us_counter1 = 0; -+ } -+ sei(); -+} -+ -+void broadcast() { -+ int i = 0, x = 0, match = 0, p = 0; -+ -+ putByte('c'); -+ putByte(':'); -+ for(i=0;i MIN_PULSELENGTH) { -+ if(ten_us_counter < MAX_PULSELENGTH) { -+ /* All codes are buffered */ -+ codes[nrpulses++] = ten_us_counter; -+ if(nrpulses > BUFFER_SIZE) { -+ nrpulses = 0; -+ } -+ /* Let's match footers */ -+ if(ten_us_counter > MIN_FOOTER_LENGTH) { -+ /* Only match minimal length pulse streams */ -+ if(nrpulses >= MIN_STREAM_LENGTH) { -+ /* -+ * Sending pulses over serial requires -+ * a lot of cpu ticks. We therefor have -+ * to be sure that we send valid codes. -+ * Therefor, only streams we at least -+ * received twice communicated. -+ */ -+ if(plslen == nrpulses) { -+ broadcast(); -+ } -+ plslen = nrpulses; -+ } -+ nrpulses = 0; -+ } -+ } -+ } -+ ten_us_counter = 0; -+ TCNT1 = 0; -+ sei(); -+} -+ -+int main(void) { -+ setup(); -+ while(1); -+} diff --git a/pilight_usb_nano.c b/pilight-usb-nano.ino similarity index 100% rename from pilight_usb_nano.c rename to pilight-usb-nano.ino From 86d575737cba0e99fd2c689c1f88f949c0b905fd Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 28 Mar 2021 13:02:22 +0200 Subject: [PATCH 02/44] Set VERSION to 2 and add a license mention --- pilight-usb-nano.ino | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 30481b6..e167a23 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -1,19 +1,13 @@ /* Copyright (C) 2015 CurlyMo - - This file is part of pilight. - - pilight is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - pilight is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. + This file is part of pilight. GNU General Public License v3.0. You should have received a copy of the GNU General Public License along with pilight. If not, see + + Copyright (C) 2021 Jorge Rivera. GNU General Public License v3.0. + - New version 2, fully Arduino IDE compatible + */ #include @@ -32,7 +26,7 @@ /* Number devided by 10 */ #define MIN_PULSELENGTH 8 //tested to work down to 30us pulsewidth (=2) #define MAX_PULSELENGTH 1600 -#define VERSION 1 +#define VERSION 2 volatile uint32_t minrawlen = 1000; volatile uint32_t maxrawlen = 0; From f29616536a206830f5d1cf4a7fd2deb61d0b3441 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 28 Mar 2021 13:28:48 +0200 Subject: [PATCH 03/44] First functional build with Arduino IDE that includes "wiring.c" - Add verification for AVR ATmega328p MCU and 16Mhz clock - Remove duplicate delayMicroseconds() function - Fix TIMER2 settings because it's changed by "wiring.c" - Add void loop() function --- pilight-usb-nano.ino | 83 +++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index e167a23..d4a9b7f 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -20,6 +20,14 @@ #include #include +#if !defined(__AVR_ATmega168P__) and !defined(__AVR_ATmega328P__) +#error "MCU must be AVR ATmega168p or ATmega328p" +#endif + +#if (F_CPU != 16000000) +#error "MCU clock must be 16Mhz" +#endif + #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 #define BAUD 57600 @@ -73,20 +81,6 @@ void initUART(void) { UCSR0C |= _BV(UCSZ01) | _BV(UCSZ00); } -/* From the Arduino library */ -void delayMicroseconds(unsigned int us) { - if(--us == 0) - return; - - us <<= 2; - us -= 2; - - __asm__ __volatile__ ( - "1: sbiw %0,1" "\n\t" // 2 cycles - "brne 1b" : "=w" (us) : "0" (us) // 2 cycles - ); -} - uint8_t getByte(void) { /* Wait for data to be buffer */ while(!(UCSR0A & (1 << RXC0))); @@ -149,10 +143,58 @@ void setup() { // TIMER = (F_CPU / PRESCALER) // OCR = ((F_CPU / PRESCALER) * SECONDS) - 1 - OCR2A = 0x13; - TIMSK2 |= _BV(OCIE2A); - TCCR2A = TCCR2A | (1 << WGM21); - TCCR2B = TCCR2B | (1 << CS21); + + /* *** TIMER2 CONFIG TCCR2A *** + Original TCCR2A = TCCR2A | (1 << WGM21); + Expected TCCR2A = 0b0000 0010 --> Mode 2 (CTC) + + TCCR2A – Timer/Counter Control Register A, Initial Value 0 + Bits 1:0 – WGM21:0: Waveform Generation Mode + + WARNING! Arduino set WGM20 in /cores/arduino/wiring.c + #if defined(TCCR2A) && defined(WGM20) + sbi(TCCR2A, WGM20); + */ + + bitSet(TCCR2A, WGM21); bitClear(TCCR2A, WGM20); + + /* *** TIMER2 CONFIG TCCR2B *** + Original TCCR2B = TCCR2B | (1 << CS21); + Expected TCCR2B = 0b0000 0010 --> clkT2S/8 (from prescaler) + + TCCR2B – Timer/Counter Control Register B, Initial Value 0 + Bit 2:0 – CS22:0: Clock Select + + WARNING! Arduino set CS22 in /cores/arduino/wiring.c + #if defined(TCCR2B) && defined(CS22) + sbi(TCCR2B, CS22); + */ + + bitClear(TCCR2B, CS22); bitSet(TCCR2B, CS21); bitClear(TCCR2B, CS20); + + /* *** SET COMPARE FLAG *** + OCF2A: Output Compare Flag 2 A + The OCF2A bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2A – output + compare register2. OCF2A is cleared by hardware when executing the corresponding interrupt handling vector. + Alternatively, OCF2A is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE2A (Timer/Counter2 compare + match interrupt enable), and OCF2A are set (one), the Timer/Counter2 compare match interrupt is executed. + */ + + OCR2A = 0x13; + + /* *** ENABLE TIMER2 COMPARE INTERRUPT *** + TIMSK2 – Timer/Counter2 Interrupt Mask Register + OCIE2A: Timer/Counter2 Output Compare Match A Interrupt Enable + + TIMSK2 – Timer/Counter2 Interrupt Mask Register, Initial Value 0 + Bit 1 – OCIE2A: Timer/Counter2 Output Compare Match A Interrupt Enable + + When the OCIE2A bit is written to one and the I-bit in the status register is set (one), the Timer/Counter2 compare match A + interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter2 occurs, i.e., when the + OCF2A bit is set in the Timer/Counter 2 interrupt flag register – TIFR2 + */ + + bitSet(TIMSK2, OCIE2A); PCMSK2 |= _BV(PCINT18); PCICR |= _BV(PCIE2); @@ -355,7 +397,6 @@ ISR(PCINT2_vect){ sei(); } -int main(void) { - setup(); - while(1); +void loop(){ + // put your main code here, to run repeatedly: } From 9d78816f082f1de251667e32ee03e2751f39865c Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 29 Mar 2021 10:31:23 +0200 Subject: [PATCH 04/44] Change serial UART init and RX interrupt hander to Arduino style. --- pilight-usb-nano.ino | 65 +++++++++----------------------------------- 1 file changed, 13 insertions(+), 52 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index d4a9b7f..0d392a6 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -41,10 +41,6 @@ volatile uint32_t maxrawlen = 0; volatile uint32_t mingaplen = 10000; volatile uint32_t maxgaplen = 5100; -const uint16_t MIN_2X_BAUD = F_CPU / (4 * (2 * 0XFFF + 1)) + 1; - -#include - // Code formatting meant for sending // on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486;r:5@ // off c:102020202020202020220202020020202200202200202020202020202020202203;p:279,2511,1395,9486;r:5@ @@ -53,40 +49,12 @@ const uint16_t MIN_2X_BAUD = F_CPU / (4 * (2 * 0XFFF + 1)) + 1; // on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486@ // off c:102020202020202020220202020020202200202200202020202020202020202203;p:279,2511,1395,9486@ -char data[BUFFER_SIZE]; +char data[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer for serial uart inputs and outputs volatile unsigned long ten_us_counter1 = 0; volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYPES]; volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; -void initUART(void) { - uint16_t x = 0; - - if((F_CPU != 16000000UL || BAUD != 57600) && BAUD > MIN_2X_BAUD) { - UCSR0A = 1 << U2X0; - x = (F_CPU / 4 / BAUD - 1) / 2; - } else { - UCSR0A = 0; - x = (F_CPU / 8 / BAUD - 1) / 2; - } - - UBRR0H = x >> 8; - UBRR0L = x; - - UCSR0B |= _BV(RXEN0); - UCSR0B |= _BV(RXCIE0); - UCSR0B |= _BV(TXEN0); - - UCSR0C |= _BV(USBS0); - UCSR0C |= _BV(UCSZ01) | _BV(UCSZ00); -} - -uint8_t getByte(void) { - /* Wait for data to be buffer */ - while(!(UCSR0A & (1 << RXC0))); - return (uint8_t)UDR0; -} - void putByte(unsigned char data) { /* Wait for empty transmit buffer */ while(!(UCSR0A & (1 << UDRE0))); @@ -101,18 +69,6 @@ void writeString(char *line) { } } -char *readString(void) { - static char rxstr[32]; - static char *temp; - temp = rxstr; - - while((*temp = getByte()) != '\n') { - ++temp; - } - - return rxstr; -} - void setup() { uint8_t oldSREG = SREG; @@ -199,7 +155,8 @@ void setup() { PCMSK2 |= _BV(PCINT18); PCICR |= _BV(PCIE2); - initUART(); + // Arduino build-in function to set serial UART data baud rate (depends board) + Serial.begin(BAUD); sei(); } @@ -294,13 +251,17 @@ void receive() { } } -ISR(USART_RX_vect) { - char c = UDR0; - data[q++] = c; +// Arduino build-in function called by INT when serial data is available (depends board) +void serialEvent() { + // get the new byte + char c = (char)Serial.read(); + // add it to the inputString + data[q++] = c; + // if the incoming character is a @ call receive() if(c == '@') { - data[q++] = '\0'; - receive(); - q = 0; + data[q++] = '\0'; + receive(); + q = 0; } } From e0f0db9ee8ecf4e72501e53054494078997947ab Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 29 Mar 2021 10:41:51 +0200 Subject: [PATCH 05/44] Change serial UART TX to Arduino style --- pilight-usb-nano.ino | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 0d392a6..01b3882 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -55,20 +55,6 @@ volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYP volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; -void putByte(unsigned char data) { - /* Wait for empty transmit buffer */ - while(!(UCSR0A & (1 << UDRE0))); - UDR0 = (unsigned char) data; -} - -/*! \brief Writes an ASCII string to the TX buffer */ -void writeString(char *line) { - while(*line != '\0') { - putByte(*line); - ++line; - } -} - void setup() { uint8_t oldSREG = SREG; @@ -217,7 +203,7 @@ void receive() { * Once we tuned our firmware send back our settings + fw version */ sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); - writeString(data); + Serial.print(data); } else if(scode > 0 && spulse > 0 && srepeat > 0) { z = strlen(&data[spulse]); s = spulse; @@ -271,7 +257,7 @@ ISR(TIMER2_COMPA_vect) { ten_us_counter++; ten_us_counter1++; if(ten_us_counter1 > 100000) { - putByte('\n'); + Serial.println(); ten_us_counter1 = 0; } sei(); @@ -280,8 +266,7 @@ ISR(TIMER2_COMPA_vect) { void broadcast() { int i = 0, x = 0, match = 0, p = 0; - putByte('c'); - putByte(':'); + Serial.print("c:"); for(i=0;i Date: Mon, 29 Mar 2021 17:24:14 +0200 Subject: [PATCH 06/44] Change RF RX ISR to Arduino style configurable pin --- pilight-usb-nano.ino | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 01b3882..a873b61 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -28,6 +28,8 @@ #error "MCU clock must be 16Mhz" #endif +#define RX_PIN 2 // Pin for ASK/OOK pulse Input from RF module data out. + #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 #define BAUD 57600 @@ -55,6 +57,8 @@ volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYP volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; +void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt handler instead specific AVR ISR(vector, attributes) + void setup() { uint8_t oldSREG = SREG; @@ -138,8 +142,8 @@ void setup() { bitSet(TIMSK2, OCIE2A); - PCMSK2 |= _BV(PCINT18); - PCICR |= _BV(PCIE2); + // Arduino built-in function to attach Interrupt Service Routines (depends board) + attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); // Arduino build-in function to set serial UART data baud rate (depends board) Serial.begin(BAUD); @@ -305,8 +309,11 @@ void broadcast() { nrpulses = 0; } -ISR(PCINT2_vect){ - cli(); +// Generic ISR function for RF RX pulse interrupt handler +void ISR_RX(){ + // Disable ISR for RF RX interrupt handler only + detachInterrupt(digitalPinToInterrupt(RX_PIN)); + /* We first do some filtering (same as pilight BPF) */ if(ten_us_counter > MIN_PULSELENGTH) { if(ten_us_counter < MAX_PULSELENGTH) { @@ -336,8 +343,9 @@ ISR(PCINT2_vect){ } } ten_us_counter = 0; - TCNT1 = 0; - sei(); + + // Re-enable ISR for RF RX interrupt handler + attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); } void loop(){ From d7a80531240cc79a98d3409f5c237e8aba204988 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 29 Mar 2021 18:27:57 +0200 Subject: [PATCH 07/44] Change RF TX output to Arduino style configurable pin --- pilight-usb-nano.ino | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index a873b61..55cd0dd 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -6,7 +6,10 @@ along with pilight. If not, see Copyright (C) 2021 Jorge Rivera. GNU General Public License v3.0. - - New version 2, fully Arduino IDE compatible + New v2 firmware features: + - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. + - Configurable RF receiver output (RX_PIN); must be interrupt captable, depends board (D2 as default). + - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). */ @@ -28,7 +31,9 @@ #error "MCU clock must be 16Mhz" #endif -#define RX_PIN 2 // Pin for ASK/OOK pulse Input from RF module data out. +/* Configurable RX & TX pins */ +#define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. +#define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 @@ -83,8 +88,8 @@ void setup() { power_timer1_disable(); //power_timer2_disable(); - DDRD |= _BV(DDD5); - DDRB |= _BV(DDB5); + pinMode(TX_PIN, OUTPUT); + SREG = oldSREG; // TIMER = (F_CPU / PRESCALER) @@ -221,23 +226,27 @@ void receive() { } plstypes[nrpulses++] = atoi(&data[s]); + /* Begin RF TX */ codelen = strlen(&data[scode]); repeats = atoi(&data[srepeat]); - cli(); + // Disable all interrupts + noInterrupts(); for(i=0;i Date: Mon, 29 Mar 2021 19:23:25 +0200 Subject: [PATCH 08/44] Remove power save settings --- pilight-usb-nano.ino | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 55cd0dd..8834d6d 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -65,7 +65,6 @@ volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt handler instead specific AVR ISR(vector, attributes) void setup() { - uint8_t oldSREG = SREG; cli(); @@ -77,21 +76,8 @@ void setup() { plstypes[r] = 0; } - ADCSRA &= ~_BV(ADEN); - ACSR = _BV(ACD); - DIDR0 = 0x3F; - DIDR1 |= _BV(AIN1D) | _BV(AIN0D); - - power_twi_disable(); - power_spi_disable(); - power_timer0_disable(); - power_timer1_disable(); - //power_timer2_disable(); - pinMode(TX_PIN, OUTPUT); - SREG = oldSREG; - // TIMER = (F_CPU / PRESCALER) // OCR = ((F_CPU / PRESCALER) * SECONDS) - 1 From 9640a076a25cea7e936b9ef6b635cca6f1dd5cd6 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 29 Mar 2021 19:27:32 +0200 Subject: [PATCH 09/44] Initialize plstypes array to zero at declare time --- pilight-usb-nano.ino | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 8834d6d..32285ad 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -58,7 +58,7 @@ volatile uint32_t maxgaplen = 5100; char data[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer for serial uart inputs and outputs volatile unsigned long ten_us_counter1 = 0; -volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYPES]; +volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYPES] = {0}; volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; @@ -68,14 +68,6 @@ void setup() { cli(); - /* We initialize our array to zero - * here to spare resources while - * running. - */ - for(r=0;r Date: Mon, 29 Mar 2021 20:20:22 +0200 Subject: [PATCH 10/44] Replaces 10us custom Timer2 ticks to standard Arduino micros() function --- pilight-usb-nano.ino | 92 +++++++++----------------------------------- 1 file changed, 19 insertions(+), 73 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 32285ad..51b6ee4 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -35,6 +35,8 @@ #define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. +#define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. + #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 #define BAUD 57600 @@ -57,8 +59,10 @@ volatile uint32_t maxgaplen = 5100; // off c:102020202020202020220202020020202200202200202020202020202020202203;p:279,2511,1395,9486@ char data[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer for serial uart inputs and outputs -volatile unsigned long ten_us_counter1 = 0; -volatile uint16_t ten_us_counter = 0, codes[BUFFER_SIZE], plstypes[MAX_PULSE_TYPES] = {0}; +volatile uint16_t codes[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer to store pulses length +volatile uint16_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) +volatile uint32_t new_counter = 0; // Global time counter to store initial pulse micros(). Replaces global ten_us_counter. + volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; @@ -66,72 +70,14 @@ void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt han void setup() { - cli(); - pinMode(TX_PIN, OUTPUT); - // TIMER = (F_CPU / PRESCALER) - // OCR = ((F_CPU / PRESCALER) * SECONDS) - 1 - - /* *** TIMER2 CONFIG TCCR2A *** - Original TCCR2A = TCCR2A | (1 << WGM21); - Expected TCCR2A = 0b0000 0010 --> Mode 2 (CTC) - - TCCR2A – Timer/Counter Control Register A, Initial Value 0 - Bits 1:0 – WGM21:0: Waveform Generation Mode - - WARNING! Arduino set WGM20 in /cores/arduino/wiring.c - #if defined(TCCR2A) && defined(WGM20) - sbi(TCCR2A, WGM20); - */ - - bitSet(TCCR2A, WGM21); bitClear(TCCR2A, WGM20); - - /* *** TIMER2 CONFIG TCCR2B *** - Original TCCR2B = TCCR2B | (1 << CS21); - Expected TCCR2B = 0b0000 0010 --> clkT2S/8 (from prescaler) - - TCCR2B – Timer/Counter Control Register B, Initial Value 0 - Bit 2:0 – CS22:0: Clock Select - - WARNING! Arduino set CS22 in /cores/arduino/wiring.c - #if defined(TCCR2B) && defined(CS22) - sbi(TCCR2B, CS22); - */ - - bitClear(TCCR2B, CS22); bitSet(TCCR2B, CS21); bitClear(TCCR2B, CS20); - - /* *** SET COMPARE FLAG *** - OCF2A: Output Compare Flag 2 A - The OCF2A bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2A – output - compare register2. OCF2A is cleared by hardware when executing the corresponding interrupt handling vector. - Alternatively, OCF2A is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE2A (Timer/Counter2 compare - match interrupt enable), and OCF2A are set (one), the Timer/Counter2 compare match interrupt is executed. - */ - - OCR2A = 0x13; - - /* *** ENABLE TIMER2 COMPARE INTERRUPT *** - TIMSK2 – Timer/Counter2 Interrupt Mask Register - OCIE2A: Timer/Counter2 Output Compare Match A Interrupt Enable - - TIMSK2 – Timer/Counter2 Interrupt Mask Register, Initial Value 0 - Bit 1 – OCIE2A: Timer/Counter2 Output Compare Match A Interrupt Enable - - When the OCIE2A bit is written to one and the I-bit in the status register is set (one), the Timer/Counter2 compare match A - interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter2 occurs, i.e., when the - OCF2A bit is set in the Timer/Counter 2 interrupt flag register – TIFR2 - */ - - bitSet(TIMSK2, OCIE2A); - // Arduino built-in function to attach Interrupt Service Routines (depends board) attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); // Arduino build-in function to set serial UART data baud rate (depends board) Serial.begin(BAUD); - sei(); } /* Everything is parsed on-the-fly to preserve memory */ @@ -242,18 +188,6 @@ void serialEvent() { } } -/* Our main timer */ -ISR(TIMER2_COMPA_vect) { - cli(); - ten_us_counter++; - ten_us_counter1++; - if(ten_us_counter1 > 100000) { - Serial.println(); - ten_us_counter1 = 0; - } - sei(); -} - void broadcast() { int i = 0, x = 0, match = 0, p = 0; @@ -301,6 +235,11 @@ void ISR_RX(){ // Disable ISR for RF RX interrupt handler only detachInterrupt(digitalPinToInterrupt(RX_PIN)); + uint32_t current_counter = micros(); + uint16_t ten_us_counter = uint16_t((current_counter-new_counter)/10); + + new_counter = current_counter; + /* We first do some filtering (same as pilight BPF) */ if(ten_us_counter > MIN_PULSELENGTH) { if(ten_us_counter < MAX_PULSELENGTH) { @@ -329,7 +268,6 @@ void ISR_RX(){ } } } - ten_us_counter = 0; // Re-enable ISR for RF RX interrupt handler attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); @@ -337,4 +275,12 @@ void ISR_RX(){ void loop(){ // put your main code here, to run repeatedly: + +#ifdef EVERY_SEC_LINE_FEED + static unsigned long line_feed_counter = 0; + if (millis() > line_feed_counter){ + line_feed_counter = millis()+1000; + Serial.println(); + } +#endif } From 8f4dc38a0eb0eec5aab8f54e6588f150401c7d91 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 29 Mar 2021 20:37:31 +0200 Subject: [PATCH 11/44] Adds all boards support --- pilight-usb-nano.ino | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 51b6ee4..dc22572 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -7,8 +7,10 @@ Copyright (C) 2021 Jorge Rivera. GNU General Public License v3.0. New v2 firmware features: + - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. + - Can run on other platforms like Arduino DUE, M0 (any SAMD boards), ESP8266, ESP32, Teensy, even Raspberry Pico. - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. - - Configurable RF receiver output (RX_PIN); must be interrupt captable, depends board (D2 as default). + - Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default). - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). */ @@ -23,14 +25,6 @@ #include #include -#if !defined(__AVR_ATmega168P__) and !defined(__AVR_ATmega328P__) -#error "MCU must be AVR ATmega168p or ATmega328p" -#endif - -#if (F_CPU != 16000000) -#error "MCU clock must be 16Mhz" -#endif - /* Configurable RX & TX pins */ #define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. From 7ca2160c57bbe61014497cbc85862d1d21e629cc Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 29 Mar 2021 20:37:51 +0200 Subject: [PATCH 12/44] Update Readme file --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f0a6f32..35ae7d0 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,37 @@ -# pilight USB Nano +# pilight USB Nano v2 (Arduino compatible) -The pilight Arduino Nano software allows any computer with an USB port to work with pilight. +The pilight USB Nano software allows any computer with an USB port to work with pilight. + +[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) + +## New v2 firmware features: + - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. + - Can run on other platforms like Arduino DUE, M0 (any SAMD boards), ESP8266, ESP32, Teensy, even Raspberry Pico. + - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. + - Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default). + - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). + +## Usage: 1. Compile the firmware: -``` -avr-gcc -Os -Wall -DF_CPU=16000000UL -mmcu=atmega328p -c -o pilight_usb_nano.o pilight_usb_nano.c -lm -I. -avr-gcc -mmcu=atmega328p pilight_usb_nano.o -o pilight_usb_nano -avr-objcopy -O ihex -R .eeprom pilight_usb_nano pilight_usb_nano.hex -``` -2. Flash the firmware on the Arduino Nano: -`avrdude -b 57600 -p atmega328p -c arduino -P COM5 -U flash:w:pilight_usb_nano.hex` -3. Connect the receiver data pin to D2 and the sender to D5. -4. Connect the Arduino Nano to your computer. -5. Check what COM port the Arduino Nano is using. -6. Configure pilight to interface with the Arduino Nano (see below). + ``` + - Open Ardino IDE application + - File> Open> Select file "pilight-usb-nano.ino" + - Tools> Board> Select your board + - Sketch> Verify/Compile + ``` +2. Flash the firmware on the board: + ``` + - Tools> Port> Select your USB/Serial COM port + - Sketch> Upload + ``` +3. Connect the receiver data pin to configured RX_PIN (D2 as default) and the transmitter data pin to configured TX_PIN (D5 as default). +4. Connect the Arduino to your computer. +5. Check what Serial/COM port the Arduino is using. +6. Configure pilight to interface with the Arduino (see below). 7. Start pilight normally and it should work OOTB. -pilight USB nano hardware configuration: +## pilight USB Arduino hardware configuration: Linux example: ``` @@ -33,4 +48,25 @@ Windows Example: "comport": "COM5" } } -``` \ No newline at end of file +``` + +# License + +Copyright (C) 2015 CurlyMo. This file is part of pilight. GPLv3. + +Copyright (C) 2021 Jorge Rivera. GNU General Public License v3.0. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + From 3ec280ce3d6864579a540f13fa1b45c15104c6e1 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Tue, 30 Mar 2021 09:41:16 +0200 Subject: [PATCH 13/44] Remove redundant includes --- pilight-usb-nano.ino | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index dc22572..95184fb 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -15,16 +15,6 @@ */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - /* Configurable RX & TX pins */ #define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. From 65e6bc066b45a932d5508d5e428bf5d9f0d7f2fc Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Tue, 30 Mar 2021 09:48:05 +0200 Subject: [PATCH 14/44] Remove global vars codelen and repeats --- pilight-usb-nano.ino | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 95184fb..bc5fade 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -47,7 +47,6 @@ volatile uint16_t codes[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer to st volatile uint16_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) volatile uint32_t new_counter = 0; // Global time counter to store initial pulse micros(). Replaces global ten_us_counter. -volatile uint8_t state = 0, codelen = 0, repeats = 0, pos = 0; volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt handler instead specific AVR ISR(vector, attributes) @@ -135,12 +134,10 @@ void receive() { plstypes[nrpulses++] = atoi(&data[s]); /* Begin RF TX */ - codelen = strlen(&data[scode]); - repeats = atoi(&data[srepeat]); // Disable all interrupts noInterrupts(); - for(i=0;i Date: Tue, 30 Mar 2021 10:09:30 +0200 Subject: [PATCH 15/44] Remove unused vars --- pilight-usb-nano.ino | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index bc5fade..24fa888 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -47,7 +47,9 @@ volatile uint16_t codes[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer to st volatile uint16_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) volatile uint32_t new_counter = 0; // Global time counter to store initial pulse micros(). Replaces global ten_us_counter. -volatile uint8_t valid_buffer = 0x00, r = 0, q = 0, rawlen = 0, nrpulses = 0; +volatile uint8_t q = 0; // Index of data buffer +volatile uint8_t rawlen = 0; // Flag to ensure to call broadcast() after reveive two same lenght pulse train +volatile uint8_t nrpulses = 0; // Index of pulse lenght buffer void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt handler instead specific AVR ISR(vector, attributes) @@ -144,8 +146,9 @@ void receive() { } digitalWrite(TX_PIN,LOW); - for(r=0;r Date: Tue, 30 Mar 2021 11:17:17 +0200 Subject: [PATCH 16/44] Add precompiler option to include stripped spaces --- pilight-usb-nano.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 24fa888..7ae854e 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -20,6 +20,7 @@ #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. #define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. +//#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 @@ -181,6 +182,8 @@ void broadcast() { for(x=0;x Date: Tue, 30 Mar 2021 10:37:17 +0200 Subject: [PATCH 17/44] Move broadcast() to loop() --- pilight-usb-nano.ino | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 7ae854e..f259cb2 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -45,12 +45,13 @@ volatile uint32_t maxgaplen = 5100; char data[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer for serial uart inputs and outputs volatile uint16_t codes[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer to store pulses length -volatile uint16_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) + uint16_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) volatile uint32_t new_counter = 0; // Global time counter to store initial pulse micros(). Replaces global ten_us_counter. volatile uint8_t q = 0; // Index of data buffer volatile uint8_t rawlen = 0; // Flag to ensure to call broadcast() after reveive two same lenght pulse train volatile uint8_t nrpulses = 0; // Index of pulse lenght buffer +volatile uint8_t broadcast_flag = 0; // Flag to call broadcast with nrpulses value void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt handler instead specific AVR ISR(vector, attributes) @@ -173,7 +174,7 @@ void serialEvent() { } } -void broadcast() { +void broadcast(uint8_t nrpulses) { int i = 0, x = 0, match = 0, p = 0; Serial.print("c:"); @@ -223,7 +224,6 @@ void broadcast() { plstypes[i] = 0; } Serial.print('@'); - nrpulses = 0; } // Generic ISR function for RF RX pulse interrupt handler @@ -256,7 +256,7 @@ void ISR_RX(){ * received twice communicated. */ if(rawlen == nrpulses) { - broadcast(); + broadcast_flag = nrpulses; } rawlen = nrpulses; } @@ -265,12 +265,23 @@ void ISR_RX(){ } } - // Re-enable ISR for RF RX interrupt handler - attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); + // If no broadcast, re-enable ISR for RF RX interrupt handler + if (broadcast_flag == 0){ + attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); + } } void loop(){ - // put your main code here, to run repeatedly: + + // if broadcast flag is set + if (broadcast_flag > 0){ + // Call to broadcast() + broadcast(broadcast_flag); + // Clear flag + broadcast_flag = 0; + // Re-enable ISR for RF RX interrupt handler + attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); + } #ifdef EVERY_SEC_LINE_FEED static unsigned long line_feed_counter = 0; From dd13b775d7b991afeb419246abde11f4fc0d429e Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Tue, 30 Mar 2021 13:56:53 +0200 Subject: [PATCH 18/44] Move receive() to loop() --- pilight-usb-nano.ino | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index f259cb2..112f453 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -30,10 +30,10 @@ #define MAX_PULSELENGTH 1600 #define VERSION 2 -volatile uint32_t minrawlen = 1000; -volatile uint32_t maxrawlen = 0; -volatile uint32_t mingaplen = 10000; -volatile uint32_t maxgaplen = 5100; +uint32_t minrawlen = 1000; +uint32_t maxrawlen = 0; +uint32_t mingaplen = 10000; +uint32_t maxgaplen = 5100; // Unused. Preserved for legacy compatibility. // Code formatting meant for sending // on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486;r:5@ @@ -52,6 +52,7 @@ volatile uint8_t q = 0; // Index of data buffer volatile uint8_t rawlen = 0; // Flag to ensure to call broadcast() after reveive two same lenght pulse train volatile uint8_t nrpulses = 0; // Index of pulse lenght buffer volatile uint8_t broadcast_flag = 0; // Flag to call broadcast with nrpulses value +volatile uint8_t receive_flag = 0; // Flag to call receive() in loop() void ISR_RX(); // Generic ISR function declaration for RF RX pulse interrupt handler instead specific AVR ISR(vector, attributes) @@ -162,16 +163,18 @@ void receive() { // Arduino build-in function called by INT when serial data is available (depends board) void serialEvent() { - // get the new byte - char c = (char)Serial.read(); - // add it to the inputString - data[q++] = c; - // if the incoming character is a @ call receive() - if(c == '@') { - data[q++] = '\0'; - receive(); - q = 0; - } + while (Serial.available() and !receive_flag ) { + // get the new byte + char c = (char)Serial.read(); + // add it to the inputString + data[q++] = c; + // if the incoming character is a @ set receive_flag call receive() in loop() outside ISR + if(c == '@') { + data[q++] = '\0'; + receive_flag = true; + q = 0; + } + } } void broadcast(uint8_t nrpulses) { @@ -273,6 +276,14 @@ void ISR_RX(){ void loop(){ + // if receive flag is set + if (receive_flag){ + // Call to receive() + receive(); + // Clear flag + receive_flag = 0; + } + // if broadcast flag is set if (broadcast_flag > 0){ // Call to broadcast() From 07d2e64ff8759bfe10af79e1ba2fdfa122892963 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Tue, 30 Mar 2021 14:24:46 +0200 Subject: [PATCH 19/44] Add support to led blink on valid RX --- pilight-usb-nano.ino | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 112f453..6a23a8c 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -12,6 +12,7 @@ - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. - Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default). - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). + - Support to configure a digital output so that a led blinks on valid RF code reception. */ @@ -21,6 +22,7 @@ #define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. //#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. +//#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 @@ -60,6 +62,10 @@ void setup() { pinMode(TX_PIN, OUTPUT); +#ifdef LED_BLINK_RX + pinMode(LED_BLINK_RX, OUTPUT); +#endif + // Arduino built-in function to attach Interrupt Service Routines (depends board) attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); @@ -286,10 +292,20 @@ void loop(){ // if broadcast flag is set if (broadcast_flag > 0){ + +#ifdef LED_BLINK_RX + digitalWrite(LED_BLINK_RX, HIGH); // Led blink on RF RX +#endif + // Call to broadcast() broadcast(broadcast_flag); // Clear flag broadcast_flag = 0; + +#ifdef LED_BLINK_RX + digitalWrite(LED_BLINK_RX, LOW); // Led blink on RF RX +#endif + // Re-enable ISR for RF RX interrupt handler attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); } From fa63ecd1a74c217b1247b2fd4cd3964906a4a664 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Tue, 30 Mar 2021 14:39:44 +0200 Subject: [PATCH 20/44] Add support to sets valid RX settings at boot --- pilight-usb-nano.ino | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 6a23a8c..3af4bb0 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -12,7 +12,9 @@ - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. - Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default). - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). - - Support to configure a digital output so that a led blinks on valid RF code reception. + - Support to configure a digital output so that a led blinks at valid RF code reception. + - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. + - Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'. */ @@ -23,18 +25,26 @@ #define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. //#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. //#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. +//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:22,200,3000,51000@' #define BUFFER_SIZE 256 #define MAX_PULSE_TYPES 10 #define BAUD 57600 /* Number devided by 10 */ #define MIN_PULSELENGTH 8 //tested to work down to 30us pulsewidth (=2) -#define MAX_PULSELENGTH 1600 +#define MAX_PULSELENGTH 3600 // v2 change from 1600 #define VERSION 2 +#ifdef DEFAULT_RX_SETTINGS +uint32_t minrawlen = 22; +uint32_t maxrawlen = 200; +uint32_t mingaplen = 300; +#else uint32_t minrawlen = 1000; uint32_t maxrawlen = 0; uint32_t mingaplen = 10000; +#endif + uint32_t maxgaplen = 5100; // Unused. Preserved for legacy compatibility. // Code formatting meant for sending From 9ee31d17f2752a8e1967e4f66b26ee7e43e97e15 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Tue, 30 Mar 2021 18:32:23 +0200 Subject: [PATCH 21/44] Update Readme.md --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35ae7d0..fe99579 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,23 @@ The pilight USB Nano software allows any computer with an USB port to work with [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) ## New v2 firmware features: - - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. - - Can run on other platforms like Arduino DUE, M0 (any SAMD boards), ESP8266, ESP32, Teensy, even Raspberry Pico. + - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. any clock speed allowed. + - Can run on other platforms like Arduino SAMD boards (DUE, M0, etc.), ESP8266, ESP32, Teensy, even Raspberry Pico. + - Works using the MCU's internal USB-Serial COM port (CDC/ACM device class) or any onboard/external USB-Serial adapter. - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. - Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default). - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). + - Support to configure a digital output so that a led blinks at valid RF code reception. + - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. + - Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'. + - Fix TX pulse generator drift from 9.95µS to 0.69µS (AVR@16Mhz). + - Improve RX pulse meter resolution from 10µS to 4µS (AVR@16Mhz). ## Usage: 1. Compile the firmware: ``` - - Open Ardino IDE application + - Open Arduino IDE application - File> Open> Select file "pilight-usb-nano.ino" - Tools> Board> Select your board - Sketch> Verify/Compile @@ -50,6 +56,51 @@ Windows Example: } ``` +## Example: +Transmitter code: +``` +c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800;r:4@ +``` + * Receive with spaces: + ``` + c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@ + ``` + + * Receive without spaces: + ``` + c:100011100010001010111010000000002;p:1400,600,6800@ + ``` + +## Decoding: +You can decode and encode any code using an external tool **"picoder"** from https://github.com/latchdevel/picoder + +Decode example: +``` +$ picoder decode -s "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@" +``` +return: +``` + [{ + "conrad_rsl_switch": { + "id": 1, + "unit": 2, + "state": "on" + } + }] +``` + +Encode example: +``` +$ picoder encode -f '{ "conrad_rsl_switch" : {"id":1,"unit":2,"on":1} }' -r 5 +``` +return: +``` +c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800;r:5@ +``` + +## To do: +- [ ] Support to measure RSSI of receivers that provide it. + # License Copyright (C) 2015 CurlyMo. This file is part of pilight. GPLv3. From 0e44e7d6fdbe99079d14316090675819fe3f24c8 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Wed, 31 Mar 2021 12:03:06 +0200 Subject: [PATCH 22/44] Fix compiler warnings, and others cosmetics --- pilight-usb-nano.ino | 323 ++++++++++++++++++++++--------------------- 1 file changed, 162 insertions(+), 161 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 3af4bb0..ded9088 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -1,14 +1,15 @@ /* - Copyright (C) 2015 CurlyMo + Copyright (C) 2015 CurlyMo This file is part of pilight. GNU General Public License v3.0. - You should have received a copy of the GNU General Public License - along with pilight. If not, see + You should have received a copy of the GNU General Public License + along with pilight. If not, see Copyright (C) 2021 Jorge Rivera. GNU General Public License v3.0. + New v2 firmware features: - - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. - - Can run on other platforms like Arduino DUE, M0 (any SAMD boards), ESP8266, ESP32, Teensy, even Raspberry Pico. + - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, Mega, Leonardo, etc. + - Can run on other platforms like Arduino SAMD boards (DUE, M0, etc.), ESP8266, ESP32, Teensy, even Raspberry Pico. - Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported. - Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default). - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). @@ -27,13 +28,13 @@ //#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. //#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:22,200,3000,51000@' -#define BUFFER_SIZE 256 -#define MAX_PULSE_TYPES 10 -#define BAUD 57600 +#define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type +#define MAX_PULSE_TYPES 10 +#define BAUD 57600 /* Number devided by 10 */ -#define MIN_PULSELENGTH 8 //tested to work down to 30us pulsewidth (=2) -#define MAX_PULSELENGTH 3600 // v2 change from 1600 -#define VERSION 2 +#define MIN_PULSELENGTH 8 // tested to work down to 30us pulsewidth (=2) +#define MAX_PULSELENGTH 3600 // v2 change from 1600 +#define VERSION 2 // Version 2 (Arduino compatible) #ifdef DEFAULT_RX_SETTINGS uint32_t minrawlen = 22; @@ -77,104 +78,104 @@ void setup() { #endif // Arduino built-in function to attach Interrupt Service Routines (depends board) - attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); - + attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); + // Arduino build-in function to set serial UART data baud rate (depends board) - Serial.begin(BAUD); + Serial.begin(BAUD); } /* Everything is parsed on-the-fly to preserve memory */ void receive() { - unsigned int scode = 0, spulse = 0, srepeat = 0, sstart = 0; - unsigned int i = 0, s = 0, z = 0, x = 0; - - nrpulses = 0; - - z = strlen(data); - for(i = 0; i < z; i++) { - if(data[i] == 's') { - sstart = i + 2; - break; - } - if(data[i] == 'c') { - scode = i + 2; - } - if(data[i] == 'p') { - spulse = i + 2; - } - if(data[i] == 'r') { - srepeat = i + 2; - } - if(data[i] == ';') { - data[i] = '\0'; - } - } - /* - * Tune the firmware with pilight-daemon values - */ - if(sstart > 0) { - z = strlen(&data[sstart]); - s = sstart; - x = 0; - for(i = sstart; i < sstart + z; i++) { - if(data[i] == ',') { - data[i] = '\0'; - if(x == 0) { - minrawlen = atol(&data[s]); - } - if(x == 1) { - maxrawlen = atol(&data[s]); - } - if(x == 2) { - mingaplen = atoi(&data[s])/10; - } - x++; - s = i+1; - } - } - if(x == 3) { - maxgaplen = atol(&data[s])/10; - } - /* - * Once we tuned our firmware send back our settings + fw version - */ - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); - Serial.print(data); - } else if(scode > 0 && spulse > 0 && srepeat > 0) { - z = strlen(&data[spulse]); - s = spulse; - nrpulses = 0; - for(i = spulse; i < spulse + z; i++) { - if(data[i] == ',') { - data[i] = '\0'; - plstypes[nrpulses++] = atoi(&data[s]); - s = i+1; - } - } - plstypes[nrpulses++] = atoi(&data[s]); + unsigned int scode = 0, spulse = 0, srepeat = 0, sstart = 0; + unsigned int i = 0, s = 0, z = 0, x = 0; + + nrpulses = 0; + + z = strlen(data); + for(i = 0; i < z; i++) { + if(data[i] == 's') { + sstart = i + 2; + break; + } + if(data[i] == 'c') { + scode = i + 2; + } + if(data[i] == 'p') { + spulse = i + 2; + } + if(data[i] == 'r') { + srepeat = i + 2; + } + if(data[i] == ';') { + data[i] = '\0'; + } + } + /* + * Tune the firmware with pilight-daemon values + */ + if(sstart > 0) { + z = strlen(&data[sstart]); + s = sstart; + x = 0; + for(i = sstart; i < sstart + z; i++) { + if(data[i] == ',') { + data[i] = '\0'; + if(x == 0) { + minrawlen = atol(&data[s]); + } + if(x == 1) { + maxrawlen = atol(&data[s]); + } + if(x == 2) { + mingaplen = atoi(&data[s])/10; + } + x++; + s = i+1; + } + } + if(x == 3) { + maxgaplen = atol(&data[s])/10; + } + /* + * Once we tuned our firmware send back our settings + fw version + */ + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); + Serial.print(data); + } else if(scode > 0 && spulse > 0 && srepeat > 0) { + z = strlen(&data[spulse]); + s = spulse; + nrpulses = 0; + for(i = spulse; i < spulse + z; i++) { + if(data[i] == ',') { + data[i] = '\0'; + plstypes[nrpulses++] = atoi(&data[s]); + s = i+1; + } + } + plstypes[nrpulses++] = atoi(&data[s]); /* Begin RF TX */ // Disable all interrupts - noInterrupts(); - for(i=0;i MIN_PULSELENGTH) { - if(ten_us_counter < MAX_PULSELENGTH) { - /* All codes are buffered */ - codes[nrpulses++] = ten_us_counter; - if(nrpulses > BUFFER_SIZE) { - nrpulses = 0; - } - /* Let's match footers */ - if(ten_us_counter > mingaplen) { - /* Only match minimal length pulse streams */ - if(nrpulses >= minrawlen && nrpulses <= maxrawlen) { - /* - * Sending pulses over serial requires - * a lot of cpu ticks. We therefor have - * to be sure that we send valid codes. - * Therefor, only streams we at least - * received twice communicated. - */ - if(rawlen == nrpulses) { - broadcast_flag = nrpulses; - } - rawlen = nrpulses; - } - nrpulses = 0; - } - } - } + /* We first do some filtering (same as pilight BPF) */ + if(ten_us_counter > MIN_PULSELENGTH) { + if(ten_us_counter < MAX_PULSELENGTH) { + /* All codes are buffered */ + codes[nrpulses++] = ten_us_counter; + if(nrpulses >= BUFFER_SIZE-1) { + nrpulses = 0; + } + /* Let's match footers */ + if(ten_us_counter > mingaplen) { + /* Only match minimal length pulse streams */ + if(nrpulses >= minrawlen && nrpulses <= maxrawlen) { + /* + * Sending pulses over serial requires + * a lot of cpu ticks. We therefor have + * to be sure that we send valid codes. + * Therefor, only streams we at least + * received twice communicated. + */ + if(rawlen == nrpulses) { + broadcast_flag = nrpulses; + } + rawlen = nrpulses; + } + nrpulses = 0; + } + } + } // If no broadcast, re-enable ISR for RF RX interrupt handler if (broadcast_flag == 0){ From dd65006c3f60fd7bc36662275db9afca5180b3ee Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Wed, 31 Mar 2021 16:41:39 +0200 Subject: [PATCH 23/44] Add "Compile tests" GitHub Action --- .github/workflows/CompileTests.yml | 104 +++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/workflows/CompileTests.yml diff --git a/.github/workflows/CompileTests.yml b/.github/workflows/CompileTests.yml new file mode 100644 index 0000000..72c7850 --- /dev/null +++ b/.github/workflows/CompileTests.yml @@ -0,0 +1,104 @@ +# This is the name of the workflow, visible on GitHub UI. +name: 'Compile tests' + +#description: 'Run the Arduino CLI to compile the sketch and check if it compiles fine for multiple boards' +#author: 'Jorge Rivera' + +# Controls when the action will run. +# Here we tell GitHub to run the workflow when a commit. +on: + # Triggers the workflow on push or pull request events but only for the "arduino" branch + push: + branches: [ arduino ] + paths: + - '*.ino' + - '.github/workflows/*.yml' + + pull_request: + branches: [ arduino ] + paths: + - '*.ino' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# This is the list of jobs that will be run concurrently. +# Since we use a build matrix, the actual number of jobs +# started depends on how many configurations the matrix +# will produce. +jobs: + boards: + + # This is the name of the job + name: "Compile test for ${{ matrix.config.board }}" + + # This is the platform GitHub will use to run our workflow, we + # pick Linux for no particular reason. + runs-on: ubuntu-latest + + # Here we tell GitHub that the jobs must be determined + # dynamically depending on a matrix configuration. + strategy: + + # Set to false so that GitHub does not cancel all jobs + # in progress if any array job fails. + fail-fast: false + + # The matrix will produce one job for each configuration: + matrix: + config: + - board: "Arduino Nano" + fqbn: "arduino:avr:nano" + platform: "arduino:avr" + + - board: "Arduino UNO" + fqbn: "arduino:avr:uno" + platform: "arduino:avr" + + - board: "Arduino Leonardo" + fqbn: "arduino:avr:leonardo" + platform: "arduino:avr" + + - board: "Arduino Due (Native USB Port)" + fqbn: "arduino:sam:arduino_due_x" + platform: "arduino:sam" + + - board: "Arduino M0" + fqbn: "arduino:samd:mzero_bl" + platform: "arduino:samd" + + - board: "ESP8266 NodeMCUv2" + fqbn: "esp8266:esp8266:nodemcuv2" + platform: "esp8266:esp8266" + additional-url: "--additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json" + + # This is the list of steps this job will run. + steps: + # First of all, we clone the repo using the "checkout" action. + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout + uses: actions/checkout@v2 + + # We use the "arduino/setup-arduino-cli" action to install and + # configure the Arduino CLI on the system. + - name: Setup Arduino CLI + uses: arduino/setup-arduino-cli@v1.1.1 + + # We then install the platform, which one will be determined + # dynamically by the build matrix. + - name: Install platform ${{ matrix.config.platform }} + run: | + arduino-cli config init -v ${{ matrix.config.additional-url }} + arduino-cli core update-index -v + arduino-cli core install -v ${{ matrix.config.platform }} --run-post-install + + # Finally, we compile the sketch, using the FQBN that was set in the build matrix. + - name: Compile sketch for ${{ matrix.config.board }} + run: arduino-cli compile -v --fqbn ${{ matrix.config.fqbn }} --export-binaries --warnings all --log-level info + + # Upload binary (.hex) files to artifacts + - name: Upload compiled binaries files to Artifacts + uses: actions/upload-artifact@v1 + with: + name: "Binaries for ${{ matrix.config.board }}" + path: ./ From bc7e90fabd3311d30c9406818da88aa217e3bf09 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Wed, 31 Mar 2021 17:47:36 +0200 Subject: [PATCH 24/44] Add compile tests action status badge --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fe99579..fa39e12 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ The pilight USB Nano software allows any computer with an USB port to work with pilight. [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) +[![Compile tests](https://github.com/latchdevel/pilight-usb-nano/actions/workflows/CompileTests.yml/badge.svg?branch=arduino)](https://github.com/latchdevel/pilight-usb-nano/actions/workflows/CompileTests.yml) ## New v2 firmware features: - Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. any clock speed allowed. @@ -40,7 +41,7 @@ The pilight USB Nano software allows any computer with an USB port to work with ## pilight USB Arduino hardware configuration: Linux example: -``` +```json "hardware": { "433nano": { "comport": "/dev/ttyUSB0" @@ -48,7 +49,7 @@ Linux example: } ``` Windows Example: -``` +```json "hardware": { "433nano": { "comport": "COM5" @@ -79,7 +80,7 @@ Decode example: $ picoder decode -s "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@" ``` return: -``` +```json [{ "conrad_rsl_switch": { "id": 1, @@ -90,7 +91,7 @@ return: ``` Encode example: -``` +```json $ picoder encode -f '{ "conrad_rsl_switch" : {"id":1,"unit":2,"on":1} }' -r 5 ``` return: From 50666482b5915d519c7c937132c05ee384d5485a Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 3 May 2021 09:42:13 +0200 Subject: [PATCH 25/44] Add support to configure show settings at boot --- pilight-usb-nano.ino | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index ded9088..7b73150 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -16,6 +16,7 @@ - Support to configure a digital output so that a led blinks at valid RF code reception. - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. - Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'. + - Support to configure show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' */ @@ -27,6 +28,7 @@ //#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. //#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. //#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:22,200,3000,51000@' +#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' #define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type #define MAX_PULSE_TYPES 10 @@ -78,10 +80,16 @@ void setup() { #endif // Arduino built-in function to attach Interrupt Service Routines (depends board) - attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); + attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); // Arduino build-in function to set serial UART data baud rate (depends board) - Serial.begin(BAUD); + Serial.begin(BAUD); + +#ifdef BOOT_SHOW_SETTINGS + // Show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); + Serial.print(data); +#endif } From 6ace4c1c150be1cf4aecfa4b891ba78b1a42eae1 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 3 May 2021 10:03:10 +0200 Subject: [PATCH 26/44] Support to configure add line feed '\n' each line output --- pilight-usb-nano.ino | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 7b73150..fff9f47 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -16,7 +16,8 @@ - Support to configure a digital output so that a led blinks at valid RF code reception. - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. - Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'. - - Support to configure show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' + - Support to configure show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@'. + - Support to configure add line feed '\n' each line output. */ @@ -24,11 +25,12 @@ #define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. -#define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. -//#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. -//#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. -//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:22,200,3000,51000@' +//#define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. +#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. +#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. +#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:22,200,3000,51000@' #define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' +#define ADD_LINE_FEED // If defined, add line feed '\n' each line output. #define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type #define MAX_PULSE_TYPES 10 @@ -88,8 +90,12 @@ void setup() { #ifdef BOOT_SHOW_SETTINGS // Show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); +#ifdef ADD_LINE_FEED + Serial.println(data); +#else Serial.print(data); #endif +#endif } @@ -149,7 +155,11 @@ void receive() { * Once we tuned our firmware send back our settings + fw version */ sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); +#ifdef ADD_LINE_FEED + Serial.println(data); +#else Serial.print(data); +#endif } else if(scode > 0 && spulse > 0 && srepeat > 0) { z = strlen(&data[spulse]); s = spulse; @@ -251,7 +261,11 @@ void broadcast(uint8_t nrpulses) { } plstypes[i] = 0; } +#ifdef ADD_LINE_FEED + Serial.println('@'); +#else Serial.print('@'); +#endif } // Generic ISR function for RF RX pulse interrupt handler From c3ea2be6bc34e587a51dd350c7f86f782ec7f1a1 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 10 May 2021 00:02:52 +0200 Subject: [PATCH 27/44] Fix MIN/MAX PULSELENGTH values and their display --- pilight-usb-nano.ino | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index fff9f47..f7ec1ab 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -28,26 +28,28 @@ //#define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. #define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. #define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. -#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:22,200,3000,51000@' -#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' +#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,3000,51000@' +#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,3000,51000,2,1,1600@' #define ADD_LINE_FEED // If defined, add line feed '\n' each line output. #define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type -#define MAX_PULSE_TYPES 10 +#define MAX_PULSE_TYPES 10 // From 0 to 9 #define BAUD 57600 -/* Number devided by 10 */ -#define MIN_PULSELENGTH 8 // tested to work down to 30us pulsewidth (=2) -#define MAX_PULSELENGTH 3600 // v2 change from 1600 + +/* Show numbers devided by 10 */ +#define MIN_PULSELENGTH 10 // v2 change from 8 to 10 and show devided by 10 +#define MAX_PULSELENGTH 16000 // v2 change from 1600 to 16000 and show devided by 10 + #define VERSION 2 // Version 2 (Arduino compatible) #ifdef DEFAULT_RX_SETTINGS -uint32_t minrawlen = 22; -uint32_t maxrawlen = 200; -uint32_t mingaplen = 300; +uint32_t minrawlen = 20; +uint32_t maxrawlen = 200; +uint32_t mingaplen = 300; // Used and showing multiplied by 10 #else -uint32_t minrawlen = 1000; -uint32_t maxrawlen = 0; -uint32_t mingaplen = 10000; +uint32_t minrawlen = 1000; +uint32_t maxrawlen = 0; +uint32_t mingaplen = 10000; // Used and showing multiplied by 10 #endif uint32_t maxgaplen = 5100; // Unused. Preserved for legacy compatibility. @@ -89,7 +91,7 @@ void setup() { #ifdef BOOT_SHOW_SETTINGS // Show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -154,7 +156,7 @@ void receive() { /* * Once we tuned our firmware send back our settings + fw version */ - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH, MAX_PULSELENGTH); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -255,7 +257,7 @@ void broadcast(uint8_t nrpulses) { } Serial.print(";p:"); for(i=0;i Date: Mon, 10 May 2021 00:06:03 +0200 Subject: [PATCH 28/44] Fix type size of plstypes from int16_t to int32_t --- pilight-usb-nano.ino | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index f7ec1ab..d39afab 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -15,8 +15,8 @@ - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). - Support to configure a digital output so that a led blinks at valid RF code reception. - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. - - Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'. - - Support to configure show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@'. + - Support to configure initial RX settings at boot, like as 's:20,200,3000,51000@'. + - Support to configure show settings at boot, like as: 'v:20,200,3000,51000,2,1,1600@'. - Support to configure add line feed '\n' each line output. */ @@ -25,12 +25,12 @@ #define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. -//#define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. -#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. -#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. -#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,3000,51000@' -#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,3000,51000,2,1,1600@' -#define ADD_LINE_FEED // If defined, add line feed '\n' each line output. +#define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. +//#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. +//#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. +//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,3000,51000@' +//#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,3000,51000,2,1,1600@' +//#define ADD_LINE_FEED // If defined, add line feed '\n' each line output. #define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type #define MAX_PULSE_TYPES 10 // From 0 to 9 @@ -64,7 +64,7 @@ uint32_t maxgaplen = 5100; // Unused. Preserved for legacy compatibilit char data[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer for serial uart inputs and outputs volatile uint16_t codes[BUFFER_SIZE] = {0}; // Fill to 0 // Buffer to store pulses length - uint16_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) + uint32_t plstypes[MAX_PULSE_TYPES] = {0}; // Fill to 0 // Buffer to store pulse types (RX and TX) volatile uint32_t new_counter = 0; // Global time counter to store initial pulse micros(). Replaces global ten_us_counter. volatile uint8_t q = 0; // Index of data buffer From 8e803a9d5850c60efd28ad7876495f408a1d2f69 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Mon, 10 May 2021 16:14:31 +0200 Subject: [PATCH 29/44] Add maxgaplen check, and improve long pulses accuracy --- pilight-usb-nano.ino | 55 ++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index d39afab..7eada3a 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -15,8 +15,8 @@ - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). - Support to configure a digital output so that a led blinks at valid RF code reception. - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. - - Support to configure initial RX settings at boot, like as 's:20,200,3000,51000@'. - - Support to configure show settings at boot, like as: 'v:20,200,3000,51000,2,1,1600@'. + - Support to configure initial RX settings at boot, like as 's:20,200,3000,82000@'. + - Support to configure show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@'. - Support to configure add line feed '\n' each line output. */ @@ -52,7 +52,7 @@ uint32_t maxrawlen = 0; uint32_t mingaplen = 10000; // Used and showing multiplied by 10 #endif -uint32_t maxgaplen = 5100; // Unused. Preserved for legacy compatibility. +uint32_t maxgaplen = 82000; // v2 used and change from 5100 to 82000 (for quigg_gt7000 protocol) set and show as is. // Code formatting meant for sending // on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486;r:5@ @@ -90,8 +90,8 @@ void setup() { Serial.begin(BAUD); #ifdef BOOT_SHOW_SETTINGS - // Show settings at boot, like as: 'v:22,200,3000,51000,2,8,3600@' - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + // Show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -144,19 +144,19 @@ void receive() { maxrawlen = atol(&data[s]); } if(x == 2) { - mingaplen = atoi(&data[s])/10; + mingaplen = atol(&data[s])/10; } x++; s = i+1; } } if(x == 3) { - maxgaplen = atol(&data[s])/10; + maxgaplen = atol(&data[s]); } /* * Once we tuned our firmware send back our settings + fw version */ - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -169,32 +169,47 @@ void receive() { for(i = spulse; i < spulse + z; i++) { if(data[i] == ',') { data[i] = '\0'; - plstypes[nrpulses++] = atoi(&data[s]); + plstypes[nrpulses++] = atol(&data[s]); s = i+1; } } - plstypes[nrpulses++] = atoi(&data[s]); + plstypes[nrpulses++] = atol(&data[s]); + s = strlen(&data[scode]); + x = (unsigned int)atoi(&data[srepeat]); + + // Check for maxgaplen + for(z = scode; z < scode + s; z++) { + if (plstypes[data[z] - '0'] >= maxgaplen){ + return ; + } + } - /* Begin RF TX */ - // Disable all interrupts + /* Begin RF TX */ + // Disable all interrupts noInterrupts(); - for(i=0;i<(unsigned int)atoi(&data[srepeat]);i++) { - for(z = scode; z < scode + strlen(&data[scode]); z++) { + for(i=0;i Date: Sun, 16 May 2021 01:09:03 +0200 Subject: [PATCH 30/44] Add maxgaplen check also in RX, and clear buffer in TX --- pilight-usb-nano.ino | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 7eada3a..afae214 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -28,8 +28,8 @@ #define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. //#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. //#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. -//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,3000,51000@' -//#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,3000,51000,2,1,1600@' +//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,3000,82000@' +//#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' //#define ADD_LINE_FEED // If defined, add line feed '\n' each line output. #define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type @@ -180,6 +180,11 @@ void receive() { // Check for maxgaplen for(z = scode; z < scode + s; z++) { if (plstypes[data[z] - '0'] >= maxgaplen){ + // Clear pulse types array + for(i=0;i mingaplen) { + if((ten_us_counter > mingaplen) and (ten_us_counter < maxgaplen/10)) { /* Only match minimal length pulse streams */ if(nrpulses >= minrawlen && nrpulses <= maxrawlen) { /* From 0316341506c02e443115711dcbf9fecf27b5f9ad Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Wed, 19 May 2021 15:57:33 +0200 Subject: [PATCH 31/44] Optimize size of maxgaplen from uint32_t to unit16_t --- pilight-usb-nano.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index afae214..21ac699 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -52,7 +52,7 @@ uint32_t maxrawlen = 0; uint32_t mingaplen = 10000; // Used and showing multiplied by 10 #endif -uint32_t maxgaplen = 82000; // v2 used and change from 5100 to 82000 (for quigg_gt7000 protocol) set and show as is. +uint16_t maxgaplen = 8200; // v2 used and change from 5100 to 8200 (for quigg_gt7000 protocol) set and show multiplied by 10 // Code formatting meant for sending // on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486;r:5@ @@ -91,7 +91,7 @@ void setup() { #ifdef BOOT_SHOW_SETTINGS // Show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -151,12 +151,12 @@ void receive() { } } if(x == 3) { - maxgaplen = atol(&data[s]); + maxgaplen = uint16_t(atol(&data[s])/10); } /* * Once we tuned our firmware send back our settings + fw version */ - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, maxgaplen, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -179,7 +179,7 @@ void receive() { // Check for maxgaplen for(z = scode; z < scode + s; z++) { - if (plstypes[data[z] - '0'] >= maxgaplen){ + if (plstypes[data[z] - '0'] >= uint32_t(maxgaplen*10)){ // Clear pulse types array for(i=0;i mingaplen) and (ten_us_counter < maxgaplen/10)) { + if((ten_us_counter > mingaplen) and (ten_us_counter < maxgaplen)) { /* Only match minimal length pulse streams */ if(nrpulses >= minrawlen && nrpulses <= maxrawlen) { /* From f5c19c7b61d0cd643f5b45903271a405bdce8602 Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Wed, 19 May 2021 17:00:08 +0200 Subject: [PATCH 32/44] Optimize size of mingaplen from uint32_t to unit16_t --- pilight-usb-nano.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 21ac699..b351f02 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -45,11 +45,11 @@ #ifdef DEFAULT_RX_SETTINGS uint32_t minrawlen = 20; uint32_t maxrawlen = 200; -uint32_t mingaplen = 300; // Used and showing multiplied by 10 +uint16_t mingaplen = 300; // Minimum length of footer pulse and maximum length of previous pulses. Used and showing multiplied by 10 #else uint32_t minrawlen = 1000; uint32_t maxrawlen = 0; -uint32_t mingaplen = 10000; // Used and showing multiplied by 10 +uint16_t mingaplen = 10000; // Used and showing multiplied by 10 #endif uint16_t maxgaplen = 8200; // v2 used and change from 5100 to 8200 (for quigg_gt7000 protocol) set and show multiplied by 10 @@ -91,7 +91,7 @@ void setup() { #ifdef BOOT_SHOW_SETTINGS // Show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -144,7 +144,7 @@ void receive() { maxrawlen = atol(&data[s]); } if(x == 2) { - mingaplen = atol(&data[s])/10; + mingaplen = uint16_t(atol(&data[s])/10); } x++; s = i+1; @@ -156,7 +156,7 @@ void receive() { /* * Once we tuned our firmware send back our settings + fw version */ - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, mingaplen*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else From 771c4df68580bb4fa933a19ce451eb7163a6c578 Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Wed, 19 May 2021 17:42:23 +0200 Subject: [PATCH 33/44] Optimize size of minrawlen and maxrawlen from uint32_t to uint8_t --- pilight-usb-nano.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index b351f02..e7dc430 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -43,12 +43,12 @@ #define VERSION 2 // Version 2 (Arduino compatible) #ifdef DEFAULT_RX_SETTINGS -uint32_t minrawlen = 20; -uint32_t maxrawlen = 200; +uint8_t minrawlen = 20; // Minimum number of pulses +uint8_t maxrawlen = 200; // Maximum number of pulses uint16_t mingaplen = 300; // Minimum length of footer pulse and maximum length of previous pulses. Used and showing multiplied by 10 #else -uint32_t minrawlen = 1000; -uint32_t maxrawlen = 0; +uint8_t minrawlen = UINT8_MAX; // Maximum value for uint8_t from (stdint.h) +uint8_t maxrawlen = 0; uint16_t mingaplen = 10000; // Used and showing multiplied by 10 #endif @@ -91,7 +91,7 @@ void setup() { #ifdef BOOT_SHOW_SETTINGS // Show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -138,10 +138,10 @@ void receive() { if(data[i] == ',') { data[i] = '\0'; if(x == 0) { - minrawlen = atol(&data[s]); + minrawlen = uint8_t(atoi(&data[s])); } if(x == 1) { - maxrawlen = atol(&data[s]); + maxrawlen = uint8_t(atoi(&data[s])); } if(x == 2) { mingaplen = uint16_t(atol(&data[s])/10); @@ -156,7 +156,7 @@ void receive() { /* * Once we tuned our firmware send back our settings + fw version */ - sprintf(data, "v:%lu,%lu,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); #else From f9d1fd5694874b02f4ea45ecba6f30e7e028905f Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Wed, 19 May 2021 18:52:40 +0200 Subject: [PATCH 34/44] Increased mingaplen because Maclean protocol (ELECTRO DH 60.531/M) have pulses arround 3500 usecs --- pilight-usb-nano.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index e7dc430..39afef6 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -15,8 +15,8 @@ - Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default). - Support to configure a digital output so that a led blinks at valid RF code reception. - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. - - Support to configure initial RX settings at boot, like as 's:20,200,3000,82000@'. - - Support to configure show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@'. + - Support to configure initial RX settings at boot, like as 's:20,200,4000,82000@'. + - Support to configure show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@'. - Support to configure add line feed '\n' each line output. */ @@ -28,8 +28,8 @@ #define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. //#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. //#define LED_BLINK_RX LED_BUILTIN // If defined, sets the digital output to blink on valid RF code reception. -//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,3000,82000@' -//#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' +//#define DEFAULT_RX_SETTINGS // If defined, sets valid RX settings at boot, like sets 's:20,200,4000,82000@' +//#define BOOT_SHOW_SETTINGS // If defined, show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@' //#define ADD_LINE_FEED // If defined, add line feed '\n' each line output. #define BUFFER_SIZE 256 // Warning: 256 max because buffer indexes "nrpulses" and "q" are "uint8_t" type @@ -45,7 +45,7 @@ #ifdef DEFAULT_RX_SETTINGS uint8_t minrawlen = 20; // Minimum number of pulses uint8_t maxrawlen = 200; // Maximum number of pulses -uint16_t mingaplen = 300; // Minimum length of footer pulse and maximum length of previous pulses. Used and showing multiplied by 10 +uint16_t mingaplen = 400; // Minimum length of footer pulse and maximum length of previous pulses. Used and showing multiplied by 10 #else uint8_t minrawlen = UINT8_MAX; // Maximum value for uint8_t from (stdint.h) uint8_t maxrawlen = 0; @@ -90,7 +90,7 @@ void setup() { Serial.begin(BAUD); #ifdef BOOT_SHOW_SETTINGS - // Show settings at boot, like as: 'v:20,200,3000,82000,2,1,1600@' + // Show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@' sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); #ifdef ADD_LINE_FEED Serial.println(data); From 638a211fae00542eb73708e6b82e0dcfba15f40d Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Wed, 19 May 2021 21:15:10 +0200 Subject: [PATCH 35/44] Remove interrupt management for better RX --- pilight-usb-nano.ino | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 39afef6..f79e72b 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -292,8 +292,6 @@ void broadcast(uint8_t nrpulses) { // Generic ISR function for RF RX pulse interrupt handler void ISR_RX(){ - // Disable ISR for RF RX interrupt handler only - detachInterrupt(digitalPinToInterrupt(RX_PIN)); uint32_t current_counter = micros(); uint16_t ten_us_counter = uint16_t((current_counter-new_counter)/10); @@ -328,11 +326,6 @@ void ISR_RX(){ } } } - - // If no broadcast, re-enable ISR for RF RX interrupt handler - if (broadcast_flag == 0){ - attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); - } } void loop(){ @@ -360,9 +353,6 @@ void loop(){ #ifdef LED_BLINK_RX digitalWrite(LED_BLINK_RX, LOW); // Led blink on RF RX #endif - - // Re-enable ISR for RF RX interrupt handler - attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); } #ifdef EVERY_SEC_LINE_FEED From 6ff047f349d3c026a02cd56568771cf3120a96af Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Thu, 20 May 2021 09:47:24 +0200 Subject: [PATCH 36/44] Tune MIN_PULSELENGTH to 6, for 100 usec minimal pulse --- pilight-usb-nano.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index f79e72b..78bc053 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -37,7 +37,7 @@ #define BAUD 57600 /* Show numbers devided by 10 */ -#define MIN_PULSELENGTH 10 // v2 change from 8 to 10 and show devided by 10 +#define MIN_PULSELENGTH 6 // v2 change from 8 to 6 and show devided by 10 #define MAX_PULSELENGTH 16000 // v2 change from 1600 to 16000 and show devided by 10 #define VERSION 2 // Version 2 (Arduino compatible) From 0bde571ca706c2cf0a8d8653fe50cde1ea72562e Mon Sep 17 00:00:00 2001 From: Jorge Rivera <> Date: Thu, 20 May 2021 10:21:22 +0200 Subject: [PATCH 37/44] Reduce MAX_PULSELENGTH to maxgaplen initial setting --- pilight-usb-nano.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 78bc053..998b7aa 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -38,7 +38,7 @@ /* Show numbers devided by 10 */ #define MIN_PULSELENGTH 6 // v2 change from 8 to 6 and show devided by 10 -#define MAX_PULSELENGTH 16000 // v2 change from 1600 to 16000 and show devided by 10 +#define MAX_PULSELENGTH 8200 // v2 change from 1600 to 8200 (for quigg_gt7000 protocol footer pulse around 81000 usecs) #define VERSION 2 // Version 2 (Arduino compatible) @@ -52,7 +52,7 @@ uint8_t maxrawlen = 0; uint16_t mingaplen = 10000; // Used and showing multiplied by 10 #endif -uint16_t maxgaplen = 8200; // v2 used and change from 5100 to 8200 (for quigg_gt7000 protocol) set and show multiplied by 10 +uint16_t maxgaplen = MAX_PULSELENGTH; // v2 used and change from 5100 to MAX_PULSELENGTH, set and show multiplied by 10 // Code formatting meant for sending // on c:102020202020202020220202020020202200202200202020202020220020202203;p:279,2511,1395,9486;r:5@ @@ -91,7 +91,7 @@ void setup() { #ifdef BOOT_SHOW_SETTINGS // Show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@' - sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH); #ifdef ADD_LINE_FEED Serial.println(data); #else @@ -156,7 +156,7 @@ void receive() { /* * Once we tuned our firmware send back our settings + fw version */ - sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH/10); + sprintf(data, "v:%u,%u,%lu,%lu,%d,%d,%d@", minrawlen, maxrawlen, uint32_t(mingaplen)*10, uint32_t(maxgaplen)*10, VERSION, MIN_PULSELENGTH/10, MAX_PULSELENGTH); #ifdef ADD_LINE_FEED Serial.println(data); #else From f885f2ffd7b148c4e143773944141d96a19a14c5 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 5 Sep 2021 20:24:25 +0200 Subject: [PATCH 38/44] Update .gitignore file --- .gitignore | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index edf6645..6ff2b5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,35 @@ +# Compiler outputs +build/* + +# Visual Studio Code +.vscode/ +*.code-workspace +.history/ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +Thumbs.db + +# Prerequisites +*.d + +# Precompiled Headers +*.gch +*.pch + # Object files *.o *.ko *.obj *.elf +*.bin +*.eep +*.lo +*.slo # Precompiled Headers *.gch @@ -12,7 +39,7 @@ *.lib *.a *.la -*.lo +*.lai # Shared objects (inc. Windows DLLs) *.dll From 4d20d83f9b09a6e6ab8aea468952d47cb0bc2186 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 5 Sep 2021 20:59:02 +0200 Subject: [PATCH 39/44] Add support to configure a tx enable pin (PTT_PIN) --- README.md | 3 +++ pilight-usb-nano.ino | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index fa39e12..0db45fc 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ The pilight USB Nano software allows any computer with an USB port to work with - Support to configure a digital output so that a led blinks at valid RF code reception. - Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware. - Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'. + - Support to configure show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@'. + - Support to configure add line feed '\n' each line output. + - Support to configure a tx enable pin (PTT_PIN), useful for use transceivers. - Fix TX pulse generator drift from 9.95µS to 0.69µS (AVR@16Mhz). - Improve RX pulse meter resolution from 10µS to 4µS (AVR@16Mhz). diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 998b7aa..5badb05 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -18,12 +18,14 @@ - Support to configure initial RX settings at boot, like as 's:20,200,4000,82000@'. - Support to configure show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@'. - Support to configure add line feed '\n' each line output. + - Support to configure a tx enable pin (PTT_PIN), useful for use transceivers. */ /* Configurable RX & TX pins */ #define RX_PIN 2 // Pin for ASK/OOK pulse input from RF receiver module data output. #define TX_PIN 5 // Pin for ASK/OOK pulse output to RF transmitter module data input. +#define PTT_PIN 4 // If a pin is defined, it will set to high state during transmissions. #define EVERY_SEC_LINE_FEED // If defined, print line feed '\n' every second, to emulate legacy firmware. //#define SEND_STRIPPED_SPACES // If defined, send every 'space' before 'pulse' in broadcast(), which stripped in legacy firmware. @@ -83,6 +85,12 @@ void setup() { pinMode(LED_BLINK_RX, OUTPUT); #endif +#ifdef PTT_PIN + // If defined PTT PIN set output low + pinMode(PTT_PIN,OUTPUT); + digitalWrite(PTT_PIN,LOW); +#endif + // Arduino built-in function to attach Interrupt Service Routines (depends board) attachInterrupt(digitalPinToInterrupt(RX_PIN), ISR_RX, CHANGE); @@ -190,6 +198,10 @@ void receive() { } /* Begin RF TX */ + #ifdef PTT_PIN + // Enable PTT + digitalWrite(PTT_PIN,HIGH); + #endif // Disable all interrupts noInterrupts(); for(i=0;i Date: Thu, 23 Sep 2021 14:25:05 +0200 Subject: [PATCH 40/44] Fix serialEvent() ISR call unimplemented --- pilight-usb-nano.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 5badb05..0ce08f1 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -346,6 +346,11 @@ void ISR_RX(){ void loop(){ + // Workaround for Leonardo, Micro, and others MCUs like ESP8266 and ESP32 +#ifndef HAVE_HWSERIAL0 + if (Serial.available()) serialEvent(); +#endif + // if receive flag is set if (receive_flag){ // Call to receive() From 1b20d451b291cad706f85bc78277546dcb9a6560 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 26 Sep 2021 09:32:29 +0200 Subject: [PATCH 41/44] Fix ISR_RX() ram attribute on ESP8266 and ESP32 --- pilight-usb-nano.ino | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pilight-usb-nano.ino b/pilight-usb-nano.ino index 0ce08f1..f72650e 100644 --- a/pilight-usb-nano.ino +++ b/pilight-usb-nano.ino @@ -306,8 +306,18 @@ void broadcast(uint8_t nrpulses) { #endif } +#if defined ESP8266 + // interrupt handler and related code must be in RAM on ESP8266 + #define RECEIVE_ATTR ICACHE_RAM_ATTR +#elif defined ESP32 + // interrupt handler and related code must be in RAM on ESP32 + #define RECEIVE_ATTR IRAM_ATTR +#else + #define RECEIVE_ATTR +#endif + // Generic ISR function for RF RX pulse interrupt handler -void ISR_RX(){ +void RECEIVE_ATTR ISR_RX(){ uint32_t current_counter = micros(); uint16_t ten_us_counter = uint16_t((current_counter-new_counter)/10); From ee6fe2d1af84ee88a64c5cfde9851150f22e5691 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 26 Sep 2021 09:37:56 +0200 Subject: [PATCH 42/44] Add Compile Test for ESP32 platform --- .github/workflows/CompileTests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/CompileTests.yml b/.github/workflows/CompileTests.yml index 72c7850..280e2ea 100644 --- a/.github/workflows/CompileTests.yml +++ b/.github/workflows/CompileTests.yml @@ -72,6 +72,11 @@ jobs: platform: "esp8266:esp8266" additional-url: "--additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json" + - board: "ESP32 NodeMCU-32S" + fqbn: "esp32:esp32:nodemcu-32s" + platform: "esp32:esp32" + additional-url: "--additional-urls https://dl.espressif.com/dl/package_esp32_index.json" + # This is the list of steps this job will run. steps: # First of all, we clone the repo using the "checkout" action. From 6579e79e4bb9ac5873715b550d73de7219adb63f Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Sun, 26 Sep 2021 09:44:00 +0200 Subject: [PATCH 43/44] Change --warnings from 'all' to 'none' --- .github/workflows/CompileTests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CompileTests.yml b/.github/workflows/CompileTests.yml index 280e2ea..6a7542d 100644 --- a/.github/workflows/CompileTests.yml +++ b/.github/workflows/CompileTests.yml @@ -99,7 +99,7 @@ jobs: # Finally, we compile the sketch, using the FQBN that was set in the build matrix. - name: Compile sketch for ${{ matrix.config.board }} - run: arduino-cli compile -v --fqbn ${{ matrix.config.fqbn }} --export-binaries --warnings all --log-level info + run: arduino-cli compile -v --fqbn ${{ matrix.config.fqbn }} --export-binaries --warnings none --log-level info # Upload binary (.hex) files to artifacts - name: Upload compiled binaries files to Artifacts From 22858437d83d76d0848081601d8ef74f15c85e76 Mon Sep 17 00:00:00 2001 From: Jorge Rivera Date: Wed, 3 Jul 2024 19:11:38 +0200 Subject: [PATCH 44/44] Update action versions --- .github/workflows/CompileTests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CompileTests.yml b/.github/workflows/CompileTests.yml index 6a7542d..73f8d42 100644 --- a/.github/workflows/CompileTests.yml +++ b/.github/workflows/CompileTests.yml @@ -82,12 +82,12 @@ jobs: # First of all, we clone the repo using the "checkout" action. # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 # We use the "arduino/setup-arduino-cli" action to install and # configure the Arduino CLI on the system. - name: Setup Arduino CLI - uses: arduino/setup-arduino-cli@v1.1.1 + uses: arduino/setup-arduino-cli@v2 # We then install the platform, which one will be determined # dynamically by the build matrix. @@ -103,7 +103,7 @@ jobs: # Upload binary (.hex) files to artifacts - name: Upload compiled binaries files to Artifacts - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v4 with: name: "Binaries for ${{ matrix.config.board }}" path: ./