Processing -> HC-05 -> ATmega328P -> pancake vibromotors - data-loss problem?

-----While waiting for inspiration to strike we fixed the pancakes on. For some reason it all works now.

Thanks for reading. ;)---

Dear forum,

Me and a buddy are working on a project, and are at a dead end at the moment. We are making two devices that are supposed to activate pancake vibromotors, based on whether certain keys are pressed on a computer keyboard. A Processing Sketch detects whether a key is pressed, and if so, sends a message to the appropriate HC-05 Bluetooth module. This message is then interpreted by an ATmega 328P-PU loaded with some Arduino code, which is supposed to activate the pancakes.

The design worked on breadboard (although we didn't have the equipment to test both devices running together), so we went on to make the actual prototypes. The problem is that first one of the two devices was working perfectly, but then we tried putting together the other device, and something strange happened. We turned it on and only a few of the pancake connections worked (we haven't actually put the pancakes on yet, but are using a voltage meter to check). Then we turned it off/on, reconnected and another set of pancakes worked, but still not all. And again and again. So random pancakes are working, but never all. Then we tried on the first device again, and the same thing is happening now. When we tried turning both on together, we noticed some very odd blinking Bluetooth leds.

We apologize if this is not the right forum, but we don't)whether our problems are caused by the HC-05s, the ATmegas, the codes, or shoddy soldering.

We are now trying to get one device to work at a time. We have used four different ATmegas, and bootloaded them all a few times.

Both devices have the exact same problem, so it seems unlikely there's a problem in the ATmega or the Bluetooth modules, or in the soldering, but you never know. So, maybe it's in the Processing or Arduino code? Or our board design?

Here is the Processing code:

import processing.serial.*;
  Serial leftPort;
  Serial rightPort;
  Serial readPort;  // We don't use this anymore
  float boxX;
  float boxY;
  int boxSize = 20;
  String displayText= "Cool machine"; 
    
  Serial port;

  void setup() {
    size(800, 800);
    //writing
    //Left-hand device
    leftPort = new Serial(this, "COM4", 9600); // Starts the serial communication
    leftPort.bufferUntil('n'); // Defines up to which character the data from the serial port will be read. The character 'n' or 'New Line'
    //Right-hand device
    rightPort = new Serial(this, "COM8", 9600); // Starts the serial communication
    rightPort.bufferUntil('n'); // Defines up to which character the data from the serial port will be read. The character 'n' or 'New Line'

    //reading - we got rid of all this stuff because we don't need to read anything anymore

    //readPort = new Serial(this, "COM5", 9600); // Starts the serial communication
    //readPort.bufferUntil('n'); // Defines up to which character the data from the serial port will be read. The character 'n' or 'New Line'
    //tableOfFeedback = new Table();
    //tableOfFeedback.addColumn("feedback");
    //TableRow newRow = tableOfFeedback.addRow();
    //newRow.setString("feedback", feedback);
    //saveTable(tableOfFeedback, "feedback.csv");


    //Window
    boxX = width / 2.0;
    boxY = height / 2.0;
    rectMode(RADIUS);
  }
  
  //Got rid of this stuff because we don't want to read anything
  //void serialEvent (Serial myPort){ // Checks for available data in the Serial Port
  //  feedback = myPort.readStringUntil('n'); //Reads the data sent from the Arduino (the String "LED: OFF/ON) and it puts into the "ledStatus" variable
  //  println("Inside the serial event");
  //}

  void draw() {
    //Display screen
    background(237, 240, 241);
    fill(20, 160, 133);
    stroke(33);
    strokeWeight(1);
    textSize(32);
    text(feedback, 180, 200);
 //   println(displayText);
    if (keyPressed) {
        //This is where a keyboard key gets translated into something for the HC-05 to read
        //left hand
        if (key == 'a'){
          leftPort.write(1);
        } else if (key == 's'){
          leftPort.write(2);
        } else if (key == 'd'){
          leftPort.write(3);
        } else if (key == 'e'){
          leftPort.write(4);
        } else if (key == 'f'){
          leftPort.write(5);
        } else if (key == 'w'){
          leftPort.write(6);
        } else if (key == 'r'){
          leftPort.write(7);
        } else if (key == 't'){
          leftPort.write(8);
        } else if (key == 'g'){
          leftPort.write(9);
        //right-hand
        } else if (key == 'h'){
          rightPort.write(10);
        } else if (key == 'y'){
          println ( "Fuck yeah");
          rightPort.write(11);
        } else if (key == 'u'){
          rightPort.write(12);
        } else if (key == 'o'){
          rightPort.write(13);
        } else if (key == 'j'){
          rightPort.write(14);
        } else if (key == 'i'){
          rightPort.write(15);
        } else if (key == 'k'){
          rightPort.write(16);
        } else if (key == 'l'){
          rightPort.write(17);
        } else if (key == ';'){
          rightPort.write(18);
        } 
    }
    
    delay(25);  // We use this to match up the Arduino and Processing sketches
  }

This is the Arduino code for the left device.

const int motorPinBack = 2;
const int motorPinUp = 3;
const int motorPinRight = 4;
const int motorPinForward = 11;
const int motorPinLeft = 12;
const int motorPinDown = 13;

int loopCount = 0; // counts the amount of loops, which is used for when the pancakes move in a rotating pattern, and for the 'grab' pattern
int state = 0; // state stores the message sent by processing. Determines which behavior to perform this loop
void setup() {
  pinMode(motorPinBack, OUTPUT);
  pinMode(motorPinUp, OUTPUT);
  pinMode(motorPinRight, OUTPUT);
  pinMode(motorPinForward, OUTPUT);
  pinMode(motorPinLeft, OUTPUT);
  pinMode(motorPinDown, OUTPUT);

  //Set all pins to LOW
  Serial.begin(9600); // Default communication rate of the Bluetooth module
}
void loop() {
  Serial.println("beginning of loop");
  if (Serial.available() > 0) { // Checks whether data is coming from the serial port
    state = Serial.read(); // Reads the data from the serial port
  }
   if (state == 0) {
    Serial.print("State = 0 so put everything to LOW n");
//turning on/off pins
   }

  //--------------left-hand----------------//
  //Down
 else if (state == 9) {
    Serial.print("Perform down n");
//turning on/off pins    state = 0;
  }
  //Up
  else if (state == 8) {
    Serial.print("Perform up n");
//turning on/off pins
    state = 0;
  }
//ETC

 loopCount++;
}

We have tried removing the printlines. The arduino code ran faster so Processing could barely keep up, but still the same problems occurred. Only a random set of pancakes connections responded. We have glued several components to make stick, could that cause problems?

I have added pictures and a schematic. We switched the capacitor with a bigger one (470microFahrad) to deal with some earlier power issues, and we switched the 1kOhm and the 2.2kOhm resistors because they were causing connectivity problems earlier. Initially, one device had the original resistor configuration (as in the schematic) and one had the new one (switched), but both devices had the same troubles.

We have completely run out of options to try. Do you guys have any advice?