Arduino => raspberry pi MQTT communication & data saving

I have the Arduino nano 33 IoT and I am doing a project where I want it to send the IMU data to a rapsberry pi, which will change that data into visuals/audio and output it to a little stereo and screen. I have the pi encoding figured out, but I don't understand how to send data from the Arduino -> pi. Do I use an MQTT? Arduino IoT cloud? I've done a lot of research, but this is my first IoT project so I am very confused. Can someone point me to good resources or recommendations? I would ideally like to save the data that is collected from the Arduino and then have the communication "start" at a certain time. In other words, have the raspberry pi "translate" the data at a certain point in the day. Thank you so much!

EDITED TO UPDATE:
I am trying to have an Arduino communicate with a friend's pi using MQTT, but we are having issues with MQTT connection. This is the sketch that we are using. I am wondering if we need a host broker to configure the network traffic? Would Arduino cloud solve this, or do we need to use another cloud like hive? This is my first time with MQTT, so I'm not quite sure what the problem is. Thanks!!

The dots contain the IPAddress and my internet/password that have been double-checked. I just didn't want to share this information.

#include <SPI.h>
#include <WiFiNINA.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.
IPAddress server(.......);

const char* ssid = ".....";

const char* password = ".....";

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

WiFiClient wifiClient;
PubSubClient client(wifiClient);

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("arduinoClient")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("outTopic","hello world");
      // ... and resubscribe
      client.subscribe("inTopic");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}


void setup()
{
  Serial.begin(57600);

  client.setServer(server, 1883);
  client.setCallback(callback);

  WiFi.begin(ssid, password);
  while( WiFi.status() != WL_CONNECTED){


    delay(500);

    Serial.print("-"); 

  }


  // Allow the hardware to sort itself out
  delay(1500);
}

void loop()
{
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
}

the nano 33 IoT has WiFi and bluetotth so you could use either
for WiFi you could write your own TCP/UDP client server application but it probably be simpler to use MQTT - try a web search for arduino raspberry pi mqtt
if Bluetooth you could create a simple serial type connection, e.g. Bluetooth classic using ESP32 or ESP32 using BLE although the examples are for an ESP32 you should be able to port them to a nano 33

updated with new problem...

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