Making a DIY data cable for the Zoop Novo Diving Computer

Few months ago, I went diving and decided it’s time to get a my first diving computer.
A little research and I came into conclusion that the Suunto Zoop Novo is what I should buy.
It’s cheap (around $200 in Eilat, Israel), and have many positive reviews.

This diving computer has an option to sync it with your PC and watch the diving logs in Suunto DM5 app (or other open source apps), but unfortunately it sold without the data sync cable 🙁

If you wish to get an official cable from Suunto, you will have to pay around $84 on Amazon ! (with shipping it’s $100 to Israel )

A little googling and I found many DIY cables, but for the old generation of the Zoop Novo.

How hard can it be to make this diving computer to talk with my PC?
Well, not so hard if don’t care using other apps for syncing ,
and a little harder if you wish to use Suunto DM5 app.

Lets try to make it short

I will write in more details when I’ll have time (it took me 3 months to write this post :S)

The diving computer has a connector with 2 connection points and a ground.
After poking with it for a ‘few’ hours (I drained all my computer battery and had only 6 dives with it!!) I found that:

  • A voltage on the Enable pin makes the diving computer enter the Data Transfer mode.
  • The Data pin is a bi-directional line, using UART for communication.
  • All the metal around the pins is ‘ground’.

The Suunto DM5 application is looking for a communication port named ‘Suunto USB Serial Port’.
I used an Arduino Pro Micro, which has build in USB functions and can act as USB Serial COM device, and had to change the driver so it’s name will be ‘Suunto USB Serial Port’. It’s very easy but require to disable driving signing enforcement .

I can still sync the diving computer without doing this, but I have to use other apps like ‘Subsurface’.

Because there is only one data line, it was not possible to connect both RX and TX of the Arduino’s UART together as is.
I used the Arduino’s hardware UART to read the data from the diving computer, and used Software Serial to write to the diving computer. When not reading – I changed the TX line gpio to ‘Input Pullup’ so it’s won’t interfere with the reading operation.

A command that was sent from the Arduino, and a response from the diving computer (the lower voltage signal)

I used the 5V from the Arduino pins. I didn’t know it’s safe to use 5V here, so I used 330ohm resistors in series with for the ENABLE and the TX of the DATA. I found this value gives about 3.2V, but maybe using a higher value will work too and it will be even safer.

How it works:


DM5 app is sending data for the Diving Computer in a COM port called ‘Suunto Diving computer’, but it’s actually sending this data to the Arduino.
The Arduino receives is in it’s default serial that is connected to the usb, and forward it to the Diving Computer using SoftwareSerial on gpio 8.
When the DM5 app is not sending anymore data, the Arduino change gpio 8 to “Input Pullup”, and starts reading data from ‘Serial1’ (this is HW serial), and forward is on ‘Serial’ (which is connected thru USB to the computer)

Arduino Code

#include <SoftwareSerial.h>
#define SW_TX 8

SoftwareSerial mySerial(4, SW_TX); // RX, TX

void setup(){
  Serial.begin(115200);     // Between computer and Arduino
  Serial1.begin(115200);    // Between Arduino and Diving Computer
  mySerial.begin(115200);   // Between Arduino and Diving Computer
  
    while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  pinMode(SW_TX,INPUT_PULLUP);
}

void loop(){
  if(Serial.available() > 0) {
    pinMode(SW_TX,OUTPUT);  
    digitalWrite(SW_TX,HIGH); //UART lines should be HIGH on IDLE
  
      while(Serial.available()  > 0){
        mySerial.write(Serial.read());
      }
    pinMode(SW_TX,INPUT_PULLUP);
  }
  
  while(Serial1.available() > 0){
    Serial.write(Serial1.read());
  }
}

The Ugly Side

I didn’t find and novel way to connect this connector.
I took a clamp and drilled holes in it, then pushed ‘pogo pins’ in such a way they will touch the connection points.
I need to think and make something more simple.

awwww..

And.. that’s it.
I can now sync my diving computer with my PC.

You can find the modified .inf file and the code in my gitlab:
https://gitlab.com/itaysp/suunto-data-cable

And you can download the full driver from Sparkfun’s website (just use my .inf file)

DIY USB Media Dial

Recently few Media Dial project popped out to my Facebook feed.

It seems pretty cool project to built, but I couldn’t fabricate the files needed in their instructions.
Moreover, they used some expansive microcontrollers and the total build was way above $5.

I decided to challenge myself and build a cheap version which I could print in my 3D printer and the
total cost would be around $5.

The Components

These are the main components I used:

Name Quantity Price (USD)
Digispark Clone 1 1.5

WS2812 Ring (with 16 leds)

1 2.79

Rotary encoder

1 1.72

The microcontroller I choose is the ATtiny85. With few tweaks it fits perfectly with me needs.
I bought a Digispark clone board. It is very small and has a micro usb connector which connects to pins PB3 and PB4 of the ATtiny .
This board is able to emulate HID device with the Digispark libraries.

The LED ring is not a must, but it can add some nice effects when I turn the dial or press the button.
The WS2812 is an addressable led, so we only need 1 gpio from the ATtiny to control all the 16 leds.
Digispark provides a version of the Adafruit Nexopixel library to the Digispark boards.

