Turing Pi – Installing I2C and Turing Pi Scripts

In Video by dbtech

In this post we’re going to look at how to install I2C and the Turing Pi scripts to make remote management of your Turing Pi cluster even easier.

If you want to get your own Turing PI, check out this link (affiliate link) and get 10% off your order!!

I2C is a serial protocol to connect low-speed devices like microcontrollers or RPis

Before you get started, make sure your Pis are updated.

Add dtoverlay to /boot/config.txt and save

Raspberry Pi kernels and firmware use a Device Tree (DT) to describe the hardware present in the Pi.
sudo nano /boot/config.txt

dtoverlay=i2c1,pins_44_45
dtoverlay=i2c-rtc,mcp7940x

Enable I2C in raspi-config
sudo raspi-config
Select “Interfacing”
Select “I2C”
Select “Yes”

REBOOT
sudo reboot now

Check to make sure I2c is installed
dmesg | grep i2c
Should return something like: [ 5.085178] i2c /dev entries driver

ls /dev/*i2c*
Should return something like: /dev/i2c-l

ls /dev/*rtc*
Should return something like: /dev/rtc /dev/rtc0

Install I2C tools
sudo apt-get install i2c-tools

Verify installation
sudo i2cdetect -y 1

You can see three I2C devices Ethernet Switch (0x04h), I2C expander (0x57h) and RTCC (0x6Fh). Actual values may be different, but you should see 3 values in the matrix on the screen.

Install Turing Pi Scripts

More info here: https://github.com/nicholaswilde/turing-pi-scripts

Copy and paste each of these commands into your SSH prompt
cd ~
mkdir git
cd git
git clone https://github.com/nicholaswilde/turing-pi-scripts.git
cd turing-pi-scripts
chmod +x turn-on-nodes.sh
chmod +x turn-off-nodes.sh

Edit nodes.cfg
nano nodes.cfg

Verify that your nodes.cfg file looks like this:
# Node #1 (Master)
#0x02
# Node #2 (Worker 1)
0x04
# Node #3 (Worker 2)
0x08
# Node #4 (Worker 3)
0x10
# Node #5 (Worker 4)
0x80
# Node #6 (Worker 5)
0x40
# Node #7 (Worker 6)
0x20

Notice that node 1 is listed, but is commented it out. That is to keep the scripts from turning off ALL of the nodes and making it difficult to get back into your cluster.

Copy node files

You can also copy the scripts to the bin folder to easily run them from anywhere

sudo cp turn-on-nodes.sh /usr/bin/turn-on-nodes
sudo cp turn-off-nodes.sh /usr/bin/turn-off-nodes

Copy the config file to the home folder
cd ~
sudo mkdir .config
cd /git/turing-pi-scripts
sudo cp nodes.cfg ~/.config/

Edit turn-on-nodes.service file with the installation location of the turn-on-nodes.sh script.

sudo nano turn-on-nodes.service

You should see a line in the files that starts with ExecStart. You can put a # in front of it and paste this below it:
ExecStart=/bin/bash /home/pirate/git/turing-pi-scripts/turn-on-nodes.sh

Copy the nodes file
sudo cp turn-on-nodes.service /etc/systemd/system/turn-on-nodes.service

Change the permission of the file
sudo chmod 664 /etc/systemd/system/turn-on-nodes.service

Enable it at start
sudo systemctl enable /etc/systemd/system/turn-on-nodes.service

Turn on all worker nodes
sudo ./turn-on-nodes.sh
or
sudo turn-on-nodes

Turn off all worker nodes
sudo ./turn-off-nodes.sh
or
sudo turn-off-nodes

Turn ALL Nodes On and Off
sudo turn-on-nodes
sudo turn-off-nodes
Source: https://github.com/nicholaswilde/turing-pi-scripts

Turn Individual Nodes Off
Node 1: sudo i2cset -m 0x02 -y 1 0x57 0xf2 0x00
Node 2: sudo i2cset -m 0x04 -y 1 0x57 0xf2 0x00
Node 3: sudo i2cset -m 0x08 -y 1 0x57 0xf2 0x00
Node 4: sudo i2cset -m 0x10 -y 1 0x57 0xf2 0x00
Node 5: sudo i2cset -m 0x80 -y 1 0x57 0xf2 0x00
Node 6: sudo i2cset -m 0x40 -y 1 0x57 0xf2 0x00
Node 7: sudo i2cset -m 0x20 -y 1 0x57 0xf2 0x00

Note: It’s probably NOT a good idea to turn off ALL of the nodes.

Turn Individual Nodes On
Node 1: sudo i2cset -m 0x02 -y 1 0x57 0xf2 0xff
Node 2: sudo i2cset -m 0x04 -y 1 0x57 0xf2 0xff
Node 3: sudo i2cset -m 0x08 -y 1 0x57 0xf2 0xff
Node 4: sudo i2cset -m 0x10 -y 1 0x57 0xf2 0xff
Node 5: sudo i2cset -m 0x80 -y 1 0x57 0xf2 0xff
Node 6: sudo i2cset -m 0x40 -y 1 0x57 0xf2 0xff
Node 7: sudo i2cset -m 0x20 -y 1 0x57 0xf2 0xff