Good Day All,
I am 3D printing a OS Railway train set for my grandson which can be found on thingiverse.
I have never owned or programed an Arduino I am just trying to follow the instructions included with one of the engine print files.
If you could take a look at the following sketch and the errors and point me in the right direction it would be greatly appreciated.
Thank You.
Merry Christmas,
Terry N
Here is the sketch,
/* Copyright Olle Sköld 2017
*
- Wifi accesspoitn using NodeMCU and ESP8266.
- This software is provided free and you may use, change and distribute as you like.
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "TimerObject.h"
#define forward 0
#define backward 1
/* Set these to your desired credentials. */
const char *ssid = "OSRHector";
const char *password = "osrailway";
bool highBeamActive = false;
bool motionActive = false;
bool motionDirection = forward;
int target_speed;
int actual_speed;
int acceleration_step = 5;
int LED_BL2 = 15; // Red light on side 2 GPIO15
int LED_BL1 = 13; // Red light on side 1 GPIO13
int LED_HB2 = 14; // High beam side 2 GPIO12
int LED_HB1 = 12; // High beam side 1 GPIO14
int LED_HDL = 2; //PWM for headlights controlled by motor board
int motor_AIN1 = 5; //GPIO5
int motor_AIN2 = 4; //GPIO4
int motor_PWM = 0; //GPIO0
TimerObject *timer1 = new TimerObject(10);
ESP8266WebServer server(80);
/**************************************************************************
*
- Server IP address is: http://192.168.4.1
- When you have connected your device to the wifi network, open the browser and enter the IP address above.
/
void handleRoot() {
/***********************************************************************
void motionControl(){
if(motionActive){
if(actual_speed < target_speed){
actual_speed = actual_speed + acceleration_step;
} else if(actual_speed > target_speed){
actual_speed = actual_speed - acceleration_step;
}
if(actual_speed > 1023){
actual_speed = 1023;
}
if(actual_speed < 0){
actual_speed = 0;
}
analogWrite(motor_PWM, actual_speed);
} else {
analogWrite(motor_PWM, 0);
}
}
/**************************************************
- Motor operation
*/
void motorOperation(){
motionActive = true;
String move_dir = server.arg("dir");
String motion_speed = server.arg("speed");
target_speed = motion_speed.toInt();
//Execute change of direction, but only if actual_speed is below 100, otherwise set target speed to 0 and initiate a slowdown.
if(move_dir == "backward"){
if(motionDirection != backward && actual_speed > 100){
target_speed = 0;
} else {
motionDirection = backward;
}
} else {
if(motionDirection != forward && actual_speed > 100){
target_speed = 0;
} else {
motionDirection = forward;
}
}
digitalWrite(motor_AIN1, motionDirection);
digitalWrite(motor_AIN2, !motionDirection);
digitalWrite(LED_BL2, motionDirection);
digitalWrite(LED_BL1, !motionDirection);
if(highBeamActive){
digitalWrite(LED_HB2, motionDirection);
digitalWrite(LED_HB1, !motionDirection);
} else {
digitalWrite(LED_HB2, 0);
digitalWrite(LED_HB1, 0);
}
}
void updateSpeed(){
String motion_speed = server.arg("speed");
target_speed = motion_speed.toInt();
}
void switchLightOn(){
highBeamActive = true;
digitalWrite(LED_HB2, motionDirection);
digitalWrite(LED_HB1, !motionDirection);
}
void switchLightOff(){
highBeamActive = false;
digitalWrite(LED_HB2, 0);
digitalWrite(LED_HB1, 0);
}
void motionStop(){
motionActive = false;
analogWrite(motor_PWM, 0);
}
/*********************************************************************
- SETUP
*/
void setup() {
delay(1000);
pinMode(LED_BL2, OUTPUT);
pinMode(LED_BL1, OUTPUT);
pinMode(LED_HB2, OUTPUT);
pinMode(LED_HB1, OUTPUT);
pinMode(LED_HDL, OUTPUT);
pinMode(motor_AIN1, OUTPUT);
pinMode(motor_AIN2, OUTPUT);
pinMode(motor_PWM, OUTPUT);
digitalWrite(LED_BL2, 0);
digitalWrite(LED_BL1, 0);
digitalWrite(LED_HB2, 0);
digitalWrite(LED_HB1, 0);
digitalWrite(motor_AIN1, 0);
digitalWrite(motor_AIN2, 1);
analogWrite(motor_PWM, 0);
analogWrite(LED_HDL, 1023);
timer1->setOnTimer(&motionControl);
timer1->Start();
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
/****************************************************************************
- Here you find the functions that are called when the browser sends commands.
*/
server.on("/", handleRoot);
server.on("/run", motorOperation);
server.on("/stop", motionStop);
server.on("/lighton", switchLightOn);
server.on("/lightoff", switchLightOff);
server.on("/updateSpeed", updateSpeed);
server.begin();
}
void loop() {
server.handleClient();
timer1->Update();
}
Here are the errors.
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o: in function `esp8266webserver::ESP8266WebServerTemplate::_prepareHeader(String&, int, char const*, unsigned int)':
C:\Users\Terry\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:427: undefined reference to `TimerObject::setOnTimer(void (*)())'
c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\Terry\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:427: undefined reference to `TimerObject::Start()'
c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o:(.text.setup+0x137): undefined reference to TimerObject::setOnTimer(void (*)())' c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o:(.text.setup+0x13f): undefined reference to
TimerObject::Start()'
c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o: in function esp8266webserver::ESP8266WebServerTemplate<WiFiServer>::~ESP8266WebServerTemplate()': C:\Users\Terry\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:100: undefined reference to
TimerObject::TimerObject(unsigned long)'
c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o:C:\Users\Terry\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WiFi\src/WiFiServer.h:82: undefined reference to TimerObject::TimerObject(unsigned long)' c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o: in function
esp8266webserver::ESP8266WebServerTemplate::handleClient()':
C:\Users\Terry\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:347: undefined reference to TimerObject::Update()' c:/users/terry/documents/arduinodata/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: sketch\OSR_Hectorrail_WifiAP.ino.cpp.o: in function
loop':
C:\Users\Terry\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h:355: undefined reference to `TimerObject::Update()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.