The encoder is the obvious choice for detecting the direction of the wheel and also to counts steps.
It also has a button and I can add more features with a button click or double clicks.

Modifying the Digispark

To use the Digispark board from the areduino IDE, I needed to add it with it’s libraries to the Arduino board manager.
Here is a quick guide from their website:
https://digistump.com/wiki/digispark/tutorials/connecting

TL;DRBoard Manager URL:    http://digistump.com/package_digistump_index.json

I also need to make few tweaks to the board as I mentions earlier:

  •  Change the fuses so PB5 won’t reset the board (this is the default state). I need all the IO of the ATtiny85
  • Remove the LED from the board (it will interfere with the reset of the components)

To change the fuse, I used USBASP V2.0 I had laying around.
This is how I connected the IO to the USBASP:

PB0 – MOSI
PB1 – MISO
PB2 – SCK
PB5 – RESET
VCC to 5V, and of course the grounds.

Then I used ‘avrdude’ to check if everything is connected and responding, and the current
fuse settings with the command: (the path might be different in other systems)

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude.exe -C "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -c usbasp -p attiny85 -n

I got this respond:

avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.
avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude.exe: Device signature = 0x1e930b (probably t85)

avrdude.exe: safemode: Fuses OK (E:FE, H:DD, L:E1)

avrdude.exe done.  Thank you.

Everything is good.

I entered the fuse values in this calculator:  http://www.engbedded.com/fusecalc/
and checked the ‘RSTDISBL’ (external reset disabled) to get the new fuse values.

Only the HIGH fuse changed, so I only change it with this command: (hfuse – HIGH, w – WRITE, 0x5F – Fuse Value, m Program )

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude.exe -C "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -c usbasp -p attiny85  -U hfuse:w:0x5F:m

and this is the respond:

avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.
avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude.exe: Device signature = 0x1e930b (probably t85)
avrdude.exe: reading input file "0x5F"
avrdude.exe: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude.exe: 1 bytes of hfuse written
avrdude.exe: verifying hfuse memory against 0x5F:
avrdude.exe: load data hfuse data from input file 0x5F:
avrdude.exe: input file 0x5F contains 1 bytes
avrdude.exe: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude.exe: verifying ...
avrdude.exe: 1 bytes of hfuse verified

avrdude.exe: safemode: Fuses OK (E:FE, H:5F, L:E1)

avrdude.exe done.  Thank you.

Perfect.

Now for the LED, I just remove the resistor connected to PB1.
It’s the small resistor between the ATtiny85 and the voltage regulator.

Designing and Printing

The design I made (using Fusion 360) contains 3 main parts:

  • The bottom part where the Digispark sits
  • The center part where the Encoder and the led ring sits
  • The top part that will be turned to control the dial.
    • The top part is made from 3 pieces, because I wanted to have
      a transparent ring for viewing the leds.

I printed all the parts in a black PLA, and the top transparent ring in a clear PLA.
After few hours in my 3D printer (I used the CR-10 Mini), this is what came up:

Assembling

First I assembled the top part. I inserted the transparent ring to the top part body (and added few drops of glue),
and then did the same thing with the center part.

Then I solders 3 wires to the led ring where is says  V+, IN and G,
and I passed them through the holes in the middle parts.

I also solders wires to all the encoders legs and fixed it to the center part as well.

Now I solders the wires to the Digispark board as the following scheme:

I used the ATtiny internal pullups for the encoder A and B, and also for the button so no external pullups resistors are needed.

Now I connected the Digispark board to the bottom part with two 3mm M3 screws, and connected the middle part to the bottom part with two long M3 screw.

At the bottom part, I room for 8mm anti-slip stickers, but it’s not a must.

Code

I used the Digispark library for the HID emulation of keyboard (or mouse, I used only keyboard) and the Adafruit library for the Neopixels to control the leds.
I wrote one function that handles the encoder (check for changes), and one function that handles the button pressings.
Those functions are called constantly (polling, no interrupts here) and if there is a change – it calls one of the assigned operation functions.
There is function for button click, double click, scrolling the wheel ‘Down’ or ‘Up’.

This is a very fast draft I made, but it’s easy to continue of change it from here.

Every encoder change will turn the next led in the ring (or the previews, depend on the direction) with Blue color.
One click on the button will turn 4 leds to Green, and double click to Red.

The first use I came up for this Media Dial is for Lightroom.
Rotating the dial with increase of decrease the slider values.
One button click will cycle through the next panel slider, and double click will cycle through the previous.

You can see the final result here:

You can find the STL for the 3D files and the source code in my gitlab repository:

https://gitlab.com/itaysp/Media-Dial

(My) Light Paiting Proposal

The time has come and I decided to surprise my girlfriend with a weekend in Prague during which I will ask her to marry me.

I wanted it to be special in my way. I’m Electrical Engineer and consider as a “Maker” so it must be involved with some electronics and building something!

I had few ideas, some involved with creating a custom PCB with LEDs flashing “Will You Marry Me”, but it was too simple and BORING!

