What is the best way to read 2 GPIO sensors in real time and show on simple webserver?

Hello everyone!
I just started a new project. The idea is to have have motion sensors that can detect paintballs hitting them and then sending a simple digital signal to a ESP8266 that can display it on a AP webserver. I need it to be kinda instant, since it's supposed to be a snap shooting training tool. (Google "Paintball snap shooting" to get a picture of what i want)

For the motion sensors i used MPU6050s connected to arduino nanos which uses the "getMotionInterruptStatus" to detect the motion and in turn sets a GPIO pin to HIGH. This can then be read by the ESP8266. (Don't know if this is the best solution, maybe another sensor type is better? I'm planning on having an aluminium plate about the size of a head as the target.)

Motion sensor code:

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>

Adafruit_MPU6050 mpu;

#define PIN 5
#define NUMPIXELS 1

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);
  mpu.begin();
  mpu.setHighPassFilter(MPU6050_HIGHPASS_0_63_HZ);
  mpu.setMotionDetectionThreshold(10);
  mpu.setMotionDetectionDuration(20);
  mpu.setInterruptPinLatch(true);
  mpu.setInterruptPinPolarity(true);
  mpu.setMotionInterrupt(true);
  pixels.begin();
  pinMode(4, OUTPUT);
}

void loop() {

  if (mpu.getMotionInterruptStatus()) {
    Serial.println("HIGH");
    pixels.setPixelColor(0, pixels.Color(0, 255, 0));
    pixels.show();
    digitalWrite(4, HIGH);
    delay(200);
    pixels.setPixelColor(0, pixels.Color(0, 0, 0));
    pixels.show();
    
    delay(300);
    digitalWrite(4, LOW);
  }
}

I want to connect 2 of these sensors to the ESP8266 and I have no idea how im going to solve all the timings to get "instant" feedback on the web page. I have tried to make a very simple ajax web page that just reads the digital pin in the loop and displays the value, which works sometimes, but far from every time. I have thought about using interups, but i have no idea how to implement that with 2 sensors and a webserver.

Does someone here know how I can solve this?

@harleyberglund,
Probably wise to ignore the advice from @gmail.com , hopefully someone else can help.

I've removed all the junk from this topic, thank you to everyone who flagged it.

1 Like

When you get it working consistently, then worry about minimizing the time between steps. Realize that real-time begins when your Arduino reads the sensor. Work from there for minimum times. No one here has your setup so no one here can test changes.
Perhaps the first step is to actually quantify the times for the steps. Then you have a meter to tell you if you are getting better or worse results.

display it on a AP webserver

What is the exact purpose of the web server?
Who would view the webpage?
How would it be displayed?

If the web server's purpose is to give feedback to the trainee, I wonder if there might be an easier way to give fast feedback. Rather than using a web server, something like a sound or a light-up signal could be triggered right from the microcontroller.

If there was some extra "non-time-critical" information to be displayed, it could also be shown with a web server, following slightly behind the immediate sound/light feedback.

The purpose is to visualise hits on the target, display a timer and count hits. I’m thinking about a very simple UI with just a split screen (to visualise each target with a color ) and then a circle in the middle or something with timer and counter. This is meant for both the user and for example a coach. But also as a target practice mini game.

I have no experience with ESP8266, so this might be a silly question to ask, but is there any particular reason than you can't get rid of the Nanos and handle the interrupts directly on the ESP8266?

I see your code for the Nanos, but is there any code you could show for the ESP8266 side so far?

I only previously read this topic from the perspective of what needed to be done for moderation purposes, I never really considered the actual question.

Now you mention your point I don't see any reason for interrupts or multiple processors, the ESP should be able to do everything.

I cant connect multiple mpu6050s to one microcontroller. Thats why I decided to have one nano for each mpu6050.

Why not? :thinking:

Their address / addressing? Is that configurable? Or a hardware fix?

Howbeit, there will be latency, unavoidable.

You certainly don't need a Six-Axis (Gyro + Accelerometer) MEMS MotionTracking™ Device just to detect the impact of a paintball on a target!
It does sound like serious overkill!

Indeed - and I'd have thought the largest latency would come from doing this via a webserver!

1 Like

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