Category Archives: Uncategorized

DS28EA00 and Arduino

Recently I found two sample Maxim DS28EA00 temperature sensors that I requested for a project I haven’t finished. I’m currently working on a project requiring somewhat accurate temperature measuring and I will finally be able to use this sensor.

Firstly I needed a way to connect this sensor to Arduino and I made simple breakout board that allows to connect MSOP8 package sensor to breadboard. I wanted to expose three pins: ground, IO and Vcc. Unfortunately I didn’t remember that SMD parts aren’t through holes and therefore they need to be mirrored. Because of this mistake (that I noticed after etching) 3rd outer pin is connected to NC pin on chip and not on the Vcc. Thankfully, 1-wire protocols allows for parasite mode which means that voltage can be sourced from data line, so my breakout board is still useful.

Hardware

To connect this sensor to Arduino you need to:

  • connect sensor GND to Arduino GND,
  • connect sensor IO to one of the digital pins (pin 10 in my case),
  • connect 4.7k ohm resistor from IO line at Arduino to 5V.

In my case it works fine with 2.7k ohm resistor, but 4.7k is recommended. This pull-up resistor allows the use of parasite mode by providing 5V to IO pins of devices.

 

Software

I haven’t found any examples of connecting this sensor to Arduino, so I had to read datasheet and understand what I need to send and what I get back from the sensor. After I finished my code, I found out that the communication is the same as for DS18*20 sensors which is very popular and you can find many examples. I actually started with example for that sensor and removed sensor specific code.

Anyway, here is the code:

#include <OneWire.h>
OneWire ds(10);

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
     Serial.print("No more addresses.\n");
     delay(1000000);
     ds.reset_search();
      return;
  }

  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] == 0x42) {
      Serial.print("DS28EA00 detected\n");
  }else{
    return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); //convert temperature, parasite mode

  delay(1000); //wait at least 750ms for the conversion to finish

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE); //read scratchpad

  Serial.print("P=");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();

  byte lsb = data[0];
  byte msb = data[1];
  int16_t temp = (((int16_t)msb) << 8 ) | lsb;
  Serial.println((float)temp * 0.0625, DEC);//0.0625 for 12bit
}

One thing missing with examples for DS18*20 sensors was the explanation of the code. I really like to understand what I’m using and I like to discover how things works.

ds.search searches for OneWire devices on that Arduino pin and continues with the code if it finds one.

if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

crc8(byte array, count) calculates CRC code of first 7 bytes and compares it to precalculated CRC code in 8th item of array. If it matches, it means that we received right data, otherwise there is obviously problem with data transfer.

 if ( addr[0] == 0x42) {
      Serial.print("DS28EA00 detected\n");
  }else{
    return;
  }

This checks if first byte matches 0×42, because address of DS28EA00 family of temperature sensors starts with this byte. Otherwise we just return and the loop starts again.

ds.reset();
 ds.select(addr);
 ds.write(0x44,1); //convert temperature, parasite mode

 delay(1000); //wait at least 750ms for the conversion to finish

According to datasheet we need to send reset, select our device and then send the code for starting the conversion (in this case it’s 0×44). Second parameter in write call is used to tell OneWire library that we use it in parasite mode and that the IC needs to source 5V from IO pin.

Datasheet specifies that the conversion will took at most 750ms. We don’t want to push the limits and we will survive to wait additional 250ms.

present = ds.reset();
 ds.select(addr);
 ds.write(0xBE); //read scratchpad


Again, we reset OneWire, select the device and write code for reading the scratchpad (0xBE).

for ( i = 0; i < 9; i++) {
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }

We read first 9 bytes from the device and print it to serial port.

First and second bytes are temperature, third and fourth are for high and low temperature alarm, fifth is for setting precision, and others are reserved.

Ninth byte is CRC of first 8 bytes and we match it to see if there were any transmission errors.

byte lsb = data[0];
 byte msb = data[1];

We save LSB in MSB bytes so sepeperate variables.

int16_t temp = (((int16_t)msb) << 8 ) | lsb;

Temperature is 16-bit number divided to least and most significat byte.

Serial.println((float)temp * 0.0625, DEC);//0.0625 for 12bit

