Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 21 of 21

Thread: Pozyx library issue

  1. #1

    Pozyx library issue

    Hello,

    The pozyx library examples do run fine on an Arduino board but I can't get the compiled for a Teensy 3.1 on Arduino 1.8.5/Teensy 1.4.1.

    It seems there is an incompatibility with the Pozyx.h file included by the code in all the examples from the library. I have plenty of error messages like this:

    D:\Programmation\Arduino\libraries\Pozyx/Pozyx.h:449:90: warning: converting to non-pointer type 'uint16_t {aka short unsigned int}' from NULL [-Wconversion-null]

    static int getRead(uint8_t reg_address, uint8_t *pData, int size, uint16_t remote_id=NULL);


    You can get the library here.

    What's wrong with this code? Should the library be deeply modified to function with Teensy boards?

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,964
    change NULL to “0UL” and it should work

    nothing is broken, teensy runs a newer toolchain where NULL is deprecated, on arduino you will compile but it should give a warning still. Library just needs an update... If arduino upgrades their toolchain, you’d be having the same problem.

  3. #3
    Quote Originally Posted by tonton81 View Post
    change NULL to “0UL” and it should work

    nothing is broken, teensy runs a newer toolchain where NULL is deprecated, on arduino you will compile but it should give a warning still. Library just needs an update... If arduino upgrades their toolchain, you’d be having the same problem.
    Is there a way to modify the lib to be compatible with both toolchains? With #ifdef statements for instance?

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,964
    if you change it to the value 0 or 0UL, it will work both ways. NULL is actually “0” (zero)

    to make it more clear:

    old toolchain:
    NULL == 0

    new toolchain:
    NULL is deprecated, so throw an error and stop compiling

    so setting it to 0 will make it work for both old and new toolchain.

  5. #5
    Great! Thanks a lot tonton81!

  6. #6
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    84
    Quote Originally Posted by tonton81 View Post
    change NULL to “0UL” and it should work
    To be pedantic, the “L” suffix is only needed for 32 bits and above. (Longs are at least 32 bits.) And I say “needed” loosely, ignoring type conversions and stuff.

  7. #7
    Well, it seems the incompatibility has also something to do with the interrupts. Any insight on how to adapt AVR P328 interrupts for the Teensy 3.1?

  8. #8
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,964
    put this in your setup:


    Code:
    attachInterrupt(your_interrupt_pin, PozyxClass::IRQ, RISING);
    teensy isn’t defined in the class which is why it didnt enable the interrupt handler
    rather than modify the library you can just enable it manually with the line above

  9. #9
    I was just about to modify the library, so it's good to know it's possible to solve the issue this way. Much easier. Thanks a lot!

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    Quote Originally Posted by amundsen View Post
    Well, it seems the incompatibility has also something to do with the interrupts. Any insight on how to adapt AVR P328 interrupts for the Teensy 3.1?
    Some time ago I made an update to this library. Here's the code.

    https://github.com/PaulStoffregen/Pozyx-Arduino-library

    Here's the thread about the problem.

    https://forum.pjrc.com/threads/47047...d-audio-player

    As you can see, there was never any followup about whether this code change actually works. So no attempt was made to contribute the change back to the original library. If you do use this and get it works, please post a followup here. A photo is ideal, but even just saying "yes it works" is enough.

    I generally don't send a pull request to the original author until at least 1 person has confirmed the change actually works with the real hardware.

  11. #11
    Quote Originally Posted by PaulStoffregen View Post
    Some time ago I made an update to this library. Here's the code.

    https://github.com/PaulStoffregen/Pozyx-Arduino-library

    Here's the thread about the problem.

    https://forum.pjrc.com/threads/47047...d-audio-player

    As you can see, there was never any followup about whether this code change actually works. So no attempt was made to contribute the change back to the original library. If you do use this and get it works, please post a followup here. A photo is ideal, but even just saying "yes it works" is enough.

    I generally don't send a pull request to the original author until at least 1 person has confirmed the change actually works with the real hardware.
    This is great, Paul! Thanks a lot. I'll report here if it works.

  12. #12
    Paul, your modifications on the Pozyx lib were made on version 1.1.3 and current version is 1.2.1. So I made what I think are the required modifications on latest version:
    - replacement of all occurences of "NULL" by "0";
    - inclusion of these lines in Pozyx_core.cpp:
    Code:
    #elif defined(__arm__) && defined(TEENSYDUINO)
        // Teensy LC & 3.x
        attachInterrupt(interrupt_pin+2, IRQ, RISING);
    As I am running Teensyduino 1.4.1, adding the abort() function was not required.

    I could load the pozyx_basic_troubleshooting program into the Teensy but when opening a serial window, nothing appears. The Teensy 3.2 is currently connected to a Pozyx tag board using a Sparkfun Teensy Arduino shield adaptor. I'll try again with jumper wires instead of the adaptor as soon as possible but I don't have any at disposal at the moment.

  13. #13
    When trying to load the unit_tests_core example into the Teeny, I get a lot of warnings and some error messages:

    Here's the code (any NULL was replaced by 0 if any) and after that you'll see the error messages:

    Code:
    #line 2 "unit_tests_core.ino"
    #include <ArduinoUnit.h>
    
    #include <Pozyx.h>
    #include <Pozyx_definitions.h>
    #include <Wire.h>
    
    // can we read a single byte
    test(regRead_singlebyte)
    {
      uint8_t whoami = 0;
      int status = Pozyx.regRead(POZYX_WHO_AM_I, &whoami, 1);
      
      assertEqual(status, POZYX_SUCCESS);
      assertEqual(whoami, 0x43);
    }
    
    // can we write a single byte
    test(regWrite_singlebyte)
    {
      uint8_t writebyte = 19;  
      
      // write the value 1 to this register
      int status = Pozyx.regWrite(POZYX_POS_X, &writebyte, 1);
      
      assertEqual(status, POZYX_SUCCESS);
      
      // this delay is necessary because pozyx is still processing the write operation first.
      delay(1);
      
      uint8_t testbyte = 0;
      Pozyx.regRead(POZYX_POS_X, &testbyte, 1);
    
      assertEqual(testbyte, writebyte);
    }
    
    // can we write multiple bytes at once
    test(regWrite_multibyte)
    {
      uint32_t pos[3] = {1, 2, 3};  
      
      // write the value 1 to this register
      int status = Pozyx.regWrite(POZYX_POS_X, (uint8_t*)&pos, 3*sizeof(uint32_t));
      
      assertEqual(status, POZYX_SUCCESS);
      
      // this delay is necessary because pozyx is still processing the write operation first.
      delay(1);
      
      pos[0] = 0;
      pos[1] = 0;
      pos[2] = 0;
      Pozyx.regRead(POZYX_POS_X, (uint8_t*)&pos, 3*sizeof(uint32_t));
    
      assertEqual(pos[0], 1);
      assertEqual(pos[1], 2);
      assertEqual(pos[2], 3);
    }
    
    // can we write a single byte quickly after one-another.
    test(regWrite_quick)
    {
      int num_cycles = 10;
      uint8_t i = 0;
      for(i=1; i <= num_cycles; i++){
        int status = Pozyx.regWrite(POZYX_POS_X, (uint8_t*)&i, 1);
        assertEqual(status, POZYX_SUCCESS);
      }
      
      // this delay is necessary because pozyx is still processing the write operation first.
      delay(1);
      
      uint8_t result = 0;
      Pozyx.regRead(POZYX_POS_X, (uint8_t*)&result, 1);
    
      assertEqual(result, num_cycles);
    }
    
    test(regFunction_simple)
    {
      uint8_t input = 0x88;  
     
      // call function to write to some buffer
      int status = Pozyx.regFunction( POZYX_LED_CTRL, (uint8_t*)&input, 1, 0, 0);
      assertEqual(status, POZYX_SUCCESS);
    }
    
    // can we call a register function?
    test(regFunction)
    {
      uint16_t input[3] = {1, 2, 3};  
     
      // call function to write to some buffer
      int status = Pozyx.regFunction( POZYX_POS_SET_ANCHOR_IDS, (uint8_t*)&input, 3*sizeof(uint16_t), 0, 0);
      assertEqual(status, POZYX_SUCCESS);
      
      // call function to read from some buffer
      uint16_t result[3] = {0,0,0};
      status = Pozyx.regFunction( POZYX_POS_GET_ANCHOR_IDS, 0, 0, (uint8_t*)&result, 3*sizeof(uint16_t));
      
      assertEqual(result[0], 1);
      assertEqual(result[1], 2);
      assertEqual(result[2], 3);
      
      assertEqual(status, 3);  
    }
    
    test(waitForFlag)
    {
      Pozyx.begin(false, MODE_INTERRUPT, POZYX_INT_STATUS_ERR);
      //Pozyx.begin(false, MODE_POLLING, POZYX_INT_STATUS_ERR);
      
      // read out the interrupt status register to reset it.
      uint8_t dummy;
      Pozyx.regRead(POZYX_INT_STATUS, &dummy, 1);  
      
      // cause an error interrupt by writing to a read-only register
      uint8_t causes_error = 0x01;
      Pozyx.regWrite(POZYX_WHO_AM_I, &causes_error, 1);
    
      // if the interrupt was caught, the result is true
      boolean result = Pozyx.waitForFlag(POZYX_INT_STATUS_ERR, 100);
      
      assertTrue(result);
    }
    
    void setup()
    {
      Serial.begin(115200);
      while(!Serial); // for the Arduino Leonardo/Micro only
      
      Wire.begin();
    }
    
    void loop()
    {
      Test::run();
    }
    Here's the first batch of error messages:

    Code:
    In file included from D:\Programmation\Arduino\libraries\ArduinoUnit\src/ArduinoUnit.h:12:0,
    
                     from unit_tests_core.ino:2:
    
    D:\Programmation\Arduino\libraries\ArduinoUnit\src/ArduinoUnitUtility/Compare.h: In instantiation of 'static bool Compare<A, B>::less(const A&, const B&) [with A = long unsigned int; B = int]':
    
    D:\Programmation\Arduino\libraries\ArduinoUnit\src/ArduinoUnitUtility/Compare.h:13:18:   required from 'static bool Compare<A, B>::equal(const A&, const B&) [with A = long unsigned int; B = int]'
    
    D:\Programmation\Arduino\libraries\ArduinoUnit\src/ArduinoUnitUtility/Compare.h:38:171:   required from 'bool compareEqual(const A&, const B&) [with A = long unsigned int; B = int]'
    
    unit_tests_core.ino:55:3:   required from here
    (some warnings in between)

    Code:
    D:\Programmation\Arduino\libraries\ArduinoUnit\src\ArduinoUnitUtility\ArduinoUnitMockPrint.cpp:136:95: error: no matching function for call to 'MockPrint::concat(const char*, size_t&)'
    
     size_t MockPrint::write(const uint8_t *buffer, size_t size) { concat((const char *)buffer,size); return size; }
    
                                                                                                   ^
    
    In file included from D:\Programmation\Arduino\libraries\ArduinoUnit\src\ArduinoUnitUtility\ArduinoUnitMockWString.h:4:0,
    
                     from D:\Programmation\Arduino\libraries\ArduinoUnit\src\ArduinoUnitUtility\ArduinoUnitMockPrint.h:11,
    
                     from D:\Programmation\Arduino\libraries\ArduinoUnit\src\ArduinoUnitUtility\ArduinoUnitMockPrint.cpp:5:
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:127:11: note: candidate: String& String::concat(const String&)
    
      String & concat(const String &str)  {return append(str);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:127:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:128:11: note: candidate: String& String::concat(const char*)
    
      String & concat(const char *cstr)  {return append(cstr);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:128:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:129:11: note: candidate: String& String::concat(const __FlashStringHelper*)
    
      String & concat(const __FlashStringHelper *pgmstr) {return append(pgmstr);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:129:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:130:11: note: candidate: String& String::concat(char)
    
      String & concat(char c)    {return append(c);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:130:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:131:11: note: candidate: String& String::concat(unsigned char)
    
      String & concat(unsigned char c)  {return append((int)c);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:131:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:132:11: note: candidate: String& String::concat(int)
    
      String & concat(int num)   {return append(num);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:132:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:133:11: note: candidate: String& String::concat(unsigned int)
    
      String & concat(unsigned int num)  {return append(num);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:133:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:134:11: note: candidate: String& String::concat(long int)
    
      String & concat(long num)   {return append(num);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:134:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:135:11: note: candidate: String& String::concat(long unsigned int)
    
      String & concat(unsigned long num)  {return append(num);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:135:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:136:11: note: candidate: String& String::concat(float)
    
      String & concat(float num)   {return append(num);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:136:11: note:   candidate expects 1 argument, 2 provided
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:137:11: note: candidate: String& String::concat(double)
    
      String & concat(double num)   {return append(num);}
    
               ^
    
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WString.h:137:11: note:   candidate expects 1 argument, 2 provided
    
    Erreur de compilation pour la carte Teensy 3.2 / 3.1

  14. #14
    The pozyx_UWB_configurator example is loaded and runs without any issue (device detection, modifying and saving UWB settings) over the shield adaptor. Great!

  15. #15
    Any update with this? I am trying to work with the Pozyx system and a Teensy, but want to make sure I am using the most up to date library for the pozyx. @amundsen do you have any updates?

    Thanks!

  16. #16
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    Just to be clear, I do not own the Pozyx hardware. The changes I made were based on the same sorts of compatibility issues that are common with all Arduino libs.

  17. #17
    Thanks Paul. I was hoping there were some other Pozyx users who may have kept up with this. If you have a chance could you look at the latest Pozyx library and see if there are any changes since you made your last mods? I would greatly appreciate it.
    https://github.com/pozyxLabs/Pozyx-Arduino-library

  18. #18
    Hi Paul,
    One of the pozyx engineers is trying to update the library so it works with teensy and seems to be running into an issue where the code works sometimes and sometimes does not.
    https://github.com/pozyxLabs/Pozyx-A...ment-405090548

  19. #19
    Actually I am not an engineer from Pozyx. Adding
    Code:
    delay(1000)
    after opening of the serial port seems to have solved the issue but further tests are required.

  20. #20
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,718
    I replied on the github issue.

    I'm pretty sure it's a simple case of missing this in the examples.

    Code:
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
    If the example prints stuff just once and you open the serial monitor after it's printed, then you get "nothing works", when in fact it did work perfectly but happened quickly before you could get the serial monitor open.

  21. #21
    For the record,on the Pozyx board, connecting the +5V pin to a 3.3V source and powering the board with 5V on the debug VDD pin seems to help a lot. The connection is more stable and doesn't interrupt after one or two minutes as before.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •