Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions BaseConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
R. J. Tidey 2019/12/30
Basic config
*/
#define FILESYSTYPE 1

/*
Wifi Manager Web set up
*/
#define WM_NAME "uselessbox"
#define WM_PASSWORD "password"

//Update service set up
String host = "uselessbox";
const char* update_password = "password";

//define actions during setup
//define any call at start of set up
#define SETUP_START 1
//define config file name if used
#define CONFIG_FILE "/uselessConfig.txt"
//set to 1 if SPIFFS or LittleFS used
#define SETUP_FILESYS 1
//define to set up server and reference any extra handlers required
#define SETUP_SERVER 1
//call any extra setup at end
#define SETUP_END 1

// comment out this define unless using modified WifiManager with fast connect support
#define FASTCONNECT true

#include "BaseSupport.h"
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
# Smart Useless Box with ESP8266 and Gesture Sensor
# Smart Useless Box with ESP8266 and Gesture Sensor modified

This is a modification of the excellent Useless Box from balassy.

https://github.com/balassy/useless-box

The enclosure is the same but the software now has following additions.

- Wifi support via WifiManager
- SPIFFS support with filing and uploads
- Configuration via a file in SPIFFS
- Software update via OTA web browser
- Modfied schematic with an amplifier and loudspeaker to give speech responses
- Audio output via a software DAC using ESP8266Audio library

The SPIFFS config file controls
- servo positions and speeds
- Actions are defined in the config file as sequences of base commands which control servo movements, delays, audio responses and sensor control
- Sensor audio responses may be varied
- Comments in the example config file list possible commands to be used in the sequences.
- Sequences can either run one after another or can be selected at random.

For my hardware I used an ESP-12F rather than the Wemos but that is a personal preference.
The speaker in my case was a 21mm diameter but larger ones can be used.
I made the switch a bit easier to toggle by taking 1mm off the internal spindle to reduce spring tension.

![Schematic](./wiring/Schematic_UselessBox.jpg)