We need to multimly calculated 16-bit integer with 0.0625 (in case of 12bit resolution) and convert it to float. Then we print it to serial port.

Output on serial port:

R=42 F0 25 5 0 0 0 64 DS28EA00 detected
P=1 5D 1 3 3 7F FF 3 10 63 CRC=63
21.8125000000

How to display certain page content only to users who have liked our page on Facebook?

Sometimes it would be convenient if we could display portion of our web page only to people who have liked our page on Facebook.

For example, we decide to giveaway five concert tickets to random participants. We can get more recognizable if participants have to liked our page and possible publish that on their profile page. So let’s create example web page that where people can participate after following this procedure:

1. person connects our web site with Facebook

2. person likes our Facebook page

3. person fill out form with his information to participate in giveaway

 

Firstly we need to create Facebook page for our web site and get URL like this:

https://www.facebook.com/pages/Lemnin/145152362222716

Secondly, we need Facebook application which can be created in a few minutes on Facebook. We will get application id and secret key to use Facebook API.

Our giveaway page will look like this (step 1):

After clicking on Login with Facebook button, we get a nice popup saying what information will this application be able to access:

After user successfully connects our web site (application) with his Facebook profile, we show step 2:

In this step, user has to like our Facebook page, and after that we show him step 3 – final giveaway form:

We automatically fill out name field with information we get through Facebook API. Mind you, step 3 loads via AJAX, because requests to Facebook servers can sometimes be slow and we want to load our page as quickly as possible.

 

How will we do it?

We will use Facebook’s javascript API which allows us to connect our website with user’s Facebook account and allow them to like our page. As far as i know, we don’t even need server-side scripting to check Facebook Like status, however, user’s can bypass JS-only solution and therefore we will be using client-side javascript in connection with server-side PHP.

 

1. How to connect to Facebook API with PHP?

Connecting to Facebook API is pretty simple and everything you need is to create new instance of Facebook class and pass it array with your appId and secret key.

<?php
include (“facebook.php”);
$facebook = new Facebook(array(  ‘appId’  => ’172133412841299′,
‘secret’ => ‘<secret key>’,
‘cookie’ => true,));

 

2. Is user logged in?

Facebook JS API creates session cookie when user logged in to Facebook comes to our page, so that we can get user’s information with PHP.

<?php
$session = $facebook->getSession();
$fbme = null;
if ($session) {
try {
$uid = $facebook->getUser();
$fbme = $facebook->api(‘/me’);
} catch (FacebookApiException $e) {                }
}
?>

This code gets FB’s session, checks if user allowed us access to his information and fills variable $fbme with his data (username, first_name, last_name, etc.)

 

3. Has user liked our Facebook page?

<?php
$created_time = $facebook->api(
array( ‘method’ => ‘fql.query’,
‘query’ => ‘SELECT created_time FROM page_fan WHERE uid= ‘.intval($uid).’ AND page_id = 145152362222716′ )
);
?>

This uses FQL to check if user liked our page and returns date and time of when that happend. If user hasn’t liked our page, $created_time is empty.

 

With a bit of javascript magic and PHP we can create web page, that checks if user liked our page and if he is logged in.

Here is the download link: download

Weather map

Weather map for Slovenia and Europe.

  • - written in PHP
  • - uses Google Maps API
  • - weather data gathered from website of Environmental Agency of the Republic of Slovenia
  • - supports caching of data in xml files

Download:

weather.zip

R/C Lawnmower

Hack a Day has great articles about hacks from all over the world. This time I want to write about a very interesting project about radio controlled lawnmower.

[center][img]/media/kiwi/uploads/z1-300×224.jpg[/img][/center]

I wanted to build similar lawnmower with the difference that I would use Wiimote for controlling it. But interfering Wiimote directly to an AVR or other micro controller is a bit hard, so I thought of using the laptop to connect Wiimote to a mower. I already made some plans, but then I realized about the biggest problem – danger of using something like this without my direct control over it.

After all, I’m perfectly capable of hurting myself without additional help, so building this could end badly.

Anyway I’m happy that someone actually made something like this, and I have no problems about him using it as long as it’s far away from me. :-D

