Pozyx Arduino lib. porting to Photon, could I ask for help?

I have the super cool Pozyx platform for accurate indoor positioning of projects BUT I need / want to use it with my Photon and I have no experience with porting a lib.(not even a real programmer) The Arduino lib. is avaliable at Github ( https://github.com/pozyxLabs/Pozyx-Arduino-library). I am reaching out for some help by some of the brilliant real software gurus in this community, is it possible to have a look at the lib. to see if it will be very difficult or not?

@Duke, the library looks very simple to port. I’ll test tonight and let you know if that’s the case or not :wink:

You are truly amazing, I am very very grateful for you support !

1 Like

I had a go at this on my own but now I am kind of lost and need some guidance, this is the first time I am trying to post a lib. I am using particle.dev and have taking an error at the time but no successful compiling yet, stuck on these errors:

BUFFER_LENGHT and ceil was not declared in this scope: “Pozyx_core.ccp” as far as I understand this has something to do with the truncation of data in the i2c communication but… I have included application.h.

Grateful for any hint on where to look

ceil() is a function defined via #include <math.h>

One down(ceil) ! but BUFFER_LENGTH is still a blocker any hint on that one ?

I can’t see a BUFFER_LENGTH defined for I2C (aka Wire), but the Arduino default for it seems to be 32.
Maybe Paul knows this off the top of his head, but I’d go with this value to start with.

There is an I2C_BUFFER_LENGTH in the firmware (which is also #define I2C_BUFFER_LENGTH 32).

1 Like

Sucess now it compiles BUT it does not go into POZYX_SUCESS aka. Unable to connect and aborts/restarts.

#include <Pozyx.h>
#include <Pozyx_definitions.h>
#include <application.h>

// #include <Wire.h> 

uint8_t num_anchors = 4;
uint16_t anchors[4] = {0x6640,0x6F2E,0x6F1C,0x6F23};
int32_t heights[4] = {2500, 2500, 2500, 2500};

void setup(){

  if(Pozyx.begin() == POZYX_FAILURE){
    Serial.println(F("ERROR: Unable to connect to POZYX shield"));
    Serial.println(F("Reset required"));

  Serial.println(F("----------POZYX POSITIONING V1.0----------"));
  Serial.println(F("- No parameters required."));
  Serial.println(F("- System will auto start calibration"));
  Serial.println(F("- System will auto start positioning"));
  Serial.println(F("----------POZYX POSITIONING V1.0----------"));
  Serial.println(F("Performing auto anchor calibration:"));

  // clear all previous devices in the device list

  int status = Pozyx.doAnchorCalibration(POZYX_2D, 10, num_anchors, anchors, heights);

  if (status != POZYX_SUCCESS){
    Serial.println(F("ERROR: calibration"));
    Serial.println(F("Reset required"));


  Serial.println(F("Starting positioning: "));


void loop(){
  coordinates_t position;

  int status = Pozyx.doPositioning(&position, POZYX_2_5D, 1000);

  if (status == POZYX_SUCCESS){

void printCoordinates(coordinates_t coor){

  Serial.print("x_mm: ");
  Serial.print("y_mm: ");
  Serial.print("z_mm: ");

void printCalibrationResult(){
  uint8_t list_size;
  int status;

  status = Pozyx.getDeviceListSize(&list_size);
  Serial.print("list size: ");

  uint16_t device_ids[list_size];
  status &= Pozyx.getDeviceIds(device_ids,list_size);

  Serial.println(F("Calibration result:"));
  Serial.print(F("Anchors found: "));

  coordinates_t anchor_coor;
  for(int i=0; i<list_size; i++)

    Serial.print("Anchor ");
    Serial.print(": 0x");
    Serial.println(device_ids[i], HEX);

    status = Pozyx.getDeviceCoordinates(device_ids[i], &anchor_coor);


A week later and many hours (learning some but also learnt how little I know about real coding) QED : I do need help again.

Compiling is successful (Particle.dev) after following modification of the Pozyx Arduino lib from github.

a, replacing arduino.h with application.h
b, adding math.h (solved the issue with ceil)

I introduced a level shifter to rule out any issues with 3V3 and 5V. I have done a simple i2c test and get the right answer from the Pozyx shield (0x4B). (n.b the Shield works with my Arduino UNO)

I do suspect I have an problem with the interrupt. Does interrupt work differently in Photon compared with Arduino? I do think I understand that Arduino has some kind of predefined interrupt pins?

If that is the case and were do I attach an interupt in Photon that corresponds to that Arduino pin or do I missunderstand this?

Interrupts are set up pretty much the same way in wiring as on the Arduinos, but there are some differences too (which pins to use)
Have a look here

So some of the sanity checks in the lib would need adapting
e.g the Photon allows more than these two pins, especially since these are already used for I2C on the Photon, you need to choose a different interrupt pin

  // check if the pin is valid
  if((interrupt_pin != 0) && (interrupt_pin != 1)) 
    return POZYX_FAILURE;

or here you’d need to check if pinMode() needs setting differently and what that int_mask does.

  if(_mode == MODE_INTERRUPT){
    // set the function that must be called upon an interrupt
    attachInterrupt(interrupt_pin, IRQ, RISING);

    // use interrupt as provided and initiate the interrupt mask
    uint8_t int_mask = interrupts;
    if (interrupt_pin == 1){
      int_mask |= POZYX_INT_MASK_PIN;
    if (regWrite(POZYX_INT_MASK, &int_mask, 1) == POZYX_FAILURE){
      return POZYX_FAILURE;

BTW: I2C would not need level shifting between 5V & 3V3, due to its way how it works and the Photon pins being 5V tolerant in I2C mode.