Category: Wemos mini

Basic Node for the Internet of Sex Toys – part 3: software

This the third part of the tutorial which has the following parts:

part 1: Basic Node for the Internet of Sex Toys

part 2: Molding the Basic Node

part 3: Software for the Basic Node

For the basic node a simple software realizes all features like Mqtt communication, Web server, basic web user interface, reading data from the accelerometer. Please use the code at github and send request over github. Now the imported parts of the code are explained.

To communicate with the IOT Mqtt is used (read more here). This is a fast protocol for data transmission. Therefore we need a Mqtt server. You can install one on your local computer or use a cloud-based Mqtt server. We use the free CloudMqtt. The following variables must be initiated with the data  of your server. Please get your own account at CloudMqtt or use my server (but don’t spam it, please). Please remember: Transmission is not encrypted, everybody can read it.

const char* mqtt_server = "m12.cloudmqtt.com";
uint16_t mqtt_port = 15376;
const char* mqtt_user = "nvcuumkf";
const char* mqtt_password = "C-X6glwisHOP";

We have now  7 different modes. In each mode the basic node behaves different.

const int offMode = 0;
const int maxMode = 1;
const int sinusMode = 2;
const int motionMode = 3;
const int constantMode = 4;
const int listenMode = 5;
const int listenAndMotionMode = 6;

In off mode the basic node is off, in max mode the vibration is maximum. In sinus mode the vibration speed is altered according to a sinus curve.

Web user interface of the basic node

In motion mode the vibration changes according to the movement of the basic node. When moved fast the speed goes up, when moved slowly or movement stops, the speed goes down. In constant mode any vibration speed can be set to any strength. This feature is only available by Mqtt messages eg. from the IOT node-RED user interface. The listen mode is still experimental. In this mode the speed will be changed by OTHER basic nodes. Finally in the listenAndMotionMode the speed is changed by movements of the basic node and by other nodes. This feature was already available with the body interaction 1 development board as standard mode!

The basic node starts a web server (see image). A web page is generated which build up the user interface. There are buttons for every mode. In addition the speed and the battery power is displayed. This is done in this function:

