Home Automation – Receiver

 Arduino, DIY, Electronics, Home Automation  Comments Off on Home Automation – Receiver
Aug 112015
 

I have made a couple of attempts over the past years to make a Home Automation Receiver with an Arduino Uno and a simple 433MHz receiver.
But so far I have failed, believing the Uno maybe wasn't fast enough for the task at hand.
By chance a colleague of mine stumbled upon my blog, and wondered if I did not have any such receiver at hand, since I had made transmitters way back in time.
I told him about my endeavors and my disbelief about the performance. Luckily he did not listen too much, and did some internet searching.
Of course there are sketches out there for the receiver task. After looking at some of them I decided to try to do one myself.
One major difference in my new sketch, compared to my older attempts, is the use of pulseIn(). Before I tried to sample with digitalRead()  but could never get a consistent result.
With pulseIn() we detect only the low part of the pulses, and by comparing the length of the low part, conclude what type of bit it was.

This is what the HW setup looks like.
DSC_0952

Here is the sketch.

/*
   Joakim Wesslen
   2015-08-10

   We detect data pulses by catching the low part of every pulse.   

*/

/*
More info at:  
http://tech.jolowe.se/home-automation-rf-protocol-update/
http://tech.jolowe.se/home-automation-rf-protocols/


Physical data structure (in air):
Bit
0        10        20        30        40        50           60
1234567890123456789012345678901234567890123456789012 34 56 7890 1234
--------------------------------------------------------------------
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT GG OO DDDD NNNN

Bits #01-52 -> TxCode (T)
Bits #53-54 -> Group (G)
Bits #55-56 -> On/Off (O)
Bits #57-60 -> ? Dimming/Channel ? (D)
Bits #61-64 -> Device Nbr (N)


Logical data structure:
0        10        20           30  
12345678901234567890123456 7 8 90 12
------------------------------------
TTTTTTTTTTTTTTTTTTTTTTTTTT G O DD NN

Bits #01-26 -> TxCode (T)
Bits #27 -> Group (G)
Bits #28 -> On/Off (O)
Bits #29-30 -> ? Dimming/Channel ? (D)
Bits #31-32 -> Device Nbr (N)

*/


int rxPin = 12;

boolean debugOn = false;  // enable debug prints

int tPause = 0; // debugging
int tSync = 0; // debugging

unsigned long loopCounter = 0;  // stats
unsigned long dataCounter = 0;  // stats

// Setting limit boundaries
int pauseMinTime = 7000;
int pauseMaxTime = 14000;

int syncMinTime = 2100;
int syncMaxTime =  3200;
 
int oneMinTime = 70;
int oneMaxTime = 300;

int zeroMinTime = 1000;
int zeroMaxTime = 1900;

signed long timeout1 = 1000000;
signed long timeout2 = 100000;


#define MAX_STR 150

char bin[MAX_STR + 1];

// get a 'binary' 32 bit string from value
char *dec2binStr(unsigned long ul)
{
 int len = sizeof(ul) * 8;
  int c, d;
  int count = 0;

  memset(bin, len, '0');

  for (c = len-1 ; c >= 0 ; c-- )
  {
    d = ul >> c;

    if ( d & 1 )
       bin[count] = '1';
    else
       bin[count] = '0';
    
    count++;
  }
  bin[len] = '\n';
  return bin;
}

// log function
void ilog(const char *fmt, ...)
{
  char tmpStr[MAX_STR + 1];
  va_list ap;

  va_start(ap, fmt);
  vsnprintf(tmpStr, MAX_STR + 1, fmt, ap);
  va_end(ap);
  Serial.println(tmpStr);
}

// debug log function
void dlog(const char *fmt, ...)
{
  if (debugOn) 
  {
    char tmpStr[MAX_STR + 1];
    va_list ap;

    va_start(ap, fmt);
    vsnprintf(tmpStr, MAX_STR + 1, fmt, ap);
    va_end(ap);
    Serial.println(tmpStr);
  }
}

char binPhy[MAX_STR + 1];

