Nano 33 IOT / gyroscope

Hello, everyone,
I want to create a project with an Arduino Nano 33 IOT to send the coordinates of the gyyroscope x,y and z through the serial port (displaying on the serial monitor). To do this, I'm using an example sketch created by Riccardo Rizzo. I can see that the coordinates are displayed on the serial monitor when I move the board to a certain position, but the values are not maintained and return to previous values.
I searched the internet for some help and found this video tutorial which corresponds to what I want but the board used is a Nano Ble and not a Nano 33 IOT even though they use the same LM9DS3 library.

Can anyone help me solve this problem?
Thank you very much!

Actually, the Nano 33 IoT uses a LSM6DS3 (6 DoF IMU) while the the Nano 33 BLE uses a LSM9DS1 (9 DoF IMU). They are not the same chip.

The gyro measures rates of rotation about three axes. The rates have nothing to do with coordinates. Likewise, the accelerometer measures rates of change of velocity along three axes, not coordinates.

Please post your code, using code tags.

Nano 33 BLE has LSM9D51
Nano 33 BLE Rev2 has BMI270 + BMM150

Hello jremington,

I used this code:

/*
  Arduino LSM6DS3 - Simple Gyroscope

  This example reads the gyroscope values from the LSM6DS3
  sensor and continuously prints them to the Serial Monitor
  or Serial Plotter.

  The circuit:
  - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT

  created 10 Jul 2019
  by Riccardo Rizzo

  This example code is in the public domain.
*/

#include <Arduino_LSM6DS3.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");

    while (1);
  }

  Serial.print("Gyroscope sample rate = ");
  Serial.print(IMU.gyroscopeSampleRate());
  Serial.println(" Hz");
  Serial.println();
  Serial.println("Gyroscope in degrees/second");
  Serial.println("X\tY\tZ");
}

void loop() {
  float x, y, z;

  if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(x, y, z);

    Serial.print(x);
    Serial.print('\t');
    Serial.print(y);
    Serial.print('\t');
    Serial.println(z);
  }
}

The code looks fine.

Do you understand that the behavior you observed for the printed rotation rates is as expected?

Hello,

I have the board built into a box with a video camera that moves with a servo motor. I want the board to send the coordinate data to a patch I've created in Max/msp in a synthesis image application. The problem is that when the camera changes position and stops, the values change while there is movement but do not stabilise when the camera stops.

What do you mean by coordinate data? The sensor you have does not measure coordinates.

If properly calibrated, the sensor can be used with fusion filter code to estimate 3D orientation angles for a short while. Is that what you are thinking?

Thank you for your response. I tried creating a code that would compensate for the readings, but it is still not stable enough to produce accurate readings of the positions the camera assumes. This can be observed in the point cloud generated by my patch in Max/MSP. I am attaching the code and the link to the project video.

#include <WiFiNINA.h>           // Biblioteca Wi-Fi para a Nano 33 IoT
#include <WiFiUdp.h>            // Biblioteca UDP para envio de pacotes
#include <OSCMessage.h>         // Biblioteca OSC para mensagens OSC
#include <Arduino_LSM6DS3.h>    // Biblioteca para o giroscópio LSM6DS3 integrado

// Definições de rede Wi-Fi
const char* ssid = "RedePrivadaArduino";
const char* password = "senha1234";

// Definições de IP e porta para UDP
IPAddress localIp(192, 168, 4, 21);      // IP desejado para a Nano 33 IoT
IPAddress outIp(192, 168, 4, 7);        // IP do computador com Max/MSP
IPAddress gateway(192, 168, 4, 1);       // IP do gateway (roteador)
IPAddress subnet(255, 255, 255, 0);      // Máscara de sub-rede
const unsigned int localPort = 8888;     // Porta local para envio de UDP
const unsigned int outPort = 2222;       // Porta para envio OSC ao Max/MSP

// Cliente UDP para enviar os pacotes OSC
WiFiUDP Udp;
float gyroX, gyroY, gyroZ;