void generateWebpage() {

The next lengthy procedure is this:

void mqttCallback(char* topic, byte* payload, unsigned int length) {

This is a call back function which is executed whenever a Mqtt message comes in. It parses the Mqtt message which is in the popular JSON format. The commands which are communicated within JSON are explained here. In principle there is a command for every mode, when the command “set mode to off” is send the mode is set to offMode.

In the setup() part of the code you will find a lot of lines like that:

httpServer.on("/MOTOR=MAX", []() {

They corresponds to the generateWebpage() function. When say the max button on the web page is pressed than the affiliated httpServer function is executed. So for every button on the webpage you need a corresponding httpServer function to implement the functionality. In this case (MOTOR=MAX) the mode is set to the constant speed maxMode.

Finally in the loop section of the code the following functions are implemented:

  • reading the accelerometer data
  • change the vibration motor speed according to the mode
  • generate a new JSON message which is send out via Mqtt
  • do the timing

Not mentioned is the OTA (over the air update) function, which is integrated in the code.

Node-RED

For controlling the toy via the internet you can use node-Red. You can find the code at github via this link.

The flow is explained here and here.

 

Basic Node for the Internet of Sex Toys – part 2: 3d printed form, assembly, molding

In this series of posts we describe how-to make a vibrating sex toy which is part of the Internet of Things.

part 1: Basic Node for the Internet of Sex Toys

part 2: Molding the Basic Node

part 3: Software for the Basic Node

In part 2 we describe how-to make a mold form for the basic node. We need three forms:

  • the mold form which consists of two parts
  • the inlay which protects the electronics of the basic node
  • a “hanging” for the inlay

 

 

 

We used Tinkercad to construct the parts. The molding form is based on Tinkercad’s banana form. You can edit and share them from your browser:

Inlay: https://tinkercad.com/things/h5fFOBqlmjw

Hanging: https://tinkercad.com/things/jUxc2oAamww

Form: https://tinkercad.com/things/6HS3XScOsCM

Instructions

Print out all forms. The STL files are available at Thingiverse. You might want to use XTC or similar for smoothing the inner part of the mold form.

Assembling the Inlay

We use the inlay to protect the electronics.

Simply put the electronics inside so that the upper body of the switch is on the same level as the upper inlay. We use hot glue to fix the basic node.

Then fix the receiver coil of the wireless charging module on top of the inlay. The next step is to fix the hanging at the inlay.

Now fix the LiPo battery on the bottom side of the inlay using hot glue or similar. Fix the wires. Finally you might fix the wires of the vibration motor next to the middle of the LiPo battery.

Use tinkering wire to fix both parts of the molding form.

Put the inlay in the form. Fix the hanging with a tape or similar. The motors shouldn’t touch the inner part of the form.

Now prepare the silicone. We use Shore A 45 silicone (approx. 250 ml) from Silikonfabrik.de. It is hard but still a bit flexible. You may add color, too. You have about 10 minutes to stir the silicone and poor it in the form.

After some hours you can remove the form. As you can see there is overhang which make removing the form very hard. The form could break when removing. Better preparation of the form (eg rasping) could improve the results.

If the blue LED of the Wemos board is still active you were successful.

Now you need a charging station. The construction is shown here. It is also possible to connect the sender (or transmitter) module with a 5V power source (eg. from the USB port). Just put the bottom of the molded basic node on the sender coil.

 

In the next part we introduce an updated version of the software including over the air update and WiFi management.

Basic Node for the Internet of Sex Toys (part 1)

Wemos mini modules: ESP8266, motor driver and battery charging (in the middle); Wireless charging module (right side); wireless charging coil (top side); encapsulated vibration motors (left side)

In previous posts we showed how to build a vibrating sex toy in principle as part of the Internet of Things (IOT). In addition we have selected a hardware platform – the popular ESP8266 – for controlling a vibrator motor, gathering motion data and connecting to the internet. Now we want to build the toy itself.

part 1: Basic Node for the Internet of Sex Toys

part 2: Molding the Basic Node

part 3: Software for the Basic Node

Brief Review of development boards

There are a lot of development boards which are equipped with the ESP8266. The popular NodeMCU was already introduced here. Here is a quick overview and comparison:

NodeMCU

  • plus: very popular, cheap, USB connector for programming
  • minus: quite large (for being part of a sex toy), no support for battery charging

Adafruit Feather Huzaah ESP

  • plus: USB connector for programming and battery charging, smart form factor (only 23 mm wide), very good support (libraries, tutorials)
  • minus: quite expensive

WeMos D1 mini (pro)

  • plus: very cheap, USB connector for programming, additional stackable modules (eg. battery charging, TFT screens, motor driver), good form factor
  • minus: no real support (but there is a forum, problems with modules reported

ESP8285 (variant of the ESP8266)

  • plus: really small (!!!) and smart form factor, USB programming and battery charging, optional sensors on board (but no motion sensors)
  • minus: quite expensive, only 1MB memory (nevertheless enough for a lot of application)

For our project we selected the WeMos mini cause we get almost everything we need:

  • USB connector for programming
  • module for battery charging
  • module for a motor driver
  • good form factor (eg. to be put in a vibrator handle or in the base of a dildo)
  • cheap, fast delivery

But there is no shield for motion detection (accelerometer,gyroscope). So we have to use an additional board eg equipped with the MPU9250.

But there is a problem with the WeMos motor shield: After a few seconds it stopped working. And in addition the MPU9250 stopped working, too. Hours and hours we tried different configurations, changed the libraries … The problem was the motor driver shield itself. Fortunately there is an easy work around. Read here.

Another issue is the battery shield. It has an extra USB connector for charging the battery. So you have two USB connectors (one for battery charging and one for uploading). Two USB connectors are not handy. Fortunately we can do without the USB connector for uploading as it is possible to update the software over the air (OTA) using WiFi.

Material

As the body interaction philosophy uses motion for controlling the device we have to add the MPU. Again we use the MPU9250 which has an accelerometer, gyroscope and magnetometer.

Another insight was that you need at least a switch for rebooting. As we want to mold everything the switch must meet the IP67 requirements, which means it is water- (and silicone) proof. If you don’t want to mold the electronics you can use the RESET button on the WeMos mini board.

A perfect basic node has a wireless charging option, too.

Material list for the basic node:

  • Wemos mini board
  • Wemos motor driver shield
  • Wemos battery shield
  • Wemos prototyping board
  • Wemos set of pins
  • LiPo battery (eg. 3,7V 650mAh, 2C, JST plug, available at ebay)
  • MPU 9250 board (for motion control)
  • 1 or 2 encapsulated vibration motors, 3V, available at Alibabaexpress
  • Optional: Switch IP 67 protected (eg. Cherry Switches DC1C-K8AA IP67) – for molding
  • Optional: Wireless charging receiver 5V eg from Seeed Studio

Material: battery shield, Wemos mini ESP8266, motor shield, MCU9250 (first row), LiPo battery, switch, vibration motor (second row)

 

Soldering the basic node

We use one connector (part of the Wemos set of pins) to connect the Wemos mini with the battery shield and the motor shield. This is done to save space. If your application has enough space you would use one connector for every shield.

Battery shield, Wemos mini ESP 8266, motor shield (from top to bottom)

Now have a look at the bottom side where the motor shield should be. We can connect up to 2 motors. Solder motor 1 to A1 and A2. Motor 2 has to be soldered to B1 and B2. In addition we need input power for the motor. We just use the 5V provided by the Wemos mini battery shield. Connect 5V to VM and GND (from the pins) and GND. But you could use other (more powerful) power sources, too.

Wemos offers a prototyping board. We use it for mounting the switch and for the MPU9250. Connect the MPU9250 to the bottom side of the prototyping board. Therefore 4 pins have to be soldered

Solder pin (1 row, 4 pins)  on the top side next to TX, RX, D1, D2

 

Now look at the bottom side of the prototyping board. Put the MPU 9250 so that VCC, GND, SDA, SCL are connected to the pins.

Next, solder the MPU 9250.

Then add more pins to the prototyping board at both sides. The picture shows the bottom side of the prototyping board.

Now wire the prototyping board. The picture shows the top side.

Now you can add the switch. Place it in the middle of the board on the top side. Connect GND and RST to the switch. Now you have a switch for rebooting which can be molded.

Now we have both parts ready and can stack them together.

Stack them together!

Now add the LiPo battery, which should have a JST header. Now your basic node is ready.

Wireless charging option

Especially for sex toys a wireless charging option is reasonable as this is a requirement for silicone molding of the toy.  And when the toy is molded it is safe and washable.

The wireless charging module consists of a sender (or transmitter module) and a receiver module. You have to solder the receiver module to the battery shield. Don’t mix the modules.

unfortunately there is only  a USB connector. If you don’t want to remove the USB connector you can solder the red (+) wire to the R330 resistor as shown on the pictures. The black (-) wire can be soldered to any pin labeled (GND).

Now put the receiver module on top of the battery module.

Now stack the protoytping board on top of the battery shield.  And connect the battery.To charge the battery connect the sender (or transmitter) module to 5V. To power the sender module you may use a USB port power source which has about 500mAh or more. Place sender and receiver coil about each other.  For a more professional charging solution you need a charging station. The making of a charging station using 3d printing is described here.

Learn how to construct the mold form in part 2:

part 2: Molding the basic node

part 3: Software for the basic node