tag:blogger.com,1999:blog-81131781596117268042024-03-14T04:32:16.989+01:00G33ky dadjfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-8113178159611726804.post-75923512001226730562018-10-04T08:54:00.001+02:002018-10-04T08:54:02.337+02:00Anycubic I3 Mega settings<pre style="background-color: #f8f9fa; border: 1px solid rgb(234, 236, 240); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em; white-space: pre-wrap;">G1 X0 Y180 F9000;</pre>
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-1934946044344455262015-05-13T22:55:00.000+02:002015-05-13T23:18:43.701+02:00Web service in Mule 3.6 (producer)<h2 style="clear: both;">
</h2>
I wouldn't call it a tutorial. This "article" depicts my first attempt to produce a web service using Mule 3.6. Probably (well, for sure) there is a better, more efficient approach, but this one works and for my purposes is sufficient. In next part, I'll show how to consume it.<br />
<br />
We will start with WSDL file. I prefer contract first apporach, therefore in the very first step I have prepared <a href="https://drive.google.com/open?id=0B3aizVidmymIdVFGbjVWMFRlRmM&authuser=0">WSDL contract</a>.<br />
<br />
<br />
Now, lets start Mule with a new project - I have called mine "SimpleWS". Nothing special to be set, just use default options. After project and its structure is created, copy hasher.wsdl to src/main/api:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-KHMuZgV60NE/VVOWMUHYYCI/AAAAAAAAIMI/8OUM8uGcGFM/s1600/01_structure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="http://2.bp.blogspot.com/-KHMuZgV60NE/VVOWMUHYYCI/AAAAAAAAIMI/8OUM8uGcGFM/s200/01_structure.png" width="185" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h2 style="clear: both; text-align: left;">
</h2>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
First, we have to define HTTP connector and its configuration. By simply dragging HTTP icon from toolbox (?) we will create a new flow (assuming that there has been no flow yet):</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-TSwrMaA-Js8/VVOXGYeGOqI/AAAAAAAAIMQ/4ZbqCyAf0YA/s1600/02_http_conn.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-TSwrMaA-Js8/VVOXGYeGOqI/AAAAAAAAIMQ/4ZbqCyAf0YA/s1600/02_http_conn.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now configuration. Click on HTTP connector and in its General properties, General Settings tab, add new Connector Configuration:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-TfaJGfwZJ7M/VVOX8A16eoI/AAAAAAAAIMY/H1zKXwQlaHs/s1600/03_http_conf.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="307" src="http://2.bp.blogspot.com/-TfaJGfwZJ7M/VVOX8A16eoI/AAAAAAAAIMY/H1zKXwQlaHs/s320/03_http_conf.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
First - give it a moreless meaningful name, then define a port that will be used by this connector. Next, in Basic Settings > Path enter the path to your WS:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-oRKt2QHSrHQ/VVOY7ygNquI/AAAAAAAAIMk/6jWJOljAhR4/s1600/04_http_conn_sett.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="121" src="http://3.bp.blogspot.com/-oRKt2QHSrHQ/VVOY7ygNquI/AAAAAAAAIMk/6jWJOljAhR4/s320/04_http_conn_sett.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
It's high time we created a web service. Mule documentation encourages to use CXF component, so let it be:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-M7rsCrc9CS8/VVOaCODtcOI/AAAAAAAAIMs/mn6fVD6Qd_Q/s1600/05_cxf_intro.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-M7rsCrc9CS8/VVOaCODtcOI/AAAAAAAAIMs/mn6fVD6Qd_Q/s1600/05_cxf_intro.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
CXF component requires a bit more effort to configure it. At the beginning add new CXF configuration (General > Generic> Config Reference). I personally don't find it necessary to change anything, default values are ok.</div>
<div class="separator" style="clear: both; text-align: left;">
Next we choose the purpose of this component (General > Generic > Operation). In this case you should choose "JAX-WS service".</div>
<div class="separator" style="clear: both; text-align: left;">
Since we are applying contract-first apporach, we can now choose a WSDL file and generate java classes for our service:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-LWQXKq8OH5I/VVOgD0BKm2I/AAAAAAAAIM8/yV2MaBJJKqw/s1600/06_wsdl.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="142" src="http://2.bp.blogspot.com/-LWQXKq8OH5I/VVOgD0BKm2I/AAAAAAAAIM8/yV2MaBJJKqw/s320/06_wsdl.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
In dialog window, enter a path to WSDL file and a package for java classes that will be generated from definition file:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-GkSHWfjUwS0/VVOlVRNRjeI/AAAAAAAAINY/LlPmkl3N5f8/s1600/07_wsdl2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="284" src="http://1.bp.blogspot.com/-GkSHWfjUwS0/VVOlVRNRjeI/AAAAAAAAINY/LlPmkl3N5f8/s320/07_wsdl2.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
After confirmation, you can see that a Service Class has been chosen automagically (in fact this is an interface, but that is not relevant at this momemnt).</div>
<div class="separator" style="clear: both; text-align: left;">
We could run our application now, and call a service, but we would end up with an error:</div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Courier New, Courier, monospace;">org.apache.cxf.interceptor.Fault: Marshalling Error: Instance of "pl.edu.pwr.isi.hasher.HashRequest" is substituting "pl.edu.pwr.isi.hasher.HashResponse"</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Why did it happen? Well, after http request reaches HTTP connector it's being transformed and send to CXF component, which performs its magic, and in the end we have a payload set to an instance of a HashRequest class . Payload is not being changed and is treated as a response, which should be a HashResponse object (and that's the reason for substitution issue)</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
We should handle somehow this request and prepare a response. </div>
<div class="separator" style="clear: both; text-align: left;">
I have chosen a Spring bean for that purpose :)</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
In your first window choose "Global Elements" and create a new bean: (Beans > Bean):</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-Bvqt2X7_mYY/VVOka8I-pYI/AAAAAAAAINQ/kxnb8lvUjnk/s1600/08_bean.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="122" src="http://4.bp.blogspot.com/-Bvqt2X7_mYY/VVOka8I-pYI/AAAAAAAAINQ/kxnb8lvUjnk/s320/08_bean.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
We have to provide a bean definition (and add a new class implementing HashPort interface):</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-mrQnT6IhziY/VVOmHWELV4I/AAAAAAAAINg/8sVzL_pfY9g/s1600/09_beandef.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-mrQnT6IhziY/VVOmHWELV4I/AAAAAAAAINg/8sVzL_pfY9g/s320/09_beandef.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The only thing left is to call our newly defined bean. Add an Expression component to our flow:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-yGBWibjULzg/VVOok36MRpI/AAAAAAAAINs/IEbsxFA0sgI/s1600/10_expression.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-yGBWibjULzg/VVOok36MRpI/AAAAAAAAINs/IEbsxFA0sgI/s1600/10_expression.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
and enter proper expression for this component:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Courier New, Courier, monospace;">payload = app.registry['requestHandler'].handleRequest(payload);</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
And that's all... What is happening in our flow?</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul>
<li>ws client calls our service - HTTP connector receives the request and forwards it to CXF component</li>
<li>CXF analyses request and based on which operation is called, transforms request data into proper java object, which becomes now the payload in the flow</li>
<li>Expression component calls a method handleRequest with a payload as its parameter. Thanks to method overloading we can have one expression that could handle all possible operations.</li>
<li>Bean "requestHandler" creates a proper response object, which becomes now the payload in the flow.</li>
<li>CXF takes a response object and transforms it into a response data that are being sent back to client</li>
</ul>
<div class="separator" style="clear: both; text-align: left;">
If you don't know how to call this web service - use SoapUI. Create a new SOAP project, with WSDL at this location: http://localhost:8888/ws/hasher?wsdl. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Whole project is <a href="https://drive.google.com/open?id=0B3aizVidmymIZlJKQ0duRUltYU0&authuser=0">here</a>.</div>
<div>
<br /></div>
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-67395150590802753052014-08-05T20:12:00.000+02:002014-08-10T18:56:24.783+02:00Matrix editor[Under construction]<br />
<br />
Description soon... Working functionality first ;)<br />
<script src="http://code.jquery.com/jquery-2.1.1.js"></script><br />
<br />
<style type="text/css">
/* <![CDATA[ */
#matrix { border: 1px solid }
#matrix td { width: 25px; height: 25px; text-align:center; border: 1px solid; user-select:none}
#columnValues { width: 250px; height: 150px; text-align:left; }
.numVal { width: 30px }
.on {background: green !important}
/* ]]> */
</style><br />
<script>
function updateNumbers() {
var m = $("#matrix");
var rowz = m.prop("rows")[0];
var colNr = rowz.childElementCount;
var rowNr = m.prop("rows").length;
var ta = $("#columnValues");
ta.empty();
for (c = 0; c < colNr; c++) {
var strVal = "B";
for (r = rowNr-1; r >=0; r--) {
var id = "#c_" + c + "_" + r;
var val = $(id).text();
strVal += val;
}
ta.append(strVal + ", ");
}
}
function toggle(cell) {
var c = $(cell);
//c.addClass("on");
var val = c.text();
c.text(val=='0'?'1':'0');
c.toggleClass("on");
updateNumbers();
}
function reset() {
var tds = $("#matrix td");
tds.removeClass("on");
tds.text("0");
updateNumbers();
}
function generate() {
var rowNr = $("#rows").val();
var colNr = $("#columns").val();
var matrixCnt = $("#matrixContainer");
matrixCnt.empty();
matrixCnt.append("<table id='matrix'></table>");
var matrix = $("#matrix");
for (r = 0; r < rowNr; r++) {
var tr = "<tr>";
for (c=0; c < colNr; c++) {
var id = "c_" + c + "_" + r;
tr += "<td id='" +id+ "' onclick='toggle(this);'>0</td>"
}
tr += "</tr>";
matrix.append(tr);
}
updateNumbers();
}
$( document ).ready(generate());
</script><br />
<div id="matrixParams">Rows: <input class="numVal" id="rows" value="8" /> <br />
Columns: <input class="numVal" id="columns" value="8" /> <br />
<input onclick="generate()" type="button" value="Generate" /><br />
<input onclick="reset()" type="button" value="Reset" /><br />
</div><br />
<div id="matrixContainer"></div><br />
<br />
<div id="columnValues"></div>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-73989246357041801002014-08-01T09:53:00.000+02:002014-08-06T20:18:09.018+02:00SoonAnd now... Some pictures as a teaser of upcoming post :)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-p5gbcGDSmas/UZCbhN2AfiI/AAAAAAAAHlk/10Y41rKqTpU/s1600/DSCN2680.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-p5gbcGDSmas/UZCbhN2AfiI/AAAAAAAAHlk/10Y41rKqTpU/s320/DSCN2680.JPG" height="240" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-TmVXH8BBbY8/UZCbiTkSTGI/AAAAAAAAHlo/tIpRr45d6zA/s1600/DSCN2681.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-TmVXH8BBbY8/UZCbiTkSTGI/AAAAAAAAHlo/tIpRr45d6zA/s320/DSCN2681.JPG" height="240" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-2pVa4loXO_8/UZCbhKWEAeI/AAAAAAAAHlg/CEzo2RIEWOU/s1600/DSCN2678.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-2pVa4loXO_8/UZCbhKWEAeI/AAAAAAAAHlg/CEzo2RIEWOU/s320/DSCN2678.JPG" height="240" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-T-aygR7hA-c/UZCbhJJwiCI/AAAAAAAAHlc/uOjc52FAVOU/s1600/DSCN2679.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-T-aygR7hA-c/UZCbhJJwiCI/AAAAAAAAHlc/uOjc52FAVOU/s320/DSCN2679.JPG" height="240" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
What will that be?</div>
<div class="separator" style="clear: both; text-align: left;">
[Date reedited :) Project restarted. ]</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-90106718810882808562013-09-17T08:22:00.000+02:002013-09-17T08:22:01.803+02:00How to disable annoying java updates.I use java. Every day. I know precisely what version I should use for given task, therefore I do mind being notified about "There is an update availabe. Would you....? " <br />
NO. I would not :)<br />
<br />
To disable this annoying feature on windows 7 (probably on every windows) you have to:<br />
* run console as administrator<br />
* run file C:\Program Files (x86)\Java\jre6\bin\javacpl.exe<br />
* disable updated :)<br />
<br />
Or you could run the file directly as an administrator, but using console is more natural to me :)<br />
<br />
And that's all.jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-69182832578660936552013-09-02T08:33:00.002+02:002013-09-17T08:22:41.875+02:00SQL Developer and the User-Related Information LocationSql Developer generates a lot of data stored by default in home directory. Usually it is not a problem, but if you have a quota on your directory, well... Fortunatelly there is a way to change the location of user related data: <a href="http://docs.oracle.com/cd/E18464_01/doc.30/e17472/intro.htm#CIHFCGCD">http://docs.oracle.com/cd/E18464_01/doc.30/e17472/intro.htm#CIHFCGCD</a><br />
The only thing that must be done is to define <i>IDE_USER_DIR </i>environment variable.<br />
But!<br />
Before doing that you should copy already existing data to new directory, or at least export your connections :)<br />
<br />
<br />
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-3312936510184003112013-04-16T21:05:00.001+02:002013-04-16T21:05:44.907+02:00RPi - Running services at bootI wanted to start a few services while my Rasperry Pi is booting. Since my days as linux "administrator" are gone, I needed to do some research how to achieve that.<br />
<br />
Services to be started: H2 database server, serial port listening service, tomcat - in that order.<br />
<br />
Naturally, all applications have been installed.<br />
First step - prepare script files:<br />
<br />
/etc/init.d/h2 file:<br />
<pre>#!/bin/bash
### BEGIN INIT INFO
# Provides: h2
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: h2 database
# Description: h2 database
### END INIT INFO
test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions
H2_HOME=/opt/h2
DAEMON=h2server
ARGS=
#PID=$(get_pid $DAEMON)
case "$1" in
start)
log_begin_msg "Starting h2 database"
$H2_HOME/bin/$DAEMON $ARGS & #>/dev/null
log_end_msg 0
;;
stop)
log_begin_msg "Stopping $DAEMON"
kill `ps aux | awk '/h2.*jar/{print $2}'` > /dev/null
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
</pre>
<br />
<br />
/etc/init.d/rxreader file:<br />
<pre>#!/bin/bash
### BEGIN INIT INFO
# Provides: rxreader
# Required-Start: $tomcat
# Required-Stop: $tomcat
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: rxreader
# Description: rxreader
### END INIT INFO
test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions
RXRD_HOME=/opt/rxreader
DAEMON=read
ARGS=
case "$1" in
start)
log_begin_msg "Starting h2 database"
#[ -z "$PID" ] &&
$RXRD_HOME/bin/$DAEMON $ARGS & #>/dev/null
log_end_msg 0
;;
stop)
log_begin_msg "Stopping $DAEMON"
kill `ps aux | awk '/rxreader/{print $2}'` > /dev/null
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
</pre>
<br />
/etc/init.d/tomcat file:<br />
<pre>#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $h2
# Required-Stop: $h2
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: tomcat
# Description: tomcat
### END INIT INFO
test -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions
TOMCAT_HOME=/opt/apache-tomcat-7
DAEMON=startup.sh
ARGS=
case "$1" in
start)
log_begin_msg "Starting apache tomcat"
$TOMCAT_HOME/bin/$DAEMON $ARGS & #>/dev/null
log_end_msg 0
;;
stop)
log_begin_msg "Stopping $DAEMON"
$TOMCAT_HOME/bin/shutdown.sh
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
</pre>
<br />
When file are in /etc/init.d directory we have to run update-rc command, which installs (or removes) System-V style init script links:<br />
<pre>sudo update-rc.d h2 defaults
sudo update-rc.d tomcat defaults
sudo update-rc.d rxreader defaults
</pre>
<br />
Now you can restart RPi or start services manually:<br />
<pre>sudo service h2 start
sudo service rxreader start
sudo service tomcat start
</pre>
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-13569515458876749402013-01-22T07:26:00.002+01:002013-01-22T20:42:23.146+01:00Java and RPi - continued<br />
After I had installed both jdk (open and oracle's), I started wondering what is the difference between them, when it comes to performance. Recently I found some time in the evening and wrote simple tests, which are not very accurate, but give the general notion about performance.<br />
<br />
Let's take a look into tests:<br />
<b>ArrayListAppendTest</b><br />
<pre>List<Long> list = new ArrayList<Long>();
for (long l = 0; l <1000000; l++) {
list.add(l);
}
</pre><br />
<b>ArrayListInsertMiddleTest</b><br />
<pre>List<Long> list = new ArrayList<Long>();
for (long l = 0; l < 1000; l++) {
list.add(l);
}
for (long l = 0; l < 10000; l++) {
list.add(500, l);
}
</pre><br />
<b>ArrayListSortTest</b><br />
<pre>List<string> list = new ArrayList<string>();
for (int i = 100000; i > 0; i--) {
String str = String.format("String nr %5s", i);
list.add(str);
}
Collections.sort(list);
</string></string></pre><br />
<b>LinkedListAppendTest</b>, <b>LinkedListInsertMiddleTest</b>, <b>LinkedListSortTest</b> are exactly the same as for ArrayList, but with subtle change...<br />
<br />
<b>DoubleAddTest</b><br />
<pre>double val = 0.0;
for (int i = 0; i< 1000000; i++) {
val += (double) i;
}
</pre><br />
<b>SinusTest</b> <br />
<pre>for(int i = 0; i < 1000000; i++) {
double val = Math.sin((double) i);
}
</pre><br />
<b>StringAppendTest</b> <br />
<pre>String [] strings = new String[1000];
for (int i = 0; i < strings.length; i++) {
strings[i] = String.format("Str %d", i);
}
String concat = "";
for (int i = 0; i < strings.length; i++) {
concat += strings[i];
}
</pre><br />
All tests <b>*ISTest</b> use various input streams, <b>*OSTest</b> - output streams.<br />
<br />
When it comes to reflection tests, I tried to instantiate class using classe's newInstance method, in case of CallMethod test I'm calling one argument method using reflection. Simple...<br />
<br />
For comparison I executed test on my ancient computer (Amd64 3500+). After that I compiled and run tests on Raspberry Pi using proper JDK.<br />
<br />
And the resulst are... interesting (execution time is in ms):<br />
<br />
<table class="datatable" style="width: 90%px;"><tbody>
<tr> <th>Test name</th><th>JDK Oracle 1.7 @ AMD64 3500</th><th>Oracle JDK 1.8 ea @ RPi</th><th>Open JDK 1.7 @ RPi</th><th>Ratio</th></tr>
<tr> <th align="left">ArrayListAppendTest</th> <td>348,6</td> <td>2632</td> <td>10965,1</td> <td>4,2</td> </tr>
<tr> <th align="left">ArrayListInsertMiddleTest</th> <td>72,6</td> <td>285,7</td> <td>1024,7</td> <td>3,6</td> </tr>
<tr> <th align="left">ArrayListSortTest</th> <td>19,6</td> <td>292,9</td> <td>2394,4</td> <td>8,2</td> </tr>
<tr> <th align="left">BufferedFileOS</th> <td>12,2</td> <td>45,4</td> <td>856,4</td> <td>18,9</td> </tr>
<tr> <th align="left">DoubleAddTest</th> <td>0,2</td> <td>35,8</td> <td>390,5</td> <td>10,9</td> </tr>
<tr> <th align="left">FileISTest</th> <td>25,3</td> <td>183,8</td> <td>231,5</td> <td>1,3</td> </tr>
<tr> <th align="left">FileOSTest</th> <td>96,8</td> <td>524,9</td> <td>1618,9</td> <td>3,1</td> </tr>
<tr> <th align="left">LinkedListAppendTest</th> <td>636,1</td> <td>3393,7</td> <td>16634,3</td> <td>4,9</td> </tr>
<tr> <th align="left">LinkedListInsertMiddleTest</th> <td>23,3</td> <td>99,5</td> <td>2159</td> <td>21,7</td> </tr>
<tr> <th align="left">LinkedListSortTest</th> <td>44,8</td> <td>270,9</td> <td>2225,9</td> <td>8,2</td> </tr>
<tr> <th align="left">ReflectionCallMethodTest</th> <td>116,3</td> <td>803,2</td> <td>3496,7</td> <td>4,4</td> </tr>
<tr> <th align="left">ReflectionNewInstanceTest</th> <td>55,5</td> <td>202,5</td> <td>542,4</td> <td>2,7</td> </tr>
<tr> <th align="left">SinusTest</th> <td>268,6</td> <td>562,5</td> <td>3722</td> <td>6,6</td> </tr>
<tr> <th align="left">StringAppendTest</th> <td>49,3</td> <td>254,4</td> <td>489,1</td> <td>1,9</td> </tr>
</tbody> </table><div><br />
As you can see Open JDK in those test is far behind oracle's (in column <b>Ratio</b> you can see, how much slower Open JDK was :/).<br />
I think I stick to JDK 1.8 ea...<br />
<br />
</div>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-68792751115240479992013-01-19T22:48:00.000+01:002013-01-19T22:48:53.453+01:00Java and RPiIf you gave a java developer a Raspberry Pi board, what programming language would he choose? You can make additional assumption, that he would be interested in writing a web application for RPi.<br />
He would choose:<br />
<ol>
<li>C++</li>
<li>Python</li>
<li>or maybe Java?</li>
</ol>
<br />
Please send your answer anywhere you wish, in the meantime we start installing Java on RPi.<br />
<br />
Most searches in google, if you want to find phrase "java raspberry pi", ends with plenty of links to articles, how to install the only proper one version, namely oracle java. But I would like to install for starters an open version.<br />
<br />
Actually, installation process is not very sophisticated:<br />
<pre>sudo apt-get install openjdk-7-jdk</pre>
<br />
When it's done, you can verify it quickly:<br />
<pre>myuser@raspberrypi ~ $ java -version
java version "1.7.0_07"
OpenJDK Runtime Environment (IcedTea7 2.3.2) (7u7-2.3.2a-1+rpi1)
OpenJDK Zero VM (build 22.0-b10, mixed mode)</pre>
<br />
When it comes to web application, web container could be quite handy when running application. So far I haven't used jetty, therefore:<br />
<pre>sudo apt-get install jetty8</pre>
<br />
When installation is completed (ignore an error while starting jetty) you need to update you startup scripts. But first, the only valid text editor should be installeed: <br />
<pre>sudo apt-get install vim</pre>
<br />
Before we update a configuration file, let's see where java has landed: <br />
<pre>update-alternatives --list java</pre>
<br />
and we get:<br />
<pre>/usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java</pre>
<br />
so java home is: /usr/lib/jvm/java-7-openjdk-armhf<br />
<br />
Knowing all that important stuff we can modify a script file:<br />
<pre>sudo vim /etc/default/jetty8</pre>
<br />
first thing, we shall allow jetty to start along wiht the system:<br />
<pre># change to 0 to allow Jetty to start
NO_START=0</pre>
<br />
after that, setting JAVA_HOME is proper thing to do:<br />
<pre># Home of Java installation.
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-armhf</pre>
<br />
If we completed our work now, jetty could be accessed only on... localhost. In order to access web server from anywhere, we need to set JETTY_HOST as well:<br />
<pre># Listen to connections from this network host
# Use 0.0.0.0 as host to accept all connections.
# Uncomment to restrict access to localhost
#JETTY_HOST=$(uname -n)
JETTY_HOST=0.0.0.0</pre>
<br />
Let's restart jetty:<br />
<pre>sudo /etc/init.d/jetty8 restart</pre>
<br />
and what we get is default page for our jetty server:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-aK6IWM0X4ts/UNxEuwjnV6I/AAAAAAAAHXY/3BwrZLdaVMg/s1600/Zrzut+ekranu+z+2012-12-27+13:52:31.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="http://3.bp.blogspot.com/-aK6IWM0X4ts/UNxEuwjnV6I/AAAAAAAAHXY/3BwrZLdaVMg/s320/Zrzut+ekranu+z+2012-12-27+13:52:31.png" width="320" /></a></div>
<br />
<br />
However...<br />
I would like to have the possibility to use oracle's jdk as well. <br />
But... <br />
It's not so easy for me... At least not on a wheezy version I have installed nor with jdk 1.7.0_10. <br />
The problem is that I had wanted to have more efficient system, therefore I've installed wheezy with hardware ABI, and current oracle's jdk can use only slower soft-bloat ABI.<br />
<br />
Fortunatelly, Oralce released "early access" jdk 1.8 with JavaFX included (you can get that package from <a href="http://jdk8.java.net/fxarmpreview/">http://jdk8.java.net/fxarmpreview/</a>)<br />
<br />
Whern you download it and unpack in /usr/lib/jvm directory, following command should be executed:<br />
<pre>myuser@raspberrypi ~ $ <b>sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0/bin/java 1</b>
myuser@raspberrypi ~ $ <b>sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0/bin/javac 1</b>
</pre>
<br />
One more thing to - setting which java alternative should be used:<br />
<pre>myuser@raspberrypi ~ $ <b>sudo update-alternatives --config java</b>
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java 1063 auto mode
1 /usr/lib/jvm/java-7-openjdk-armhf/jre/bin/java 1063 manual mode
2 /usr/lib/jvm/jdk1.8.0/bin/java 1 manual mode
Press enter to keep the current choice[*], or type selection number: <b>2</b>
myuser@raspberrypi ~ $ <b>sudo update-alternatives --config javac</b>
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-openjdk-armhf/bin/javac 1063 auto mode
1 /usr/lib/jvm/java-7-openjdk-armhf/bin/javac 1063 manual mode
2 /usr/lib/jvm/jdk1.8.0/bin/javac 1 manual mode
Press enter to keep the current choice[*], or type selection number: <b>2</b>
</pre>
<br />
Version check is simple:<br />
<pre>myuser@raspberrypi ~ $ <b>java -version</b>
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b36e)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)
</pre>
<br />
Last thing to is is changing jetty configuration. I did that, and for now everything seems to work fine.jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-43087656479785269282013-01-05T21:32:00.003+01:002013-01-05T21:32:32.665+01:00New Year's ResolutionNew year has come and with many New Year's Resolutions I've made one affecting this blog, namely I would like to try writing my posts in English (naturally I would like to translate all previous entries as well).<br />
Why? There are many reasons. First of all I have to improve it. Not only my blog naturally ;) I haven't used written English for a long time (come on, short e-mails at work do not count). Besides, I really like this language and don't treat it as a tool. <br />
Moreover, maybe I write something valuable one day... I that case more people could use that information (whatever).<br />
<br />
At least my primordial assumption that this blog serves mainly me, is still valid.<br />
<br />
Enjoy!jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-57312822328981776452012-12-27T18:32:00.000+01:002013-01-06T15:49:11.934+01:00Logging to Raspberry without passwordOnce upon a time I was spending a lot of time working with Linux servers. It's a distant past, but I still can recall some tips. One of them, quite useful when it comes to playing with RPi, is logging without password. I don't mean to give up passwords and allow anyone to enter my realms, but rather to automate the whole process from trusted machine.<br />
<br />
How to achieve that?<br />
<br />
On your workstations you need to generate authentication keys:<br />
<pre>myuser@myhost:~$ <b>ssh-keygen </b>
Generating public/private rsa key pair.
Enter file in which to save the key (/home/myuser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): <ENTER>
Enter same passphrase again: <ENTER>
Your identification has been saved in /home/myuser/.ssh/id_rsa.
Your public key has been saved in /home/myuser/.ssh/id_rsa.pub.
The key fingerprint is:
2d:2c:d5:d1:cc:cc:1a:aa:a3:11:28:da:1b:1a:2a:3a
</pre><br />
<br />
When you have them, the next step is copying your public key to RPi:<br />
<pre>myuser@myhost:~$ <b>ssh-copy-id -i ~/.ssh/id_rsa.pub myuser@raspberrypi</b>
myuser@raspberrypi's password:
Now try logging into the machine, with "ssh 'myuser@raspberrypi'", and check in:
~/.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
</pre><br />
And that's all. <br />
From now on you will be automatically logged to your precious board. <br />
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-71513529155359144882012-12-26T10:17:00.000+01:002012-12-27T22:52:24.012+01:00Malinowo :) W tym roku Mikołaj był przesłodki. Jak malina. Więc zaczyna się zabawa z nową płytką, czyli Raspberry Pi. Oby tylko czasu starczyło...<br />
<br />
Pracę z Raspberry Pi wypada rozpocząć od przygotowania karty SD. Minimalny rozmiar karty do 2GB, ja użyję 8GB klasy 10.<br />
<br />
Po włożeniu karty do czytnika, sprawdzamy urządzenie skojarzone z kartą:<br />
<pre>df -h</pre><div><br />
Zakładajac, że jest to sdb, należy odmontować kartę:</div><pre>sudo umount /dev/sdb1</pre>a następnie za pomocą dd skopiować obraz na kartę<br />
<pre>sudo dd bs=1M if=./2012-12-16-wheezy-raspbian.img of=/dev/sdb</pre>Pomimo wielu zalet, dd ma zasadniczą wadę - nie informuje o postępie kopiowania. Jednakże można zmusić dd do współpracy. Najpierw trzeba poznać PID procesu. W tym celu otwieramy drugą konsolę:<br />
<pre>ps aux | grep dd.*wheez</pre>a następnie wysłać sygnał do procesu:<br />
<pre>sudo kill -USR1 <PID></pre>W pierwszej konsoli dd łaskawie ujawni swoje tajemnice:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-4Lhz7CFgWy4/UNmpHdiir8I/AAAAAAAAHW4/87FIl4fady4/s1600/dd_output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="65" src="http://4.bp.blogspot.com/-4Lhz7CFgWy4/UNmpHdiir8I/AAAAAAAAHW4/87FIl4fady4/s400/dd_output.png" width="400" /></a></div><br />
Kiedy karta jest gotowa, można za pomocą Gparted rozszerzyć partycję, tak by zajmowała całą kartę, jednakże nie jest to konieczne. Przy pierwszym starcie uruchomi się raspi-config, który umożliwia wstępną konfigurację malinki:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-TSsUSpRv8kY/UNwF4669AnI/AAAAAAAAHXI/p7loneQo6zk/s1600/rconfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="http://3.bp.blogspot.com/-TSsUSpRv8kY/UNwF4669AnI/AAAAAAAAHXI/p7loneQo6zk/s400/rconfig.png" width="400" /></a></div><br />
Z przydatnych ustawień:<br />
<ul><li>expand_rootfs</li>
<li>change_pass</li>
<li>change_locale</li>
<li>change_timezone</li>
<li>ssh</li>
<li>boot_behaviour</li>
</ul>Jeśli czegoś nie ustawimy, można konfigurator uruchomić ponownie:<br />
<pre>sudo raspi-config</pre>Po zakończeniu konfiguracji można się zalogować do systemu.<br />
<br />
Pierwszym krokiem po uruchomieniu, jest nadanie stałego IP.<br />
W pliku <i>/etc/network/interfaces</i> należy wpisać (wybierając odpowiednie IP :) )<br />
<pre>auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.10
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
# w moim przypadku nie używam sieci bezprzewodowej
#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
</pre><br />
Jeśli nie chcemy używać domyślnego użytkownika (pi), można dodać własnego:<br />
<pre>sudo adduser myuser</pre>A następnie nadać mu nieco większe uprawnienia:<br />
<pre>sudo visudo</pre>wpisując<br />
<pre>myuser ALL=(ALL) NOPASSWD: ALL</pre><br />
Możemy jeszcze dodać naszego użytkownika do tych samych grup, do których należy pi. W tym celu (bedąc zalogowanym jako pi) wykonujemy polecenie:<br />
<pre>sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input myuser</pre>albo mniej zrozumiałe polecenie:<br />
<pre>sudo usermod -a -G `groups | sed -e 's/pi //g;s/ /,/g'` myuser</pre><br />
Po przelogowaniu się na naszego nowego użytkownika możemy sprawdzić czy się udało:<br />
<pre>groups</pre><br />
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-23076075170790341852012-12-11T20:23:00.001+01:002012-12-11T20:44:11.719+01:00Szeregowo i kolorowo...Dużo czasu minęło od ostatniego posta... Spręża brak, więc na dobry początek coś łatwego, szybkiego i... mało potrzebnego.<br />
<br />
Potrzebowałem zobaczyć, jak skomplikowane jest komunikowanie się aplikacji uruchomionej na komputerze z Arduino. Oczywiście wybór padł na złącze szeregowe :/<br />
<br />
Pytanie, czym sterować, żeby się nie narobić... Albo serwo, a może jakaś dioda? A może dioda RGB? Akurat miałem pod ręką małe trójkolowe coś w wersji smd, więc...<br />
<br />
Najpierw mała aplikacja w Processingu, ot trzy suwaki...<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-ftfcc7Iyl2U/UMeDJkkY3JI/AAAAAAAAHVs/krmV4IElYKE/s1600/suwaki.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://4.bp.blogspot.com/-ftfcc7Iyl2U/UMeDJkkY3JI/AAAAAAAAHVs/krmV4IElYKE/s320/suwaki.jpg" width="157" /></a></div>
<br />
Każdy z "suwaków" aktualizuje poszczególne składowe, które następnie są łączone w jeden łańcuch i wysyłane przez port szeregowy do Arduino:<br />
<br />
<pre class="brush:cpp">float mr = map(r, 0, 255, 0, 255);
float mg = map(g, 0, 255, 0, 255);
float mb = map(b, 0, 255, 0, 255);
String rgbString = str((int)mr) + " " + str((int)mg) + " " + str((int)mb) + "\n";
print("rgbString:"); println(rgbString);
port.write(rgbString);
</pre>
<br />
Arduino zaś odbiera łańcuch i parsuje poszczególne składowe:<br />
<br />
<pre class="brush:cpp">if (Serial.available() > 0) {
redValue = Serial.parseInt();
greenValue = Serial.parseInt();
blueValue = Serial.parseInt();
if (Serial.read() == '\n') {
redValue = constrain(redValue, 0, 255);
greenValue = constrain(greenValue, 0, 255);
blueValue = constrain(blueValue, 0, 255);
analogWrite(redPin, redValue);
analogWrite(greenPin,greenValue);
analogWrite(bluePin, blueValue);
}
}
</pre>
<br />
Próby wysyłania poszczególnych składowych osobno, jako sekwencja bajtów, się nie sprawdziła, więc póki co pozostaje tworzenie łańcucha znaków...<br />
<br />
A działa to mniej więcej tak:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-9Ug5zkO9GWQ/UMeIDPiqw8I/AAAAAAAAHV8/5klESIqMGG8/s1600/rgb.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="288" src="http://4.bp.blogspot.com/-9Ug5zkO9GWQ/UMeIDPiqw8I/AAAAAAAAHV8/5klESIqMGG8/s320/rgb.png" width="320" /></a></div>
<br />
Kody źródłowe:<br />
<ul>
<li><a href="https://docs.google.com/open?id=0B3aizVidmymIcEFVUm9Bd0MweVU">processing</a></li>
<li><a href="https://docs.google.com/open?id=0B3aizVidmymIbXhYb0wweVVsS2s">arduino</a></li>
</ul>
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-56547839703026162202012-09-30T21:02:00.002+02:002012-09-30T21:10:08.836+02:00Tribute to Johny FiveWszyscy znają robota o imieniu Wall-e, ale czy ktoś jeszcze pamięta Jasia Piątkę, czyli Johny'ego Five?<br />
Od razu uprzedzę - nie będę budować repliki w/w robotów, przynajmniej nie w najbliższym czasie ;)<br />
Przywołuję jednak bohatera filmu "Krótkie spięcie" z 1986 r. ze względu na prosty "bajer" - linijkę diodową, która miała wizualizować aparat mowy, takie sztuczne usta. Na tyle charakterystyczny efekt, a do tego prosty, że mój pierwszy robot, jak już powstanie, będzie go mieć :)<br />
<br />
Do budowy tego efektu wydaje mi się, że najprościej jest zastosować miernik wysterowania. W sprzedaży jest wiele układów realizujących tę funkcjonalność, ja wybrałem AN6884 ze względu na minimalną ilość elementów dodatkowych, jak i małą liczbę diód - tylko 5.<br />
<br />
Schemat pochodzi ze specyfikacji technicznej układu:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-iko3h_H3s74/UGfWWB6GEBI/AAAAAAAAHUo/kzq92fViUH8/s1600/ustarobota.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="255" src="http://2.bp.blogspot.com/-iko3h_H3s74/UGfWWB6GEBI/AAAAAAAAHUo/kzq92fViUH8/s400/ustarobota.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Diody na schemacie w rzeczywistości to 10-cio segmentowy słupkowy wyświetlacz LED. Diody są połączone równolegle, tak by wyświetlana linijka była symetryczna. Napięcie zasilania może się wahać od 3.5V do 16V, więc 5V dostarczane przez Arduino w zupełności wystarczy.</div>
<div class="separator" style="clear: both; text-align: left;">
A efekt?</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/SvZ8I2lHtSU?feature=player_embedded' frameborder='0'></iframe></div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Pokrótce wyjaśnię działanie tej plątaniny: Arduino za pomocą czujnika ultradźwiękowego HC-SR04 odczytuje odległość przedmiotu przed czujnikiem, a następnie werbalizuje tę odległość odtwarzając odpowiednie pliki WAV za pomocą WaveShielda, z którego wyjścia jest również brany sygnał do AN6884. Pliki wygenerowałem programem GeSpeaker. </div>
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-67119107153854587942012-07-30T20:55:00.002+02:002012-07-30T22:34:37.783+02:00WaveShield na płytce prototypowej"Shielda" do odtwarzania plików wav na Arduino można kupić. W tym celu musimy przeznaczyć ok 75 złotych, zakładając że układ dostaniemy. Możemy też zbudować sami, niespecjalnie się wysilając, a co ważniejsze płacąc nieco mniej, że o zabawie nie wspomnę :)<br />
<br />
Wszystkie potrzebne elementy, instrukcję itd znajdziemy na <a href="http://www.ladyada.net/make/waveshield/">stronie układu</a>., więc nie będę szczegółowo wymieniał, co jest konieczne , może tylko najważniejsze elementy:<br />
<ul>
<li>złącze do kart SD (~5 PLN)</li>
<li>układ 74HC125 (~1 PLN)</li>
<li>12 bitowy przetwornik DAC - MCP4921 (~10 PLN)</li>
<li>wzmaczniacz TS922IN (~5 PLN)</li>
</ul>
<div>
Jak widać całość wyniesie nieco ponad 20 złotych. Chyba zatem warto się pokusić o chociażby wypróbowanie shielda, montując go na płytce prototypowej. </div>
<div>
Prawdę mówiąc część modułu można wykonać sobie wcześniej, wystarczy spojrzeć na poprzedni post, a czytnik kart SD może sobie leżeć na podorędziu i być pomocnym w różnych przypadkach, także wtedy, gdy chcemy zachęcić Arduino do muzykowania, mówienia itp.</div>
<div>
<br /></div>
<div>
Schemat układu bez czytnika kart SD (w oparciu o <a href="http://www.ladyada.net/images/wavshield/v11/wave11schem.png">oryginalny projekt</a>):</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-zLLQM3tN0qk/UBLijj4EleI/AAAAAAAAHTA/NcvYe4lqMiQ/s1600/waveshield.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="157" src="http://1.bp.blogspot.com/-zLLQM3tN0qk/UBLijj4EleI/AAAAAAAAHTA/NcvYe4lqMiQ/s400/waveshield.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Przetwornik MCP łączymy z Arduino następująco:</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul>
<li>CS do pinu D2 (Digital 2)</li>
<li>SCK do pinu D3</li>
<li>SDI do pinu D4</li>
<li>LDAC do pinu D5</li>
</ul>
<div>
Karta SD jest podłączana do Arduino prawie tak samo, jak w poprzednim poście. Wyjątek stanowi pin CS karty, który uprzednio był podłączony do pinu D4, teraz zaś musi być podłączony do pinu D10.</div>
<div>
<br /></div>
Po zmontowaniu cały układ wygląda następująco:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-rDoONxXsYjQ/UBbUtiK7o0I/AAAAAAAAHTU/QsnQ4YFRyR8/s1600/2012-07-30+20.30.13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="186" src="http://3.bp.blogspot.com/-rDoONxXsYjQ/UBbUtiK7o0I/AAAAAAAAHTU/QsnQ4YFRyR8/s320/2012-07-30+20.30.13.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
A to takie "Hello World" - kod programu wziąłem z przykładu dołączonego do biblioteki WaveHC (PiSpeakHC), zmieniając jedynie nazwę pliku do odtworzenia (pozbywszy się uprzednio logiki związanej z deklamacją liczby PI):<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/mjm-h0ZvfqU?feature=player_embedded' frameborder='0'></iframe><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<br /></div>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-87904182981000076182012-07-25T23:55:00.006+02:002012-07-27T21:47:21.215+02:00Karta SD (a miał być Robot)Roboty lubią zarówno mali chłopcy, ci więksi jak i ci naprawdę duzi. Przynajmniej większość "chłopców", których znam. Z reguły lubią się bawić robotami, ale są też tacy, których bawi/bawiłoby stworzenie takiego "cudeńka". Mógłbym napisać, że jestem w tej drugiej grupie, ale... Poza "Wallym" nie zrobiłem jeszcze całego robota. Przy okazji, to jest Wally:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-3_XS0-4fLuo/UBAScK9FUrI/AAAAAAAAHRw/WMtAZNkqmlU/s1600/wally.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="http://4.bp.blogspot.com/-3_XS0-4fLuo/UBAScK9FUrI/AAAAAAAAHRw/WMtAZNkqmlU/s400/wally.jpg" width="382" /></a></div>
<br />
Nie dość, że miał dość ograniczone funkcje, to do tego byłem jedynie pomocnikiem.<br />
Byłoby sympatycznie samemu coś "wydziergać". Póki co niestety kończy się na "byłoby sympatycznie". Ale... Pojawiło się światełko w tunelu, choć wcale roboty nie były mi wtedy w głowie. Szukałem sposobów odtwarzania dźwięku przez Arduino. Spośród znalezionych rozwiązań spodobały mi się dwa:<br />
<ul>
<li><a href="http://www.sparkfun.com/products/9578">SpeakJet</a></li>
<li><a href="http://www.ladyada.net/make/waveshield/index.html">WaveShield</a> dla Arduino</li>
</ul>
<div>
Niestety, póki co nie udało mi się dostać układu SpeakJet, więc pozostaje WaveShield. Nie żeby był gorszy, po prostu części są dostępne, co więcej - nie ma potrzeby sięgania po SMD!</div>
<div>
W zasadzie nie ma problemów ze zmontowaniem układu do momentu zabrania się za czytnik kart SD. Można kupić, można spróbować samemu zrobić. Co wybrać...</div>
<div>
Cóż, wybrałem ciemną stronę mocy i powstało to:</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-tVE5CWa4o3w/UBBRjRAarUI/AAAAAAAAHR8/fzhRjVjUKus/s1600/2012-07-25+17.52.02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://4.bp.blogspot.com/-tVE5CWa4o3w/UBBRjRAarUI/AAAAAAAAHR8/fzhRjVjUKus/s320/2012-07-25+17.52.02.jpg" width="320" /></a></div>
</div>
<div>
<br /></div>
<div>
Płytka była projektowana późnym wieczorem i drapana, do tego jeszcze miała błędy, a że do tego specjalnie estetyczna nie jest, więc daruję sobie wrzucanie projektu. Powiedzmy że gotowy układ realizuje poniższy schemat,</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-f__Y85GwgOQ/UBBRvQ58zzI/AAAAAAAAHSE/YabdynbLSdg/s1600/sdcardreader.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://4.bp.blogspot.com/-f__Y85GwgOQ/UBBRvQ58zzI/AAAAAAAAHSE/YabdynbLSdg/s400/sdcardreader.png" width="400" /></a></div>
<br /></div>
<div>
który wziąłem ze strony <a href="http://www.ladyada.net/images/wavshield/v11/wave11schem.png">shielda</a>, a układ wyjść wygląda tak:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-1_-Vpk46HVA/UBBcmnpvx-I/AAAAAAAAHSY/KrleVycd_eI/s1600/sdreader.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="201" src="http://3.bp.blogspot.com/-1_-Vpk46HVA/UBBcmnpvx-I/AAAAAAAAHSY/KrleVycd_eI/s320/sdreader.png" width="320" /></a></div>
<br /></div>
<div>
Ironicznie, ciesząc się że nie ma konieczności sięgania po SMD, znalazłem w swoich zasobach tylko jeden układ 74HC125, właśnie w takiej postaci :/.</div>
<div>
<br />
Moduł czytnika kart SD podłączamy następująco:<br />
<ul>
<li>MOSI do pinu 11</li>
<li>MISO do pinu 12</li>
<li>CLK do pinu 13</li>
<li>MMC_CS do pinu 4</li>
</ul>
<div>
Powyższy układ działa na Arduino 2009, Nano itp.</div>
<div>
<br /></div>
<div>
Po podłączeniu układ wygląda następująco:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-5Lx0F6Gkm5o/UBBngKUwmoI/AAAAAAAAHSk/0EtUa4oenz0/s1600/sdconnected.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="185" src="http://4.bp.blogspot.com/-5Lx0F6Gkm5o/UBBngKUwmoI/AAAAAAAAHSk/0EtUa4oenz0/s320/sdconnected.jpg" width="320" /></a></div>
<div>
<br /></div>
</div>
<div>
<br /></div>
<div>
Z biblioteki SD wybieramy przykład "CardInfo", wgrywamy i po uruchomieniu możemy dostać coś podobnego:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-fW3FKaJu8CQ/UBBozB9J9CI/AAAAAAAAHSs/-BqugCt_zAY/s1600/Zrzut+ekranu+z+2012-07-25+23:41:26.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="208" src="http://1.bp.blogspot.com/-fW3FKaJu8CQ/UBBozB9J9CI/AAAAAAAAHSs/-BqugCt_zAY/s320/Zrzut+ekranu+z+2012-07-25+23:41:26.png" width="320" /></a></div>
<br />
<br /></div>
I zasadniczo tyle. Post zaczynał się szumnie aluzją do robienia robotów, miał pierwotny tytuł "Robot cz. 1" i... ani się obejrzałem już północ. O robotach coś na pewno będzie :)<br />
Niestety, gdybym chciał wrzucić wszystko co planowałem w jeden post, sam bym się potem pogubił, więc nieco lepiej będzie podzielić całość na małe części. A oto co nas jeszcze czeka:<br />
<br />
<ul>
<li><span style="background-color: white;">"aparat głosowy", czyli WaveShield</span></li>
<li><span style="background-color: white;">usta robota, czyli co można zrobić z AN6884</span></li>
<li><span style="background-color: white;">oczy robota, czyli moduł HC-SR04.</span></li>
</ul>
<div>
Zatem... CDN</div>
<br />
<br />jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-68926751202411825582012-07-22T09:40:00.001+02:002012-07-24T20:56:48.836+02:00BMA180 i Arduino cz. 1Jakiś czas temu zakupiłem moduł z akcelerometrem <a href="http://nettigo.pl/products/99">BMA180</a>. Jednakże od początku były jakieś "ale". Pierwsza sprawa to cyfrowy interfejs - nie wystarczy mierzyć napięć, trzeba być dość rozmownym, by wydostać dane z układu. Drugim problemem był brak biblioteki dedykowanej na Arduino. Co prawda w sieci znalazłem nieoficjalne wsparcie, ale... Dlaczegóż by nie napisać czegoś samemu? No i trzeci problem - niezgodniość poziomów logicznych. Układ BMA180 pracuje w logice 3.3V, natomiast Arduino w 5V.<br />
<br />
Jak mawiają ludy anglojęzyczne "first things first" - jeśli chcemy używać układu trzeba mieć <a href="http://nettigo.pl/products/126">konwerter</a>. Można go zakupić, zresztą wiele nie kosztuje, ale dostawa chwilę trwa. Można zbudować, schemat jest dostępny na stronie <a href="http://www.sparkfun.com/datasheets/BreakoutBoards/Level-Converter-v10.pdf">producenta</a>, ale... Trzeba mieć odpowiednie tranzystory. Jak się okazało tranzystorów BSS138 nie mogłem dostać w znanych mi wrocławskich sklepach, więc trzeba było improwizować. Z tego typu tranzystorów łatwo dostać BS170, więc...<br />
<br />
Schemat ideowy części konwertera:<br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-AIIGktU2UwM/UAwRta_ClNI/AAAAAAAAHQw/O2itqgmrX1E/s1600/logicConverter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="http://3.bp.blogspot.com/-AIIGktU2UwM/UAwRta_ClNI/AAAAAAAAHQw/O2itqgmrX1E/s400/logicConverter.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">A moduł wygląda tak:</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-Hv9YSQ1CPDM/UArz1iaGvDI/AAAAAAAAHQQ/mYsmYhkPsE8/s1600/bma180_v2_breadboard.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="100" src="http://4.bp.blogspot.com/-Hv9YSQ1CPDM/UArz1iaGvDI/AAAAAAAAHQQ/mYsmYhkPsE8/s200/bma180_v2_breadboard.png" width="200" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Przed rozpoczęciem pracy z modułem trzeba się zdecydować, przez jaki interfejs będziemy się komunikować z układem. Mamy do dyspoz<span style="background-color: white;">y</span><span style="background-color: white;">cji SPI (4 przewody) i I<sup>2</sup>C (2 przewody). Osobiście wolę </span>I<sup>2</sup>C, więc dalsze rozważania będą brać po uwagę tylko ten interfejs.</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Jeśli chcemy włączyć komunikację po I<sup>2</sup>C, wystarczy na pinie CS ustawić stan wysoki (jak się można domyślić, stan niski przełącza komunikację na SPI).</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Kompletny schemat układu poniżej:</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-la6t4UMZ4mc/UAwR4yCpzBI/AAAAAAAAHQ4/5Y_u0cScy7E/s1600/bmawiiw.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="221" src="http://3.bp.blogspot.com/-la6t4UMZ4mc/UAwR4yCpzBI/AAAAAAAAHQ4/5Y_u0cScy7E/s400/bmawiiw.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: left;">Po podłączeniu otrzymujemy coś takiego:</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-aPdacdZO4gU/UAwi541A6oI/AAAAAAAAHRE/Pxn18y5-aoQ/s1600/2012-07-22+17.46.58.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://3.bp.blogspot.com/-aPdacdZO4gU/UAwi541A6oI/AAAAAAAAHRE/Pxn18y5-aoQ/s400/2012-07-22+17.46.58.jpg" width="400" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">Najmniej skomplikowanym sposobem weryfikacji połączenia jest odpytanie układu o jego ID:</div><blockquote class="tr_bq"><br />
<pre class="brush:cpp">#include <arduino.h>
#include <wire.h>
#define BMA180_ADDR 0x40
#define CHIP_ID 0x00
byte val;
void setup() {
Serial.begin(9600);
Wire.begin();
val = readI2C((uint8_t)CHIP_ID);
Serial.print("CHIP_ID=");
Serial.println(val);
}
void loop() {
}
byte readI2C(uint8_t offset) {
byte val;
Wire.beginTransmission(BMA180_ADDR);
Wire.write((uint8_t)offset);
Wire.endTransmission();
Wire.requestFrom(BMA180_ADDR, 1);
while (Wire.available()) {
val = Wire.read();
}
return val;
}
</wire.h></arduino.h></pre><br />
<div style="text-align: left;"><span style="background-color: white;">Je</span><span style="background-color: white;">śli w terminalu otrzymam wartość CHIP_ID=3,</span></div></blockquote><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-MjwhIpZtwAk/UAwm5H1-ZkI/AAAAAAAAHRQ/MsaDa6EEyIg/s1600/Zrzut+ekranu+z+2012-07-22+18:10:36.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://2.bp.blogspot.com/-MjwhIpZtwAk/UAwm5H1-ZkI/AAAAAAAAHRQ/MsaDa6EEyIg/s320/Zrzut+ekranu+z+2012-07-22+18:10:36.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"> możemy zaczynać bardziej skomplikowane zabawy z akcelerometrem. </div>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com1tag:blogger.com,1999:blog-8113178159611726804.post-46731926227702364272012-07-16T21:35:00.000+02:002013-01-10T13:00:51.254+01:00Arduino Nano po polskuW ostatnim poście pisałem o tanim Arduino na mikrokontrolerze Atmega8. Moduł jest tani, bo koszt całości zamyka się w 20 zł, ale nieco bardziej uciążliwy w użyciu, jeśli chcemy szybko prototypować. Na szczęście AVT wypuściło inny kit - <a href="http://sklep.avt.pl/p/pl/493946/minimodul+z+atmega8+-+plytka+drukowana.html">AVT 1622 - Minimoduł z Atmega8</a><br />
Układ ten, w odróżnieniu od poprzedniego, posiada wbudowany konwerter UART<->USB, zatem może być używany prawie jak oryginalne Arduino Nano.<br />
<br />
Decydując się na zakup kitu, wybieram samą płytkę. Choćby dlatego, że finalnie będzie to minimoduł z Atmegą 328.<br />
<br />
Lista potrzebnych elementów:<br />
<ul>
<li>płytka drukowana modułu </li>
<li>Atmega328</li>
<li>FT232RL</li>
<li>78M05 (TO252)</li>
<li>3x 470om 0805</li>
<li>10k 0805</li>
<li>2x 1k 0806</li>
<li>2x 10mikroF . 16V</li>
<li>4x 100nF 0805</li>
<li>2x 22pF 0805</li>
<li>niski kwarc 16 MHz</li>
<li>diody led smd 0805 - zielona, czerwona, żółta</li>
<li>gniazdo mini usb</li>
<li>goldpiny</li>
</ul>
<br />
<div>
Instrukcja kitu zaleca rozpoczęcie montażu od mikrokontrolera, kondensatorów i diod LED na jednej stronie. W kolejnym kroku FT232, stabilizator, rezystory i kontensatory po drugiej stronie, a na końcu gniazdo USB i goldpiny.<br />
Lutowanie elementów smd jest relatywnie proste, nawet dla takiego początkującego jak ja, jeśli się ma pod ręką plecionkę lutowniczą:<br />
<br />
<br />
<object style="height: 390px; width: 640px;"><param name="movie" value="http://www.youtube.com/v/IhDsNbqIToc?version=3&feature=player_detailpage"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/IhDsNbqIToc?version=3&feature=player_detailpage" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="320" height="180"></object> </div>
<div>
<br />
Po zlutowaniu moduł wygląda tak: <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ELQWUvGard0/UAcNoUN2mHI/AAAAAAAAHPA/Cr_CZkmePHE/s1600/img_1958.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="150" src="http://1.bp.blogspot.com/-ELQWUvGard0/UAcNoUN2mHI/AAAAAAAAHPA/Cr_CZkmePHE/s200/img_1958.jpg" width="200" /></a></div>
<br />
Jeszcze można zauważyć mnóstwo kalafonii po "odsączaniu" nadmiaru cyny. Ważne, że sposób działa... </div>
<div>
Po zakończeniu lutowania można moduł podłączyć do komputera - powinna świecić się zielona dioda (PWR), a diody RX i TX pobłyskiwać od czasu do czasu. Dodatkowo, w IDE powinien pojawić się nowy port. Jeśli nic takiego się nie dzieje, trzeba sprawdzić, czy np drobinki lutu nie zwierają pinów złącza USB czy też układów sclaonych. Nim wgramy bootloader sprawdźmy FUSE bity: <br />
<pre>avrdude -p m328p -c stk500v2 -P /dev/ttyACM0 -U lfuse:r:-:h -U lfuse:r:-:b -U hfuse:r:-:h -U hfuse:r:-:b </pre>
i otrzymujemy: <br />
<pre>avrdude: Device signature = 0x1e950f
reading lfuse memory: 0x62
reading hfuse memory: 0xd9 </pre>
<br />
Teraz możemy wgrać bootloader. Podłączamy moduł do programatora i za pomącą IDE ładujemy oprogramowanie. Możemy sprawdzić FUSE bity ponownie. To co powinniśmy otrzymać to 0xff (lfuse) i 0xda (hfuse). </div>
Mogłoby się wydawać, że to już koniec. Niestety nie. Próba załadowania programu z IDE z reguły skończy się komunikatem: <br />
<pre>Binary sketch size: 1,084 bytes (of a 30,720 byte maximum) avrdude: stk500_recv(): programmer is not responding </pre>
<code></code>Nasze nowe Arduino będzie trudno programować przez USB, gdyż moduł dostarczany przez AVT nie posiada możliwości autoresetu, co więcej przycisku RESET też na płytce nie ma. O ile drugi problem można usunąć przez podłączenie zewnętrznego przycisku do resetowania układu, o tyle ja osobiście wolę nic nie naciskać. Prostym rozwiązaniem jest dodanie połączenia pinu DTR# układu FT232RL poprzez kondensator 100nF z pinem RESET mikrokontrolera. Do tego celu najlepiej użyć bardzo cienkiego przewodu, choć jak nie ma nic pod ręką, można użyć przewodu ze skrętki: <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-JdnxOPAns8M/UAclEE9u8ZI/AAAAAAAAHPQ/TyNwLhNQFOU/s1600/autorst.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="215" src="http://4.bp.blogspot.com/-JdnxOPAns8M/UAclEE9u8ZI/AAAAAAAAHPQ/TyNwLhNQFOU/s400/autorst.jpg" width="400" /></a></div>
Moje lutowanie wygląda tak: <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-ZRvGvmaYH2Q/UAcmJLSfT5I/AAAAAAAAHPc/7eK3LrswM08/s1600/img_1963.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://1.bp.blogspot.com/-ZRvGvmaYH2Q/UAcmJLSfT5I/AAAAAAAAHPc/7eK3LrswM08/s400/img_1963.jpg" width="400" /></a></div>
<br />
Może nie najwyższych lotów, ale nie ma zwarć, a wgrywanie programów nie stanowi już żadnego problemu. <br />
<br />
Mapa pinów modułu: <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-lnCimM9_HOo/UAf2KCcAfoI/AAAAAAAAHP0/aN-zlz-TWWU/s1600/avt_1622_with_atmega328.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-lnCimM9_HOo/UAf2KCcAfoI/AAAAAAAAHP0/aN-zlz-TWWU/s320/avt_1622_with_atmega328.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-7760221737180556752012-07-03T21:53:00.000+02:002012-07-22T19:01:12.968+02:00Niedrogie Arduino na Atmega8Od pewnego czasu "bawię" się Arduino. Prosty sposób, by osoba nie mająca doświadczenie z mikrokontrolerami mogła się nimi zająć, bez żmudnego wgryzania się w detale. <br />
Jednakże kiedy przychodzi moment, że trzeba przejść od prototypu to finalnego produktu, robi się problem. Najlepiej by było zaprojektować płytkę dedykowaną pod konkretne rozwiązanie. Ale kto ma czas? A co jeśli za jakiś czas zrezygnuję z budowanego urządzenia? Itd, itp...<br />
Można użyć Arduino... Ale raz że duże, dwa - ciut drogie. Na szczęście niedrogie rozwiązanie istnieje; jest to wypuszczony przez AVT kit AVT2892/2 - minimoduł z mikrokontrolerem Atmega8. <br />
Można zamówić cały kit, ale ja zamawiam tylko płytkę - z reguły atmegę mam, a poza kwarcem nic innego nie potrzebuję (ale o tym za chwilę).<br />
<br />
Składanie modułu nie jest specjalnie trudne, nawet osoba nie mająca doświadczenia w lutowaniu SMD powinna sobie poradzić. <br />
<br />
Moja lista elementów:<br />
<br />
<ul><li><span style="background-color: white;">płytka</span></li>
<li><span style="background-color: white;">Atmega8A</span></li>
<li><span style="background-color: white;">kwarc 16MHz</span></li>
<li><span style="background-color: white;">2x 22pF 0806</span></li>
<li><span style="background-color: white;">goldpiny</span></li>
</ul><span style="background-color: white;">Nie lutuje z reguły układu stabilizatora, bo zasilanie to najczęściej osobna sprawa.</span><br />
<br />
Po zlutowanie otrzymujemy zgrabny moduł, którego konfiguracja pinów wygląda następująco:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-XcjpRhfIvTU/T_tAQAWRN2I/AAAAAAAAHNw/cPUAt-u4374/s1600/at8_white.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="190" src="http://3.bp.blogspot.com/-XcjpRhfIvTU/T_tAQAWRN2I/AAAAAAAAHNw/cPUAt-u4374/s320/at8_white.png" width="320" /></a></div><br />
<br />
Kolejnym krokiem jest przygotowanie programatora - jakby nie patrzeć będzie potrzebny, gdyż albo będę używać modułu USB<->RS232, a to wymaga bootloader, albo wgrywać programy bezpośrednio, co wymaga programatora. <br />
Osobiście używam AVRPROG v2 (firmy AndTech). Z początku nie chciało działać, ale po chwili odgadłem powód - niepoprawna konfiguracja w pliku programmers.txt :<br />
<div><code><br />
<span style="font-family: 'Courier New', Courier, monospace;"> avrisp.name=AVR ISP<br />
avrisp.communication=serial<br />
#oryginalna wartość: stk500v1<br />
avrisp.protocol=stk500v2<br />
</span></code></div><br />
Teraz tylko upload bootloadera, co warto wykonać, bez względu na to, jak będziemy w przyszłości wgrywać programy. Po prostu zostaną ustawione FUSE bity :)<br />
<br />
A zweryfikowć FB można następująco:<br />
<div><code><br />
<span style="font-family: 'Courier New', Courier, monospace;"> avrdude -p atmega8 -c stk500v2 -P /dev/ttyACM0 -U lfuse:r:-:h -U lfuse:r:-:b -U hfuse:r:-:h -U hfuse:r:-:b</span></code><br />
<code><span style="font-family: 'Courier New', Courier, monospace;"><br />
</span></code><br />
<code><span style="font-family: inherit;">Powinniśmy otrzymać: </span></code></div>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-19408878391817821692012-05-14T12:27:00.000+02:002012-12-27T22:13:28.003+01:00Zmiana hasła w AD w konsoli linuksowejHasło użytkownika w AD z konsoli linuksowej można zmienić następująco:<br />
<pre>smbpasswd -r kontroler_domeny -U username </pre>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-16806102622218237622012-05-13T11:17:00.002+02:002012-12-27T22:18:27.407+01:00Arduino na LinuxieInstalacja Arduino IDE na linuxie do skomplikowanych nie należy... <br />
<ul><li>Pobrać paczkę z arduino.cc</li>
<li>Rozpakować w wybranej lokalizacji (ja preferuje /opt/apps/) </li>
<li>Pobrać i zainstalować gcc-avr i avr-libc <br />
<code> sudo apt-get install gcc-avr avr-libc</code> </li>
<li>I niby wszystko powinno działać. Jednakże może się okazać, że nie można wybrać z IDE portu USB. <br />
Wtedy należy dodać swojego użytkownika do grupy dialout: <br />
<pre>sudo usermod -aG dialout username </pre></li>
</ul>Voila!<br />
<br />
A przynajmniej tak było do wersji 1.0. Kolejna wersja ma coś sknoconego, podczas próby uruchomienia rzucany jest wyjątek:<br />
<pre>java.lang.IllegalArgumentException: Illegal pattern character 'r'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
at java.text.SimpleDateFormat.
(SimpleDateFormat.java:585)</pre><br />
Taaak.... <br />
Rozwiązanie 1: przed uruchomieniem arduino wykonać w konsoli:<br />
<pre>export LANG=en_US.UTF-8</pre><br />
<br />
jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-8427609703356828512012-05-10T14:34:00.000+02:002012-12-27T22:14:58.028+01:00Environment VariablesZmienne środowiskowe na windows można na szczęście zapisać:<br />
<br />
zmienne sytemowe:<br />
<pre>reg save "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" env_var_system.bkp</pre><br />
zmienne użytkownika:<br />
<pre>reg save "HKCU\Environment" env_var_user.bkp</pre><br />
Odtwarzanie zmiennych można uzyskać wykonując odpowiednio:<br />
<pre>reg restore env_var_system.bkp</pre><pre>reg restore env_var_user.bkp</pre>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-4277247717342885472012-05-08T15:10:00.000+02:002012-12-27T22:14:05.395+01:00Transcoding"Za moich czasów" ASCII było wystarczającym kodowaniem, ba, wiele znaków znałem na pamęć (wiem, geekowate :) )<br />
<br />
Obecnie kodowań "jak mrówków". Na szczęście na linuxie można zmienić kodowanie bardzo prosto, za pomocą prostego narzędzia <code>iconv</code>:<br />
<br />
<pre>iconv --from-code=CP1250 --to-code=UTF-8 file_in > file_out
</pre>jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0tag:blogger.com,1999:blog-8113178159611726804.post-61445020948265064992012-05-01T09:01:00.000+02:002012-07-16T07:27:18.135+02:00Initial commitZdarza mi się czytać blogi, tak od czasu do czasu. A to wspominki kono... lekarzy znaczy się, a to jakieś techniczne dywagacje na tema tej czy innej technologii. Generalnie są to blogi kierowane do licznej rzeszy potencjalnych odbiorców. Ten blog zaś ma jednego podstawowego odbiorcę... Mnie :)<br />
<br />
Nie, nie popadłem w samouwielbienie itp. Bardzo często znajduję się w sytuacji "hmmm. robiłem to, ale jak to było..." albo "dlaczego sobie nie zapisałem jak te [CENZURA] kabelki połączyć". Dlatego też postanowiłem przenosić zapiski jak-ja-coś-zrobiłem, by potem móc do tego wrócić. A jeśli przy okazji komuś któryś z wpisów okaże się pomocny - jakoś to przeżyję ;)jfatherhttp://www.blogger.com/profile/01715096673983425021noreply@blogger.com0