Touchy-Feely Tech is a candidate for Female Founder Competition

The UK-based Startup magazine is looking for the best female startup company. Touchy-Feely is on the short list and you can vote for them. Touchy-Feely develops educational electronic sex toy kits accompanied by workshops on basic and advanced sex toy topics. The founders have committed to building the funniest, most educational and pleasurable DIY electronics and coding kit out there.…

Controlling two BI2 with Blynk

Controlling more than one body interaction 2 boards is very easy.

At first go to project settings in the Blynk app, go to devices and add a new device.

Then create a new device and press Email. You will get an Email with the auth token.

Add slider widget for the motor and another ZEGBRA widget for controlling the LED. For LED select a new virtual pin, e.g. V10.

You can start with this ready made app:

It should look like this:

 

Then reuse  the code from this blog post.

Change the following:

  • fill-in the auth token which you got per Email
  • change the name of the virtual pin V0 (for the LED) to e.g. V10 (the same name as in the Blynk app)

 

That’s it!

 

New body interaction 2 (BI2) boards available

The BI2 vibrator development boards are available at Tindie.  You have now 3 three options:

  • PCB only 29$
  • kit 39$: PCB + 2 motors + LiPo battery + 2 motors + 2 JST-SH connectors (BUT connectors not soldered /connected to the motors)
  • complete kit 49$: the same as the kit but connectors soldered to the motors

If you now how to solder / connect wires: Please select the kit as I am not good doing soldering.

Sending motion data to the Blynk app (part 2 of the Blynk tutorial)

In the first blog post we explained the basics of controlling the body interaction 2 (BI2) vibrator development board using the concept of  (virtual) pins. This time we want to send data from the BI2 board to the Blynk app. The BI2 has the MPU-9250 9DoF (9 Degrees of Freedom) IMU (Inertial Measurement Unit) sensor on board. This sensor is a combination of an accelerometer, gyroscope and magnetometer. Especially the accelerometer is important for motion detection. This could be used for controlling the vibrator as show with the body interaction 1 (BI1).

For measuring the motion data we use the asukiaa library. Please search and install the library in the Arduino library manager.

In the program code the library must be included and a MPU9250 sensor object must be defined. Finally we need several variables of the type float.

#include <MPU9250_asukiaaa.h>
MPU9250 mySensor;
float aX, aY, aZ, mDirection, pitch, roll, yaw;

In the setup part of the program we need to tell the MPU9250 how it is connected to the ESP8266 microcontroller. [The MPU9250 IMU is connected by the I2C bus to the ESP8266 microcontroller: the sda pin of the IMU is connected to pin 4, the scl pin to pin 5. The connection between MPU9250 and ESP8266 is managed with the standard Wire library.]

For using the accelerometer and magnetometer we have to initialize the sensor with a begiAccel() call to the IMU library.

Wire.begin(4, 5); //sda, scl
mySensor.setWire(&Wire);
mySensor.beginAccel();
mySensor.beginMag();

We have to tell the program how often data is sent to the app. Therefore we need an important concept in microcontroller programming:

Timer

With the help of the timer we can tell the microcontroller to do a given tasks again and again e.g. after 1000 microsecond. You cannot use the delay function to pass time as this would interrupt the important call to the Blynk.run(); function which is located in the loop part of the program.

First we have to define an object of type Timer.

BlynkTimer timer;

In the setup part we have to say how often what the timer has to do. in this example the timer will call the function myTimerEvent every 1000 microsecond.

timer.setInterval(1000L, myTimerEvent);

In the loop part of the program we have to call the timer to keep things going:

timer.run(); // Initiates BlynkTimer

Now we need the function myTimerEvent what has to be done every 1000 seconds.

void myTimerEvent()
{
  // here add was has to be done
}

First we have to update the sensors (accelUpdate, magUpdate). Then we read out the acceleration data in the X, Y and direction. You can already use this data but they are hard to catch. Therefore we can calculate the pitch, roll and yaw. These are angles from -180° to +180°. The calculation is complicated and I don’t understand it. But with the given formulas you get a very rough approximation which makes the data quite accessible.

void myTimerEvent() {
  mySensor.accelUpdate();
  aX = mySensor.accelX();
  aY = mySensor.accelY();
  aZ = mySensor.accelZ();

  // calculate pitch, roll, yaw (raw approximation)
  float pitch = 180 * atan (aX/sqrt(aY*aY + aZ*aZ))/M_PI;
  float roll = 180 * atan (aY/sqrt(aX*aX + aZ*aZ))/M_PI;
  float yaw = 180 * atan (aZ/sqrt(aX*aX + aZ*aZ))/M_PI;

  // read gyroscope update
  mySensor.magUpdate();
  mDirection = mySensor.magHorizDirection();
}

Finally we send the data back to the Blynk app. Now we use the virtual pins. For the variables pitch we  use virtual pin 2 (V2), for roll V3, for yaw V4 and for mDirection V5. We have to add the following line to the myTimerEvent function.

void myTimerEvent() {
  // send data to app via virtual ports, e.g. virtual pin V2 is set to pitch
  Blynk.virtualWrite(V2, pitch);
  Blynk.virtualWrite(V3, roll);
  Blynk.virtualWrite(V4, yaw);
  Blynk.virtualWrite(V5, mDirection);
}

Now the data are continously sent to the Blynk app. To visualize the data we add the widget SuperChart.

For each variable we have to define the input (virtual) pin. For pitch we use the virtual pin V2. In addition we define the color and style of the graph and more.

 

Finally the super graph shows us the date from the accelerometer which are updated every second.

First part of the tutorial (setup Arduino, setup Blynk, LED and motor control) is here

Here is the complete code:

 

/*************************************************************
bodyinteraction.org
sample program for reading MPU data, setting LED color and motor speed
*/
#define BLYNK_PRINT Serial
// include this library in the Arduino library manager
#include "FastLED.h"

// How many leds in your strip?
#define NUM_LEDS 1
// LED data pin is connected to pin?
#define DATA_PIN 14

// Define the array of leds
CRGB leds[NUM_LEDS];
int wave;

// include this library in the Arduino library manager
#include <MPU9250_asukiaaa.h>
MPU9250 mySensor;
float aX, aY, aZ, mDirection, pitch, roll, yaw;

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your Auth Token XXXXXXXXXX";

// Your WiFi credentials.
char ssid[] = "YOUR SSID   XXXXXXXXXXXXXX";
char pass[] = "YOUR Password XXXXXXXXXXXX";
BlynkTimer timer;

void myTimerEvent()
{
  // read acceleration data
  mySensor.accelUpdate();
  aX = mySensor.accelX();
  aY = mySensor.accelY();
  aZ = mySensor.accelZ();
  // read gyroscope update
  mySensor.magUpdate();
  mDirection = mySensor.magHorizDirection();
  // calculate pitch, roll, yaw (raw approximation)
  float pitch = 180 * atan (aX/sqrt(aY*aY + aZ*aZ))/M_PI;
  float roll = 180 * atan (aY/sqrt(aX*aX + aZ*aZ))/M_PI;
  float yaw = 180 * atan (aZ/sqrt(aX*aX + aZ*aZ))/M_PI;
  // send data to app via virtual ports, e.g. virtual pin V2 is set to pitch
  Blynk.virtualWrite(V2, pitch);
  Blynk.virtualWrite(V3, roll);
  Blynk.virtualWrite(V4, yaw);
  Blynk.virtualWrite(V5, mDirection);
}

BLYNK_WRITE(V0) // set RGB color values which are transmitted from the app as V0 (virtual pin 0)
{ 
  int i = param[0].asInt();
  int j = param[1].asInt();
  int k = param[2].asInt();
  leds[0].setRGB(j,i,k);
  FastLED.show();
}

void setup()
{
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);

  Wire.begin(4, 5); //sda, scl
  mySensor.setWire(&Wire);
  mySensor.beginAccel();
  mySensor.beginMag();

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

 

Please feel free to comment or write to jacardano@gmail.com

Programming the body interaction 2 (BI2) with Blynk part 1

This in an intro to using and programming the BI2 with the Blnyk app. Read here how to set up Arduino. For a more general basic intro (based on the body interaction 1 board) read here.

Pins

The communication between app and BI2 microcontroller is realized by pins. The idea is very easy: Each widget in the Blynk app is connected to a physical pin of the microcontroller. Every microcontroller has several pins where you can connect other electronic parts like a LED or a vibration motor. For each pin you have to configure if it is a output or input pin. Output pins are for controlling actuators, like LED, motor or display. Input pins are connected to sensors, like buttons, temperature sensors, acceleration sensor.  In addition each pin can be digital, analog or virtual.