[![Smart Useless Box in Action](./media/Useless-Box1Preview.jpg)](https://youtu.be/ker99iGVxNo "Smart Useless Box in Action")

##Set up Notes
- Use BaseSupprt library at https://github.com/roberttidey/BaseSupport
- Modify passwords for Wifimanager and firmware updates in BasicConfig.h.ino
- Compile and serial upload using Arduino ESP8266 IDE. Code / SPIFFS split needs to be 2MB/2MB to allow for OTA to work.
- WifiManager will start an AP portal when first used to set local wifi parameters. After that it will hook into local network.
- Browse to the device using its IPaddress/upload and upload from data director (edit.htm.gz, favicon.ico, graphs.js.gz). From then on IPaddress/edit may be used to manage SPIFFs content
- Upload uselessConfig.txt, index.html, and .mp3 audio files to SPIFFs
- You can customise these as required. Audio files can be created using an online text to audio service like Notevibes.
- Simple test of servos and audio may be done from base index page at IPaddress/edit
- OTA updates may be done by exporting a compiled binary in Arduino IDE and then browsing to IPAddress/firmware


The following is directly from balassy README

## Smart Useless Box with ESP8266 and Gesture Sensor modified

A useless box made smarter with an ESP8266 microcontroller on a Wemos D1 Mini board and an APDS-9960 proximity sensor to give more funny responses.

Expand Down
21 changes: 7 additions & 14 deletions config.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
const char* APP_VERSION = "0.0.1";
//const char* APP_VERSION = "0.0.1";

#ifndef LED_BUILTIN
#define LED_BUILTIN D4
#define LED_BUILTIN 2
#endif

const int PIN_LID_SERVO = D8; // The GPIO number of the pin where the lid opener servo is connected.
const int PIN_SWITCH_SERVO = D0; // The GPIO number of the pin where the switch manipulator servo is connected.
const int PIN_SWITCH = D5; // The GPIO number of the pin where the switch is connected.
const int PIN_SENSOR_SDA = D2; // The GPIO number of the pin where the SDA pin of the APDS-9660 sensor is connected.
const int PIN_SENSOR_SCL = D1; // The GPIO number of the pin where the SCL pin of the APDS-9660 sensor is connected.
const uint8_t SENSOR_TRIGGER_THRESHOLD = 100; // The proximity value level that triggers a lid opening. (lower=brighter, higher=darker)

const int LID_START_POSITION = 90;
const int LID_END_POSITION = 40;
const int SWITCH_START_POSITION = 0;
const int SWITCH_END_POSITION = 145;
const int SWITCH_HALF_POSITION = 90;
const int PIN_LID_SERVO = 12; // The GPIO number of the pin where the lid opener servo is connected.
const int PIN_SWITCH_SERVO = 5; // The GPIO number of the pin where the switch manipulator servo is connected.
const int PIN_SWITCH = 4; // The GPIO number of the pin where the switch is connected.
const int PIN_SENSOR_SDA = 13; // The GPIO number of the pin where the SDA pin of the APDS-9660 sensor is connected.
const int PIN_SENSOR_SCL = 14; // The GPIO number of the pin where the SCL pin of the APDS-9660 sensor is connected.
Binary file added data/00.mp3
Binary file not shown.
Binary file added data/01.mp3
Binary file not shown.
Binary file added data/02.mp3
Binary file not shown.
Binary file added data/03.mp3
Binary file not shown.
Binary file added data/04.mp3
Binary file not shown.
Binary file added data/05.mp3
Binary file not shown.
Binary file added data/06.mp3
Binary file not shown.
Binary file added data/07.mp3
Binary file not shown.
Binary file added data/08.mp3
Binary file not shown.
Binary file added data/09.mp3
Binary file not shown.
Binary file added data/10.mp3
Binary file not shown.
Binary file added data/11.mp3
Binary file not shown.
Binary file added data/12.mp3
Binary file not shown.
16 changes: 16 additions & 0 deletions data/audio.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
00 a-round-of-applause-for-trying-again1574765538
01 back-and-forth-back-and-forth-never1574765904
02 cant-quite-make-it-lets-try-again1574765609
03 cant-you-read-the-instructions1574765146
04 i-am-getting-bored-with-this1574765806
05 i-said-i-was-useless1574764811
06 i-told-you-not-to1574764680
07 my-arm-is-getting-tired1574765448
08 slow-slow-quick-quick-slow1574765781
09 you-are-wasting-your-time-here1574765348
10 you-did-it-again
11 This is fun. Not.
12 Here we go again.


sensor Naughty. Naughty.
Binary file added data/edit.htm.gz
Binary file not shown.
Binary file added data/favicon.ico
Binary file not shown.
Binary file added data/graphs.js.gz
Binary file not shown.
30 changes: 30 additions & 0 deletions data/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<meta name = "viewport" content = "width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
<title>ESP8266 Useless test</title>
<style>
"body { background-color: #808080; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; font-size: xx-large}"
</style>
</head>
<body>
<h1>Useless</h1>
<form action="/switch" method="get">
<P>
<input type="text" name="pos" value="0">Switch Position<BR>
<input type="submit" value="Set switch">
</P>
</form>
<form action="/lid" method="get">
<P>
<input type="text" name="pos" value="90">Lid Position<BR>
<input type="submit" value="Set lid">
</P>
</form>
<form action="/audio" method="get">
<P>
<input type="text" name="audio" value="0">Audio File<BR>
<input type="submit" value="Play Audio">
</P>
</form>
</html>
Binary file added data/sensor1.mp3
Binary file not shown.
Binary file added data/sensor2.mp3
Binary file not shown.
38 changes: 38 additions & 0 deletions data/uselessConfig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Config file for weather / train access
# lines are
#host;switchStart;switchHalf;switchEnd;switchFast;switchSlow;lidStart;lidEnd;lidSlow;lidFast
#sensorTriggerThreshold (0= no sensor)
#mode (0=sequence, 1=random)
#audioGain (0-39)
#modeLines made up following actions
#SS switch start slow;SF witch start fast;HS switch half slow;HF switch half fast;ES switch end slow;EF switch end fast
#CS lid close slow;CF lid close fast;OS lid open slow;OF lid open fast
#XSSPPP switch move to PPP with speed factor SS
#YSSPPP lid move to PPP with speed factor SS
#M0 proximity monitor off;M1 proximity monitor on
#P0 mode to sequential;P1 mode to random
#Afilename play audio from filename
esp8266-useless
0
90
118
5
15
90
50
5
15
190
0
25
OS,A05,ES,SS,CS
OS,A06,ES,SS,CS,M0
D5000,OF,A10,EF,SF,CF
OF,A03,EF,SF,CF
OF,A09,EF,SF,CF,OF,CF,M1
OS,A04,D2000,CS,D2000,OF,EF,SF,CF,M0
OF,HS,A02,D3000,SS,D3000,EF,SF,CF
OS,A01,D4000,EF,SF,CF,M0
OF,A00,CF,OF,CF,OF,CF,OF,CF,OF,EF,SF,CF,M2
OF,HS,A07,D3000,EF,SF,CS,M0
OS,A08,HS,EF,SF,CS,P1
Binary file added media/Useless-Box1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/Useless-Box1Preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 17 additions & 34 deletions speed-servo.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
#include "speed-servo.h"

const int SLOW_MOVE_DELAY = 15;
const int Fast_MOVE_DELAY = 2;

void SpeedServo::attach(uint8_t pin) {
_servo.attach(pin);
}

// Valid position: 0-180.
void SpeedServo::moveNowTo(int newPosition) {
_lastPosition = newPosition;
_servo.write(newPosition);
_servo.attach(pin);
}

// Valid position: 0-180.
void SpeedServo::moveFastTo(int newPosition) {
_moveTo(newPosition, Fast_MOVE_DELAY);
}

// Valid position: 0-180.
void SpeedServo::moveSlowTo(int newPosition) {
_moveTo(newPosition, SLOW_MOVE_DELAY);
}

// Valid position: 0-180.
void SpeedServo::_moveTo(int newPosition, unsigned long stepDelay) {
if(newPosition > _lastPosition) {
for (int pos = _lastPosition; pos <= newPosition; pos++) {
_servo.write(pos);
delay(stepDelay);
}
} else {
for (int pos = _lastPosition; pos >= newPosition; pos--) {
_servo.write(pos);
delay(stepDelay);
}
}

_lastPosition = newPosition;
void SpeedServo::moveTo(int newPosition, unsigned long stepDelay) {
if(stepDelay == 0) {
_lastPosition = newPosition;
_servo.write(newPosition);
} else if(newPosition > _lastPosition) {
for (int pos = _lastPosition; pos <= newPosition; pos++) {
_servo.write(pos);
delay(stepDelay);
}
} else {
for (int pos = _lastPosition; pos >= newPosition; pos--) {
_servo.write(pos);
delay(stepDelay);
}
}
_lastPosition = newPosition;
}
5 changes: 1 addition & 4 deletions speed-servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
class SpeedServo {
public:
void attach(uint8_t pin);
void moveNowTo(int position);
void moveFastTo(int position);
void moveSlowTo(int position);
void moveTo(int newPosition, unsigned long stepDelay);

private:
Servo _servo;
int _lastPosition;
void _moveTo(int newPosition, unsigned long stepDelay);
};

#endif /* speed_servo_h */
Loading