Connecting uno wifi rev 2 and MaxMSP

Hello,

I am trying to connect the uno wifi rev 2 using an access point (FileHub) that is connected to the laptop and MaxMSP. The code from MaxMSP is packing and sending two floats (from two mugic sensors) to the Arduino (picture of max patch attached). The uno wifi rev 2 says it is connected to the wifi but nothing is happening on the device with the LEDs. I tried trouble shooting the Arduino connection with PacketSender using the port, IP address, and type of information being sent but there was no connection detected. I am using an adafruit 24 circle led that is connected via conductive thread. Any help in keeping these three (Arduino-MaxMSP-mugic) connections robust will be appreciated!

#include <WiFiNINA.h>
#include <Adafruit_NeoPixel.h>

#define PIN        6       // Pin connected to the NeoPixel
#define NUMPIXELS  24      // Number of pixels in the NeoPixel strip

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGBW + NEO_KHZ800);

const char* ssid = "####";          // Replace with your network SSID
const char* password = "####";  // Replace with your network password

WiFiServer server(8888); // Port 8888, should match the port used in Max MSP

// Define a 2D array to hold 7 pairs of points
int points[7][2] = {
  {2, 5},   // First set of points
  {7, 10},  // Second set of points
  {12, 15}, // Third set of points
  {17, 20}, // Fourth set of points
  {22, 0},  // Fifth set of points
  {3, 6},   // Sixth set of points
  {8, 11}   // Seventh set of points
};

int currentSetIndex = 0; // Index to keep track of the current set of points
float angle1, angle2;    // Angles received over WiFi

void setup() {
  Serial.begin(9600);    // Initialize Serial communication at 9600 baud rate
  pixels.begin();        // Initialize NeoPixel library
  pixels.show();         // Clear the NeoPixel strip

  // Connect to WiFi
  while (WiFi.begin(ssid, password) != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi!");
  Serial.println("IP Address: ");
  Serial.println(WiFi.localIP());  // Print the IP address

  server.begin(); // Start the WiFi server
}

void loop() {
  WiFiClient client = server.available(); // Check if a client has connected

  if (client) { // If there is a client
    String inputData = "";
    while (client.connected()) {
      if (client.available()) {
        inputData = client.readStringUntil(';'); // Read input until semicolon
        processInput(inputData);                 // Process the received data
        client.flush();                          // Clear client buffer
      }
    }
  }
}

// Function to handle the received data and update angles
void processInput(String input) {
  Serial.println("Received data: " + input); // Debug: print received data to Serial Monitor
  int commaIndex = input.indexOf(',');
  if (commaIndex > 0) {
    angle1 = input.substring(0, commaIndex).toFloat();
    angle2 = input.substring(commaIndex + 1).toFloat();

    // Calculate pixel indices from angles
    int pixelIndex1 = round(angle1 / 15.0); // Convert angle1 to corresponding pixel index
    int pixelIndex2 = round(angle2 / 15.0); // Convert angle2 to corresponding pixel index

    // Light up the calculated pixels with red color for the angles
    pixels.setPixelColor(pixelIndex1, pixels.Color(255, 0, 0)); // Red color for angle1
    pixels.setPixelColor(pixelIndex2, pixels.Color(255, 0, 0)); // Red color for angle2

    // Get the current set of points from the array
    int point1 = points[currentSetIndex][0];
    int point2 = points[currentSetIndex][1];

    // Light up the specified points with white color
    pixels.setPixelColor(point1, pixels.Color(255, 255, 255)); // White color for point1
    pixels.setPixelColor(point2, pixels.Color(255, 255, 255)); // White color for point2

    // Show the updates on the strip
    pixels.show();

    // Check if the calculated pixel indices match the specified points
    if (pixelIndex1 == point1 && pixelIndex2 == point2) {
      // Move to the next set of points
      nextSet();
    }
  }
}

// Function to move to the next set of points
void nextSet() {
  // Move to the next set in the array
  currentSetIndex++;
  // Loop back to the first set if we've reached the end of the array
  if (currentSetIndex >= 7) {
    currentSetIndex = 0;
  }
}

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