ArduinoCloud.update() and I2C

I have a main loop like this:

void loop() {
  // Your code here 

Everything happens in the callback functions, like:

void onBassToneChange()  {
  // Add your code here to act upon BassTone change
  if (discant_tone <= bass_tone)
    // move discant mallet out of way
    discant_tone = bass_tone + 1;
    servobank->setPWM(14, angles[1][discant_tone][0]);
  servobank->setPWM(12, angles[0][bass_tone][0]);
  Serial.println("bass tone change");
  bass_horiz = angles[0][bass_tone][0];
  bass_higher = angles[0][bass_tone][1];
  bass_lower = angles[0][bass_tone][2];


I get the "bass tone change" message in my serial monitor, showing that the callback is working. But what is not working is the servobank->setPWM() call. My servos are dead! They work in the setup() function, where the servobank is initiated (PCA9685_RT lib) and I place the servos in their initial positions. But when the program advances to the loop() part, the servos die. I guess it has to do with the ArduinoCloud.update() call. Would it help to put a delay, or is the Cloud in a total conflict with the PCA9685_RT lib? Yes, I should be testing that, but I'm not at the workshop right now.

Seems the I2C stops working after Arduino Cloud is involved. The timer or timers that I2C is set to, in the PCA9685_RT function calls, is overrun by something that Arduino Cloud wants. I think the PCA9685 is quite flexible what comes to timing, so I probably need to change all my parameters so that the PCA9685 can output correct pulse lengths. Right now I output quite peculiar numbers to the servos, instead of the standard 0 to 180 degrees.

The solution was to ditch the whole PCA9685. Instead I connected the four servos direct to the MKR1000. And I had yet to find digital pins on the MKR1000 that had no extra function. No MOSI, MISO, SCL, SDA.

The whole setup is for calibrating 4 servos to play two mallets on 27 glockenspiel bars, both in fortissimo and pianissimo. The final glockenspiel will use the PCA9685, so I have to first calibrate the servos using servo.writeMicroseconds(), then I have to convert the microsecond values to the form the PCA9685 understands.

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