Posts

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

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/

Collection of OpenWRT Tips | DzQ39 |

Here is a list of OpenWRT tips which I find useful.

Network

Network configuration
https://wiki.openwrt.org/doc/uci/network

Build System

OpenWrt build system – Installation
https://wiki.openwrt.org/doc/howto/buildroot.exigence

OpenWrt build system – Usage
https://wiki.openwrt.org/doc/howto/build

Building your own package for OpenWRT
https://vivekian2.wordpress.com/2007/03/28/building-your-own-package-for-openwrt/

How to Build a Single Package
https://wiki.openwrt.org/doc/howtobuild/single.package

OPKG

Where to get packages
https://wiki.openwrt.org/doc/packages



Exchange Files Between OpenWRT and Windows PC

SFTP server
https://wiki.openwrt.org/doc/howto/sftp.server

WinSCP Downloads
https://winscp.net/eng/download.php

File Download

wget vs curl: How to Download Files Using wget and curl
https://adamscheller.com/systems-administration/rtl8192cu-fix-wifi/

Check Kernel Version

How To Check the Kernel Version in Linux / Ubuntu / CentOS
https://www.liquidweb.com/kb/how-to-check-the-kernel-version-in-linux-ubuntu-centos/

Search for directory or file

find  / -name "filename"

References:

LuCI

OpenWrt luci web interface logo picture and modify strings

Adding new elements to LuCI
https://wiki.openwrt.org/doc/devel/luci

Mounting USB Drive

OpenWRT — Setting Up USB Storage Support
https://medium.com/openwrt-iot/lede-openwrt-setting-up-usb-storage-support-adec9c0d484e

Safely Shutdown OpenWRT

How to shut down openwrt without corrupting file systems?
https://superuser.com/questions/694297/how-to-shut-down-openwrt-without-corrupting-file-systems

Misc.

OpenWrt, ash alias profile
http://www.cesareriva.com/openwrt-shell-alias/

Some binaries from additional packages return "not found" (wrong libc link possible)
https://dev.openwrt.org/ticket/19893

OpenWrt - How to enable support for external USB Drive | DzQ39 |

This is a quick summary on how to enable support for external USB Drive.

1st - Follow the steps in https://medium.com/openwrt-iot/lede-openwrt-setting-up-usb-storage-support-adec9c0d484e to install the needed packages.


2nd - Use dmesg | grep sd to check the result.


3rd - Use the commands below to create a mounting point and  mount the USB drive to it.

root@mylinkit:/Media# mkdir flashdrive
root@mylinkit:/Media# mount /dev/sda /Media/flashdrive

4th - Check the content of the USB drive.


To safely remove the USB drive.

Use the command below to unmount the USB drive.

root@mylinkit:/Media/flashdrive# umount /dev/sda


Reference:

OpenWRT — Setting Up USB Storage Support
https://medium.com/openwrt-iot/lede-openwrt-setting-up-usb-storage-support-adec9c0d484e

How do I access an external drive mounted on a machine on my own network?
http://askubuntu.com/questions/50104/how-do-i-access-an-external-drive-mounted-on-a-machine-on-my-own-network

How to umount a USB drive?
http://unix.stackexchange.com/questions/45820/how-to-umount-a-usb-drive

Linux (Ubuntu): safely remove USB flash disk via command line [closed]
http://stackoverflow.com/questions/13224509/linux-ubuntu-safely-remove-usb-flash-disk-via-command-line

OpenWrt Wiki - USB Storage
http://webcache.googleusercontent.com/search?q=cache:swXK9O6jidEJ:https://wiki.openwrt.org/doc/howto/usb.storage&num=1&hl=en&gl=tw&strip=1&vwsrc=0

How to create line chart with 2 y-axis using chart.js | DzQ39 |

This is a quick post about how to create line chart with 2 y-axis using chart.js.


 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<!-- For latest CDN version of Chart.js, visit https://cdnjs.com/libraries/Chart.js -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js"></script>