// get a 'binary' 64 bit string from value
char *dec2binPhyStr(unsigned long ul)
{
 int len = sizeof(ul) * 8;
  int c, d;
  int count = 0;

  memset(binPhy, MAX_STR, '0');

  for (c = len-1 ; c >= 0 ; c-- )
  {
    d = ul >> c;

    if ( d & 1 )
    {
       binPhy[count] = '1';
       binPhy[count+1] = '0';
    }
    else
    {
       binPhy[count] = '0';
       binPhy[count+1] = '1';
    }
    
    count += 2;
  }
  binPhy[len*2] = '\n';
  return binPhy;
}

// debug statistics printout
void printStats(unsigned long loopCnt, unsigned long dataCnt)
{
  ilog("Loops: %d, Packets: %d", loopCnt, dataCnt);
}

// print decoded receiver data
void printPacketData(unsigned long data)
{
  ilog("Received: %s", dec2binStr(data));
//  ilog("ReceivedPhy: %s", dec2binPhyStr(data));
}

// receiver for home automation data
void dataReceiver(void)
{
  dlog("--- Wait for Pause and Sync ---");

start_over:  
  int i = 0;
  signed long t = 0;
  
  byte prevBit = 0;
  byte currBit = 0;
  
  // Packet data, logical structure
  unsigned long dataPacket = 0;

  loopCounter++;
  
  // Wait for Pause bit (10500 us).
  while ((t < pauseMinTime) || (t > pauseMaxTime))
  { 
    t = pulseIn(rxPin, LOW, timeout1);
  }
  tPause = t; // Save timing for debugging purposes
  if (t == 0)
  {
    dlog("!!! - Pause Timeout - Start over.");
    goto start_over;
  }

  // Wait for Sync bit (2750 us).
  while ((t < syncMinTime) || (t > syncMaxTime))
  { 
    t = pulseIn(rxPin, LOW, timeout1);
  }
  tSync = t; // Save timing for debugging purposes
  if (t == 0)
  {
    dlog("!!! - Sync Timeout - Start over.");
    goto start_over;
  }

  // data collection loop
  while (i < 64)
  {
    t = pulseIn(rxPin, LOW, timeout2);  // shorter timeout?
    if (t == 0)
    {
      dlog("!!! - Data Timeout - Start over.");
      goto start_over;
    }
    else if (t > zeroMinTime && t < zeroMaxTime)
    {
      currBit = 0;
    }
    else if (t > oneMinTime && t < oneMaxTime)
    { 
      currBit = 1;
    }
    else
    { 
      dlog("Incorrect data - Start over. t=%d", t);
      goto start_over;
    }

    if (i % 2 == 1)
    {
      if ((prevBit ^ currBit) == 0)
      { 
        // must be either 01 or 10, not allowed to be 00 or 11
        dlog("Bad data - Start over");
        goto start_over;
      }
  
      // Store packet bits
      dataPacket <<= 1;
      dataPacket |= prevBit;
     }
     prevBit = currBit;
     ++i;
   }
   if (i > 0)
   { 
     dataCounter++;
     printPacketData(dataPacket);
   }
}


void setup()
{ 
  pinMode(rxPin, INPUT);
  
  Serial.begin(9600);
  ilog("Home Automation Receiver");
}


void loop()
{
  dataReceiver();
}

Next, I shall try and make this into a library.

Arduino with Relay module

 Arduino, DIY, Electronics  Comments Off on Arduino with Relay module
Nov 022013
 

Got myself a relay module the other day, as I wanted to use an actuator, and the current supplied from the Arduino itself was not enough to make it work.

This is what I got, http://www.kjell.com/sortiment/el/elektronik/mikrokontroller/arduino/relamodul-for-arduino-p87878.

Here is how I connected the 'Songle SRD-05VDC-SL-C' relay with an actuator to an Arduino.

The pin marked:
'+'  connected to 5V from Arduino
'- ' connected to GND from Arduino
'S' connected to GPIO#2 from Arduino