void setup() {
  Serial.begin(9600);
  delay(1000);

  // Configurar IP estático antes de conectar
  WiFi.config(localIp, gateway, subnet);

  // Conectar ao Wi-Fi
  Serial.print("Conectando-se a ");
  Serial.println(ssid);

  int retryCount = 0;
  const int maxRetries = 5; // Número de tentativas de conexão antes de reiniciar o Wi-Fi

  WiFi.begin(ssid, password);

  // Tentar conectar até o limite de tentativas
  while (WiFi.status() != WL_CONNECTED) {
    delay(2000); // Aguardar 2 segundos entre as tentativas
    Serial.print("Tentativa de conexão ");
    Serial.print(retryCount + 1);
    Serial.println(" falhou. Tentando novamente...");

    retryCount++;

    // Se o número de tentativas ultrapassar o máximo, reiniciar o Wi-Fi e recomeçar as tentativas
    if (retryCount >= maxRetries) {
      Serial.println("Número máximo de tentativas atingido. Reiniciando Wi-Fi...");
      WiFi.disconnect();
      delay(2000); // Aguardar um pouco antes de tentar novamente
      WiFi.begin(ssid, password); // Recomeçar a tentativa de conexão
      retryCount = 0; // Reiniciar o contador de tentativas
    }
  }

  Serial.println("\nConectado ao Wi-Fi!");
  Serial.print("Endereço IP da Nano 33 IoT: ");
  Serial.println(WiFi.localIP());

  // Inicializar o cliente UDP com a porta local
  Udp.begin(localPort);

  // Inicializar o giroscópio
  if (!IMU.begin()) {
    Serial.println("Falha ao iniciar o giroscópio LSM6DS3!");
    while (1); // Travar o programa se o giroscópio não for inicializado
  }
  Serial.println("Giroscópio LSM6DS3 iniciado com sucesso.");
}

void loop() {
  if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(gyroX, gyroY, gyroZ);

    // Exibir as coordenadas no Monitor Serial
    Serial.print("Giroscópio - X: ");
    Serial.print(gyroX);
    Serial.print(" Y: ");
    Serial.print(gyroY);
    Serial.print(" Z: ");
    Serial.println(gyroZ);

    // Criar e enviar mensagem OSC com os valores X, Y e Z
    OSCMessage gyroMsg("/gyroscope");
    gyroMsg.add(gyroX);
    gyroMsg.add(gyroY);
    gyroMsg.add(gyroZ);

    Udp.beginPacket(outIp, outPort);
    gyroMsg.send(Udp); // Enviar a mensagem OSC corretamente formatada
    Udp.endPacket();
    gyroMsg.empty();   // Limpar a mensagem para reutilização

    // Confirmação de envio no Monitor Serial
    Serial.println("Mensagem OSC enviada para o Max/MSP");

    delay(10); // Intervalo entre envios para evitar sobrecarga
  }
}



camera

Please explain what you actually want to measure and how the measurements will be used.

Knowing that my project involves sending OSC messages via wifi, at this point we'll simplify matters and focus on solving the problem by displaying coordinates on the serial monitor.

So, I want the x, y and z coordinate values for the board positions to be displayed on the serial monitor. I can see from the example code in the Arduino LSM9DS3 library that the x, y and z coordinates change when I move the board to a certain position, but then return to their initial values. This prevents me from being able to determine the coordinates of each position the board assumes.

Thank you very much for your attention.

You want to know position the base is, like a clock face - where it has spun to?

You will need something that measures x, y and z coordinates.

The LSM9DS3 does not measure x, y and z coordinates.

Yes, I want to know the x,y and z coordinates of the plate when it assumes a certain position.

The accelerometer's X, Y can tell you the pitch and roll - and whether it's upside-down.
A magnetometer can give you an idea of position - like a compass heading. (That may be subject to local magnetic fields.)

Actually, of orientation, usually direction of travel when used as an electronic compass.

Use three rulers or distance sensors instead, one for each x, y and z coordinate.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.