Digital output pins can only set the actuator to on or off e.g. turning the LED on or off. Analog pins can set the actuator to a specific value in a given range. Usual this in done in the range [0..255] or [0..1023]. For a motor 0 will set the motor off, 50 may be make the motor move very slowly and 255 will be full speed. An analog output pin is sometimes called PWM. (PWM is a method to simulate an analog signal with a sequence of digital on/off signals.)

Digital input pins can read the position of a button (on/off). Analog input pins can read a value in a given range, e.g. the acceleration in the X-axis or the temperature.

So what you have to do to connect a widget to a pin? Just set the widget (e.g. on/off switch widget) to the pin you want to set on/off (e.g. a pin which is connected to a LED). That’s all. No programming required. All you need is this small program which must be uploaded to the microcontroller with the Arduino IDE.

The body interaction 2 use the ESP8266 microcontroller. There are 16 pins, all could be used as digital or analog, input or output. But only pin 12 and 13 are free to use (the rest if for internal communication). Pin 14 is connected to the LED WS2821B.

The Arduino sketch

The first 3 lines are for configuring Blynk and using two libraries. The 3 variables auth, ssid and pass are defined. (The variables are from thy type char (=character) and in this case it is not only one character but an array which you can see by the “[” and “]”. Here you have to add your AUTH token from the Blynk app, and SSID and password from your local WLAN/WIFI.

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h> 
#include <BlynkSimpleEsp8266.h> 

char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
char ssid[] = "XXXXXXXX"; 
char pass[] = "XXXXXXXX";

Each Arduino program consists of a setup and a loop procedure. The setup is called only one time when the microcontroller is started (or connected to a battery). It is used to initialize the microcontroller, in this case Blynk is started. The loop will be called indefinitely and all statements are executed in the given order. To get Blynk running you have to call Blynk again and again (“Blynk.run();”). According to the Blynk manual, you should not add a delay() function here, because this could disturb the communication between the app and the microcontroller.

void setup() { 
  Blynk.begin(auth, ssid, pass); 
} 

void loop() { 
  Blynk.run(); 
}

Virtual pins

So far communication is only possible with physical pins. But how can you exchange other information? Maybe you want to tell the microcontroller to “shut up immediately”,  or you want to play a given vibration pattern like a sinus curve. For this you can use “virtual pins”. (IMHO there is no reason to call this mean of data exchange “virtual” and it is has nothing to do with a pin. You can call it a variable or channel for data exchange.) The zeRGBa widget is a good example. The color of the LED is controlled by 3 values, the amount of red, green and blue color. This 3 values can be connected to one virtual pin (“V0”) and then they will be transmitted to the microcontroller. To change the color of the LED you have to program the microcontroller  to read out the amount of each color and set the LED to the appropriate value.

We will demonstrate virtual pins with the LED. The WS2821B LED is connected to pin 14, but you cannot control the LED directly by setting the pin to a given value. This is done by a library which controls the LED.

First we have to include the library, we use FastLED.

#include "FastLED.h"

Then  we have to tell how many LEDs we have (you can put several of them in a chain). The BI2 has only one on board (but you can add more).

#define NUM_LEDS 1 // number of LEDs

The you have to tell to which physical pin the LED is connected (14). Finally you have to set up a (instance of an) object “CRGB” for the LED where all relevant data is hidden.

#define DATA_PIN 14 // pin for LED 
CRGB leds[NUM_LEDS]; // define the array of leds

Now comes the more difficult part. The zeRGBa widget has 3 values (one for red, one for green, one for blue) and all are put in the virtual variable V0.

We have add a new function called “BLYNK_WRITE(V0)”. To get the first value we have to read out “param[0]”, for the second “param[1]” etc. We want to store this first value in a variable “i” of the type integer. To assure that param[0] is also from the type integer we add “.asInt()”. The value for red is put in variable i, green in j and blue in k.

BLYNK_WRITE(V0) {
  int i = param[0].asInt();
  int j = param[1].asInt(); 
  int k = param[2].asInt();
}

Now we have to tell the function BLYNK_WRITE what to do with the values i, j an k. This is done by using the method setRGB which is attached to the LED (which is number 0)

leds[0].setRGB(j,i,k);

Now we can make changes to other LEDs (if we have more than one). If you are ready you have to tell the LED to show the new color.

FastLED.show();

In addition a new statement has to be added to setup the LED within the setup part.

void setup() { 
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  [...]

Now we can put everything together the script will look like this:

/*************************************************************
Controling the body interaction 2 board with the Blynk app
*/

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Auth Token infor the Blynk App.
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Your WiFi credentials.
char ssid[] = "XXXXXXXX";
char pass[] = "XXXXXXXX";

// Library for controlling the WS2821B (Neopixel) LED or LED strip
#include "FastLED.h"
#define NUM_LEDS 1 // number of LEDs
#define DATA_PIN 14 // pin for LED
CRGB leds[NUM_LEDS]; // define the array of leds

// This function set the LED color according to the selected RGB values in the app.
// RGB values are controlled in the app with zeRGBa widget
// values are stored in the virtual pin V0
// V0 consists of 3 values for Red, Green, Blue
BLYNK_WRITE(V0) // set LED RGB color values
{
  int i = param[0].asInt();
  int j = param[1].asInt();
  int k = param[2].asInt();
  leds[0].setRGB(j,i,k);
  FastLED.show();
}

void setup()
{
  // init LEDs
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);

  // connect to Blynk
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
}

Do you like this, do you need this, do you understand this? Tell me jacardano@gmail.com

The new BI2 black vibrator development board

The new black BI2 board is ready. I have a few assembled boards ready for shipping. Have a look at www.tindie.com

3 JST 1mm plugs (battery, motor 2, motor 3), LED, reset button, M+/M- is for motor 1

JST 1mm plug for motor 1, alternative RESET button

Features

  • ESP8266 Microcontroller with WLAN
  • MPU9250 (accelerometer, gyroscope)
  • LiPo battery charging
  • 3 motors can be connected (simple motor driver circuits)
  • 1 WS2812B LED – a  colourful LED (16 Mill. colours). They are commonly known as Adafruit Neopixel – a strip or a ring of individual programmable LEDs (when use the WS2812B only two motors can be connected)
  • design based on the great Adafruit Feather Huzaah ESP8266
  • vibration motors and LiPo battery can be easily connected with JST 1mm connectors
  • two reset buttons (the button next to the USB connector can be overmolded)
  • USB connector for battery charging and code uploading
  • programmable with the Arduino IDE or NodeMCU
  • white LED for indicating charging
  • standard LED (yellow) on GPIO00
  • round 40mm diameter

 

There are 3 free GPIO ports. Standard layout are for driving 2 motors (GPIO 12 = M2, GPIO 13 = M3) and 1 LED (GPIO14). Alternatively you can use 3 motors (GPIO12,13,14) but no LED.

Standard: SJ2 not connected, SJ3 connected

Alternative: SJ2 connected, SJ3 not connected

 

Here is the schematic which is adapted from Adafruit.

References:

  • Quick start up guide with Blynk app is here
  •  Assembling a silicone molded vibrator with 3D printed form – tutorial here
  • Complete guide including wireless charging, control with Node-RED and data transmission via MQTT is here

Blynk: Controlling BI2 from the smartphone

Readers ask me for an easy way to control the body interaction vibrator development board. Without or with limited  programming knowledge, without complicated Internet of thing technology, like the visual programming tool NODERED or the MQTT protocol and server.

That’s what Blynk is for. Started in 2016 as a kickstarter  campaign, they have built a tool which hides a lot of the complexity of the Internet of Things. Blynk consists of the following parts:

Blynk app. With this app you can build a User Interface in just a few minutes. You have all the usual elements like switches, slider,  graphs and much more for controlling IOT devices.

Blynk Server / Cloud is responsible for the communications between the smart phone and IOT devices. There is nothing to do, everything works in the background

IOT devices library: So far everything is very simple. But at the end you have to program your IOT device – the body interaction 2 board for example. They support a great number of boards. For this they created the blynk  library – with the library you need only some lines of code which must be uploaded to the board. Even when you change the user interface the code can stay the same. At least for simple changes. They offer a code generator where you code for your board and use case is generated automatically.

You find a lot of information in the Internet about the pros and cons. In short: It is easy compared to other tools, but if you want to implement your own algorithms programming knowledge is needed. Blynk limits the number of free User Interface elements. If you need more you have to pay  a small fee.

 

Here is short tutorial to run you BI2 with Blynk. (takes 30 minutes)

Download the Blynk app (Android or iPhone).

Within the Blynk app: Register for Blynk and get AUTHenitfication code.

Upload Arduino

You can download Arduino from the Arduino Website or from the Microsoft Store (Windows only)

 

Add or update the following libraries with the library manager: FastLED and Blynk.

Select Include libraries -> library manager

Search for FastLED and install this library (press install button).

Now search for “Blynk” and install the Blynk software. However Blynk suggests to install the Blynk app manually.

 

Add board definition for the ESP8266

Select Tools -> Board -> Board management

Search for ESP and install “esp8266”

Select Board -> Adafruit Feather

Build a connection between BI2 and your computer.

First download the USB driver from here and install the driver. Connect the BI2 with your computer. After some while windows will notice a new device. Windows will communicate with the board over a COM port (e.g. COM3). If you have any problemes check your USB wire. It must support all lines, not only + and – for charging.

Now go back to Arduino and select Tools -> Port. Select the new COM portcom port arduino

Compile and upload the code to BI2 board

Now copy and paste the following code in a Arduino sketch (use File -> new). Then press the Upload button.

/*************************************************************
Controling the body interaction 2 board with the Blynk app
*/

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Auth Token infor the Blynk App.
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Your WiFi credentials.
char ssid[] = "XXXXXXXX";
char pass[] = "XXXXXXXX";

// Library for controlling the WS2821B (Neopixel) LED or LED strip
#include "FastLED.h"
#define NUM_LEDS 1 // number of LEDs
#define DATA_PIN 14 // pin for LED
CRGB leds[NUM_LEDS]; // define the array of leds

// This function set the LED color according to the selected RGB values in the app.
// RGB values are controlled in the app with zeRGBa widget
// values are stored in the virtual pin V0
// V0 consists of 3 values for Red, Green, Blue
BLYNK_WRITE(V0) // set LED RGB color values
{
  int i = param[0].asInt();
  int j = param[1].asInt();
  int k = param[2].asInt();
  leds[0].setRGB(j,i,k);
  FastLED.show();
}

void setup()
{
  // init LEDs
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);

  // connect to Blynk
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
}