In the other end connect the middle connector ('Common') to an external voltage source,
in my case 5V, as the actuator was a 5V actuator. The NO ('Normally Open') connector is strapped to one of the actuators input. The NC ('Normally Closed') connector is not used. The other actuator pin is connected to the external power sources GND completing the circuit.

When the GPIO#2 is put high, the external 5V source is fed to the actuator, making it move.
So the only thing you need in your Arduino sketch is 'digitalWrite' of the proper GPIO.
It took me some time to figure the relay out, since I watched some instruction on the internet on how to connect a relay, and all of them used some external diodes and transistors.
But that is not necessary with this one, as it is already mounted on the PCB of the relay module.

ASCII art of the setup:

---------
        |
Arduino |      -----------------
        |      |               |
        |      |     Relay     | 
   5V  --- + --|               |-- NC
        |      |     module    |
   GND --- - --|               |-- Common ---------------- 5V external src
        |      |               | 
GPIO#2 --- S --|               |-- NO -----|
        |      |               |           |       ------- GND external src
        |      |               |           |       |
        |      -----------------           |       |
---------                                  |       |
                                           |       |
                                         --------------
                                         |            |
                                       ==|  Actuator  |=====|
                                         |            |
                                         --------------

Link:
The vendor data sheet of the module, http://www.songle.com/en/pdf/20084141716341001.pdf

Arduino – Home Automation Project, part 2.

 Arduino, DIY, Home Automation  Comments Off on Arduino – Home Automation Project, part 2.
Apr 242012
 

Well, at last I have made a simple Arduino library of the previous Tx433_Proove sketch. I have pushed the complete code up on GitHub.

Here is the public class interfaces.

class Tx433_Proove
{
public:
/*
@digitalpin - the digitalpin to send data on to transmitter
@transmittercode - the unique code of the transmitter (52 bits)
@channelcode - the channel code (4 bits)
*/
Tx433_Proove(int digitalpin, char *transmittercode, char *channelcode);

/*
@unit - the device to turn on.
0,1,2 are the three separate devices.
3 is the complete group.
*/
void Device_On(int unit);

/*
@unit - the device to turn off.
0,1,2 are the three separate devices.
3 is the complete group.
*/
void Device_Off(int unit);
}

Made a new page at http://elektronikforumet.syntaxis.se/wiki/index.php/RF_Protokoll_-_Proove_self_learning to give something back to a great site.

Also added a new link at http://arduino.cc/playground/Main/LibraryList pointing at the Github upload.

Arduino – Home Automation project

 Arduino, DIY, Home Automation  Comments Off on Arduino – Home Automation project
Apr 152012
 

Something I have thought about, on and off, for a long long time is to setup some remote controlled lamps at home.
I have read about the Tellstick from Telldus, but that requires a computer for controlling it. Also I have read and heard that the RF performance/reach is somewhat restricted.
Another solution is of course to use the Arduino together with a RF transmitter.
The different devices available in the stores are all using the same RF frequency, 433.92 MHz, with ASK modulation.

As this is the true DIY solution, I got both a transmitter and a receiver for this frequency 🙂

The transmitter, http://www.kjell.com/sortiment/el/elektronik/fjarrstyrning/433-mhz-sandarmodul-p88901
Data sheet, http://www.kjell.com/.mvc/Document/File?id=6d308334-d5c5-4ef1-8060-9fb700fc0f01

 _______
|       |
|   O   |
|       |
 -------
 | | | |
 | | | |
 1 2 3 4

pin    name
1      GND
2      Data In
3      Vcc
4      ANT

The receiver, http://www.kjell.com/sortiment/el/elektronik/fjarrstyrning/433-mhz-mottagarmodul-p88900
Data sheet, http://www.kjell.com/.mvc/Document/File?id=18c020a8-2364-4ee9-a99e-9fb700fc0d73

 ____________________
|                    |
|             O []   |
|                    |
 --------------------
 | | | |      | | | |
 | | | |      | | | |
 1 2 3 4      5 6 7 8