More: [url=http://hackaday.com/2009/11/14/rc-lawnmower/]http://hackaday.com/2009/11/14/rc-lawnmower/[/url]

(In)Security of RFID Credit Cards

Hacker explains how easy is it to read data from RFID chips which are integrated in newer credit cards. And he talks about risks of having unencrypted data (owner\’s name, credit card number, expiration date, etc.) on these chips. He uses $10 RFID reader from eBay.
[youtube]http://www.youtube.com/v/vmajlKJlT3U[/youtube]

Wireless power

I stumbled upon an interesting article about wireless transmission of power and thought of sharing it here.

[center][img]/media/kiwi/uploads/b-300×225.jpg[/img][/center]

It’s really simple and cheap way to wirelessly transmit electricity on really short distance. It’s made of big and small coil, a couple of capacitors and LED diode.

More info: [url=http://www.instructables.com/id/Wireless-Power-Transmission-Over-Short-Distances-U/]http://www.instructables.com/id/Wireless-Power-Transmission-Over-Short-Distances-U/[/url]

Omni-car

I’m interested in omnidirectional wheels from when I watched [url=http://dsc.discovery.com/tv/prototype-this/prototype-this.html]Prototype This![/url], The Discovery Channel TV series. They used these wheels in episode Six-Legged All Terrain Vehicle.

[center][img]/media/kiwi/uploads/a-300×300.jpg[/img][/center]

I thought a few times about building a RC car with these omni wheels, but never got around to even buy needed materials. And of course there is also a lack of tutorials/articles about it on the Internet.

Well, I then forgot about it, but a few days ago I found a post about Omni-car on Hack a Day blog. [url=http://hackaday.com/2009/11/17/omni-car/]http://hackaday.com/2009/11/17/omni-car/[/url]

Really interesting project, but sadly these wheels are a bit too expensive.

Direct link: [url=http://didyoumakethat.webs.com/projects.htm]http://didyoumakethat.webs.com/projects.htm[/url]

Home Automation

Nothing here …

RFM12B Module

In the following files you can find code for AVR micro controllers to use this modules.

Source (.c) file: [url=/media/kiwi/uploads/hopeTx.c]hopeTx[/url]

Source (.c) file: [url=/media/kiwi/uploads/hopeRx.c]hopeRx[/url]

PDF file: [url=/media/kiwi/uploads/RFM12B.pdf]RFM12B[/url]

[b]RFM12B and AVR – quick start[/b]
I found this tutorial when I searched for connecting this module to AVR.
You can download the tutorial at: PDF file: [url=http://zenburn.net/%7Egoroux/rfm12b/rfm12b_and_avr-%20quick_start.pdf]zenburn.net[/url]

[b]My Experience[/b]
My attempts to get this module working were all unsuccessful.

Windows VDS

Hi all,

I know my way around Linux server configuration and PHP programming, because I have a lot of experience. However, I always wanted to try programming in ASP.Net 3.5 and deploying that application to Windows Server 2008.

And so I rent Virtual Dedicated Server (apparently that\’s another name for Virtual Private Server) with Windows Server 2008 installed for 1 month. First of all, I had to get familiar with Windows way of work (point & click). I managed to get the idea about how to configure IIS and other tools. In Linux environment, you just connect to SSH and start typing commands. In Windows environment, you connect to a server via RDP. It\’s like working at a physical computer loaded with Windows.

After I successfully configured that, I started to “write” web site in ASP.Net. It is more clicking that writing source code. I had some previous experience in Classic ASP and ASP.Net 2.0, so it wasn\’t that hard. But more that I was programming that website, more I thought what\’s the point of this thing?

Yes, you can write applications, and usually you succeed. But what\’s with that clicking? I want to write code, not click through this and other wizard. I rented a VDS, so I guess there is no way back. And with that thought I continued with my work … Until I realized that this is going nowhere. I rather use PHP and actually do the programming thing. Next thing is the cost. Linux VPS is not that expensive and Windows VPS can cost even a double the Linux VPS\’s price.

So a decision was made. Let\’s get back to PHP & Linux. And yes, I will cancel my Windows VPS.