I also like photography very much, and long exposures.

Then remembered that tutorial on Adafruit about light painting.

And then it hit me!

I will ask her to take a long exposure photo of me, and then I will do all the painting.
She won’t be able to see or understand what I’m doing until the long exposure will end.
Then, she will see “Will You Marry Me?” on the camera screen!

So how it works?

The camera’s sensor capture everything it “sees” while the shutter is open.
If you open the shutter for a long period of time, and your hands are not stable – you will get a blurry image.

The same principle is here; The camera will be stable on a tripod, but the object will be moving.
I will open the shutter for a very long time (about 15 seconds) and will start moving a light source.
The result will be that light source “smeared” on the photo.

Now imagine that the light source is a bar like in the picture, and I can change the colors very fast (about 60 changes per second)!
When I will move my hand while the shutter is opened, the camera’s sensor will “see” and capture all the changes of the light bar.
If I will sync my movement to the lights changing in the bar – I will be able to “paint” texts or even images.

 

The hardware

It’s easiest to control such amount of leds (about 70) if they are addressable leds, so I used here 0.5m a of a WS2812B strip (I bought 1 meter of 144 pixels/meter).

In addition I will need a place to store our images. SD Card is very convenient for loading new photos so we will need a SD card adapter / module.

If I want to make it portable then we need a battery. Since I want to make it very portable, and 70 leds will consume a lot of current, I choose to use lipo batteries.

One 18650 battery will give me about 3.7v-4.2v, which is not enough to operate WS2812B which needs 5V, so two of them in series will give me about 7.4v-8.4v.
Now I need to regulate the voltage to 5V, so an adjustable 5A switching step down regulator will do the job here.

I will need a button to start the painting, a switch turn the device on and off, and a knob to change the speed or light intensity (I didn’t use that feature but there is a support for that).
For the knob I used 5k potentiometer.

To control the leds and the sd card reading, I will use a small Arduino pro mini clone. It’s small and it has enough power to drive the leds for this purpose.

BOM

Component Quantity
WS2812B 1M 144 leds 1
Protected 18650 2600mAh 2
Micro SD Card Module 1
5K potentiometer 1
470uf 16v Capacitor 1
7mm Push button 1
12mm Latching switch 1
5A XL4005 DC-DC Step Down 1
Arduino Pro Mini 5V 16MHZ 1

If you need a charger for the 18650 battery, you can use the NITECORE D4 (it support more types of batteries like AA, AAA and more..)

The Build

I’m not the first one who build such a light painter.
I got this idea and based all this on this cool project I saw on Adafruit:
https://learn.adafruit.com/neopixel-painter/overview

The general principle is the same, and I even used their code to run my bar (with few tiny changes), but I wanted a small and portable device.

So I started sketching something I could print using my 3D printer, and came with this:

The top and bottom orange parts are sliding into the black parts.
The tiny orange part is for the Arduino and sd card module from the other side.
The big orange part is for the battries and the voltage regulator.
The handle can be removed and the potentiometer hides there (I didn’t want to change it accidentally) .
On the right near the handle lays the button for easy press while holding the handle.

The bar is made from two parts because I can’t print it in once piece with my printer.

Here’s a photo of all the electronics and almost all the printed parts (did you notice what’s missing? )

I had a little space problem with the voltage regulator (it was too high), so I removed it’s potentiometer and replaced it with a small resistor to get about 5v.
From the datasheet I got the formula for Vout, and on the module I have R1 = 330 ohm, so I used 1.6k ohm resistor I had to get 4.84V which is still fine (above 4.5v is good).

 

Schematics for the entire light bar:

And this is what came up, exactly how I imagined it:

So I have a working led bar, I can change the colors but now is the hard part – the software.
I need a software to take a photo with a width 72 pixels (because I have 72 leds) and translate each row in the photo to commands for the leds.
(The text is inverted because the software assume that the pixels are connected from the bottom of the bar, and I connected them from the top)


Fortunately, this is what Adafruit did, and since I didn’t have much time for writing my own code – I used their’s this time:
https://github.com/adafruit/NeoPixel_Painter/

Testing

Timing is everything here.
If I move too fast or too slow – the text will be warped.

So I need to find the correct pace, and keep moving smoothly at the same speed.

After few tries I found the golden ratio: 60 lines per second!

The second problem was a little minor, but I needed to know the limits inside the frame, so I wouldn’t go out.
This took some practice, but I counted steps from the camera and to the starting position and then I could estimate my limits.

SHE SAID YES

I designed the text I want to display.
I didn’t want to it be one long row with a tiny text, so I splited it to two rows.
The device thinks it’s one long row and keep displaying it.
In the middle of the image I created, I put a long black break. That brake signaled me that I need to lower the
lightbar and start going backwards (I also mirrored the text).

 

I asked her to take a photo (I changed all the camera parameters before), and then I started walking with the bar in my hand (sorry for the bad quality but you get the idea)

And this is the result of all the hard work:

Of course she said yes 😉

 

Smart Door Lock

The idea of controlling my home door lock from remote was in my mind for a while.

Recently I purchased an Amazon Echo Dot device and I wanted to write my own skills.