pin    name
1      GND
2      Data Out
3      Linear out
4      Vcc
5      Vcc
6      GND
7      GND
8      ANT

I bought the receiver to be able to sniff the data from the remote controller.

Initially I was going to get some Nexa devices. Something like these, http://www.nexa.se/PB3Ny3packsjalvlarande.htm.
But when I got to the store they didn't have these. Instead they had , http://www.kjell.com/sortiment/el/el-produkter/starkstrom/fjarrstrombrytare/sjalvlarande/fjarrstrombrytare-p50207, which is of the brand Proove. They told me it was the same thing(TM), but of course it would turn out it wasn't.

The reason for me to get Nexa was my research done prior to the purchase.
http://sebastiannilsson.com/open-source/arduino/104-433-mhz-rf-nexa-saendare-och-mottagare-med-arduino
http://arduino.cc/playground/Code/HomeEasy
http://homeeasyhacking.wikia.com/wiki/Home_Easy_Hacking_Wiki
Well, well, they said it was the same in the store.

At home I fired up the Arduino IDE, and made a first attempt on controlling some lights, by just importing the HomeEasyCtrl library into a sketch as the example showed.
But of course that didn't work. It didn't even compile!
Some quick searching on the net, and I found out that old libraries, using #include "WProgram.h", needs to be updated with the following.

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#include <pins_arduino.h>
#endif

With this change it compiles, but it does nothing with my remote controlled light.

Time for some extended research. Found out that Nexa has, at least, two different protocols. The old simple protocol, and the new self learning protocol.
A very good web site describing these protocols are http://elektronikforumet.syntaxis.se/wiki/index.php/Huvudsida, at least if you understand swedish.
I took this information, translated it, at put it on a single page here, http://tech.jolowe.se/home-automation-rf-protocols/.

My next approach, after reading up on the protocol, is to use the receiver to get the data from the remote, without needing to open it up.
After some tries, I got some result which I think is the code sent for turning on device number one.

? 1010100101101001010101100101011001010101010101010110 10 01 0101 0101 ?
? = seems like the start bit and stop bit described in the protocol does not exist.

But when I try to send this myself from the Arduino setup, nothing happens. Frustrating!
I tried this approach several times for several days, with modifications, but without any success.
As I ran out of new ideas on how to proceed, I open up the remote.
This is what it looked like.

The Xtal says 'ND13.560'.
The IC says 'Holtek HT48(or 46)R01T3 ...". Web here, http://www.holtek.com/english/.
Holtek IC pinout:
(by measurement, visual inspection and looking in the datasheet)

       ______
Dout -|1   16|- SW5
SW1  -|2   15|- Sw6
SW2  -|3   14|- SW7
SW3  -|4   13|- SW8
SW4  -|5   12|- Vcc?
?    -|6   11|- ?
?    -|7   10|- ?
Vcc? -|8    9|- Vcc?
       ------
SWx, is the buttons on the remote.

Web: http://www.holtek.com/english/docum/consumer/4xr01t3.htm
Datasheet: http://www.holtek.com/pdf/consumer/4xR01T3v130.pdf
Pin #1, Dout, is the actual data sent via RF!! This is what we want!
Time to decode (by probing Dout):
Pressing button #1 On switch and capture data with oscilloscope.
A Pause is, approx. 10 ms low.
A Sync is, high 240 us, low approx. 2.5 ms.
Data sent is: 10101001011010010101011001010110010101010101010101101001010101010
Pressing button #1 Off switch.
Data sent is: 10101001011010010101011001010110010101010101010101101010010101010
Zero = high 300 us, low 1.3 ms
One = high 280 us, low 250 us

A packet consist of:
Pause
Sync
Data 64 bits
The same packet is sent four times.

The above data is THE SAME(!) as I managed to sniff out of the air with my RX433 sketch!
Still, when I send this data, the receiver does nothing.
But if I look at the data I am sending, it doesn't look as nice as the one the remote is sending.
Especially the 'ones' are kind of distorted. The low part is not as 'distinct'. Wonder what the reason could be? Faulty HW?

Continued to probe all data patterns of the remote, while I still had it opened.

#                10        20        30        40        50           60
#       1234567890123456789012345678901234567890123456789012 34 56 7890 1234
----------------------------------------------------------------------------
#1 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 0101
#1 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 0101
#2 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 0110
#2 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 0110
#3 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 1001
#3 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 1001
Gr On:  1010100101101001010101100101011001010101010101010110 01 01 0101 0101
Gr Off: 1010100101101001010101100101011001010101010101010110 01 10 0101 0101

Here is oscilloscope pictures of a data packet.

Now when I know I have the correct data from the remote, I try and change the HomeEasyCtrl lib accordingly.
But still, nothing happens when I try to send the data.
Just to rule out HW failure, I bought a second TX433 transmitter. But the result was the same. Conclusion, not a HW issue.
Start looking over my TX433 sketch again, and ... ARGHH!!!..., I found an error in my sendZero function.
Correcting that, and moving the Pause bit to after data instead of before Sync - IT WORKS!
Somehow, at least. Every fourth try fails, could it be a timing issue?
Changing the timing of the pulses, and now it works 100%!!!
The timing used now is:
Zero = 250 high, 1250 low
One = 250 high, 250 low
Sync = 250 high, 2500 low
Pause = 250 high, 10000 low.
A packet is sent as Sync + Data + Pause.

Here is my sketch for TX433 Proove,

/*
TX433 - a 433.92 MHz ASK transmitter
Joakim Wesslen
2012-04-03

This program handles the 'Proove' devices, not Nexa.

Found the 'Nexa Self learning' protocol description here (in swedish),
http://m.diigo.com/bookmark/http%3A%2F%2Fwww.elektronikforumet.com%2Fwiki%2Findex.php%3Ftitle%3DRF_Protokoll_-_Nexa_sj%25C3%25A4lvl%25C3%25A4rande?tab=comment
From which I started out.

But as it turns out, the Proove protocol is somewhat different.

Here is a brief description.

A packet is 64 bits in toatal (without dimming bits, whichI do not know if it handles).

Packet structure:
Bit nbr:    Name:
01-52       Transmitter code. 26 bits, but sent as 52 as every other bit is the inverse of the previous.
53-54       Group On(01), Off(10)
55-56       On(01), Off(10) (or Dim(11)?)
57-60       Channel. 1=1010, 2=1001, 3=0110, 4=0101
61-64       Switch.  1=1010, 2=1001, 3=0110, 4=0101
(65-73       Dimmer value, 16 steps. (optional))

Every message is started by a Sync (high pulse followed by a 2.5 ms low)
Every mesage is ended by a Pause (high pulse followed by a 10 ms low)
Every message is sent four (4) times.

*/

#define DBGpin  13

#define TXpin  4
#define RETRANSMIT  4

int tOneHigh = 250; //275;
int tOneLow = 250; //170;

int tZeroHigh = 250;
int tZeroLow = 1250;

int tSyncHigh = 250;
int tSyncLow = 2500;

int tPauseHigh = 250;
int tPauseLow = 10000;

char *dim[15] = {
"01010110",
"01011001",
"01011010",
"01100101",
"01100110",
"01101001",
"01101010",
"10010101",
"10010110",
"10011001",
"10011010",
"10100101",
"10100110",
"10101001",
"10101010"
};

char *On1   = "1010100101101001010101100101011001010101010101010110100101010101";
char *Off1  = "1010100101101001010101100101011001010101010101010110101001010101";

char *On2   = "1010100101101001010101100101011001010101010101010110100101010110";
char *Off2  = "1010100101101001010101100101011001010101010101010110101001010110";

char *On3   = "1010100101101001010101100101011001010101010101010110100101011001";
char *Off3  = "1010100101101001010101100101011001010101010101010110101001011001";

char *GrOn  = "1010100101101001010101100101011001010101010101010110010101010101";
char *GrOff = "1010100101101001010101100101011001010101010101010110011001010101";

