Hello!
I trying to create a touch sensor that sends OSC data over wifi. It workes just fine until like 4 or 5th time i start it, and then suddenly the code stops at the "communication with wifi module failed". This has happened with three different arduinos now, and every time it works a couple of times when try with a new one and then this happens. Pasted the code below
#include <touch_config_samd.h>
#include <touch_api_SAMD.h>
#include <Arduino_MCHPTouch.h>
#include <DataStreamer.h>
#include <SLIPEncodedSerial.h>
#include <OSCData.h>
#include <OSCBundle.h>
#include <OSCBoards.h>
#include <OSCTiming.h>
#include <OSCMessage.h>
#include <OSCMatch.h>
#include <SLIPEncodedUSBSerial.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <SPI.h>
#include <OSCMessage.h>
#include "Arduino_MCHPTouch.h"
// WIFI
//#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = "mias iphone"; // your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
WiFiUDP Udp;
//the Arduino's IP
IPAddress ip(172, 20, 10, 2);
//destination IP
IPAddress outIp(172, 20, 10, 5);
const unsigned int outPort = 57121; // local port to listen on
int count = 0;
void setup() {
// put your setup code here, to run once:
Udp.begin(8080);
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial)
;
// wait for serial port to connect. Needed for native USB port only
// }
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
//while (!Serial)
;
//Set custom sensitivity on X channel
//TOUCH.setSensorsSensitivity(*newSensitivity*, channel);
TOUCH.setSensorsSensitivity(1000, 0);
TOUCH.setSensorsSensitivity(1023, 1);
// QTouch initialization
if (!TOUCH.begin())
{
Serial.println("Error in sensors initialization!");
while (1)
;
}
Serial.println("Touch initialization Done!");
}
void loop()
{
// put your main code here, to run repeatedly:
// polling the sensor for new measure
TOUCH.poll();
// Checks if new data are available
if (TOUCH.available())
{
//reads sensors
Serial.print("Sensor 1 status: ");
Serial.println(TOUCH.read(0));
Serial.print("Sensor 2 status: ");
Serial.println(TOUCH.read(1));
}
delay(100);
//the message wants an OSC address as first argument
OSCMessage msg("/imusic/play/instrument1A");
msg.add(TOUCH.read(0));
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP strea
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
OSCMessage msg2("/imusic/play/instrument1B");
msg2.add(TOUCH.read(1));
Udp.beginPacket(outIp, outPort);
msg2.send(Udp); // send the bytes to the SLIP strea
Udp.endPacket(); // mark the end of the OSC Packet
msg2.empty(); // free space occupied by message
delay(100);
}