I also wanted to practice mechanical design for 3D printing and this idea combines all my wishes.

I will try to describes the project and explain what I did, why I did it and how I did it.

Mechanical Design

Turning the lock

My home door is heavy and when I lock the door, it anchored in several places.
It takes a little force to lock and unlock so a geared servo motor like the MG995 seemed good choice.

Problem:  The servo spins only 180 degrees and I need few tuns to lock and unlock the door.
Solutions:

  • Hack the servo so it will spins 360 degrees
  • Buy a version of this servo that spins 360
  • Plan gears in a way that 180 degrees will be enough to lock/unlock

I’m not a mechanical engineer and I don’t know much about gears (you will see later).
I already had MG995 servo motor so I chose to hacked it.
There are many tutorials out there for this hack, this is the one I used:

Ater the hack, the motor does not stop at 180 degrees, it continues to speed forever.
I can set the direction of the motor by sending a signal for angles from 0 to 90, and from 90 to 180 to the other direction.

3D Printed mount

I used Autodesk Fusion 360 for the 3d printed parts.
There are many tutorials out there and you can start making designs really fast.
Also, for hobbyist you get can one year license for free.

From within the house there is a “fixed key”.

Problem: I did not want to remove this key or make any changes in the door.
I live in a rented apartment so I cant the risk of damaging the door.
Without any modification to the door, is it possible to connect the lock mechanics?

Solution: This “key” can be taken off the door.  There is a little spring that pushes a needle
to a hole in the key. If you push the needle you can then take out the key.
My idea was to connect the gear to this hole to, from the outer side.

The second gear will be connected to the servo, and all will mount on the door handle.
Mounting it on the handle makes it possible to lock and unlock the door manually.
When you open the door with the handle, you disconnect the gears from each other and
then it’s possible to turn the lock without any resistance from the servo motor.
This is what came out:

You can see in right photos what I described with the handle.

I’m not a mechanical engineer and I know very little about gears.
I do know that if you want to increase the torque, you need to build a gears ratio greater than 1:1.
I drew these big gears out of my head without any formulas or calculation like you should do when you
plan gears. That’s why the teeth are so big. I started with one tooth and then duplicated it.
The big gear has 26 teeth and the little gear has 13 teeth, so it’s 2:1 ratio (doubling the torque).

Some more photos:

You can find the stl files here:
https://gitlab.com/itaysp/alexa-door-lock/tree/master/STL

Firmware

After building the mechanics, I wanted to control it from remote – my phone or even Alexa.
First and simple method I thought about was to take an ESP8266 and run a webserver.
Then I could control the servo with HTTP requests and maybe build a nice web UI.

Thinking a little more and I decided to use MQTT messaging protocol instead.
MQTT is a little more complex, you need a broker server and use a library for the mqtt client,
but for the long term, if I want to build a smart home with many devices, this is a good infrastructure.

The ESP8266 is still used here for the connecting the servo to my smart home and running a MQTT client.
I used the WeMos D1 Mini board because it’s small, has a usb-serial interface already so it’s easy to flash a
firmware without any additional circuit or components, it’s cheap, and I had few lying around.

I used the ESP8266 Core for Arduino to write the firmware because it’s very fast and there are good
MQTT libraries for Arduino.
For the MQTT client I used the Pubsubclient library.
I started a Mosquitto MQTT broker on a raspberry pi, but there are good free MQTT broker services
like cloudmqtt which I can recommend from a past experience.

From the examples and the documentation of the Pubsubclient library it’s easy to start
and subscribe to an mqtt topic.
First you need to write all the server details you have.
clientId must be a unique identifier.
topic is the topic we subscribe to for controlling the door lock.

/* Mqtt Settings */
const char* mqtt_server = "YOUR_MQTT_SERVER_ADDRESS";
const char* clientUsername = "YOUR_MQTT_SERVER_USERNAME";
String clientId = "esp-door-client";
const char* clientPass = "YOUR_MQTT_SERVER_PASSWORD";
const uint16_t port = YOUR_MQTT_SERVER_PORT;
const char* topic = "DoorLock";

When a message is received with the topic I subscribed to,  I read it and then
using strcmp function check if it’s was lock or unlock message.
For large smart home network it will be wiser to use opcodes with switch statements instead.
Because I have here only 2 options and speed/efficiency is not important right now, I used
command words for simplicity.

lock and unlock are global booleans flags.
The lock/unlock will take place in the main loop according to these flags.

//Mqtt message received
void callback(char* topic, byte* payload, unsigned int length) {
 char buff[16];
 uint8_t i;

 Serial.print("Message arrived [");
 Serial.print(topic);
 Serial.print("] ");

 for (i = 0; i < length; i++) {
  Serial.print((char)payload[i]);
  buff[i] = (char)payload[i];
 }
 buff[i] = 0; //Termination char for working with strcmp

 if(strcmp(buff,"lock") == 0){
  lock = true;
 }
 else if((strcmp(buff,"unlock") == 0)){
  unlock = true;
 }

}

The door lock/unlock function will initialize the servo, write a position that now only
means speed and direction, wait a few seconds and then detach the servo.
I’m detaching the servo because after I hacked it, it’s hard to make it stop.
Setting it to 90 degrees position should make it stop, but it doesn’t.
Detaching it will stop sending pulses and it will stop moving.

I used the Arduino servo library to control the servo.
For the lock and unlock timing, I just played with it a little until I found the right
time for the servo to complete the unlock and the lock.

//Door unlock function
void doorLock(){
 //init the servo
 door_servo.attach(SERVO_PIN);

 //start pulsing the servo (for direction and speed)
 door_servo.write(DOOR_LOCK_SPEED);

 //wait duration seconds for the door to lock
 myDelay(DOOR_LOCK_DURATION);

 //stop sending pulses
 door_servo.detach(); 
}

The delay function is not the regular Delay because it blocks interrupts.
I like to write my own delay function.
In the ESP8266 there is a watchdog enabled by default so when writing such a function
it’s importat to remember feeding it.

//My delay function
void myDelay(uint32_t ms){
 uint32_t t = millis();
 while((millis() - t) < ms)
 {
  ESP.wdtFeed(); //feed the watchdog to avoid reset of the mcu
 }
}

You can find the complete firmware here:
https://gitlab.com/itaysp/alexa-door-lock/blob/master/DoorLock/DoorLock.ino

Note that you need to modify it with your wifi credentials, and this firmware
includes the code for the Arduino OTA update option so you can remove it
if you don’t need it.

Alexa Skill

After having the door lock controlled by MQTT (from my phone/
web browser with MQTT client) ,it’s time for the Alexa skill.

I decided to build  it with Node.js because I kept hearing about it and this was a good
time to start using it.

There’s a good step by step guide from Amazon for building a skill using Node.js:
https://github.com/alexa/skill-sample-nodejs-howto

And there’s the Alexa Skills Kit SDK for Node.js
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs

Reading both and looking at some of these examples, I built the skill.

I used the MQTT.js client library to publish messages to the server.

There is not much I can add after you read the tutorials and look thru the examples.
You can find the source code and the speech assets of my skill  here:
https://gitlab.com/itaysp/alexa-door-lock/tree/master/AlexaSkill

If you want to use/modify it and create a skill, just follow the first link –
it explains all the steps you need in to do in the Developer Portal and the AWS Lambda.

The project’s gitlab:
https://gitlab.com/itaysp/alexa-door-lock

 

 

 

 

 

$12 Smart Boiler

Recently I moved to a house where I don’t have a gas water heater.
Now when it’s winter I need to plan my showers and turn on the boiler in advanced.

Since the IOT era began, I can see more and more solutions for connecting the boiler
to a smart wifi switch (switcher, SwitcHeat and more..) , but hose solution are very expensive.

I consider myself as a Maker, and I like DIY solutions so I tinkered a smart wifi control using sonoff pow.

Sonoff is a wireless switch which can control electronic devices such as home appliances via WiFi.

It support max power of 3500W which should be enoughWhy I used sonoff pow:

  • It uses ESP8266 so I can flash my own / other firmwares and add MQTT control
  • It has a nice app to control it, add timers and even share the device so my girlfriend can use it as well
  • I can see the power consumption which is good to make sure the boiler is working and
    also nice addition to see the total cost each use/day/moth
  • Can be also controlled manually (like a regular switch)

Sonoff has aonther model called ‘sonoff TH16’ that also can handle 3500W.
This model does not able to measure current and unable to show the power consumption, but can also be used.
the TH16 has few more connections on the board that might ease connecting it to a switch.

Sonoff pow has one momentary button. Pressing this button will toggle the connected device on and off.
Long press (5 seconds) will make it enter into a pairing mode for pairing with the app.

Before I start writing about my installation, please note that dealing with mains electricity should
be only handled
 by electricians. If you does not know what you are doing, please don’t try this.
If you decide to make your own, please make sure you shut the boiler power
from the main switch and also check that the ‘Live’ wire is not live with a tester.
I take no responsibility.

What you will need:

I replaced the switch in the panel with the stairway momentary button.
(If you don’t want/need a manual control to start/stop the boiler you don’t need this button)
I did this because the sonoff’s button is also a momentary push button, and like I said before – long press will put it in
pairing mode. If I use a regular on/off button I need to imitate this action every time.

Then I had to trim the switch connectors because they are too big and won’t let me close the panel.
After I trimmed them, I also soldered a wire to the switch connectors

Next step is to track the sonoff’s switch on the pcb and connect it to the wires from the new switch.
(again, if you don’t use the button skip this)

Now we have to dissemble the old panel (if you didn’t already) and connect the boiler and the mains electricity.
to the sonoff. Check again that you don’t have a live electricity!

Connect Line to Line (Live/Phase) , Neutral to Neutral (Zero) and Earth to Earth.
Note that the input Line is on the right and the output Line is on the left.
I already had the Earth shorted so I didn’t connect it to the sonoff.
I also managed to break the Line connector so I soldered a thick wire straight the pcb.
In addition, I added a kapton tape on the area the new switch might touch to avoid shortening the circuit.
If you have an indicator light you can connect it to the output Line and Neutral in the sonoff as well.

Now all you have to do is carefully close the panel and put back the power on.
One press on the switch should start the boiler, another one should stop it.
If you have an indicator light you should see it turning on and off.

Download eWeLink app for Android or IOS. Start it and create a new account.
Now make a long press (5 seconds) on the switch to put the sonoff in pairing mode.
In the app add a new device and enter your home SSID and password.
At the end of the process you should have a new device in the app.
You can now control it and see it’s power consumption, add on and off timers and more..

That’s all for today 🙂

Next goal: connecting the boiler with Amazon Echo!

Update: Itead made an Alexa skill for the sonoff so it’s easy to control it with Alexa
https://www.itead.cc/blog/ewelink-works-with-alexa-tutorial

If you want to plug it to your smart home via MQTT,  you can install the Sonoff-Tasmota firmware
(but you will lose the control from their app) and control it with MQTT or HTTP requests.
https://github.com/arendst/Sonoff-Tasmota

You can see how I controlled a esp8266 device with mqtt client from Alexa here:
http://itay.mobi/blog/?p=155

Hebrew support for the Amazfit watch

UPDATE:
New watchs comes with a locked bootloader.
If you are using CN version above 1.2.13e or abobe US 1.3.2b – your bootloader is locked.
You won’t be able to use this turorial.

If your bootloader is not locked, you might want to check the PACEfied rom:
https://forum.xda-developers.com/smartwatch/other-smartwatches/rom-pacefied-amazfit-huami-amazfit-t3539431

This rom includes the Hebrew fonts and much more.
———————————————-

After I found out I’m not gonna get my Pebble Time 2, I searched for an alternative.

I heard about the Amazfit Pace watch, which is manufactured by Huami.
Amazfit Pace is an affordable GPS running watch with heart rate tracking,
based on Android 5.1 (not Android Wear) with Huami’s interface.

There are two versions for this watch, one is Chinese (A1602) for the Asian market,
and on for the global market (A1612, allso called Pace).

The CN version get updates every Friday and it’s firmware is more advanced from the global version.
(The global version did not get any update yet)

I knew there is no Hebrew support for the CN version, but I hoped the global version does,
so I bought the Amazfit Pace from amazfit.com (sold at $99 with promo code ‘NOTFITBIT’ that time).

Bad news – no Hebrew support 🙁

 

I don’t have much experience with Android development, but the first fix I thought of is change
the watch default font to a bilingual font.
The watch’s default font is Roboto. I did a little search for a bilingual font and decided to use Heboo.

Next step is to change all the Roboto font style with the matching ones of Heeboo.. but where?

The fonts in Android system are stored in the folder ‘system/fonts’, but to make changes
in this folder you must have a root access.
Luckily, the day I received my watch, xda user ‘Neuer_User’ found a way to
convert the Chinese version to the Global version, and for that he made a recovery with a root access.

I booted this recovery with fastboot, and now I have root access from adb 🙂
Now.. the ‘system’ folder is missing! After a little googling I figured out I need to mount it,
but I did not know it’s path. More googling… and the command is:

ls -l /dev/block/platform/jzmmc_v1.2.0/by-name

Output:

lrwxrwxrwx root     root              2017-01-21 12:31 boot -> /dev/block/mmcblk0p1
lrwxrwxrwx root     root              2017-01-21 12:31 cache -> /dev/block/mmcblk0p6
lrwxrwxrwx root     root              2017-01-21 12:31 data -> /dev/block/mmcblk0p8
lrwxrwxrwx root     root              2017-01-21 12:31 misc -> /dev/block/mmcblk0p5
lrwxrwxrwx root     root              2017-01-21 12:31 pretest -> /dev/block/mmcblk0p3
lrwxrwxrwx root     root              2017-01-21 12:31 recovery -> /dev/block/mmcblk0p2
lrwxrwxrwx root     root              2017-01-21 12:31 reserved -> /dev/block/mmcblk0p4
lrwxrwxrwx root     root              2017-01-21 12:31 system -> /dev/block/mmcblk0p7

I need the ‘system’ folder then I need to mount it with the command:

mount -t ext4 /dev/block/mmcblk0p7 /system

Now I can replace all the Roboto with Heboo and that’s what I did. And it worked!
But it also pushed out from the display some texts:

More readings and I found there is a file called ‘fonts.xml’ in the folder ‘etc’ that contains the system fonts
and it has a fallback font for Hebrew!
There are more languages in this file, you can find it here:
https://github.com/itaysp/AmazfitPace/blob/master/fonts.xml

The Hebrew fallback fonts are ‘NotoSansHebrew-Bold.ttf’ and ‘NotoSansHebrew-Regular.ttf’.
You can find the fonts here: https://www.google.com/get/noto/#sans-hebr
Very stange that Huami did not include them in the watch..

So now the fix is simple! just push those two fonts to the ‘system/fonts’ folder and we have Hebrew support!
The only problem now is when the screen is locked, the notifications still can’t be displayed.
When I replaced the fonts with Heboo, I did see Hebrew even the screen was locked, but it was revered.

So here is a quick guide for pushing the Hebrew fonts:
( *** I’M NOT TAKING ANY RESPONSIBILITY IF YOU DAMAGE YOUR WATCH ***)

### Files and tools needed:
### adb, fastboot and drivers. can be found here: 
### https://forum.xda-developers.com/showthread.php?t=2588979
###
### Neur_User Amazfit-mod-recovery.img from here:
### https://forum.xda-developers.com/smartwatch/other-smartwatches/tutorial-convert-xiaomi-huami-amazfit-t3532508
###
### 'fonts' folder with the fonts 'NotoSansHebrew-Bold.ttf' and 'NotoSansHebrew-Regular.ttf' 
### https://www.google.com/get/noto/#sans-hebr
###

# Create a folder with the file Amazfit-mod-recovery.img and the 'fonts'
# folder with the fonts and navigate there from command line.

# connect your watch to your PC
adb devices
# this should list your watch, otherwise something is wrong

# now reboot into bootloader
adb shell reboot bootloader

# when you see the fastboot logo, check that you can access fastboot
fastboot devices

# you should see your device listed, otherwise your fastboot installation is not correct on your PC
# then boot into the temporary recovery
fastboot boot Amazfit-mod-recovery.img

# when you see a triangle and/or the text "No command" on the watch, you are in recovery and can enter adb

# mount the /system partition
adb shell mount -t ext4 /dev/block/mmcblk0p7 /system

# overwrite the old fonts
adb push fonts /system/fonts/

# restart the phone
adb shell reboot

Next hack was to start translating apps to Hebrew.. but this is still unstable.

 

Update 27/07/2017
This watch let me down.
After about 3 months of use, the battery died..
The watch  was sitting on my desk useless until now:

Hacking the Mi Light – Adding wifi with ESP8266

After Philips came out with their Hue few years ago, we started to see many
Chinese bulbs with the same capabilities.

Usually those bulbs connect to some kind of Hub at 2.4Ghz (not wifi), and from there
the Hub is connected to the home network and we can control those bubs from the smartphone,
or you can buy a remote control that connects to the hub/directly to the bulb.

Those new Chinese bulbs are very cheap (about $10).

Another thing that came out not long ago is the the ESP8266 –  a little SOC (system on a chip) that
includes WiFi and a micro controller on the same chip, and it costs about 2-3$.

A while ago I bought some modules back never got the time to play with them very much.

So I’ve been thinking- why not taking one of those cheap bulbs that has the capability to change colors,
and replace its brain with an ESP8266 and control it from the web/smartphone!

Then, I bought a Mi Light light bulb from Banggood, and started exploring it.

After a little playing and checking,  you can see in the photo above my findings.
The Mi Light use a micro controller from STM to control the bulb,
a Low Power 2.4Ghz Transceiver to communicate with the hub/remote, a 3.3V voltage regulator,
and some transistors that controls the RGB and the WHITE leds (My guess: the white is MOS and the colors are BJT).

 

Update 10/9/2016:

There is a mix between the Green and Red colors in the picture.
Also, I made measurements for the currents of each color:

Blue: 87.6 [mA]
Red: 99.2 [mA]
Green: 71.3 [mA]
White: 158.3 [mA]

 
(I don’t have the hub or the remote so it was a little tricky to find which transistor controls which led,
I assumed that the first one control the white one because it different type of transistor)

After studying the Mi Light, I moved to the ESP8266.

I chose the ESP-03 module because it was small and has many GPIOs from the chop that are available.

The ESP-03 module header are not standard, and I wanted to use the 1″ header so I could pull
it form the Mi Light if I wand to update the firmware.
IMG_2
So apparently someone already found some nice way solder a 1″ header to this module

 

And this is what came out
IMG_3

 

Now I had to put it on a breadboard and start coding.
I connected some of the ESP GPIOs thru 200Ω resistors to Red, Green, Blue and White LEDs,
and used a breadboard power supply to supply 3.3V to the ESP.

IMG_4

I installed the “Unofficial Development Kit for Espressif ESP8266 “from here:
http://www.esp8266.com/viewtopic.php?f=9&t=820
And connected the ESP according to this (no RST in ESP-03)



(I took it schematic from here and ESP-03 image from here)

And.. after few days of struggle with the code, I managed to something that was unstable and I was not happy with.

So I tried the Arduino core for the ESP8266:  https://github.com/esp8266/Arduino
This is very easy to work with, and in a few hours of learning I had something I was happy with.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char *ssid = "YOUR SSID";
const char *password = "YOUR PASSWORD";

ESP8266WebServer server(80);

//Assign color to gpio
#define rgbRED 12
#define rgbGREEN 13
#define rgbBLUE 2
#define rgbWHITE 14

//RGB Struct
struct RGB {
  byte r;
  byte g;
  byte b;
  byte w;
};

RGB miColor;

//Update PWM according to the new values
void updateLights()
{
  analogWrite(rgbRED, miColor.r);
  analogWrite(rgbGREEN, miColor.g);
  analogWrite(rgbBLUE, miColor.b);
  analogWrite(rgbWHITE, miColor.w);
}

//Handle main page
void handleRoot() {
  server.send(200, "text/plain", "Hello from Mi Light!");
}

//Handle color change
void handleColorChange(){ 
  for (uint8_t i=0; i<server.args(); i++){
    switch (server.argName(i)[0])
    {
      case 'r':
        miColor.r = server.arg(i).toInt();
      break;
      case 'g':
        miColor.g = server.arg(i).toInt();
      break;
      case 'b':
        miColor.b = server.arg(i).toInt();
      break;
      case 'w':
        miColor.w = server.arg(i).toInt();
      break;
    }
  }
  //Update the light with to the received data
  updateLights();
  
  String message="Colors: \r\n";
  message += "Red: " + (String)miColor.r + "\r\n";
  message += "Green: " + (String)miColor.g + "\r\n";
  message += "Blue: " + (String)miColor.b + "\r\n";
  message += "White: " + (String)miColor.w + "\r\n";
  server.send(200, "text/plain", message);
  
}

void handleNotFound(){
  String message = "File Not Found\n\n"; 
  server.send(404, "text/plain", message);
}

void setup(void){
//Initialize starting color (only white on full power)  
  miColor = (RGB){0,0,0,255};

//Initialize GPIO's as OUTPUT
  pinMode(rgbRED, OUTPUT);
  pinMode(rgbGREEN, OUTPUT);
  pinMode(rgbBLUE, OUTPUT);
  pinMode(rgbWHITE, OUTPUT);

//I use 8bit RGB color space, so we will limit the PWM to 255 (2^8)
  analogWriteRange(255);

//Set the output to their initialized state (only white is on)
  updateLights();

 //Start the serial and connect to network
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("ESP_MiLight")) {
    Serial.println("MDNS responder started");
  }

//handle root page
  server.on("/", handleRoot);

//To change the colors the esp will listen to data at http://host/rgb
  server.on("/rgb", handleColorChange);

//Handle path not found
 server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}

How it works:
When the micro controller is booting – first it turns the white color by default, and then I’m starting a web sever.
Then, to change color – I’m sending HTTP POST/GET request to the ESP with all the values I want.
I’m using 8-bit color space, that means that each R-G-B color can have 255 values.
This value represents the amount of that color: 0 – no color at all, 255 – maximum of that color.
If you want to generate a pink color you will have:
PINK

For the White color, I used 255 options too that represents the lighting level.

To control the amount of light of each led, the ESP generates PWM signal
that turn the light on and off very fast, and the average voltage that the LED gets is decreased
according the width of the pulse.

So If I want only pink color, I will have to send the ESP this:
http://10.0.0.44/rgb?r=255&g=204&b=229&w=0
(let’s say that for this example ESP’s IP address  is 10.0.0.44)

 

Now that I have a working ESP, I need to take what I found about the Mi-Light and connect the ESP instead of the MCU.

So first, I cut the voltage traces that goes to the STM MCU, and to the RF transitive (at the blue lines)

Then I used 3.3V Voltage regulator that was on the board already, because the ESP takes 3.3V.
Later I found that this voltage regulator can deliver only 30mA and the ESP needs about 200-250mA max,
so I had to add one of my own, so basically you can just remove the old voltage regulator and then you don’t have to
cut the traces.
It will also help you to connect to the board power supply (16V DC) and GND  from the top of the PCB (marked as VIN and GND),
and it will be neater than the way I did it (I made my connection from the back)
* You can connect to 16V power supply from the bottom-right connector (marked as 16V) too.

To run the ESP it needs less connections than before (when I programmed it):

(schematics from here)

And of course a 100uF capacitor from GND to 3V3.
I used lm1117 voltage regulator because it’s small and what I had available.

I built a little board with a 100uF capacitor, 10k resistors and the lm1117 voltage regulator (not in the photo)

This PCB gets from a regulator that inside the bulb 16V DC and this regulator should handle this.

Before connecting the new board –  desolder the old Antenna, we have no use
for it now and we will have no room for the new board we made.

Then, I connected the GPIO to the transistors:
12 – RED
13 – GREEN
2   – Blue
14 – White

The red, green and blue are were connected before the 2.2k resistor (refer to the first image),
the white was connected after the 100k resistor and was connected the the gate of the transistor.

IMG_8  IMG_6 IMG_7

Well.. it worked and then I fried the ESP 🙁
I need to work on my soldering and practice a little more, because I had a short somewhere.
When I moved it while it was working – I created a short somewhere – and this is the end.
Now I’m waiting for a new ESP-03.
I will update when it arrives.

Next on this project:
Build a phone app to control the lights, and connect it the the phone notifications –
when I get a whatsApp message – the light will turn green etc..

 

 

Rostock 3D Printer build – Part 1

Hello everyone!
My name is Itay, I’m 25 years old and I’m currently studying for my Electrical Engineering Bsc.

It’s time to start a blog to document my project, and to encourage me to do more projects.

The first post will be about an old project, a 3D Printer.
I loved the delta design of a 3D printer, and when I started to this project, the Rostock design looked something simple to start with.
Looking back, I think I had to choose the Kossel design. Back then, I tough that  T-slot will make things more complex, and wood will be easier, but now I kind of regret I didn’t go for the Kossel.Read more