You have to change AUTH. Use the AUTH code / token that was sent to you during Blynk registration. Then you have to change the WLAN credentials. Use the name of your network (SSID) and its password. (Depending on the maximum voltage of the vibration motor you have to adjust i, j and k e.g. for a 1.5V motor divide the variables by 3.

Configure the Blynk app

Create a new project and choose this device: ESP8266. Now add user interface elements – they are called widgets -to control the BI2. You can move and resize, add and delete each widget. Press on the widget to enter parameters like GPIO port etc. The app could look like that but you may position the widgets as you like. [The pitch, roll, yaw text fields can be omitted. They are introduced later.]

Add the following Widgets

Press the “+” button and add this widget:

zeRGBA: With this tool you can control the WS2821B LED

Choose select pin V0 = Virtual Pin 0.

Choose Merge.

Send on release: off

Add Sliders

Press the “+” button and add two sliders, one for each motor.

1st silder: Select Digital Pin 12 (PWM)

2nd slider:  Select Digital Pin 13 (PWM)

Add Button

Press the “+” button and add the button widget. Select pin digital – gp0. Set mode to “switch”.

Start the app

Therefore press the Run (or play) button (top left).

 

Done!

Questions? Reply to this post, via wordpress or to jacardano@gmail.co

 

BI2 – building a silicone sex toy

Now let’s build the first ESP8266 vibrator. I use the reliable design from this blog post and the new BI2 board. The new BI2 board can be controlled from any smart phone or computer.

As the BI2 board is round there is no need to build a case for the PCB and the LiPo. The easist way is to glue the battery directly on the ESP8266. Connect the battery and one or more vibration motors with the BI2 board.

 

The form consists of two parts which are fastened together with tinker wire. Before you have to insert the board with the vibration motor(s) and the battery. Therefore I used a handle. The handle could be put on top of the form. Then fix a USB connector to the handle. Plug in the BI2 board. Fasten the second half of the form.

Very important: The USB micro connector on the board must be protected from the silicone. When silicone flow between USB plug and connector it will be impossible to pull out the plug. I use wax to seal the USB micro connector. Read more here.

 

Now pour in the silicone, wait for some hours. And open softely the form.

 

Remove the overhanging silicone.

Here ist the Link to Tinkercad where you can edit the form and download STL files for your 3D printer: Download from Tinkercad: formhandle. Download ready to print zipped STL files.

Now build YOUR personal sex toy. Here you find the code for the ESP8266 as well as an IOT server application for quantifying your sex and remote control.