Controlling two Arduino board with a single app

Hello,

How can I control two arduino board at the same time using a web app? I have two stepper motors that I want to run simultaneously with different speed, each stepper motor have its own arduino board and stepper driver and now I want to do a small web app to control them, so I want to enter from the keyboard a value and from that value each arduino should execute its stored program.

Any hints? Thank you.

First obvious question is why not control the two motors from one Arduino?

Second, have you written the code needed to make your App control a single Arduino?

Third, how is the Arduino connected to the WiFi system (assuming you are using WiFi with your phone or PC)?
OR, is your Arduino connected by USB cable to a PC and the PC is getting instructions via the Web?

...R

Hi and thank you for the reply.

So for the first question I am using one arduino with one stepper motor and with his stepper driver and similar to the second stepper motor. Each motor with his own hardware.

I wrote the code to control the stepper motors and I did not do any App for Arduino. In my case the arduinos are connected with USB, but I will purchase some WiFi modules to develop an web based app that later will control the arduinos.

Basically it should be like one button to control two arduinos. I tried with a windows app based on usb but with no succes, just for one usb so I thought that using WiFi will be much better.

dnbbrain:
So for the first question I am using one arduino with one stepper motor and with his stepper driver and similar to the second stepper motor. Each motor with his own hardware.

That does not answer my question about WHY you are using two Arduinos. 3D printers use one Arduino to control 4 stepper motors.

I wrote the code to control the stepper motors and I did not do any App for Arduino. In my case the arduinos are connected with USB, but I will purchase some WiFi modules to develop an web based app that later will control the arduinos.

That does not seem to answer my second question either. I was asking if you already have a working system that can control a single Arduino - that is a combination of a working Web App and an Arduino program that works with it. If you have, then post the programs.

Basically it should be like one button to control two arduinos. I tried with a windows app based on usb but with no succes, just for one usb so I thought that using WiFi will be much better.

Without knowing the detail of what you tried I can't comment. The devil is in the detail. Something could be 99.99% correct and still not work because of one small error.

...R

I tried with a windows app based on usb but with no succes, just for one usb so I thought that using WiFi will be much better.

Any motivation why you think that wifi would be much better?

The fact that you can’t get communication via USB working does not mean that something else is better.

Good day and sorry for such late reply , here is the code I made for a single stepper motor so far.

const int stepPin = 5; 
const int dirPin = 2; 
const int enPin = 8;
int customDelay,customDelayMapped; // Defines variables
int stepCount = 0;  // number of steps the motor has taken

float vmin = 0.9;
float vmax = 53;
float w1 = 365.37;
float w, x;

void setup() {
  Serial.begin(9600);
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);
}

int speedUp() {
    float w = w1 + 400;
    float x = 53 * w / 1000;
    float customDelay = x;
    float newCustom = map(customDelay, 0, 1023, 400,12000); 
    Serial.println(newCustom);
    return newCustom; }
    
void loop() {
    customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
    digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
  
  // Makes 200 pulses for making one full cycle rotation
    for(int x = 0; x < 200; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(customDelayMapped);
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(customDelayMapped); 
   }
}

I will do as you said, using just one arduino instead of two.
I am trying to create a mixing machine that will manipulate gas volumes, not a 3D printer.
In order to obtain 1 litre of mix in 120 seconds from the keyboard a desired concentration of the gas will be inserted, for example 5 % concentration.

For that to happend the machine need to process 50 ml of first gas and 950 ml of second gas.

For the first gas (50 ml) the first stepper should rotate 6.41 turns. For one turn we have 7.8 ml. Dividing 50ml to 7.8ml we get 6.41 turns. Regarding the angle speed of the stepper motor, we have (6.41 multiply by 360 degree) / 120 seconds, resulting 19.23 angle speed.

For the second gas (950 ml) the second stepper should rotate 121.79 turns, 950ml divided by 7.8 ml. Angle speed for the second motor will be (121.79 turns multiply by 360 degree) / 120 seconds resulting 365.37 angle speed.

In the code above 365.37 is defined as input just to test the speed for the stepper motor.

Program used to calculate the number of turns needed to for the 5% example:

// defines pins numbers
const int stepPin = 7; 
const int dirPin = 3; 
const int enPin = 10;

const int stepPin2 = 5;
const int dirPin2 = 2;
const int enPin2 = 8;

