Friday, February 24

Sainsmart 1602 i2c

1602 16x2 LCD Hat

One of the interesting things about purchasing items on ebay is having a product arrive which is not exactly how the description said it was. In this case I ordered a 16 character 2 line lcd hat for a raspberry pi. What arrived is definitely "a" display hat, yet there are several differences between what arrived, and the Adafruit 1602 LCD hat I was expecting.

After a lot of effort, web searching, and trial and error. I have found out, what I received is a, or clone of, a Sainsmart 1602 i2c hat. Looking on Amazon, eBay, etc you will find many people ranting about the issues they have using this display hat. Before I spent this time to figure it out, I almost was one of those to prepare a rant.

Also known as the: Sainsmart 1602 I2C (SKU: 20-011-221)

Detecting the LCD Hat

This was as simple as installing i2c-tools. Running the command i2cdetect -y 1. If you are using an older Raspberry Pi 1 series you will probably need to change that command to i2cdetect -y 0. After which it showed the LCD hat was connected at 20h.
apt-get install i2c-tools
i2cdetect -y 1

NodeJS Setup

Since the module we are going to use requires compiling you need to make sure you have "make" and "node-gyp" installed. After installing the tools a simple npm install of Adafruit's "adafruit-i2c-lcd" will get you almost done.
apt-get install -y make node-gyp
npm install adafruit-i2c-lcd --save


/*  don't forget to 

npm install adafruit-i2c-lcd

var LCDPLATE = require('adafruit-i2c-lcd').plate
  , lcd = new LCDPLATE(1, 0x20)

lcd.sendBytes(0, 0x1F); // Backlight on - Sainsmart 1602

lcd.message('I Work!');

lcd.on('button_change', function(button) {
  lcd.message('Button changed:\n' + lcd.buttonName(button));
  if (button==1) { // select button
    lcd.sendBytes(0, 0x3F); // Backlight off - Sainsmart 1602


A big thanks goes to

2017's Pi Setup ( Raspberrry Pi not Included )

Raspberry Pi - Initial Setup
  1. create new sd card from minbian
  2. copy & smb.conf to sd card
  3. boot raspberry pi with sd card
  4. ssh into raspberry pi
  5. login
    1. username: root
    2. password: raspberry
  6. create users
    1. adduser pi
    2. adduser node
  7. make users super users
    1. usermod -G sudo pi
    2. usermod -G sudo node
  8. run setup - part 1
  9. download and run expandfs script
  10. reboot
  11. run setup - part 2

Setup - Part 1

apt-get update && apt-get upgrade && apt-get -y dist-upgrade
apt-get clean
apt-get install -y sudo parted nano

Setup - Part 2

apt-get install -y apt-utils curl sudo samba samba-common-bin

#nodejs 6.x
curl -sL | bash -
apt-get install -y nodejs node-gyp make

apt-get install -y tmux mc i2c-tools


cp /boot/smb.conf /etc/samba/conf


    workgroup = WORKGROUP
    server string = Raspberry PI file server
    netbios name = pi2b
    security = USER
    map to guest = Bad User
    syslog = 0
    log file = /var/log/samba/log.%m
    log level = 2
    max log size = 100
    dns proxy = No
    usershare allow guests = Yes
    panic action = /usr/share/samba/panic-action %d
    idmap config * : backend = tdb
    load printers = No
    disable spoolss = Yes
    wins support = yes

[PI Shares]
    comment = Share access
    path = /home/pi/shares
    read only = No
    guest ok = Yes
    create mask=0777
    directory mask=0777
    public = yes
    force user = pi

    comment = Share access
    path = /home/node
    read only = No
    guest ok = Yes
    create mask=0777
    directory mask=0777
    public = yes
    force user = node

    comment = Share access
    path = /boot
    read only = No
    guest ok = Yes
    create mask=0777
    directory mask=0777
    public = yes
    force user = root

Wednesday, February 22

Resizing root file systems - Rasperry Pi

Resizing the File System

Anybody who has used a Raspberry Pi knows the first step is always to resize the file system. Most people use raspi-config to expand the filesystem. Others like myself who start with a distro image which is not standard for the Raspberry Pi have found it is sometimes a pain to resize the file system.

My Solution

After a rather annoying day of resetting and install a raspberry pi, I was tired of the extra time required to install raspi-config, and resize the file system. So I copied the raspi-config, which is a wonderful read, and removed all but the code required to resize the file system. This I copied into another file I choose to call "expandfs". This is instead of using resize2fs, since I found it did not always work.

I have found this to work with most linux distro's for the Raspberry Pi, including Minbian.

The Script (Download link)