</head>
<body>

<canvas id="myChart" width="400" height="250"></canvas>

<script>
var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, {
type: "line",
data: {
"labels": [
"01.12.2015",
"02.12.2015",
"03.12.2015",
"04.12.2015",
"30.12.2015"
],
"datasets": [{
"label": "DEA Burrweiler Druck Abgabe",
"fill": "false",
yAxisID: "y-axis-0",
"data": [
8.7913,
8.6985,
8.7914,
8.7948,
8.7882
]
}, {
"label": "DEA Burrweiler Druck Zulauf",
"fill": "false",
yAxisID: "y-axis-0",
"data": [
4.5997,
4.5526,
4.5915,
4.5937,
4.5795
]
}, {
"label": "DMS Flemlingen Durchfluss",
"fill": "false",
yAxisID: "y-axis-1",
"data": [
1.9588,
2.4226,
2.1392,
2.223,
1.9048
]
}]
},
options: {
scales: {
yAxes: [{
position: "left",
"id": "y-axis-0"
}, {
position: "right",
"id": "y-axis-1"
}]
}
}
});
</script>

</body>
</html>

Result


To disable the responsive feature, add "responsive: false" as shown below.


References:

Chart.js - line chart with two yAxis
http://stackoverflow.com/questions/37028536/chart-js-line-chart-with-two-yaxis

http://jsfiddle.net/dahd27d7/

How to sort multi-dimensional arrays in JavaScript | DzQ39 |

This is a continuation of my previous post on How to create a line chart using Chart.js and the data parsed from a CSV string using Papa Parse. In the previous post, the x-axis is not in ascending order (see below photo). This post will address this issue by sorting the data in the desired order before making the chart.




Code

Note, the part highlighted in yellow is the newly added part that does the sorting.


  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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html>
<head>
<!-- Load papaparse.js -->
<script src="papaparse.min.js"></script>

<!-- For latest CDN version of Chart.js, visit https://cdnjs.com/libraries/Chart.js -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js"></script>
</head>
<body>

<canvas id="myChart" width="400" height="250"></canvas>

<script>
//Parse the data.
function parseData() {
csv = "Date,Time,Station_id,Ambient Humidity,Ambient Temperature,Light,Probe Temperature,DI1,DI2" + "\n" +
"2017-03-23,16:37:38,1,70.10,22.10,859,22.50,0,0" + "\n" +
"2017-03-23,16:42:51,1,70.50,22.30,820,21.88,0,0" + "\n" +
"2017-03-23,16:32:25,1,69.90,22.10,848,22.38,0,0" + "\n" +
"2017-03-23,16:27:12,1,70.30,22.10,866,22.25,0,0" + "\n" +
"2017-03-23,14:21:11,1,71.40,22.60,577,22.38,0,0" + "\n" +
"2017-03-23,13:02:45,1,73.10,22.60,558,22.31,0,0" + "\n" +
"2017-03-23,13:34:02,1,74.00,22.60,577,22.38,0,0" + "\n" +
"2017-03-23,12:20:59,1,75.20,22.50,435,22.25,0,0" + "\n" +
"2017-03-23,11:49:39,1,76.00,22.60,572,22.31,0,0";
var parsed_data = Papa.parse(csv);
//console.log(parsed_data);
createGraph(parsed_data.data);
}

function createGraph(pd) {

// Check the length of the data array
//console.log(pd.length);

pd.sort(function (a, b) {
//return a[1] - b[1];

// The code below works. But hardwire the date is not needed because pd[0] contains the date data.
//return new Date('1970/01/01 ' + a[1]) - new Date('1970/01/01 ' + b[1]);

// The code below works by combining pd[0] and pd[1] (don't miss the space in between).
return new Date(a[0]+ " " + a[1]) - new Date(b[0]+ " " + b[1]);
});

var canvas = document.getElementById('myChart');

// Buffers for storing the selected array data for making chart
var time = [];
var light = [];

for (var i = 1; i < pd.length; i++) {
//console.log(pd[i][5]);
time.push(pd[i][1]); // Time Stamp
light.push(pd[i][5]); // Light Sensor Reading
}

// Double check the contents of the 2 arrays
console.log(time);
console.log(light);

var data = {
//labels: ["January", "February", "March", "April", "May", "June", "July"],
labels: time, // X-Axis
datasets: [
{
label: "My First dataset",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 5,
pointHitRadius: 10,
//data: [65, 59, 80, 0, 56, 55, 40],
data: light, // Y-Axis
}
]
};

var option = {
showLines: true,
responsive: false
};
var myLineChart = Chart.Line(canvas,{
data:data,
options:option
});
}

parseData();

</script>

</body>
</html>


Result

Note, the x-axis is now in ascending order.


Reference:

Sort string array containing time in format '09:00 AM'?
http://stackoverflow.com/questions/17064603/sort-string-array-containing-time-in-format-0900-am




How to create a line chart using Chart.js and the data parsed from a CSV string using Papa Parse | DzQ39 |

This is a quick summary about how to create a line chart using Chart.js and the data parsed from a CSV string using Papa Parse.


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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<!-- Load papaparse.js -->
<script src="papaparse.min.js"></script>

<!-- For latest CDN version of Chart.js, visit https://cdnjs.com/libraries/Chart.js -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.js"></script>
</head>
<body>

<canvas id="myChart" width="400" height="250"></canvas>

<script>
//Parse the data.
function parseData() {
csv = "Date,Time,Station_id,Ambient Humidity,Ambient Temperature,Light,Probe Temperature,DI1,DI2" + "\n" +
"2017-03-23,16:37:38,1,70.10,22.10,859,22.50,0,0" + "\n" +
"2017-03-23,16:42:51,1,70.50,22.30,820,21.88,0,0" + "\n" +
"2017-03-23,16:32:25,1,69.90,22.10,848,22.38,0,0" + "\n" +
"2017-03-23,16:27:12,1,70.30,22.10,866,22.25,0,0" + "\n" +
"2017-03-23,14:21:11,1,71.40,22.60,577,22.38,0,0" + "\n" +
"2017-03-23,13:02:45,1,73.10,22.60,558,22.31,0,0" + "\n" +
"2017-03-23,13:34:02,1,74.00,22.60,577,22.38,0,0" + "\n" +
"2017-03-23,12:20:59,1,75.20,22.50,435,22.25,0,0" + "\n" +
"2017-03-23,11:49:39,1,76.00,22.60,572,22.31,0,0";
var parsed_data = Papa.parse(csv);
//console.log(parsed_data);
createGraph(parsed_data.data);
}

function createGraph(pd) {

// Check the length of the data array
//console.log(pd.length);

var canvas = document.getElementById('myChart');

// Buffers for storing the selected array data for making chart
var time = [];
var light = [];

for (var i = 1; i < pd.length; i++) {
//console.log(pd[i][5]);
time.push(pd[i][1]); // Time Stamp
light.push(pd[i][5]); // Light Sensor Reading
}

// Double check the contents of the 2 arrays
console.log(time);
console.log(light);

var data = {
//labels: ["January", "February", "March", "April", "May", "June", "July"],
labels: time, // X-Axis
datasets: [
{
label: "My First dataset",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 5,
pointHitRadius: 10,
//data: [65, 59, 80, 0, 56, 55, 40],
data: light, // Y-Axis
}
]
};

var option = {
showLines: true,
responsive: false
};
var myLineChart = Chart.Line(canvas,{
data:data,
options:option
});
}

parseData();

</script>

</body>
</html>

Result

Chart
Note, For info. on how to put the x-axis in ascending order, refer to my other post at http://wei48221.blogspot.tw/2017/03/how-to-sort-multi-dimensional-arrays-in.html.

Developer Tools Output


Reference

How to Create Website Graphs from CSV Files with c3.js and PapaParse
https://youtu.be/1OK4TJfCzdY