Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReceiveDemo_Advanced work with Platform.IO and VSCode #489

Open
heman22union opened this issue Apr 26, 2023 · 1 comment
Open

ReceiveDemo_Advanced work with Platform.IO and VSCode #489

heman22union opened this issue Apr 26, 2023 · 1 comment

Comments

@heman22union
Copy link

heman22union commented Apr 26, 2023

I'm trying to get the ReceiveDemo_Advanced example to work with Platform.IO and VS Code. I'm able to get it to work with the Arduino IDE, but I prefer VS Code.

Here is what I have including adding of the #include <Ardunio.h> to both files? It seems I need to add to the output.cpp file too?

.\test_rec\ReceiveDemo_Advanced.cpp file

/*
  Example for receiving
  
  https://github.com/sui77/rc-switch/
  
  If you want to visualize a telegram copy the raw data and 
  paste it into http://test.sui.li/oszi/
*/

#include <Arduino.h>
#include <RCSwitch.h>
#include "output.cpp"


RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {
    output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
    mySwitch.resetAvailable();
  }
}

.\test_rec\output.cpp file

#include <Arduino.h>


static const char* bin2tristate(const char* bin);
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength);

void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {

  const char* b = dec2binWzerofill(decimal, length);
  Serial.print("Decimal: ");
  Serial.print(decimal);
  Serial.print(" (");
  Serial.print( length );
  Serial.print("Bit) Binary: ");
  Serial.print( b );
  Serial.print(" Tri-State: ");
  Serial.print( bin2tristate( b) );
  Serial.print(" PulseLength: ");
  Serial.print(delay);
  Serial.print(" microseconds");
  Serial.print(" Protocol: ");
  Serial.println(protocol);
  
  Serial.print("Raw data: ");
  for (unsigned int i=0; i<= length*2; i++) {
    Serial.print(raw[i]);
    Serial.print(",");
  }
  Serial.println();
  Serial.println();
}

static const char* bin2tristate(const char* bin) {
  static char returnValue[50];
  int pos = 0;
  int pos2 = 0;
  while (bin[pos]!='\0' && bin[pos+1]!='\0') {
    if (bin[pos]=='0' && bin[pos+1]=='0') {
      returnValue[pos2] = '0';
    } else if (bin[pos]=='1' && bin[pos+1]=='1') {
      returnValue[pos2] = '1';
    } else if (bin[pos]=='0' && bin[pos+1]=='1') {
      returnValue[pos2] = 'F';
    } else {
      return "not applicable";
    }
    pos = pos+2;
    pos2++;
  }
  returnValue[pos2] = '\0';
  return returnValue;
}

static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {
  static char bin[64]; 
  unsigned int i=0;

  while (Dec > 0) {
    bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
    Dec = Dec >> 1;
  }

  for (unsigned int j = 0; j< bitLength; j++) {
    if (j >= bitLength - i) {
      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
    } else {
      bin[j] = '0';
    }
  }
  bin[bitLength] = '\0';
  
  return bin;
}

platform.io terminal output

 *  Executing task in folder esp_doorbell: C:\Users\Heman\.platformio\penv\Scripts\platformio.exe run --target upload --environment nanoatmega328_test_rec 

Processing nanoatmega328_test_rec (platform: atmelavr; board: nanoatmega328; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR (4.1.0) > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr @ 5.1.0 
 - tool-avrdude @ 1.60300.200527 (6.3.0) 
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 6 compatible libraries
Scanning dependencies...
Dependency Graph
|-- rc-switch @ 2.6.4
Building in release mode
Linking .pio\build\nanoatmega328_test_rec\firmware.elf
.pio\build\nanoatmega328_test_rec\src\test_rec\output.cpp.o (symbol from plugin): In function `output(unsigned long, unsigned int, unsigned int, unsigned int*, unsigned int)':
(.text+0x0): multiple definition of `output(unsigned long, unsigned int, unsigned int, unsigned int*, unsigned int)'
.pio\build\nanoatmega328_test_rec\src\test_rec\ReceiveDemo_Advanced.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nanoatmega328_test_rec\firmware.elf] Error 1
============================================================================================= [FAILED] Took 0.93 seconds =============================================================================================

Environment             Status    Duration
----------------------  --------  ------------
nanoatmega328_test_rec  FAILED    00:00:00.934
======================================================================================= 1 failed, 0 succeeded in 00:00:00.934 ======================================================================================= 

 *  The terminal process "C:\Users\Heman\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'nanoatmega328_test_rec'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

