Skip to main content
Skip table of contents

Combination of cloud and Arduino

Introduction

The Creator Controller is a great tool to manage your Pozyx setup of one or multiple tags. However, sometimes you still require to know the position on the tag itself. This is still perfectly possible. When a tag is remotely being positioned, it is still possible to read out the position and sensor data through the I2C or USB interface and integrate it on your Arduino.

In this tutorial, we show you how to read the position data using an Arduino connected to a slave tag that is remotely positioned. The master tag can be working with Python, Arduino or the Creator Controller, and this sketch is exclusive for slave tags.

Requirements

If you're working with Arduino, you should already have everything you need.

  • One of our supported Arduinos: Uno, Mega or Nano with a slave tag

  • Arduino Create: https://create.arduino.cc

  • Pozyx Creator Controller/Arduino/Python with one master tag

Here we go!

  • Make sure you have the latest version of the Pozyx Creator Controller running.

  • Set up your anchors.

  • Connect your tag, discover it and make sure you get good positioning coordinates.

  • Install Arduino. We highly recommend the new Arduino create cloud app: https://create.arduino.cc/editor

  • In Arduino create web editor, go to libraries and search for Pozyx. Clicking this will guide you to the Pozyx Github page. Navigate to the example sketch called "pozyx_check_new_position.ino" in the folder useful under examples.

  • Plug your Arduino Uno or Mega into your computer, shield your Pozyx tag, and upload the Arduino sketch.

  • Open the serial monitor at 115200 baud rate.

  • Go back to the Arduino cloud app and discover the tag shielded to your Arduino. This will start the positioning of the remote tag.

  • You now get a steady stream of positioning coordinates on your Arduino and on the serial monitor. You access these as "position.x", position.y" and "position.z".

The following Arduino script reads out the position whenever it is available on the tag

CODE
#include <Pozyx.h>
#include <Pozyx_definitions.h>
#include <Wire.h>
void setup(){
  Serial.begin(115200);
  if(Pozyx.begin() == POZYX_FAILURE){
    Serial.println(F("ERROR: Unable to connect to POZYX shield"));
    Serial.println(F("Reset required"));
    delay(100);
    abort();
  }
}
void loop(){
  coordinates_t position;
  int status = checkLocalNewPosition(&position);
  if (status == POZYX_SUCCESS){
    // prints out the result
    printCoordinates(position);
  }else{
    // prints out the error code
    printErrorCode("positioning");
  }
}
int checkLocalNewPosition(coordinates_t *position)
{
  assert(position != NULL);
  int status;
  uint8_t int_status = 0;
  // now wait for the positioning to finish or generate an error
  if (Pozyx.waitForFlag_safe(POZYX_INT_STATUS_POS | POZYX_INT_STATUS_ERR, 2*POZYX_DELAY_INTERRUPT, &int_status)){
    if((int_status & POZYX_INT_STATUS_ERR) == POZYX_INT_STATUS_ERR)
    {
      // An error occured during positioning.
      // Please read out the register POZYX_ERRORCODE to obtain more information about the error
      return POZYX_FAILURE;
    }else{
      status = Pozyx.getCoordinates(position);
      return status;
    }
  }else{
    return POZYX_TIMEOUT;
  }
}
// prints the coordinates for either humans or for processing
void printCoordinates(coordinates_t coor){
  Serial.print("POS");
  Serial.print(", x(mm): ");
  Serial.print(coor.x);
  Serial.print(", y(mm): ");
  Serial.print(coor.y);
  Serial.print(", z(mm): ");
  Serial.println(coor.z);
}
// error printing function for debugging
void printErrorCode(String operation){
  uint8_t error_code;
  Pozyx.getErrorCode(&error_code);
  Serial.print("ERROR ");
  Serial.print(operation);
  Serial.print(", local error code: 0x");
  Serial.println(error_code, HEX);
}

As we already perform positioning via the master tag, the system checks whether new positions are available without performing the doPositioning command.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.