void setup() {
pinMode(TXpin, OUTPUT);
pinMode(DBGpin, OUTPUT);
Serial.begin(9600);
//  dimtest();
}

void loop() {
test();
//  group(on);
}

void group(boolean on) {

if (on) {
Serial.println("Group on");
sendPackets(GrOn);
} else {
Serial.println("Group off");
sendPackets(GrOff);
}
}

void test() {
Serial.println("Turn on #1");
sendPackets(On1);
delay(100);
Serial.println("Turn on #2");
sendPackets(On2);
delay(100);
Serial.println("Turn on #3");
sendPackets(On3);
delay(500);
Serial.println("Turn off #1");
sendPackets(Off1);
delay(100);
Serial.println("Turn off #2");
sendPackets(Off2);
delay(100);
Serial.println("Turn off #3");
sendPackets(Off3);
delay(500);
}

void dimtest() {
for (int d = 15; d >= 0; d--) {
for (int i = 0; i < RETRANSMIT; i++) {
sendSync();
sendCode(On1, strlen(On1));
sendCode(dim[d], strlen(dim[d]));
sendPause();
Serial.println("");
}
delay(1000);
Serial.println("");
}
sendPackets(Off1);
}

void sendPackets(char *pkt) {
for (int i = 0; i < RETRANSMIT; i++) {
sendPacket(pkt);
}
Serial.println("");
}

void sendPacket(char *pkt) {
sendSync();
sendCode(pkt, strlen(pkt));
sendPause();
Serial.println("");
}

void sendCode(char *str, int len) {
char *p = str;
int i = 0;
while (i <= len) {
if (*p == '0') {
sendZero();
}
if (*p == '1') {
sendOne();
}
p++;
i++;
}
}

void sendZero() {
Serial.print("0");
digitalWrite(TXpin, HIGH);
delayMicroseconds(tZeroHigh);
digitalWrite(TXpin, LOW);
delayMicroseconds(tZeroLow);
}

void sendOne() {
Serial.print("1");
digitalWrite(TXpin, HIGH);
delayMicroseconds(tOneHigh);
digitalWrite(TXpin, LOW);
delayMicroseconds(tOneLow);
}

// Sync
void sendSync() {
Serial.print("S");
digitalWrite(TXpin, HIGH);
delayMicroseconds(tSyncHigh);
digitalWrite(TXpin, LOW);
delayMicroseconds(tSyncLow);
}

// Pause
void sendPause() {
Serial.print("P");
digitalWrite(TXpin, HIGH);
delayMicroseconds(tPauseHigh);
digitalWrite(TXpin, LOW);
delayMicroseconds(tPauseLow);
}

Something I haven't mentioned so far, but as you might have seen in the code above, is the dimming levels.
The devices I have does not seem to use the dimming levels. But when I added it, it still worked, but without dimming.
It justed continued to turn on and off. Other Proove device though, might be able to handle this. I just don't know, as I havent tried it myself.

A small side note of information is that I found out that it is ArcTech that does the HW for Proove and Nexa et al, http://www.arctech.com.tw/html/profile.htm.

A note on the antenna. As the frequency is 433.92 MHz, I used an antenna (just a piece of wire) with a length of 690 millimeters. Also tried a quarter wave antenna, length 170 millimeters, with same result as the longer one.

As I now have a working sketch for the TX433 transmitter, the next step is to make it a library, to make it easier to re-use in other projects. Something new to learn, great!

Arduino – Display project

 Arduino, DIY  Comments Off on Arduino – Display project
Mar 192012
 

Some time ago I got myself a display, which I was thinking of hooking up to my Arduino Uno.
After having read some examples and reference stuff on arduino.cc and on ladyada.net about the 16 x 2 displays with the HD44780 chip, I was thinking about getting me one of those.
Unfortunately, what I got hold of was a ATM1602B Display, which also is a 16 x 2, but a completely different pin out.
And this is where the problem with this module is, the pin out. The documentation is everything, but clear.
This is a link to its manual and the datasheet.
As can be seen in the provided documentation, they do not number their pins as it is usually done. Starting from 1 (or zero) in one end and increasing it as you move along. No, that seems too easy, doesn't it.
After some trial and error, and measurements, I can conclude that the physical marking on the board is the correct one. Pin number one, is the third pin from the right when looking at the display from the front! The first two pins are the A (anode) and K (cathode) for the backlight.