platformio.ini file

[env:nanoatmega328_transmitter]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_src_filter = +<transmitter/> -<receiver/> -<test_rec/>
upload_port = COM5
monitor_port = COM5
lib_deps = sui77/rc-switch@^2.6.4

[env:nanoatmega328_receiver]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_src_filter = -<transmitter/> +<receiver/> -<test_rec/>
upload_port = COM6
monitor_port = COM6
lib_deps = sui77/rc-switch@^2.6.4

[env:nanoatmega328_test_rec]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_src_filter = -<transmitter/> -<receiver/> +<test_rec/>
upload_port = COM6
monitor_port = COM6
lib_deps = sui77/rc-switch@^2.6.4
@heman22union
Copy link
Author

If I remove the #include <Ardunio.h> from .\test_rec\output.cpp file

//#include <Arduino.h>


static const char* bin2tristate(const char* bin);
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength);

void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {

  const char* b = dec2binWzerofill(decimal, length);
  Serial.print("Decimal: ");
  Serial.print(decimal);
  Serial.print(" (");
  Serial.print( length );
  Serial.print("Bit) Binary: ");
  Serial.print( b );
  Serial.print(" Tri-State: ");
  Serial.print( bin2tristate( b) );
  Serial.print(" PulseLength: ");
  Serial.print(delay);
  Serial.print(" microseconds");
  Serial.print(" Protocol: ");
  Serial.println(protocol);
  
  Serial.print("Raw data: ");
  for (unsigned int i=0; i<= length*2; i++) {
    Serial.print(raw[i]);
    Serial.print(",");
  }
  Serial.println();
  Serial.println();
}

static const char* bin2tristate(const char* bin) {
  static char returnValue[50];
  int pos = 0;
  int pos2 = 0;
  while (bin[pos]!='\0' && bin[pos+1]!='\0') {
    if (bin[pos]=='0' && bin[pos+1]=='0') {
      returnValue[pos2] = '0';
    } else if (bin[pos]=='1' && bin[pos+1]=='1') {
      returnValue[pos2] = '1';
    } else if (bin[pos]=='0' && bin[pos+1]=='1') {
      returnValue[pos2] = 'F';
    } else {
      return "not applicable";
    }
    pos = pos+2;
    pos2++;
  }
  returnValue[pos2] = '\0';
  return returnValue;
}

static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {
  static char bin[64]; 
  unsigned int i=0;

  while (Dec > 0) {
    bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';
    Dec = Dec >> 1;
  }

  for (unsigned int j = 0; j< bitLength; j++) {
    if (j >= bitLength - i) {
      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
    } else {
      bin[j] = '0';
    }
  }
  bin[bitLength] = '\0';
  
  return bin;
}

platformio terminal output

 *  Executing task in folder esp_doorbell: C:\Users\Heman\.platformio\penv\Scripts\platformio.exe run --target upload --environment nanoatmega328_test_rec 

Processing nanoatmega328_test_rec (platform: atmelavr; board: nanoatmega328; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR (4.1.0) > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr @ 5.1.0 
 - tool-avrdude @ 1.60300.200527 (6.3.0) 
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 6 compatible libraries
Scanning dependencies...
Dependency Graph
|-- rc-switch @ 2.6.4
Building in release mode
Compiling .pio\build\nanoatmega328_test_rec\src\test_rec\ReceiveDemo_Advanced.cpp.o
Compiling .pio\build\nanoatmega328_test_rec\src\test_rec\output.cpp.o
src\test_rec\output.cpp: In function 'void output(long unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int)':
src\test_rec\output.cpp:10:3: error: 'Serial' was not declared in this scope
   Serial.print("Decimal: ");
   ^~~~~~
src\test_rec\output.cpp:10:3: note: suggested alternative: 'decimal'
   Serial.print("Decimal: ");
   ^~~~~~
   decimal
*** [.pio\build\nanoatmega328_test_rec\src\test_rec\output.cpp.o] Error 1
============================================================================================= [FAILED] Took 0.73 seconds =============================================================================================

Environment             Status    Duration
----------------------  --------  ------------
nanoatmega328_test_rec  FAILED    00:00:00.729
======================================================================================= 1 failed, 0 succeeded in 00:00:00.729 ======================================================================================= 

 *  The terminal process "C:\Users\Heman\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'nanoatmega328_test_rec'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant