Posts

=================================

A remote controlled AC power switch with visual monitoring capability | DzQ39 |

As a 3D printing hobbyist, I recently developed a system to help me remotely monitor my print and cut off power to my printer in case it starts making spaghetti.

Different Flavors of 3D Printed Spaghetti



Or, generating too much heat that will burn down the machine or even the house.


Reference:
http://forums.reprap.org/read.php?392,294850
http://hackaday.com/2016/12/07/dont-leave-3d-printers-unattended-they-can-catch-fire/
http://hackaday.com/2016/03/21/ask-hackaday-mrrf-edition-3d-printers-can-catch-fire/
http://www.fabbaloo.com/blog/2015/9/23/3d-printer-almost-burns-down-house

Configuration

In the photo below, the device on bottom left is the remote power switch with visual monitoring capability that I developed. In the center is a Logitech USB Webcam. On the right is a 3D printer that's printing the enclosure for the remote power switch.

The power of the 3D printer as well as the power of the heated bad (I use AC 110V heated bad) are plugged into the outlets on the remote power switch.


Left: Power Switch, Center: USB Webcam, Right: 3D Printer

User Interface

The power switch is controlled via a web app that runs on Android, iOS, Windows, and Linux devices that support modern web browser.

Switch Status

This page shows the on/off status of the power switch as well as the photo (if any) taken by the webcam.

Remote Control

This page allows the user to remotely turn on/off the power switch and take photo.


How It Works

Below are screenshots taken from my phone while I was away from home working. Things looked normal in the photo on the left. But, in the photo on the right, there was an obvious gap between the hotend and the printed object so I killed off the power to the printer remotely. When I got home, I found that the new filament is too tight to be pulled into the extruder so I loosen it up to make another print.


The Offer

I am offering this as a kit which includes:

- AC 110V / 220V, 40A Solid State Relay x 1
- Heat Sink for Solid State Relay x 1
- Control Board (with software pre-loaded) x 1
- Power Outlet (with 2 sockets and rated for AC 125V, 15A) x 1
- AC Power Cord x 1

Item Location: Taipei, Taiwan.
Delivery:
- Unless specified otherwise, delivery will be made via EMS with tracking no.
- Delivery Lead Time: Around 10 ~ 14 working days after receipt of complete payment.

Price: US$49.99 (shipping not included)

Below are the things to be prepared by the buyer:

- USB Webcam (Logitech C-series will do. Mine is C905) x 1
- Micro USB Male to USB A Female Cable x 1
- 5V, 1.5 ~ 2A Micro USB Charger x 1
- Mini tripod x 1 (for mounting the USB Webcam) x 1
- Enclosure x 1 (to be printed by buyer using the stl file provided)

If you are interested or have any questions, please leave your comment in the comment section below.













How to use Ubuntu to build C/C++ programs that run on LinkIt Smart 7688 Duo - Method 2 | DzQ39 |

This post is about how to use Ubuntu to cross-compile C/C++ programs that run on LinkIt Smart 7688 Duo running OpenWRT Chaos Calmer 15.05.1 r49203 .

It's assumed that the SDK has been downloaded and installed on the Ubuntu machine. If it hasn't been installed, please refer to http://wei48221.blogspot.tw/2017/05/linkit-smart-7688-7688-duo-using.html for instructions on how to download and install it.

Note, the method described below builds an executable file that can be executed directly by using the "./filename" command.


Step-1, Find the location of "mipsel-openwrt-linux-gcc"

sudo find -name mipsel-openwrt-linux-gcc


Note,

For an Ubuntu machine with "OpenWrt SDK for C/C++ for Linux" installed under the "SDK" folder, below is the location of the file "mipsel-openwrt-linux-gcc".

./SDK/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc

For an Ubuntu machine with "C/C++ Toolchain for Linux" installed under the "OpenWrt-Toolchain-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64" folder, below is the location of the file "mipsel-openwrt-linux-gcc".

./OpenWrt-Toolchain-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc

Judging from the experiment below, having the SDK installed on the Ubuntu machine is enough for cross compilation and there is no need to install the Toolchain.

Step-2, Prepare the helloworld.c file to be compiled

#include <stdio.h>
int main(int argc, char** argv)
{
printf("Hello, World!\n");
return 0;
}

Step-3, Use "mipsel-openwrt-linux-gcc" to compile

SDK/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc helloworld.c -o helloworld


Check the result. There is a helloworld


Check the status "ls -l".


Step-4, Use WinSCP to copy helloworld from Ubuntu to LinkIt Smart 7688 Duo.


Use "chmod +x helloworld" to make the file executable.


Step-5, Run the program.

Use "./helloworld" to run the program.


--------------------------------------------------------------------------------------------------------------------------

How to set STAGING_DIR and PATH

The section below is obtained from https://github.com/japaric/rust-on-openwrt

To verify that you got the right SDK, we'll compile a "Hello, world!" C program, and run it on the OpenWRT device.
When working with the OpenWRT SDK you'll need to set these two environment variables (STAGING_DIR & PATH), and be sure to keep them in your environment for the rest of this how-to.
# Make sure you are in the OpenWRT SDK folder
$ pwd
/home/japaric/openwrt

$ export STAGING_DIR="$PWD/staging_dir"

$ export PATH="$PWD/$(echo staging_dir/toolchain-*/bin):$PATH"
You should now be able to call the cross compiler, which should be in your PATH:
$ mips-openwrt-linux-gcc -v
gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r42625)
--------------------------------------------------------------------------------------------------------------------------

For my setup, below are the commands issued and the screenshot.

root@root-192.168.2.16:~$ cd SDK

root@root-192.168.2.16:~/SDK$ pwd
/home/root/SDK

root@root-192.168.2.16:~/SDK$ export STAGING_DIR="$PWD/staging_dir"

root@root-192.168.2.16:~/SDK$ export PATH="$PWD/$(echo staging_dir/toolchain-*/bin):$PATH"

root@root-192.168.2.16:~/SDK$ mipsel-openwrt-linux-gcc -v

In the commands above, "wei-hsiung" is replaced with "root" to shorten the line so that the command could be shown in one line.


To verify the STAGING_DIR and PATH have been set correctly

First, check to make sure that "helloworld.c" is in the working directory and there is no executable "helloworld" in the same directory.


Second, issue "mipsel-openwrt-linux-gcc helloworld.c -o helloworld". Then, check again the content of the same directory.


Indeed, there is now an executable "helloworld" in the same directory. And, there is no warning message about STAGING_DIR not defined.

Reference:

How to compile with the openwrt toolchain
http://wiki.wrtnode.com/index.php?title=How_to_compile_with_the_openwrt_toolchain

C Cross Compile for Linkit Smart 7688
https://www.slideshare.net/svrnuke/c-cross-compile-for-linkit-smart-7688

How to use Ubuntu to build C/C++ programs that run on LinkIt Smart 7688 Duo - Method 1 | DzQ39 |

This post is based on https://docs.labs.mediatek.com/resource/linkit-smart-7688/en/tutorials/c-c++-programming/using-openwrt-sdk-to-build-c-c++-programs with additional info. added from following it.

Note, The method described below uses makefile to build an *.ipk file that could be installed by using the "opkg install filename" command.

Environment:

Working Computer: Windows 8.1.
Cross Compiling Platform: Ubuntu Linux 16.04.2 on ThinkPad-Edge-E420s.

Target:

LinkIt Smart 7688 Duo, OpenWRT Chaos Calmer 15.05.1 r49203


Step-1, Download the SDK

Visit https://docs.labs.mediatek.com/resource/linkit-smart-7688/en/downloads to download the SDK.


The direct download link for the SDK is https://labs.mediatek.com/en/download/AGSSkG38.

Step-2, Copy the SDK to the Ubuntu machine

Use WinSCP to copy the the downloaded SDK (filename: OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2) to the home directory on the Ubuntu machine.

Step-3, Unzip the SDK on the Ubuntu machine

Issue the command below to unzip the SDK.

sudo tar -xvjf OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2

The content of the directory will be like the one below.


Remove "OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2" and rename the folder from "OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64" to "SDK" for easy maneuver.

rm OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
mv OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64 SDK

Step-4, Download and unzip the example package file.

The direct download link of the example file: https://labs.mediatek.com/en/download/kJWJnDta

Unzip the file on the PC, then use WinSCP to copy everything under the package directory (including the package directory) to the Ubuntu machine and place the copied directory and files under the SDK folder


Below is the directory structure.


Step-5, Build the package.

From under the SDK directory, use "make package/helloworld/compile" to build the package. Once it's built:

Navigate to SDK/bin/ramips/packages/base to find a package file named "helloworld_1.0.0-1_ramips_24kec.ipk".


Copy the .ipk file to the LinkIt Smart 7688 development board.

In the system console of the board, navigate to the location of the .ipk file and type "opkg install helloworld_1.0.0-1_ramips_24kec.ipk".

After the installation is complete, type helloworld and you'll see a string Hello world, why won't my code compile?

To remove the installed packaged. Use "opkg remove helloworld".

--------------------------------------------------------------------------------------------------------------------------

What to do when compilation failed?


Instead of "make package/helloworld/compile", use "make -j1 V=s package/helloworld/compile" for a more verbose output.

"exec: ccache: not found" is in the output message.


Use "sudo apt-get install -y ccache" to install the missing ccache.


After the installation is done, run "make package/helloworld/compile" again and we have a successful result.


References:

In English.

https://docs.labs.mediatek.com/resource/linkit-smart-7688/en/tutorials/c-c++-programming/using-openwrt-sdk-to-build-c-c++-programs

https://docs.labs.mediatek.com/resource/linkit-smart-7688/en/tutorials/c-c++-programming

In Chinese.

https://embedded2016.hackpad.com/ep/pad/static/mhxL7PPo64F

How to setup Pronterface (Printrun) for 3D printing | DzQ39 |

This is a quick example on how to setup Pronterface (Printrun) for 3D printing. The printer is a DIY Prusa i3 style printer with 30cm x 30cm x 30cm printing envelop (see below photo).



Below are the parameters that I use for printing PETG.


Below are the gcodes for the 5 buttons in the bottom of the photo above:

Extend Z Probe: M280 P0 S95
Retract Z Probe: M280 P0 S20
ABL Home: G28
ABL Probe: G29
Fan 50% Speed: M106 S127

Note:
- ABL stands for Automatic Bed Leveling;
- To use ABL, first click on "ABL Home" to move the print head to the Home position. After that, click on "ABL Probe" to activate the automatic bed leveling process. After the bed is probed, click on "Print" to start the printing process;
- IMPORTANT: after the bed is probed with "ABL Probe", DO NOT issue any command that moves the bed or the print head; otherwise it will invalid the bed leveling parameters and you will have to execute "ABL Home" and "ABL Probe" again to re-acquire the parameters.

The photo below shows the parameters relevant to printer setting.


Using eagleUp to export Eagle PCB to Sketchup | DzQ39 |

This post contains a quick summary of how to export board design done by Eagle PCB to Sketchup using eagleUp and tips on solving the followign problems that I encountered during the process.

1. Where to put the eagleUp\ sub folder.
2. How to use eagleUp;
3. How to import the exported 3D board model in Sketchup.

Installation

Follow the instruction at https://eagleup.wordpress.com/installation-and-setup/ to download and install the required files.


Be sure to enable "Install legacy utilities (e.g. convert).


Reference:
[Resolved] convert.exe missing from 7.0.1-Q16? 
https://www.imagemagick.org/discourse-server/viewtopic.php?t=29582

Running eagleUp

Launch Eagle PCB, load the demo file, then click on RUN ULP. In the pop up window, locate and select "eagleUp_export.ulp" then click Open.


Configuration

The first time "eagleUp_export.ulp" is executed, a configuration window like below will appear. Be sure to point the folders / files to the right location.


The general setting window can be brought up by left click on the "Edit general settings" when launching "eagleUp_export.ulp".


Importing the board 3D model to Sketchup

Note, the exported 3D board file is stored in the eagleUp folder under the folder where the *.brd file is stored.

Be sure to enable Ruby console before executing "Import eagleUp" under Plugins. This could help spot error. See http://developer.sketchup.com/en/content/ruby-sketchup on how to enable Ruby console.


For instance, I couldn't figure out why Sketchup fails to import the "demo3d.eup" file. After seeing the error message, I realized that it's caused by the file being on C drive and special privilege is required to access it.


The location of "demo3d.eup" is under C:\Program Files (x86)\EAGLE-6.6.0\demo files\eagleUp.


By copy the directory and its contents to D drive (where special privilege is not required), Sketchup is able to import and display demo3d.eup without problem.


References:

Welcome to eagleUp
https://eagleup.wordpress.com/

Download and installation of eagleUp
https://eagleup.wordpress.com/installation-and-setup/

Exporting PCB to Google Sketchup - Anyone Know How?
https://circuitmaker.com/forum/posts/214945/

Working with switching regulator - LM2596 | DzQ39 |

This is a quick summary of how to work with LM2596 and how to reduce its ripple.

Original Schematic


Source: http://www.ti.com/lit/ds/symlink/lm2596.pdf



Output (based on the original schematic)


Updated Schematic (with the optional ripple filter)


Source: http://www.hobbyelectronics.net/review_dctodcmodule.html

Output (based on the updated schematic)


Note, For the circuit that I use, the values for the optional output ripple filter are L2 = 33uH, C1 = 100uF, 35V.

Below is the waveform of a cheap LM2596 module that supports adjustable output.


The above waveform is taken from the module below.


Reference:

Review of DC to DC buck converter based on LM2596
http://www.hobbyelectronics.net/review_dctodcmodule.html

How to turn on/off servo power | DzQ39 |

This post is about how to turn on / off the power to servo motor using MOSFET or TIP120. According to the article at the end of this post, MOSFET is the better choice due to less power consumption. However, I've observed that it takes less voltage to turn on TIP120 than IRF530 or 2N7000. So for low power devices such as RPi that outputs 3.3V and control a servo that runs on DC 6V, it may be a good idea to use TIP120 (or, there needs to be a way to level-shift the 3.3V to 5V).

Using MOSFET



Using TIP120


Sample Code

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
Adafruit Arduino - Lesson 14. Sweep
*/

#include <Servo.h>

int servoPin = 9;

Servo servo;

int angle = 0; // servo position in degrees

void setup()
{
servo.attach(servoPin);
}


void loop()
{
// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle--)
{
servo.write(angle);
delay(15);
}
}

--------------------------------------------------------------------------------------------------------------------------

Below is the schematic for turning on/off a servo motor using 2N7000 and a 3.3V control signal.


--------------------------------------------------------------------------------------------------------------------------

The code below adds power control to the above example using interrupt. The power control pin is connected to pin 2 of the Arduino. When pin 2 is low, the servo will sweep from 0 to 180 and back. When pin 2 goes from low to high (RISING), the power to the servo motor is cut and the counting stops.


 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <Servo.h> 

int servoPin = 9;
int powerCutDetectionPin = 2;

Servo servo;

int angle = 0; // servo position in degrees

void setup()
{
servo.attach(servoPin);
pinMode(powerCutDetectionPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(powerCutDetectionPin), empty_loop, RISING);
}

void empty_loop() {
}

void loop()
{
// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle--)
{
servo.write(angle);
delay(15);
}
}

Reference:

http://sensitiveresearch.com/elec/DoNotTIP/index.html

TAKING IT TO ANOTHER LEVEL: MAKING 3.3V SPEAK WITH 5V
http://hackaday.com/2016/12/05/taking-it-to-another-level-making-3-3v-and-5v-logic-communicate-with-level-shifters/