This is the pin list I used to get it to work.

Arduino         LCD  Name
2               6    Enable
3               7    Data Bit 0 (DB0)
4               8    (DB1)
5               9    (DB2)
6               10   (DB3)
7               11   (DB4)
8               12   (DB5)
9               13   (DB6)
10              14   (DB7)
11              5    Read/Write (RW)
12              4    Register Select (RS)
pot.-out        3    Vo
+5V             2    VDD
GND             1    VSS

Please note, that the pin #1 is actually the third pin from the right when you are facing the display (as stated above).
Here is a link to a page that really help me on the way, http://www.arduino.cc/en/Tutorial/LCDLibrary.
Here is what my final setup looks like.

The potentiometer is 10kohm, and connected between Vdd and Vss, with its output connected to pin 3 (Vo) on the LCD.

Using the LiquidCrystalDisplay library does work well, and is a real time saver to get started quickly.
And here are some simple code to get something up on the display.

/* LCD fun
   2012-03-19
   Joakim Wesslen
   LCD = ATM1602B
*/
#include <LiquidCrystal.h>
// 4 bit setup
LiquidCrystal lcd = LiquidCrystal(12, 11, 2, 7, 8, 9, 10);
// 8 bit setup
//LiquidCrystal lcd = LiquidCrystal(12, 11, 2, 3 ,4, 5, 6, 7, 8, 9, 10);
void setup(void){
  pinMode(13, OUTPUT);  // dbg
  lcd.begin(16, 2);  // columns, rows
  lcd.clear();
  lcd.print("Eureka");
}

void loop(void){
  digitalWrite(13, HIGH); // dbg
  delay(1000);
  lcd.scrollDisplayRight();
}

Now when I have the basics up and running, it is time to get into the more interesting stuff to utilize the full potential of the display.

Let's see what we learn in the future!

Mar 112012
 

Made some running LEDs to have something quick and fun to show my kids.
This is what it looked like. I am using the even numbered digital outputs, connected to a LED with a 220 ohm resistor to ground.

They really liked it. When I first set it up, I only used red LEDs, but they wanted me to switch to what is shown in the picture.

Here is a short video of the live action :-), FunWithLEDs

The programming was intense, not! It is a really easy thing to use Arduino with its IDE and all help and examples available.

This is what the coding ended up in.

/*
  Fun with LEDs
 */

int pin;

void setup() {                
  // initialize the digital pins as output.
  for (pin=0; pin < 13; pin++) {
    pinMode(pin, OUTPUT);     
  }
}

void loop() {
  for (pin=0; pin < 13; pin++) {
    digitalWrite(pin, HIGH);   // set the LED on
    delay(30);              // wait
    digitalWrite(pin, LOW);    // set the LED off
    delay(30);              // wait
  }    
}

That's it! I am not sure what the next project will be. Either a Display project, or a HomeAutomation project controlling some Nexa power outlet switches.

 

Arduino

 Arduino  Comments Off on Arduino
Feb 122012
 

After having read about it for a _very_ long time, I finally got around and bought an Arduino Uno the other day.
If you do not know what it is, all I can tell you is that it is an open source hardware for learning and experimenting with electronics and software in an easy way. It has a very big supporting community, and a very good website for all levels of users. Check out http://arduino.cc/en/ for more information.

To setup the Arduino IDE on my Dell laptop running Ubuntu 10.10, I followed this guide, http://www.pluggy.me.uk/arduino-ubuntu/, and it worked straight away.

The Arduino IDE comes with many examples, which are quite nice to use in order to quickly learn how to use a certain feature. Doing the standard 'Hello world' of electronics, making a LED blink, was done within minutes, thanks to the examples and guides.

Next up will be to use it with Python...