Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Expanding the size of an existing array?

Expanding the size of an existing array?

Scheduled Pinned Locked Moved Development
14 Posts 4 Posters 192 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • alowhumA Offline
    alowhumA Offline
    alowhum
    Plugin Developer
    wrote on last edited by
    #2

    Trying some things.

    #include <SoftwareSerial.h>
    char SoftwareSerial::_receive_buffer[255];
    

    Results in error: conflicting declaration

    Strange, looking at the official code, it should support user overrides of this value.

    1 Reply Last reply
    0
    • scalzS Offline
      scalzS Offline
      scalz
      Hardware Contributor
      wrote on last edited by scalz
      #3

      not tried, but this should work better with the define before the include

      #define _SS_MAX_RX_BUFF 255                         // Override the define to increase the buffer size
      #include <SoftwareSerial.h>                                // Load the library code
      SoftwareSerial softSerial1(GSM_RECEIVE_PIN,GSM_TRANSMIT_PIN); // Create the software serial object, hopefully with a bigger than normal buffer
      
      1 Reply Last reply
      0
      • alowhumA Offline
        alowhumA Offline
        alowhum
        Plugin Developer
        wrote on last edited by
        #4

        I checked the IDE, and it also has the correct code:

        #ifndef _SS_MAX_RX_BUFF
        #define _SS_MAX_RX_BUFF 64 // RX buffer size
        #endif
        

        If I print out the value of _SS_MAX_RX_BUFF in the setup, then it shows the increased value.

        What could be causing this?

        1 Reply Last reply
        0
        • alowhumA Offline
          alowhumA Offline
          alowhum
          Plugin Developer
          wrote on last edited by
          #5

          @scalz Yes, you're right. That was how I had it originally (similar to how it works with mySensors), but that also doesn't work.

          1 Reply Last reply
          0
          • scalzS Offline
            scalzS Offline
            scalz
            Hardware Contributor
            wrote on last edited by scalz
            #6

            @alowhum oki.
            well I've no time to take a look, and not really a fan of softwareserial.. I just noticed the inversion in your 1st post
            So I guess you have few options if you can't find the solution:

            • change in lib (define, or constructor)
            • handle your own buffer in your sketch if you don't want to make changes to the lib
            1 Reply Last reply
            0
            • electrikE Offline
              electrikE Offline
              electrik
              wrote on last edited by
              #7

              Perhaps the define is used in another place somewhere in your project also, which overrides yours. You could force it in the header file, or find the other define and change that

              1 Reply Last reply
              0
              • alowhumA Offline
                alowhumA Offline
                alowhum
                Plugin Developer
                wrote on last edited by
                #8

                Perhaps the define is used in another place somewhere in your project also

                I explored that too, but it's really not. It's all a one-file sketch.

                I have now embedded the entire software serial code in my code. It works now, even though it's unsightly.

                This hasn't been cleaned, but it might be interesting. It's upgraded code for the Candle Smart Lock, which can also be triggered via SMS (and this feature can be toggled).

                Apparently the code is too long to post
                
                electrikE 1 Reply Last reply
                0
                • alowhumA alowhum

                  Perhaps the define is used in another place somewhere in your project also

                  I explored that too, but it's really not. It's all a one-file sketch.

                  I have now embedded the entire software serial code in my code. It works now, even though it's unsightly.

                  This hasn't been cleaned, but it might be interesting. It's upgraded code for the Candle Smart Lock, which can also be triggered via SMS (and this feature can be toggled).

                  Apparently the code is too long to post
                  
                  electrikE Offline
                  electrikE Offline
                  electrik
                  wrote on last edited by
                  #9

                  @alowhum said in Expanding the size of an existing array?:

                  It's all a one-file sketch.

                  Even it is only one file, the file can be included from other locations also. So is this #include <SoftwareSerial.h> also in other files inside your project?

                  you can also check it by adding this before your define. If the compiler gives an error, this define is used somewhere already.

                  #ifdef _SS_MAX_RX_BUFF
                    #error "_SS_MAX_RX_BUFF defined already"
                  #endif
                  
                  1 Reply Last reply
                  1
                  • alowhumA alowhum

                    After a lot of pulling hairs, I realised that the SoftwareSerial library has a hard coded 64 byte RX buffer.

                    I originally thought I could do something like:

                    #define _SS_MAX_RX_BUFF 255                         // Override the define to increase the buffer size
                    #include <SoftwareSerial.h>                                // Load the library code
                    SoftwareSerial softSerial1(GSM_RECEIVE_PIN,GSM_TRANSMIT_PIN); // Create the software serial object, hopefully with a bigger than normal buffer
                    

                    (updated the code to reflect that the #define came first)

                    I assumed that other libraries would work like MySensors, and I could override this value. But it seems this override doesn't work.

                    Now I could hardcode the bigger size into the library. But I was wondering: is there a way to do this without modifying the library code itself? Can I, for example, increase the size of the buffer after it's been created somehow?

                    YveauxY Offline
                    YveauxY Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #10

                    @alowhum I didn't check the code, but could the value of 255 cause an issue? Eg does it work when set to 200, or even 127?

                    http://yveaux.blogspot.nl

                    1 Reply Last reply
                    0
                    • alowhumA Offline
                      alowhumA Offline
                      alowhum
                      Plugin Developer
                      wrote on last edited by alowhum
                      #11

                      @electrik I'll have to test that. But there is only one file in my project, so..

                      @Yveaux I tried that too (well, 256 and 128), but no effect.

                      The full code (with built in software serial..) is now on Github:
                      https://github.com/createcandle/Devices/blob/master/Smart_lock/Smart_lock.ino

                      1 Reply Last reply
                      0
                      • electrikE Offline
                        electrikE Offline
                        electrik
                        wrote on last edited by
                        #12

                        I think this is your issue.

                        If your "libraries" are truly libraries (i.e. - they consist of a .h file and a .cpp file), then they get compiled separately from the .ino, so they will never see ANY #defines you put in the .ino. The compiled libraries and compiled .ino file are joined only a link time, LONG after the #defines have been tossed away. If you want both the sketch and one or more libraries to "see" #defines, then those #defines must be defined in a separate .h file that is #included into both the sketch AND the libraries.

                        From:

                        https://forum.arduino.cc/index.php?topic=445646.0

                        1 Reply Last reply
                        0
                        • alowhumA Offline
                          alowhumA Offline
                          alowhum
                          Plugin Developer
                          wrote on last edited by
                          #13

                          Ah, so that's it!

                          So then is MySensors a special case? How is it possible that #defines in the sketch work for MySensors?

                          1 Reply Last reply
                          0
                          • electrikE Offline
                            electrikE Offline
                            electrik
                            wrote on last edited by
                            #14

                            I think - am not sure - because you only include mysensors.h, which is only a header file without cpp files.

                            1 Reply Last reply
                            1
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            14

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.1k

                            Posts


                            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • MySensors
                            • OpenHardware.io
                            • Categories
                            • Recent
                            • Tags
                            • Popular