Industrial shields Mockup contest on IoT solutions world congress Barcelona

Industrial shields Mockup contest on IoT solutions world congress Barcelona

On this post is showed our mockup on the IOT world congress in Barcelona. This mockup consists on contest game to get a free PLC. The application count the maximum speed that the user can make turn the encoder. Then through Ethernet UDP client can send a char to the panel PC Touchberry Pi 3 10” and showed on the touch screen. Also users enter their name and e-mail to receive future information and participate with free PLC contest.

For this Mockup is used a M-Duino 19R and a Touchberry Pi 3 10”.

On this post is showed how to connect and how to program the M-Duino. It’s required an encoder, a stepper motor and  a stepper motor driver. How to connect them:

Also is added a push button to restart the program. On this case is used the I0.4 input. When the connections are set, M-Duino is ready to be programmed. Next it is showed how to program it:

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Pulses.h>

#define stp 3  
#define EN Q0_0 
#define dir  2 


int pushButton = I0_4; 
float gameTime = 0;
const int phaseB = I0_1; 
const int phaseA = I0_0; 
int valuePhaseB = 0;
long pulses = 0;
long _pulses = 0;
long pulsesO = 0;
long pulsesF = 0;
unsigned long timeO = 0;
unsigned long timeF = 0;
float encoderSpeed = 0;
unsigned long comparisonTime = 0;
char msg[50];
unsigned long speed0;
unsigned int localport = 8888; 

EthernetUDP Udp;
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x5C, 0x18};
IPAddress ip(10, 10, 10, 100);
IPAddress subnet(255, 255, 255, 0);
IPAddress dnServer(10,10,10,101);
IPAddress gateway(10,10,10,101);

// Interupt function
void detectPulses() {
  if (digitalRead(phaseB) == LOW) { //Confirm if we are turning on CW direction.
    pulses++;
  }
  else { //Confirm if we are turning on CCW direction.
    pulses--;
  }
}
void setup() {
  pinMode(phaseA, INPUT); // Configure the I0.X as a INPUTS
  pinMode(phaseB, INPUT);
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  
  //Enable the interrupt on a rising edge of PhaseA
  attachInterrupt(digitalPinToInterrupt(phaseA), detectPulses, RISING); 
  Ethernet.begin(mac, ip, dnServer, gateway, subnet);
  Udp.begin(localport);
  startPulses(3, 500);
}
void loop() {
  if (digitalRead(pushButton) == HIGH) {//Listenig the push button to start the game
    stopPulses(3);
    gameTime = millis();
    pulses = 0;
    comparisonTime = millis();
    while ((millis() - gameTime) <= 5000) { //5s loop
      if (millis() - comparisonTime >= 500) { //If every 0,5s
        pulsesO = pulses;
        if (pulsesO > pulsesF) {//Comparison
          pulsesF = pulsesO; 
        }
        pulses = 0;
        comparisonTime = millis();
      }
    }
    //Converting pulses by speed rev/min
    speed0 = (unsigned long)(float)(((float)pulsesF / 500.0) / ((float) 5.0 / (float) 600.0));
    
    //Sending speed through UDP port
    sprintf(msg,"%c%lu%c",'B',speed0,'E');
    Udp.beginPacket("10.10.10.101", 10001);
    Udp.write(msg);
    Udp.endPacket();

    //Stepper motor sequence
    startPulses(3, 800);
    delay(800);
    startPulses(3, 1000);
    delay(800);
    startPulses(3, 1200);
    delay(3000);
    startPulses(3, 1000);
    delay(800);
    startPulses(3, 800);
    delay(800);
    stopPulses(3);
    
    //Default game settings
    delay(2000);
    startPulses(3, 500);
    pulsesO = 0;
    pulsesF = 0;
  }
}

 

Comments are closed.