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.

 

VIM – revisited

 VIM  Comments Off on VIM – revisited
Mar 112012
 

Made some refactoring of my VIM settings the other day.

The current plugins used are:

  • colorsamplepack
  • cscope_maps
  • highlight_current_line
  • matchit
  • NERD_tree
  • SearchComplete
  • taglist

This is the current settings file, or .vimrc as it's called.

" Joakim Wesslen
"
" The inspiration for the below setup was found at these places
" http://www.derekwyatt.org/vim/
" http://www.swaroopch.com/notes/Vim_en:Programmers_Editor
" http://spf13.com/post/perfect-vimrc-vim-config-file
" http://www.catonmat.net/blog/vim-plugins-surround-vim/
" among others...
"
set nocompatible " not compatible with original vi
let mapleader="," " set mapleader to , instead of \
nmap <silent> <leader>ev :e $MYVIMRC<CR> " edit .vimrc
nmap <silent> <leader>sv :so $MYVIMRC<CR> " source .vimrc
" Status bar --------------------------------------------------------------
set ch=2 " Make command line two lines high
set showmode " show current mode in status bar
set stl=%f\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\ [%b][0x%B] " Set the status line the way I like it
set laststatus=2 " Show statusline in single window
" Color, layout etc  ------------------------------------------------------
set background=dark " background color
colorscheme darkgreen " color scheme
syntax on " Enable syntax highlightning
set tw=120 " text width
set cc=+1 " highlight column after textwidth
set nowrap " wrap text
"set smarttab " tab/backspace are smart
"set expandtab " insert spaces as tabs
set tabstop=8 " Tab length, nbr spaces
set cindent " indent according to tabstop
set smartindent " help me with indenting
set autoindent " autoindent
set sw=2 " scrollbar width
set number " show line numbers
set autoread " watch for file changes
set undolevels=1000 " nbr undo levels
set history=1000 " command history levels
set list " Show trailing spaces and tabs
set listchars=trail:+,tab:>- " Show trailing spaces and tabs
set foldminlines=5 " Folding lines shown
set foldnestmax=3 " Folding level
" Search ------------------------------------------------------------------
set ignorecase " ignore case in pattern
set smartcase " override ignorecase
set incsearch " show pattern in text as it is written
set hlsearch " highlight all matches
set wrapscan " Set the search scan to wrap around the file
set path+=** " search directories
" Copy --------------------------------------------------------------------
set cpoptions+=$ " add a $ at end of 'copy/change'
" Buffer ------------------------------------------------------------------
set hidden " change buffer without saving
noremap <C-Left> :bfirst<cr> " Switch to first buffer
noremap <C-Down> :bnext<cr> " Switch to next buffer
noremap <C-Up> :bprevious<cr> " Switch to previous buffer
noremap <C-Right> :blast<cr> " Switch to last buffer
" Windows -----------------------------------------------------------------
noremap <silent> <C-h> :wincmd h<cr> " Move the cursor to the window left of the current one
noremap <silent> <C-j> :wincmd j<cr> " Move the cursor to the window below the current one
noremap <silent> <C-k> :wincmd k<cr> " Move the cursor to the window above the current one
noremap <silent> <C-l> :wincmd l<cr> " Move the cursor to the window right of the current one
" Specials ----------------------------------------------------------------
map <C-s> :w<CR> " 'Ctrl s' to save file in command mode.
imap <C-s> <Esc>:w<CR>i " 'Ctrl s' to save file in insert mode.
" Plugins -----------------------------------------------------------------
:filetype plugin on "
" Function keys -----------------------------------------------------------------
map <F2> :TlistToggle<cr> " Taglist, need ctags
map <F3> :NERDTreeToggle<cr> " NERDtree
"map <F4> <cr> " Buflist (buflist.vim defines F4 as toggle window
map <F5> :b#<cr> " switch buffer
" file type detection
:filetype on "
autocmd FileType make set noexpandtab set sw=4
autocmd FileType c set tw=80
autocmd FileType h set tw=80
autocmd FileType patch set tw=80