float customDelay,customDelayMapped; // Defines variables
int stepCount = 0;  // number of steps the motor has taken

long val;
long val2;
float x = 7.8; // 7.8 ml produce for one turn
float y = 1000; //total volume that can pe produced
int stepCount4 = 0;
int stepCount5 = 0;
float w1, w, z, n1, newC;
float rot = 360; //complete rotation
float t = 120;  //seconds to produce the mix

void setup() {
  Serial.begin(9600);
  Serial.println("Insert concentration: [% vol.]");
  // Sets the two pins as Outputs
  
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
  pinMode(enPin,OUTPUT);

  pinMode(stepPin2, OUTPUT);
  pinMode(dirPin2, OUTPUT);
  pinMode(enPin2, OUTPUT);
  
  digitalWrite(enPin,LOW);
  digitalWrite(enPin2,LOW);
}

// I used the example from a Potentiometer
int speedUp() {
    float q = (n1 * rot) / t;
    float w = q + 400;
    float z = 53 * w / 1000;
    float customDelay = z;
  //int customDelay = analogRead(A0); // Reads the potentiometer
  //Serial.println(customDelay, DEC);
  float newCustom = map(customDelay, 0, 1023, 400,12000); // Converts the read values of the potentiometer from 0 to 1023 into desireded delay values (500 (highest speed) to 12000 (lowest speed), just try)
  //Serial.println(newCustom);
  float newC = newCustom;
  return newCustom; }

void stepperN()
{
  digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x <400; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(customDelayMapped); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(customDelayMapped); 
    }
  //delay(500); //delay 1 second
}

void stepperH()
{
   digitalWrite(dirPin2,LOW); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 100; x++) {
    digitalWrite(stepPin2,HIGH); 
    delayMicroseconds(customDelayMapped); 
    digitalWrite(stepPin2,LOW); 
    delayMicroseconds(customDelayMapped); 
    }
  //delay(500); //delay
}

void stepperL()
{
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 200; x++) {
    digitalWrite(stepPin,HIGH); 
    delayMicroseconds(customDelayMapped); 
    digitalWrite(stepPin,LOW); 
    delayMicroseconds(customDelayMapped); 
    }
  delay(1000);
}

void stepperU()
{
  digitalWrite(dirPin2,HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for(int x = 0; x < 200; x++) {
    digitalWrite(stepPin2,HIGH); 
    delayMicroseconds(customDelayMapped); 
    digitalWrite(stepPin2,LOW); 
    delayMicroseconds(customDelayMapped); 
    }
  delay(1000);
}

void loop() {
  
 if (Serial.available() >0)
  {
      val = Serial.parseInt();
      val2 = val;
     
      int c2 = val * 10;
      float n1 = c2/x;
      Serial.println(val, DEC);
    
          if (n1 > 0)
            {
              for (int i=1; i<=n1; i++)
                {
                  stepperN();
                  //customDelayMapped = speedUp();
                  Serial.println(stepCount5);
                  stepCount5++;
                  //Serial.println(newC);
                }
              Serial.print(n1, 2);
              Serial.println("[turns]"); //6.41 turns needed for the firs gas
            }
            
      int c3 = y - (val2 * 10);
      float n2 = (c3)/x;
      Serial.println(val2, DEC);
      
          if (n2 > 0)
            {
              for (int i=1; i<=n2; i++)
                { 
                  customDelayMapped = speedUp();
                  stepperH();
                  //Serial.println(stepCount5);
                  //stepCount5++;
                  Serial.println(newC);
                }
              Serial.print(n2, 2);
              Serial.println("[turns]"); //121.79 turns needed for the second gas
            }
  }
     if (Serial.available() <0)
       {
        digitalWrite(enPin,HIGH); 
       } 
}

dnbbrain:
For the first gas (50 ml) the first stepper should rotate 6.41 turns. For one turn we have 7.8 ml.

IMHO it will make the programming easier if you calculate the quantity in terms of the numbers of step. For example 7.8ml requires 200 steps (assuming you are using full steps).

…R

7.8 ml will be a static variable and will not change, the stepper motors rotate two threaded rod of M6, 1mm/turn, and yes 7.8ml do require 200 steps, a revolution.

dnbbrain:
and yes 7.8ml do require 200 steps, a revolution.

My point is that the Arduino maths will be easier if you measure things in steps rather than revolutions. In other words, if I need 23ml, how many steps does that require, not how many revolutions.

...R