Hey there
I'm making a secure remote control for a robot
I have 4 buttons connected to the WeMos D1 (same size as the uno) and only 1 is working.
The buttons are connected to pins 4, 5, 6, and 7.
I'm using the button example as a base for "interfacing" with them
I have Serial.print(); for each button so I'm aware when it is working
here is my code ( issue in void move() )
//robot control
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//=============
//finger print
#include <Adafruit_Fingerprint.h>
//=============
//wifi point
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "WebAuth.h"
#include "Armed.h"
#include "Disarmed.h"
//=============
//fingerprint
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, use software serial...
// pin #2 (GREEN wire)
// pin #3 (WHITE wire)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
//=============
//wifi point
#ifndef APSSID
#define APSSID "LauncherV2"
#define APPSK "thereisnospoonj7cl5"
#endif
//=============
//variables
/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;
bool verify1 = true;
bool serverActive = false;
bool verify2 = false;
bool armed = false;
const int forward = D4;
const int backward = D5;
const int left = D6;
const int right = D7;
int forwardState = 0;
int backwardState = 0;
int leftState = 0;
int rightState = 0;
//test variables
bool fingerprint = false;
//=============52
//creating objects
//create the RF object and bind to "radio"
RF24 radio(9, 10);
//address where the RF modules communicate
const byte address[6] = "j7cl5";
//create the fingerprint object and bind to "finger"
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
//create the server object and bind to "server"
ESP8266WebServer server(80);
//=============
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(forward, INPUT);
pinMode(backward, INPUT);
pinMode(left, INPUT);
pinMode(right, INPUT);
radio.begin();
//open the connection
radio.openWritingPipe(address);
//set as transmitter
radio.stopListening();
//fingerprint startup
while (!Serial)
; // For Yun/Leo/Micro/Zero/...
delay(100);
if (fingerprint == true) {
Serial.println("\n\nAdafruit finger detect test");
// set the data rate for the sensor serial port
finger.begin(57600);
delay(5);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
Serial.println(F("Reading sensor parameters"));
finger.getParameters();
Serial.print(F("Status: 0x"));
Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x"));
Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: "));
Serial.println(finger.capacity);
Serial.print(F("Security level: "));
Serial.println(finger.security_level);
Serial.print(F("Device address: "));
Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: "));
Serial.println(finger.packet_len);
Serial.print(F("Baud rate: "));
Serial.println(finger.baud_rate);
finger.getTemplateCount();
if (finger.templateCount == 0) {
Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
} else {
Serial.println("Waiting for valid finger...");
Serial.print("Sensor contains ");
Serial.print(finger.templateCount);
Serial.println(" templates");
}
}
//===============
//Wifi startup
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.on("/armed", armBot);
server.on("/disarmed", disarmBot);
server.on("/rearm", handleRoot);
}
void loop() {
// put your main code here, to run repeatedly:
if (verify1 != true) {
getFingerprintID();
} else if (serverActive != true) {
server.begin();
Serial.println("HTTP server started");
handleRoot();
serverActive = true;
} else if (verify2 != true) {
server.handleClient();
move();
}
}
//=====ROBOT CONTROL=====
void move() { // Print to Serial Monitor
forwardState = digitalRead(forward);
backwardState = digitalRead(backward);
leftState = digitalRead(left);
rightState = digitalRead(right);
if (armed == false) {
if (forwardState == HIGH) {
//message to send
Serial.print("forward");
char move[] = "1";
radio.write(&move, sizeof(move)); //_ , 2 , 3, 4 working clockwise
} else if (backward == HIGH) {
//message to send
Serial.print("backward");
char move[] = "3";
radio.write(&move, sizeof(move)); //1 , 2 , _, 4 working clockwise
} else if (leftState == HIGH) {
//message to send
Serial.print("left");
char move[] = "4";
radio.write(&move, sizeof(move)); //1 , 2 , 3, _ working clockwise
} else if (rightState == HIGH) {
//message to send
Serial.print("right");
char move[] = "2";
radio.write(&move, sizeof(move)); //1 , _ , 3, 4 working clockwise
} else {
//message to send
char move[] = "0";
radio.write(&move, sizeof(move)); //stop
}
} else {
//message to send
char move[] = "0";
radio.write(&move, sizeof(move)); //stop
}
}
//========================
//===FINGERPRINT SENSOR===
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
move();
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
move();
verify1 = true;
return finger.fingerID;
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
return finger.fingerID;
}
//========================
//====WIFI ACCESSPOINT====
void handleRoot() {
server.send(200, "text/html", HTML);
move();
}
void armBot() {
armed = true;
Serial.print("\nArmed State ="); Serial.print(armed);
Serial.print("\narmBot");
//(send "arm" to the bot)
//enable "armed" light
server.send(200, "text/html", ARMED);
}
void disarmBot() {
armed = false;
Serial.print("\nArmed State ="); Serial.print(armed);
Serial.print("\ndisarmBot");
//(send "disarm" to the bot)
// disable "armed" light
server.send(200, "text/html", DISARMED);
}
//========================
Would someone be able to help
thanks
