Capacitive Touch Slider (CAP1203) - Occasionally no connection

I bought a CAP1203 (SEN-15344) to provide the inputs for my Raspberry Pi project . I got it working by hooking it to an Arduino Uno and the Raspberry Pi reads the serial data through the USB connector. Occasionally the connection fails on boot-up. On power-up the Pi will boot directly into a python script which then initializes the serial communication.

So I am hoping that if the Arduino could just try again if can’t connect, that I would be up and running. How can I get the Arduino to check if it is the Wire.begin or the Serial.begin that didn’t work (or does it matter) and how do I get it to try again?

void setup() {
  Wire.begin();         // Join I2C bus
  Serial.begin(9600);   // Start serial for output
  // Setup sensor
  if (sensor.begin() == false) {
    Serial.println("Not connected. Please check connections and read the hookup guide.");
    //CAN I ADD SOMETHING HERE TO TRY AGAIN??
    while (1);
  }

Because the connection failure happens so infrequently my usual method of fixing things with trial and error is failing me, so any help in understanding how to reset the Arduino so it can try again would be great. Thanks

Thanks for reaching out to us on this.

Check out this guide on how processor interrupts work; following this should accomplish what you’re looking for: https://learn.sparkfun.com/tutorials/pr … th-arduino

Hope this helps, and happy sparking!

Thank you for your quick response. I think either you misunderstood my question or I need a little more help with why I might want an interrupt. My communication between my Arduino and my Raspberry Pi is working great. I think it is just a problem with my Arduino not connecting correctly to the Cap1203 occasionally. I2C, wire, serial communication, restarting the Arduino or understanding Arduino libraries is what I am thinking I am missing some knowledge in … I don’t see how an interrupt would help me. In the code I posted above (which comes from the CAP1203 tutorial), the Arduino knows that it didn’t connect. Maybe I can get the Arduino to just re-run the Arduino setup (or reset the Arduino)?

The arduino should be working fine, I think the issue you’re having is probably a communication issue between the pi and arduino. Closing and opening the serial port should reboot the arduino, give that a try.

Great advice. I am now closing and reopening the serial port in the Pi code if the Arduino doesn’t connect correctly. This reset covers any Arduino or Ardunio/Pi troubles that may have occurred. Thanks for the help, it was very much appreciated!